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

@@ -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);
}