correction param
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
package TP2;
|
package TP2;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.antlr.runtime.ANTLRFileStream;
|
import org.antlr.runtime.ANTLRFileStream;
|
||||||
import org.antlr.runtime.ANTLRInputStream;
|
import org.antlr.runtime.ANTLRInputStream;
|
||||||
@@ -64,6 +67,7 @@ public class Main {
|
|||||||
|
|
||||||
// Generate the intermediate representation
|
// Generate the intermediate representation
|
||||||
//System.out.println("\n\n");
|
//System.out.println("\n\n");
|
||||||
|
//PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
|
||||||
|
|
||||||
ProgramLLVMImp astLLVM = ast.toLLVM();
|
ProgramLLVMImp astLLVM = ast.toLLVM();
|
||||||
//System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n");
|
//System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n");
|
||||||
|
|||||||
@@ -145,8 +145,10 @@ public class SymTable {
|
|||||||
public Result addVar(String nomVar, TypeLLVM type) {
|
public Result addVar(String nomVar, TypeLLVM type) {
|
||||||
PMap<String, ValueVarMap> top = varMap.get(0);
|
PMap<String, ValueVarMap> top = varMap.get(0);
|
||||||
if (top.containsKey(nomVar)) {
|
if (top.containsKey(nomVar)) {
|
||||||
System.err.println("[VSL compile error] : '" + nomVar+ "' Erreur");
|
if(!top.get(nomVar).isParam){ //si non on écrase, on a plus besoin du param après
|
||||||
return new Result(this, null);
|
System.err.println("[VSL compile error] : '" + nomVar+ "' Erreur");
|
||||||
|
return new Result(this, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String realName = nomVar + "_" + id[0];
|
String realName = nomVar + "_" + id[0];
|
||||||
top = top.plus(nomVar, new ValueVarMap(type, id[0], false));
|
top = top.plus(nomVar, new ValueVarMap(type, id[0], false));
|
||||||
|
|||||||
@@ -65,13 +65,22 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
|||||||
public DefineLLVMImp visitFunction(FunctionImp fun, SymTable h) {
|
public DefineLLVMImp visitFunction(FunctionImp fun, SymTable h) {
|
||||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||||
ArrayList<VarLLVMImp> paramsLLVM = new ArrayList<>();
|
ArrayList<VarLLVMImp> paramsLLVM = new ArrayList<>();
|
||||||
|
ArrayList<InstructionLLVM> setParam = new ArrayList<>();
|
||||||
for(VarImp param: fun.params()){
|
for(VarImp param: fun.params()){
|
||||||
|
TypeLLVM type = new IntLLVMImp();
|
||||||
Result r = h.addParam(param.name());
|
Result r = h.addParam(param.name());
|
||||||
String name = r.var;
|
String nameParam = r.var;
|
||||||
VarLLVMImp var = new VarLLVMImp(new IntLLVMImp(), name,false);
|
|
||||||
h = r.symTable;
|
h = r.symTable;
|
||||||
|
Result r2 = h.addVar(param.name(),type);
|
||||||
|
String nameVar = r2.var;
|
||||||
|
h = r2.symTable;
|
||||||
|
VarLLVMImp var = new VarLLVMImp(type, nameParam,false);
|
||||||
paramsLLVM.add(var);
|
paramsLLVM.add(var);
|
||||||
|
VarLLVMImp newVar =new VarLLVMImp(type, nameVar,false);
|
||||||
|
setParam.add(new AssignLLVMImp(newVar,new allocaLLVMImp(type)));
|
||||||
|
setParam.add(new StoreLLVMImp(type,var,type,newVar));
|
||||||
}
|
}
|
||||||
|
instrLLVM.addAll(setParam);
|
||||||
instrLLVM.addAll(fun.instruction().accept(this, h));
|
instrLLVM.addAll(fun.instruction().accept(this, h));
|
||||||
TypeLLVM type = fun.type().accept(this, h);
|
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(!(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)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user