This commit is contained in:
Vu Tuan Minh
2025-04-11 13:58:57 +02:00
7 changed files with 83 additions and 31 deletions

View File

@@ -174,14 +174,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;