have to cahnge alloca

This commit is contained in:
Vu Tuan Minh
2025-04-30 15:22:38 +02:00
parent 43eccbd4c9
commit c58d524dd1
4 changed files with 22 additions and 13 deletions

View File

@@ -62,12 +62,12 @@ public class Main {
// Pretty-print the program (to debug parsing)
System.out.println(ast.prettyprinter());
//System.out.println(ast.prettyprinter());
// Verify the program semantic
// Generate the intermediate representation
System.out.println("\n\n");
//System.out.println("\n\n");
PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
ProgramLLVMImp astLLVM = ast.toLLVM();
@@ -75,12 +75,8 @@ public class Main {
String llvmStr = astLLVM.prettyprinter();
out2.println(llvmStr);
/*
utiliser la commande :
java -jar build/libs/TP2.jar file.vsl > file.ll
provoque peut provoquer de mauvais encodage (UTF16(LE) au lieu d'UTF8)
et empêche l'utilisation de print pour autre chose
*/
/*
String sortieLLVM = args[0].replace(".vsl", ".ll");
Files.write(
Paths.get(sortieLLVM),
@@ -88,7 +84,7 @@ public class Main {
);
System.out.println("\n[VSL compile Succes] : " + args[0] + " -> " + sortieLLVM +"\n");
*/
} catch (IOException | RecognitionException e) {
e.printStackTrace();

View File

@@ -112,12 +112,23 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
Integer size=instr.s().get(i).size();
if(size==null){
r= h.addVar(nom,t2);
h = r.symTable;
list.add(new AssignLLVMImp(new VarLLVMImp(t2, r.var,false),new allocaLLVMImp(t2)));
}else {
TypeLLVM arrayType = new ArrayLLVMImp(t2, size);
//Alloca
Result r_size= h.addNewTempVar();
VarLLVMImp tmpVar = new VarLLVMImp(new IntLLVMImp(), r_size.var, false);
list.add(new AssignLLVMImp(tmpVar, new allocaLLVMImp(t2)));
//Alloca table
r = h.addVar(nom, arrayType);
h = r.symTable;
list.add(new AssignLLVMImp(new VarLLVMImp(t2, r.var,false),new allocaLLVMImp(new PointerLLVMImp(t2))));
//Store
}
h = r.symTable;
list.add(new AssignLLVMImp(new VarLLVMImp(t2, r.var,false),new allocaLLVMImp(t2)));
}
return new InstrAndSymTable(list,h);
}
@@ -125,7 +136,8 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
@Override
public InstrAndSymTable visitVarDecl(VarDeclImp instr, SymTable h) {
ArrayList<InstructionLLVM> list = new ArrayList<>();
//TODO
return new InstrAndSymTable(list,h);
}