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) // Pretty-print the program (to debug parsing)
System.out.println(ast.prettyprinter()); //System.out.println(ast.prettyprinter());
// Verify the program semantic // Verify the program semantic
// Generate the intermediate representation // 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); PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
ProgramLLVMImp astLLVM = ast.toLLVM(); ProgramLLVMImp astLLVM = ast.toLLVM();
@@ -75,12 +75,8 @@ public class Main {
String llvmStr = astLLVM.prettyprinter(); String llvmStr = astLLVM.prettyprinter();
out2.println(llvmStr); 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"); String sortieLLVM = args[0].replace(".vsl", ".ll");
Files.write( Files.write(
Paths.get(sortieLLVM), Paths.get(sortieLLVM),
@@ -88,7 +84,7 @@ public class Main {
); );
System.out.println("\n[VSL compile Succes] : " + args[0] + " -> " + sortieLLVM +"\n"); System.out.println("\n[VSL compile Succes] : " + args[0] + " -> " + sortieLLVM +"\n");
*/
} catch (IOException | RecognitionException e) { } catch (IOException | RecognitionException e) {
e.printStackTrace(); e.printStackTrace();

View File

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

View File

@@ -1,4 +1,5 @@
FUNC INT main(x,y) { FUNC INT main() {
INT a,b[10],c,d[11] INT a,b[10],c,d[11]
a:=1 a:=1
c:=2
} }

Binary file not shown.