modification de l'implémentation de prototype, il implement Function
This commit is contained in:
@@ -9,7 +9,7 @@ import TP2.llvm.Interface.*;
|
||||
import TP2.llvm.ProgramLLVM.*;
|
||||
|
||||
public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>,
|
||||
FunctionVisitor<SymTable,DefineLLVM>,
|
||||
FunctionVisitor<SymTable,DefineLLVMImpl>,
|
||||
DeclVisitor<SymTable,TP2.asd.toLLVM_Visitor.InstrAndSymTable>,
|
||||
InstrVisitor<SymTable,ArrayList<InstructionLLVM>>,
|
||||
ExprVisitor<SymTable,TP2.asd.toLLVM_Visitor.InstrAndVal>,
|
||||
@@ -23,10 +23,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
une simplement un val (var ou const) ou un binop
|
||||
*/
|
||||
public static class InstrAndVal{
|
||||
public ArrayList<AssignLVMImpl> instrs;
|
||||
public ArrayList<InstructionLLVM> instrs;
|
||||
public ValLLVM val;
|
||||
|
||||
public InstrAndVal(ArrayList<AssignLVMImpl> instr, ValLLVM val){
|
||||
public InstrAndVal(ArrayList<InstructionLLVM> instr, ValLLVM val){
|
||||
this.instrs = instr;
|
||||
this.val = val;
|
||||
}
|
||||
@@ -46,15 +46,20 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
public ProgramLLVMImpl visitProgram(ProgramImp prog, SymTable h) {
|
||||
ArrayList<DefineLLVM> fonctionLLVM = new ArrayList<>();
|
||||
for(int i = 0; i<prog.fonctions().size(); i++){
|
||||
fonctionLLVM.add(prog.fonctions().get(i).accept(this, h));
|
||||
DefineLLVMImpl function = prog.fonctions().get(i).accept(this, h);
|
||||
h.addFunction(function);
|
||||
if(!(prog.fonctions().get(i) instanceof PrototypeImp)){
|
||||
fonctionLLVM.add(function);
|
||||
}
|
||||
}
|
||||
return new ProgramLLVMImpl(new ArrayList<>(),fonctionLLVM);
|
||||
}
|
||||
|
||||
|
||||
//FUNCTION
|
||||
|
||||
@Override
|
||||
public DefineLLVM visitFunction(FunctionImp fun, SymTable h) {
|
||||
public DefineLLVMImpl visitFunction(FunctionImp fun, SymTable h) {
|
||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||
ArrayList<VarLLVMImpl> paramsLLVM = new ArrayList<>();
|
||||
|
||||
@@ -70,6 +75,11 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), paramsLLVM, instrLLVM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefineLLVMImpl visitPrototype(PrototypeImp fun, SymTable h) {
|
||||
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), null,null);
|
||||
}
|
||||
|
||||
//DECLARATION
|
||||
|
||||
@Override
|
||||
@@ -245,6 +255,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@Override
|
||||
@@ -255,7 +266,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
|
||||
@Override
|
||||
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
||||
ArrayList<AssignLVMImpl> l =new ArrayList<>();
|
||||
ArrayList<InstructionLLVM> 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);
|
||||
@@ -265,7 +276,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
|
||||
@Override
|
||||
public InstrAndVal visitBinOp(BinopExpressionImp e, SymTable h) {
|
||||
ArrayList<AssignLVMImpl> list = new ArrayList<>();
|
||||
ArrayList<InstructionLLVM> list = new ArrayList<>();
|
||||
|
||||
InstrAndVal res1 = e.e1().accept(this, h);
|
||||
InstrAndVal res2 = e.e2().accept(this, h);
|
||||
@@ -290,6 +301,22 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
return new InstrAndVal(list, var);
|
||||
}
|
||||
|
||||
public InstrAndVal visitAppeal(Appeal instr,SymTable h){
|
||||
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
|
||||
for(Expression param : instr.params()){
|
||||
InstrAndVal result = param.accept(this,h);
|
||||
l.add((InstructionLLVM) result.instrs);
|
||||
paramsLLVM.add(result.val);
|
||||
}
|
||||
DefineLLVMImpl fLLVM = h.getFunction(instr.fName()); //on récupère la fonction LLVM dans la table des Symboles
|
||||
if(fLLVM == null){
|
||||
System.err.println("[VSL compile error] : la fonction n'existe pas, veuillez vous assurer de l'avoir déclarée avant l'appel");
|
||||
}
|
||||
l.add(new CallLLVMImpl(fLLVM,paramsLLVM,""));
|
||||
return new InstrAndVal(l, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeLLVM visitInt(Type_intImp t, SymTable h) {
|
||||
return new IntLLVMImpl();
|
||||
|
||||
Reference in New Issue
Block a user