Skip to content
Snippets Groups Projects
Verified Commit 4135d07a authored by Recolic Keghart's avatar Recolic Keghart
Browse files

While stmt done. Warning: binary compare not working

parent 432b5aa9
No related branches found
No related tags found
No related merge requests found
x:bool = True
y:int = 5
while x:
print(123)
y = y-1
print(y)
y = y-1
print(y)
x = False
print(y)
print("Done")
......@@ -358,18 +358,23 @@ public class CodeGenImpl extends CodeGenBase {
return null;
}
private String getLablePrefix(String name) {
String labelPrefix = "";
if(funcInfo != null) {
labelPrefix += "$" + funcInfo.getFuncName();
}
labelPrefix += "$" + name + _r_local_label_counter;
++_r_local_label_counter;
return labelPrefix;
}
@Override
public Void analyze(IfStmt node) {
node.condition.dispatch(this);
RiscVBackend.Register tmpReg = /*regMgr.borrowTmp()*/ T6;
betterBackend.emitPop(tmpReg, "IfStmt: Get condition");
String labelPrefix = "";
if(funcInfo != null) {
labelPrefix += "$" + funcInfo.getFuncName();
}
labelPrefix += "$if" + _r_local_label_counter;
++_r_local_label_counter;
String labelPrefix = getLablePrefix("if");
Label elseLabel = new Label( labelPrefix + ".else");
Label exitLabel = new Label( labelPrefix + ".exit");
......@@ -387,6 +392,29 @@ public class CodeGenImpl extends CodeGenBase {
return null;
}
@Override
public Void analyze(WhileStmt node) {
String labelPrefix = getLablePrefix("while");
Label beginLabel = new Label(labelPrefix + ".begin");
Label exitLabel = new Label(labelPrefix + ".exit");
backend.emitLocalLabel(beginLabel, "WhileStmt: Begin");
node.condition.dispatch(this);
RiscVBackend.Register tmpReg = /*borrowOneTmp*/ T6;
betterBackend.emitPop(tmpReg, "GetCondition");
backend.emitBEQ(ZERO, tmpReg, exitLabel, "WhileSTmt, IfFalse, exit");
for(Stmt stmt : node.body) {
stmt.dispatch(this);
}
backend.emitJ(beginLabel, "WhileStmt: GOTO begin");
backend.emitLocalLabel(exitLabel, "WhileStmt: End");
return null;
}
@Override
public Void analyze(CallExpr callExpr) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment