This commit is contained in:
trochas
2025-04-11 14:52:38 +02:00
parent 3a009f7fac
commit 35c2c23985
5 changed files with 13 additions and 9 deletions

View File

@@ -109,10 +109,10 @@ public class SymTable {
return this.stackmap();
}
public ValueTable getvar_Type(String s){
public Type getvar_Type(String s){
for(int i= stackMap.size()-1; i>=0; i--){
if(stackMap.get(i).containsKey(s)){
return stackMap.get(i).get(s);
return stackMap.get(i).get(s).type;
}
}
return null;

View File

@@ -192,8 +192,12 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
@Override
public InstrAndVal visitVar(VarImp e, SymTable h) {
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), e.name());
return new InstrAndVal(new ArrayList<>(), val);
ArrayList<AssignLVMImpl> l =new ArrayList<>();
ValLLVM val = new VarLLVMImpl(h.getvar_Type(e.name()).accept(this,h),h.getVar(e.name()));
VarLLVMImpl varTemp = new VarLLVMImpl(h.getvar_Type(e.name()).accept(this,h),h.addNewTempVar().var);
l.add(new AssignLVMImpl(varTemp,((ExpressionLLVM)(new LoadLLVMImpl(val)))));
return new InstrAndVal(l, varTemp);
}
@Override

View File

@@ -52,7 +52,7 @@ public interface Interface {
public interface ExpressionLLVMVisitor<H,S> {
public S visitBinOpLLVM(BinOpLLVMImpl e, H h);
public S visitAllocaLLVM(allocaLLVMImpl e,H h);
public S visitLoadLLVM(loadLLVMImpl e,H h);
public S visitLoadLLVM(LoadLLVMImpl e,H h);
public S visitValLLVM(ValLLVMImpl e,H h);
public S visitVarLLVM(VarLLVMImpl e,H h);
public S visitIcmpLLVM(IcmpLLVMImp e, H h);

View File

@@ -103,8 +103,8 @@ TypeLLVMVisitor<String,String>
@Override
public String visitLoadLLVM(loadLLVMImpl e, String h) {
return "load" + " i" + e.nbBits() + ", i"+ e.nbBits2() + "* %" + e.val().accept(this, h);
public String visitLoadLLVM(LoadLLVMImpl e, String h) {
return "load" + " " + e.getType().accept(this, h) + ", "+ e.getType().accept(this, h) + "* " + e.val().accept(this, h);
}

View File

@@ -153,7 +153,7 @@ public class ProgramLLVM {
}
public static record loadLLVMImpl(TypeLLVM type, int nbBits,int nbBits2, ValLLVM val) implements ExpressionLLVM{
public static record LoadLLVMImpl(ValLLVM val) implements ExpressionLLVM{
@Override
public <H, S> S accept(ExpressionLLVMVisitor<H, S> v, H h) {
return v.visitLoadLLVM(this, h);
@@ -161,7 +161,7 @@ public class ProgramLLVM {
@Override
public TypeLLVM getType() {
return type;
return val().getType();
}
}