params toLLVM

This commit is contained in:
trochas
2025-04-25 16:42:36 +02:00
parent 4b6942160e
commit 29ab19fd7a
4 changed files with 29 additions and 27 deletions

View File

@@ -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()));