clean todo Load
This commit is contained in:
@@ -11,8 +11,6 @@ import TP2.llvm.Interface.*;
|
||||
|
||||
public class Program{
|
||||
|
||||
static String INDENT = " ";
|
||||
|
||||
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
|
||||
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||
return v.visitProgram(this, h);
|
||||
@@ -106,77 +104,4 @@ public class Program{
|
||||
return v.visitInt(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Eval
|
||||
public static class ProgramEval implements ProgramVisitor<SymTable, Integer> {
|
||||
@Override
|
||||
public Integer visitProgram(ProgramImp e, SymTable h) {
|
||||
Integer result = null;
|
||||
SymTable symtable = new SymTable();
|
||||
FunctionEval functionEval = new FunctionEval();
|
||||
for (Function function : e.fonctions()) {
|
||||
result = function.accept(functionEval, h);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class FunctionEval implements FunctionVisitor<SymTable, Integer> {
|
||||
|
||||
@Override
|
||||
public Integer visitFunction(FunctionImp e, SymTable h) {
|
||||
h.next_layer();
|
||||
InstructionEval instructionEval = new InstructionEval();
|
||||
Integer result = null;
|
||||
for (Instruction instr : e.instructions()) {
|
||||
result = instr.accept(instructionEval, h);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class InstructionEval implements InstrVisitor<SymTable,Integer>{
|
||||
|
||||
@Override
|
||||
public Integer visitReturn(Return_instrImp e, SymTable h) {
|
||||
return e.accept(this, h);
|
||||
}
|
||||
@Override
|
||||
public Integer visitAssign(AssignImp e, SymTable h) {
|
||||
return e.accept(this, h);
|
||||
}
|
||||
@Override
|
||||
public Integer visitDeclaration(DeclarationImp e, SymTable h) {
|
||||
return e.accept(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ExprEval implements ExprVisitor<SymTable,Integer>{
|
||||
public Integer visitConst(ConstImp c, SymTable h){
|
||||
return c.c();
|
||||
}
|
||||
|
||||
public Integer visitBinOp(BinopExpressionImp e, SymTable h) {
|
||||
switch(e.op()) {
|
||||
case Op.PLUS: return e.e1().accept(this, h)+e.e2().accept(this, h);
|
||||
case Op.MINUS: return e.e1().accept(this, h)-e.e2().accept(this, h);
|
||||
case Op.TIMES: return e.e1().accept(this, h)*e.e2().accept(this, h);
|
||||
case Op.DIV: return e.e1().accept(this, h)/e.e2().accept(this, h);
|
||||
case Op.MOD: return e.e1().accept(this, h)%e.e2().accept(this, h);
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer visitVar(VarImp v, SymTable h) {
|
||||
if (h.searchVar(v.name())) {
|
||||
return 0;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
result.addAll(res.instr);
|
||||
}
|
||||
//InstructionLLVM r = new AssignLVMImp(new VarLLVMImpl(var.getType(),instr.t()),var);
|
||||
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,var.getType(),new VarLLVMImpl(var.getType(),instr.t()));
|
||||
InstructionLLVM r = new StoreLLVMImp(var.getType(),var,var.getType(),new VarLLVMImpl(var.getType(),instr.t()/*"h.getVar(instr.t())*/));
|
||||
result.add(r);
|
||||
return result;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
ArrayList<InstructionLLVM> list = new ArrayList<>();
|
||||
for(int i = 0; i<instr.s().size();i++){
|
||||
TypeLLVM t2 = instr.t().accept(this,h);
|
||||
String name = instr.s().get(i);
|
||||
String name = instr.s().get(i);//h.addVarLLVM(instr.s().get(i));
|
||||
list.add(new AssignLVMImp(new VarLLVMImpl(t2, name),new allocaLLVMImpl(t2)));
|
||||
}
|
||||
return list;
|
||||
|
||||
Reference in New Issue
Block a user