Commit f95b6bb1 authored by Christoph Reichenbach's avatar Christoph Reichenbach Committed by Noric Couderc
Browse files

Suppress unneeded return null

parent c67ada27
...@@ -168,7 +168,19 @@ aspect IRGen { ...@@ -168,7 +168,19 @@ aspect IRGen {
return BB; return BB;
} }
// same effect as startBB() except for hasBB()
public void endBB() {
BB = null;
}
public boolean hasBB() {
return BB != null;
}
public IRCodeBB getCurrentBB() { public IRCodeBB getCurrentBB() {
if (BB == null) {
startBB();
}
return BB; return BB;
} }
...@@ -324,7 +336,7 @@ aspect IRGen { ...@@ -324,7 +336,7 @@ aspect IRGen {
getBody().genCode(fctx); getBody().genCode(fctx);
if (fctx.getCurrentBB().getIRCodeExit() == null) { if (fctx.hasBB() && fctx.getCurrentBB().getIRCodeExit() == null) {
// no exit here // no exit here
fctx.addInsn(new IRConstantInsn().setDst(new IRVarRef(fctx.getReturnVar())) fctx.addInsn(new IRConstantInsn().setDst(new IRVarRef(fctx.getReturnVar()))
.setSrc(new IRNull())); .setSrc(new IRNull()));
...@@ -454,9 +466,9 @@ aspect IRGen { ...@@ -454,9 +466,9 @@ aspect IRGen {
ctx.addInsn(new IRCopyInsn(new IRVarRef(ctx.getReturnVar()), retVal)); ctx.addInsn(new IRCopyInsn(new IRVarRef(ctx.getReturnVar()), retVal));
IRCodeBB currentBB = ctx.getCurrentBB(); IRCodeBB currentBB = ctx.getCurrentBB();
currentBB.setIRCodeExit(new IRReturn(new IRVarRef(ctx.getReturnVar()))); currentBB.setIRCodeExit(new IRReturn(new IRVarRef(ctx.getReturnVar())));
// start a new basic block to hold the translation // ctx will auto-start a new basic block to hold the translation
// of any (unreachable) statements following the return. // of any (unreachable) statements following the return if needed.
ctx.startBB(); ctx.endBB();
} }
syn IRVar VarDecl.genIR() = new IRVar(getIdDecl().genIR(), variableType().genIRTypeRef()); syn IRVar VarDecl.genIR() = new IRVar(getIdDecl().genIR(), variableType().genIRTypeRef());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment