Correction SymTable, param, et Type en TypeLLVM
This commit is contained in:
@@ -7,6 +7,8 @@ import TP2.asd.Program.Type_intImp;
|
||||
import TP2.llvm.Interface.TypeLLVM;
|
||||
import TP2.llvm.ProgramLLVM.DeclarGlobalLLVMImp;
|
||||
import TP2.llvm.ProgramLLVM.DefineLLVMImp;
|
||||
import TP2.llvm.ProgramLLVM.IntLLVMImp;
|
||||
import TP2.llvm.ProgramLLVM.PointerLLVMImp;
|
||||
|
||||
|
||||
public class SymTable {
|
||||
@@ -44,10 +46,10 @@ public class SymTable {
|
||||
}
|
||||
|
||||
public static class ValueVarMap{
|
||||
public Type type;
|
||||
public TypeLLVM type;
|
||||
public int id;
|
||||
public Boolean isParam;
|
||||
public ValueVarMap(Type type,int id, Boolean isParam){
|
||||
public ValueVarMap(TypeLLVM type,int id, Boolean isParam){
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.isParam = isParam;
|
||||
@@ -121,13 +123,13 @@ public class SymTable {
|
||||
|
||||
public Result addNewTempVar(){
|
||||
String newVar = "temp"+id[0];
|
||||
SymTable newSymTab = this.addVarInTab(newVar,new Type_intImp(),false);
|
||||
SymTable newSymTab = this.addVarInTab(newVar,new IntLLVMImp(),false);
|
||||
return new Result(newSymTab,newVar);
|
||||
}
|
||||
|
||||
public Result addParam(String nomParam){
|
||||
String newParam = "param_"+nomParam;
|
||||
SymTable newSymTab = this.addVarInTab(nomParam,new Type_intImp(),true);
|
||||
SymTable newSymTab = this.addVarInTab(nomParam,new IntLLVMImp(),true);
|
||||
return new Result(newSymTab,newParam);
|
||||
}
|
||||
|
||||
@@ -140,14 +142,14 @@ public class SymTable {
|
||||
this.declarationsGlobal.add(decl);
|
||||
}
|
||||
|
||||
public Result addVar(String nomVar) {
|
||||
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);
|
||||
}
|
||||
String realName = nomVar + id[0];
|
||||
top = top.plus(nomVar, new ValueVarMap(new Type_intImp(), id[0], false));
|
||||
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);
|
||||
return new Result(newSym, realName);
|
||||
@@ -159,10 +161,12 @@ public class SymTable {
|
||||
if (scope.containsKey(nomVar)) {
|
||||
ValueVarMap value = scope.get(nomVar);
|
||||
String prefix = "";
|
||||
String id = ""+value.id;
|
||||
if(value.isParam){
|
||||
prefix = "param_";
|
||||
id ="";
|
||||
}
|
||||
return prefix + nomVar + value.id;
|
||||
return prefix + nomVar + id;
|
||||
}
|
||||
}
|
||||
System.err.println("[VSL compile error] : '" + nomVar + "' n'a pas été déclaré");
|
||||
@@ -179,7 +183,7 @@ public class SymTable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Type getvar_Type(String s){
|
||||
public TypeLLVM getvar_Type(String s){
|
||||
for (PMap<String,ValueVarMap> scope : varMap) {
|
||||
if (scope.containsKey(s)) {
|
||||
return scope.get(s).type;
|
||||
@@ -189,7 +193,7 @@ public class SymTable {
|
||||
}
|
||||
|
||||
//retourne le type de la var
|
||||
public Type getType(String nomVar){
|
||||
public TypeLLVM getType(String nomVar){
|
||||
for (PMap<String,ValueVarMap> scope : varMap) {
|
||||
if (scope.containsKey(nomVar)) {
|
||||
return scope.get(nomVar).type;
|
||||
@@ -200,7 +204,7 @@ public class SymTable {
|
||||
|
||||
|
||||
|
||||
public SymTable addVarInTab(String nomVar, Interface.Type type, boolean isParam) {
|
||||
public SymTable addVarInTab(String nomVar, TypeLLVM type, boolean isParam) {
|
||||
PMap<String,ValueVarMap> top = varMap.get(0);
|
||||
if (top.containsKey(nomVar)) {
|
||||
System.err.println(nomVar+ " déjà déclaré.");
|
||||
|
||||
@@ -97,8 +97,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
ArrayList<InstructionLLVM> list = new ArrayList<>();
|
||||
for(int i = 0; i<instr.s().size();i++){
|
||||
TypeLLVM t2 = instr.t().accept(this,h);
|
||||
//String name = instr.s().get(i);//h.addVarLLVM(instr.s().get(i));
|
||||
Result r = h.addVar(instr.s().get(i));
|
||||
Result r = h.addVar(instr.s().get(i),t2);
|
||||
String name = r.var;
|
||||
h = r.symTable;
|
||||
list.add(new AssignLLVMImp(new VarLLVMImp(t2, name,false),new allocaLLVMImp(t2)));
|
||||
@@ -229,11 +228,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
int size = 1; //le \00 est focément à la fin et compte comme un seul char
|
||||
for(int i = 0; i<instr.t().size(); i++){
|
||||
String nomVar = h.getVar(instr.t().get(i).name());
|
||||
Type typeVar = h.getType(instr.t().get(i).name());
|
||||
TypeLLVM typeVar = h.getType(instr.t().get(i).name());
|
||||
|
||||
//Ajout * par passant PointerType
|
||||
TypeLLVM baseType = typeVar.accept(this, h);
|
||||
TypeLLVM ptrType = new PointerLLVMImp(baseType);
|
||||
TypeLLVM ptrType = new PointerLLVMImp(typeVar);
|
||||
|
||||
VarLLVMImp newVar = new VarLLVMImp(ptrType, nomVar,false);
|
||||
strGlobal+="%d"; //2 char de long
|
||||
@@ -378,10 +376,10 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImp>,
|
||||
@Override
|
||||
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
||||
ArrayList<InstructionLLVM> l =new ArrayList<>();
|
||||
ValLLVM val = new VarLLVMImp(h.getvar_Type(e.name()).accept(this,h),h.getVar(e.name()),false);
|
||||
ValLLVM val = new VarLLVMImp(h.getvar_Type(e.name()),h.getVar(e.name()),false);
|
||||
Result r = h.addNewTempVar();
|
||||
h = r.symTable;
|
||||
VarLLVMImp varTemp = new VarLLVMImp(h.getvar_Type(e.name()).accept(this,h),r.var,false);
|
||||
VarLLVMImp varTemp = new VarLLVMImp(h.getvar_Type(e.name()),r.var,false);
|
||||
l.add(new AssignLLVMImp(varTemp,((ExpressionLLVM)(new LoadLLVMImp(val)))));
|
||||
return new InstrAndVal(l, varTemp);
|
||||
}
|
||||
|
||||
@@ -132,13 +132,13 @@ TypeLLVMVisitor<String,String>
|
||||
|
||||
@Override
|
||||
public String visitStoreLLVM(StoreLLVMImp instr, String h) {
|
||||
return INDENT+"store " + instr.valType().accept(this, "") + " " + instr.e().accept(this, "") + ", " + instr.varType().accept(this, "") + "* " + instr.var().accept(this,"");
|
||||
return INDENT+"store " + instr.valType().accept(this, "") + " " + instr.e().accept(this, "") + ", " + new PointerLLVMImp(instr.varType()).accept(this, "") + " " + instr.var().accept(this,"");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String visitLoadLLVM(LoadLLVMImp e, String h) {
|
||||
return "load" + " " + e.getType().accept(this, h) + ", "+ e.getType().accept(this, h) + "* " + e.val().accept(this, h);
|
||||
return "load" + " " + e.getType().accept(this, h) + ", "+ new PointerLLVMImp(e.getType()).accept(this, h) + " " + e.val().accept(this, h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user