Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/tp2-vsl-pds
This commit is contained in:
@@ -61,10 +61,16 @@ public class SymTable {
|
||||
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;
|
||||
}
|
||||
|
||||
//retourne le type de la var
|
||||
public Type getType(String nomVar){
|
||||
return this.stackMap.getLast().get(nomVar).type;
|
||||
}
|
||||
|
||||
public PStack<PMap<String,ValueTable>> next_layer(){
|
||||
return stackMap.plus(HashTreePMap.empty());
|
||||
}
|
||||
@@ -109,10 +115,10 @@ public class SymTable {
|
||||
return this.stackmap();
|
||||
}
|
||||
|
||||
public ValueTable getvar_Type(String s){
|
||||
public Type getvar_Type(String s){
|
||||
for(int i= stackMap.size()-1; i>=0; i--){
|
||||
if(stackMap.get(i).containsKey(s)){
|
||||
return stackMap.get(i).get(s);
|
||||
return stackMap.get(i).get(s).type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
public DefineLLVM visitFunction(FunctionImp fun, SymTable h) {
|
||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||
instrLLVM.addAll(fun.instruction().accept(this, h));
|
||||
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), instrLLVM);
|
||||
return new DefineLLVMImpl(fun.nom(), fun.type().accept(this, h), new ArrayList<>(), instrLLVM);
|
||||
}
|
||||
|
||||
//DECLARATION
|
||||
@@ -130,14 +130,22 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitPrint(PrintImp instr, SymTable h) {
|
||||
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||
l.add(new PrintLLVMImpl(new ArrayList())); //TODO
|
||||
ArrayList<ValLLVM> params = new ArrayList<>();
|
||||
l.add(new PrintLLVMImpl(params)); //TODO
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitRead(ReadImp instr, SymTable h) {
|
||||
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||
l.add(new ReadLLVMImpl(new ArrayList())); //TODO
|
||||
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());
|
||||
VarLLVMImpl newVar = new VarLLVMImpl(typeVar.accept(this,h), nomVar);
|
||||
ArrayList<ValLLVM> params = new ArrayList<>();
|
||||
params.add(newVar);
|
||||
l.add(new ReadLLVMImpl(params));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -213,7 +221,6 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
ValLLVM val = temp.val; //temp6
|
||||
ExpressionLLVM exTemp = new IcmpLLVMImp(val,new ValLLVMImpl(new IntLLVMImpl(), 0));
|
||||
Result temp2 = h.addNewTempVar();
|
||||
h = temp2.symTable;
|
||||
VarLLVMImpl varCond = new VarLLVMImpl(exTemp.getType(), temp2.var);
|
||||
l.add(new AssignLVMImpl(varCond,exTemp));
|
||||
l.add(new BrCondLLVMImp(varCond,labelDo,labelDone));
|
||||
@@ -238,8 +245,12 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
|
||||
@Override
|
||||
public InstrAndVal visitVar(VarImp e, SymTable h) {
|
||||
ValLLVM val = new VarLLVMImpl(new IntLLVMImpl(), e.name());
|
||||
return new InstrAndVal(new ArrayList<>(), val);
|
||||
ArrayList<AssignLVMImpl> l =new ArrayList<>();
|
||||
ValLLVM val = new VarLLVMImpl(h.getvar_Type(e.name()).accept(this,h),h.getVar(e.name()));
|
||||
|
||||
VarLLVMImpl varTemp = new VarLLVMImpl(h.getvar_Type(e.name()).accept(this,h),h.addNewTempVar().var);
|
||||
l.add(new AssignLVMImpl(varTemp,((ExpressionLLVM)(new LoadLLVMImpl(val)))));
|
||||
return new InstrAndVal(l, varTemp);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user