translator: escape store information about return on top level

This commit is contained in:
Alexey Stepanov
2016-09-02 12:57:35 +03:00
parent ddceb70326
commit d9cbced38e
3 changed files with 5 additions and 9 deletions
@@ -31,7 +31,6 @@ abstract class BlockCodegen(val state: TranslationState,
val topLevelScopeDepth = 2
var returnType: LLVMVariable? = null
var wasReturnOnTopLevel = false
fun evaluateCodeBlock(expr: PsiElement?,
startLabel: LLVMLabel? = null,
@@ -57,7 +56,6 @@ abstract class BlockCodegen(val state: TranslationState,
else -> codeBuilder.addAnyReturn(result.type, result.toString())
}
wasReturnOnTopLevel = true
}
codeBuilder.addUnconditionalJump(nextIterationLabel ?: return)
}
@@ -1104,9 +1102,7 @@ abstract class BlockCodegen(val state: TranslationState,
codeBuilder.addReturnOperator(retNativeValue)
}
}
if (scopeDepth == topLevelScopeDepth + 2) {
wasReturnOnTopLevel = true
}
return null
}
@@ -80,9 +80,9 @@ class FunctionCodegen(state: TranslationState,
generateLoadArguments()
evaluateCodeBlock(function.bodyExpression, scopeDepth = topLevelScopeDepth, isBlock = function.hasBlockBody())
if (!wasReturnOnTopLevel)
codeBuilder.addAnyReturn(returnType!!.type)
if (returnType?.type is LLVMVoidType){
codeBuilder.addAnyReturn(LLVMVoidType())
}
codeBuilder.addEndExpression()
}
@@ -44,7 +44,7 @@ class LLVMBuilder(arm: Boolean = false) {
addLLVMCodeToLocalPlace("{")
fun addEndExpression() =
addLLVMCodeToLocalPlace("}")
addLLVMCodeToLocalPlace("unreachable\n}")
fun addAssignment(lhs: LLVMVariable, rhs: LLVMNode) =
addLLVMCodeToLocalPlace("$lhs = $rhs")