correction bug id des var temp dans le while
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());
|
||||
}
|
||||
|
||||
@@ -137,7 +137,12 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
@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);
|
||||
l.add(new ReadLLVMImpl(newVar));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -213,7 +218,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));
|
||||
|
||||
@@ -32,9 +32,6 @@ public interface Interface {
|
||||
public S visitStoreLLVM(StoreLLVMImpl instr, H h);
|
||||
public S visitPrintLLVM(PrintLLVMImpl instr, H h);
|
||||
public S visitReadLLVM(ReadLLVMImpl instr, H h);
|
||||
public S visitIfThenElseLLVM(IfThenElseLLVMImp instr, H h);
|
||||
public S visitIfThenLLVM(IfThenLLVMImp instr, H h);
|
||||
public S visitWhileLLVM(WhileLLVMImp instr, H h);
|
||||
public S visitLabelLLVM(LabelLLVMImp instr, H h);
|
||||
public S visitBrLLVM(BrLLVMImp instr, H h);
|
||||
public S visitBrCondLLVM(BrCondLLVMImp instr, H h);
|
||||
|
||||
@@ -115,7 +115,7 @@ TypeLLVMVisitor<String,String>
|
||||
|
||||
@Override
|
||||
public String visitReadLLVM(ReadLLVMImpl instr, String h) {
|
||||
return INDENT+"call " + "...TODO..." +" scanf " + "...TODO...";
|
||||
return INDENT+"call " + instr.var().type().accept(this,h) + "(" + "i8*, ..." + ")" + " scanf(i8* " + "...TODO..." + ")";
|
||||
}
|
||||
|
||||
//label
|
||||
@@ -134,24 +134,6 @@ TypeLLVMVisitor<String,String>
|
||||
return INDENT+"br " + instr.var().type().accept(this, h) +" "+ instr.var().accept(this, h) + ", label %" + instr.label() + ", label %" + instr.labelElse() ;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String visitIfThenElseLLVM(IfThenElseLLVMImp instr, String h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitIfThenElseLLVM'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitIfThenLLVM(IfThenLLVMImp instr, String h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitIfThenLLVM'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitWhileLLVM(WhileLLVMImp instr, String h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitWhileLLVM'");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record ReadLLVMImpl(ArrayList<VarLLVMImpl> l) implements InstructionLLVM{
|
||||
public static record ReadLLVMImpl(VarLLVMImpl var) implements InstructionLLVM{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
@@ -89,30 +89,6 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record IfThenLLVMImp(ExpressionLLVM cond, InstructionLLVM instr) implements InstructionLLVM{
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitIfThenLLVM(this, h);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static record IfThenElseLLVMImp(ExpressionLLVM cond, InstructionLLVM intr1, InstructionLLVM instr2) implements InstructionLLVM{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitIfThenElseLLVM(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record WhileLLVMImp(ExpressionLLVM cond, InstructionLLVM instr) implements InstructionLLVM{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitWhileLLVM(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
//Expression :
|
||||
public static record BinOpLLVMImpl(TypeLLVM type,Op op, ValLLVM val1,ValLLVM val2) implements ExpressionLLVM{
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user