While toLLVM fait

This commit is contained in:
Rochas
2025-04-10 21:23:32 +02:00
parent 99b6cbc08a
commit 3a009f7fac
7 changed files with 86 additions and 29 deletions

View File

@@ -131,10 +131,10 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
@Override
public String visitWhile(WhileImp instr, String indent) {
String str = indent+"WHILE ";
str += (instr.e().accept(this, ""));
str+= " DO ";
str+= instr.i1().accept(this, "");
str+= " DONE";
str += (instr.e().accept(this, indent))+"\n";
str+= indent+"DO ";
str+= instr.i1().accept(this, indent)+"\n";
str+= indent+"DONE";
return str;
}

View File

@@ -44,7 +44,7 @@ public class SymTable {
public int getNewIdLabel(){
int a = this.idLabel;
this.id++;
this.idLabel++;
return a;
}
@@ -62,7 +62,6 @@ public class SymTable {
}
public String getVar(String nomVar){
System.out.println("getVar(" + nomVar +") -------------------------------------------");
return nomVar + this.stackMap.getLast().get(nomVar).id;
}

View File

@@ -162,14 +162,21 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
String labelDone = "done"+h.getNewIdLabel();
l.add(new LabelLLVMImp(labelWhile));
InstrAndVal temp = instr.e().accept(this,h); //retourne les instruction pour optenir le résultat ainsi que la variable contenant le résultat final
l.addAll(temp.instrs);
InstrAndVal temp = instr.e().accept(this,h); //retourne les instructionz pour obtenir le résultat de l'expression ainsi que la variable contenant le résultat final
l.addAll(temp.instrs); //instructions
ValLLVM val = temp.val; //temp6
//TODO : icmp et br
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));
l.add(new LabelLLVMImp(labelDo));
l.addAll(instr.i1().accept(this,h));
//TODO br vers label while
l.add(new BrLLVMImp(labelWhile));
l.add(new LabelLLVMImp(labelDone));
return l;