params toLLVM
This commit is contained in:
@@ -10,9 +10,11 @@ public class SymTable {
|
||||
public static class ValueTable{
|
||||
public Type type;
|
||||
public int id;
|
||||
public ValueTable(Type type,int id){
|
||||
public Boolean isParam;
|
||||
public ValueTable(Type type,int id, Boolean isParam){
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.isParam = isParam;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,19 +53,30 @@ public class SymTable {
|
||||
public Result addNewTempVar(/*Type type*/){
|
||||
//TODO
|
||||
String newVar = "temp"+id;
|
||||
SymTable newSymTab = this.addVar(newVar,new Type_intImp()); //TODO
|
||||
SymTable newSymTab = this.addVar(newVar,new Type_intImp(),false); //TODO
|
||||
return new Result(newSymTab,newVar);
|
||||
}
|
||||
|
||||
public Result addParam(String nomParam){
|
||||
String newParam = "param_"+nomParam+id;
|
||||
SymTable newSymTab = this.addVar(nomParam,new Type_intImp(),true);
|
||||
return new Result(newSymTab,newParam);
|
||||
}
|
||||
|
||||
public Result addVar(String nomVar){
|
||||
String newVar = nomVar+id;
|
||||
SymTable newSymTab = this.addVar(nomVar,new Type_intImp()); //TODO
|
||||
SymTable newSymTab = this.addVar(nomVar,new Type_intImp(),false); //TODO
|
||||
return new Result(newSymTab,newVar);
|
||||
}
|
||||
|
||||
//retourne le nom de la var déjà déclaré avec son id
|
||||
public String getVar(String nomVar){
|
||||
return nomVar + this.stackMap.getLast().get(nomVar).id;
|
||||
String prefix = "";
|
||||
ValueTable value = this.stackMap.getLast().get(nomVar);
|
||||
if(value.isParam){
|
||||
prefix = "param_";
|
||||
}
|
||||
return prefix + nomVar + value.id;
|
||||
}
|
||||
|
||||
//retourne le type de la var
|
||||
@@ -82,7 +95,7 @@ public class SymTable {
|
||||
return stackMap.getLast();
|
||||
}
|
||||
|
||||
public SymTable addVar(String s, Type t){
|
||||
public SymTable addVar(String s, Type t,Boolean isParam){
|
||||
PStack<PMap<String,ValueTable>> newpstack = null;
|
||||
if(this.stackMap.isEmpty()){
|
||||
newpstack = this.next_layer();
|
||||
@@ -91,7 +104,7 @@ public class SymTable {
|
||||
|
||||
//Save temporary if not PMap wont save
|
||||
PMap<String, ValueTable> pmap = this.peppapeek();
|
||||
pmap= pmap.plus(s/*+"_"+this.id*/,new ValueTable(t, getNewId()));
|
||||
pmap= pmap.plus(s/*+"_"+this.id*/,new ValueTable(t, getNewId(),isParam));
|
||||
//this.id++;
|
||||
//Delete old ones
|
||||
newpstack = newpstack.minus(newpstack.indexOf(newpstack.getLast()));
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package TP2.asd;
|
||||
import TP2.asd.Interface.*;
|
||||
import TP2.asd.Program.Type_intImp;
|
||||
import TP2.asd.SymTable.*;
|
||||
public class test_symtable{
|
||||
private static final Type Type_intImp = null;
|
||||
|
||||
public static void main(String[] args){
|
||||
SymTable test_symTable = new SymTable();
|
||||
test_symTable.next_layer();
|
||||
//test_symTable.peppapeek();
|
||||
test_symTable.addVar("a", Type_intImp);
|
||||
System.out.print(test_symTable.print_all());
|
||||
String a =" addsqdqsdqs";
|
||||
a.substring(1, a.length()-1);
|
||||
}
|
||||
}
|
||||
@@ -56,13 +56,18 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
@Override
|
||||
public DefineLLVM visitFunction(FunctionImp fun, SymTable h) {
|
||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||
ArrayList<ValLLVM> paramsLLVM = new ArrayList<>();
|
||||
ArrayList<VarLLVMImpl> paramsLLVM = new ArrayList<>();
|
||||
|
||||
for(VarImp param: fun.params()){
|
||||
paramsLLVM.add(param.accept(this, h).val);
|
||||
Result r = h.addParam(param.name());
|
||||
String name = r.var;
|
||||
VarLLVMImpl var = new VarLLVMImpl(new IntLLVMImpl(), name);
|
||||
h = r.symTable;
|
||||
paramsLLVM.add(var);
|
||||
}
|
||||
|
||||
instrLLVM.addAll(fun.instruction().accept(this, h));
|
||||
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), new ArrayList<>(), instrLLVM);
|
||||
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), paramsLLVM, instrLLVM);
|
||||
}
|
||||
|
||||
//DECLARATION
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
PROTO INT add(x,y)
|
||||
FUNC INT main(x,y) {
|
||||
INT a,b,c
|
||||
INT a,b,c,minh
|
||||
minh := x * y
|
||||
b:=3
|
||||
c:=1
|
||||
PRINT "coucou, tu peux réparer le visitPrint dans LLVM stp","il manque virgule au milieu", c*5+b
|
||||
|
||||
Reference in New Issue
Block a user