return 0 à la fin, suppression du typeFunction dans la symTable, Appeal renomé en Call

This commit is contained in:
Rochas
2025-04-29 23:25:07 +02:00
parent 7e9b49b08a
commit d238ac0887
9 changed files with 67 additions and 108 deletions

View File

@@ -49,8 +49,8 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
for(int i = 0; i<prog.fonctions().size(); i++){
DefineLLVMImp function = prog.fonctions().get(i).accept(this, h);
Boolean isProto = (prog.fonctions().get(i) instanceof PrototypeImp);
TypeLLVM type = prog.fonctions().get(i); //TODO
h = h.addFunction(function,isProto,type);
TypeLLVM type = function.type();
h = h.addFunction(function,isProto);
if(!isProto){ //les prototypes n'existent pas dans LLVM
fonctionLLVM.add(function);
}
@@ -73,7 +73,13 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
paramsLLVM.add(var);
}
instrLLVM.addAll(fun.instruction().accept(this, h));
DefineLLVMImp define = new DefineLLVMImp(fun.nom(), fun.type().accept(this, h), paramsLLVM, instrLLVM);
TypeLLVM type = fun.type().accept(this, h);
if(!(type instanceof VoidLLVMImp)){ //on ajoute un return 0 si la fonction n'est pas un void, et ne finit ni par un return ni pas un goto (sans condition)
if(!(instrLLVM.getLast() instanceof ReturnLLVMImp || instrLLVM.getLast() instanceof BrLLVMImp)){
instrLLVM.add(new ReturnLLVMImp(type, new ValLLVMImp(type,0)));
}
}
DefineLLVMImp define = new DefineLLVMImp(fun.nom(), type, paramsLLVM, instrLLVM);
return define;
}
@@ -273,9 +279,6 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
h=h.outBlock();
l.add(new LabelLLVMImp(labelFin));
if (h.getFuncType() instanceof IntLLVMImp) {
l.add(new ReturnLLVMImp(new IntLLVMImp(), new ValLLVMImp(new IntLLVMImp(), 0)));
}
return l;
}
@@ -388,7 +391,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
return new InstrAndVal(list, var);
}
public InstrAndVal visitAppeal(AppealImp instr,SymTable h){
public InstrAndVal visitCall(CallImp instr,SymTable h){
ArrayList<InstructionLLVM> l = new ArrayList<>();
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
for(Expression param : instr.params()){
@@ -397,10 +400,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
paramsLLVM.add(result.val);
}
ValueFunMap 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");
return new InstrAndVal(l, null);
}
//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");
// return new InstrAndVal(l, null);
//}
//Pour c=func(x,y)
Result res = h.addNewTempVar();