correction toLLVM

This commit is contained in:
trochas
2025-04-08 11:56:06 +02:00
parent b0aa0d98ff
commit 92c52eaadc
2 changed files with 15 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import TP2.asd.Interface.*;
import TP2.llvm.ProgramLLVM.*;
public class Program{
//Prog
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {

View File

@@ -11,7 +11,7 @@ import TP2.llvm.ProgramLLVM.*;
public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>,
FunctionVisitor<SymTable,DefineLLVM>,
InstrVisitor<SymTable,ArrayList<InstructionLLVM>>,
ExprVisitor<SymTable,TP2.asd.toLLVM_Visitor.InstrOrVal>,
ExprVisitor<SymTable,TP2.asd.toLLVM_Visitor.InstrAndVal>,
TypeVisitor<SymTable,TypeLLVM>
{
@@ -21,13 +21,13 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
toLLVM ne renvoit pas la même chose si l'expression est
une simplement un val (var ou const) ou un binop
*/
public static class InstrOrVal{
public static class InstrAndVal{
public ArrayList<AssignLVMImp> instr = null;
public ValLLVM val = null;
public InstrOrVal(ArrayList<AssignLVMImp> instr, ValLLVM val){
public InstrAndVal(ArrayList<AssignLVMImp> instr, ValLLVM val){
this.instr = instr;
this.val = instr.getLast().var();
this.val = val;
}
}
@@ -57,7 +57,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
@Override
public ArrayList<InstructionLLVM> visitReturn(Return_instrImp instr, SymTable h) {
InstrOrVal res = instr.e().accept(this,h);
InstrAndVal res = instr.e().accept(this,h);
ValLLVM var = res.val;
InstructionLLVM r = new ReturnLLVMImp(var.getType(),var);
@@ -70,7 +70,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
@Override
public ArrayList<InstructionLLVM> visitAssign(AssignImp instr, SymTable h) {
InstrOrVal res = instr.e().accept(this,h);
InstrAndVal res = instr.e().accept(this,h);
ValLLVM var = res.val;
ArrayList<InstructionLLVM> result = new ArrayList<>();
result.addAll(res.instr);
@@ -98,23 +98,23 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
}
@Override
public InstrOrVal visitConst(ConstImp e, SymTable h) {
public InstrAndVal visitConst(ConstImp e, SymTable h) {
ValLLVM val = new ValLLVMImpl(new IntLLVMImpl(),e.c());
return new InstrOrVal(new ArrayList<>(), val);
return new InstrAndVal(new ArrayList<>(), val);
}
@Override
public InstrOrVal visitVar(VarImp e, SymTable h) {
public InstrAndVal visitVar(VarImp e, SymTable h) {
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), e.name());
return new InstrOrVal(new ArrayList<>(), val);
return new InstrAndVal(new ArrayList<>(), val);
}
@Override
public InstrOrVal visitBinOp(BinopExpressionImp e, SymTable h) {
public InstrAndVal visitBinOp(BinopExpressionImp e, SymTable h) {
ArrayList<AssignLVMImp> list = new ArrayList<>();
InstrOrVal res1 = e.e1().accept(this, h);
InstrOrVal res2 = e.e2().accept(this, h);
InstrAndVal res1 = e.e1().accept(this, h);
InstrAndVal res2 = e.e2().accept(this, h);
ValLLVM val1 = res1.val;
ValLLVM val2 = res2.val;
@@ -131,7 +131,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
VarLLVMImpl var = new VarLLVMImpl(type,temp);
list.add(new AssignLVMImp(var, new BinOpLLVMImp(type,e.op(),val1,val2)));
return new InstrOrVal(list, var);
return new InstrAndVal(list, var);
}
@Override