Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/tp2-vsl-pds
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package TP2;
|
||||
|
||||
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.ANTLRInputStream;
|
||||
@@ -26,6 +29,8 @@ java -jar build/libs/TP2.jar tests/aLaMain.vsl
|
||||
frament 1 :
|
||||
java -jar build/libs/TP2.jar tests/fragment1/print4.vsl
|
||||
|
||||
java -jar build/libs/TP2.jar tests/fragment1/while2.vsl > tests/fragment1/while2.ll
|
||||
clang tests/fragment1/while2.ll -o tests/fragment1/while2
|
||||
|
||||
*/
|
||||
|
||||
@@ -62,6 +67,7 @@ public class Main {
|
||||
|
||||
// Generate the intermediate representation
|
||||
//System.out.println("\n\n");
|
||||
//PrintWriter out2 = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
|
||||
|
||||
ProgramLLVMImp astLLVM = ast.toLLVM();
|
||||
//System.out.println("\n\n PRETTYPRINTER LLVM : \n--------------\n");
|
||||
|
||||
@@ -145,10 +145,12 @@ public class SymTable {
|
||||
public Result addVar(String nomVar, TypeLLVM type) {
|
||||
PMap<String, ValueVarMap> top = varMap.get(0);
|
||||
if (top.containsKey(nomVar)) {
|
||||
System.err.println("[VSL compile error] : '" + nomVar+ "' Erreur");
|
||||
return new Result(this, null);
|
||||
if(!top.get(nomVar).isParam){ //si non on écrase, on a plus besoin du param après
|
||||
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));
|
||||
id[0]++;
|
||||
SymTable newSym = new SymTable(varMap.minus(0).plus(0, top), functionsMap, id,this.declarationsGlobal);
|
||||
@@ -161,7 +163,7 @@ public class SymTable {
|
||||
if (scope.containsKey(nomVar)) {
|
||||
ValueVarMap value = scope.get(nomVar);
|
||||
String prefix = "";
|
||||
String id = ""+value.id;
|
||||
String id = "_"+value.id;
|
||||
if(value.isParam){
|
||||
prefix = "param_";
|
||||
id ="";
|
||||
|
||||
@@ -65,13 +65,22 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
public DefineLLVMImp visitFunction(FunctionImp fun, SymTable h) {
|
||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||
ArrayList<VarLLVMImp> paramsLLVM = new ArrayList<>();
|
||||
ArrayList<InstructionLLVM> setParam = new ArrayList<>();
|
||||
for(VarImp param: fun.params()){
|
||||
TypeLLVM type = new IntLLVMImp();
|
||||
Result r = h.addParam(param.name());
|
||||
String name = r.var;
|
||||
VarLLVMImp var = new VarLLVMImp(new IntLLVMImp(), name,false);
|
||||
String nameParam = r.var;
|
||||
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);
|
||||
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));
|
||||
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)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user