diff options
Diffstat (limited to 'src/ast/nodes/WhileStmtNode.java')
-rw-r--r-- | src/ast/nodes/WhileStmtNode.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/ast/nodes/WhileStmtNode.java b/src/ast/nodes/WhileStmtNode.java index 43bf5ff..64b0b71 100644 --- a/src/ast/nodes/WhileStmtNode.java +++ b/src/ast/nodes/WhileStmtNode.java @@ -4,6 +4,7 @@ import ast.types.*; import java.util.ArrayList; import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; +import codegen.Label; /** * Node for the `while_stmt` statement of the grammar. @@ -33,12 +34,21 @@ public class WhileStmtNode implements Node { return new VoidType(); } - /** - * NOTE: It is not a part for this project. - */ @Override public String codeGeneration() { - return ""; + String startLabel = Label.newBasic("start"); + String endLabel = Label.newBasic("end"); + + String exprS = expr.codeGeneration(); + String blockS = block.codeGeneration(); + + return startLabel + ":\n" + + exprS + + "storei T1 0\n" + + "beq A0 T1 " + endLabel + "\n" + + blockS + + "b " + startLabel + "\n" + + endLabel + ":\n"; } @Override |