translator: escape store information about return on top level
This commit is contained in:
@@ -31,7 +31,6 @@ abstract class BlockCodegen(val state: TranslationState,
|
|||||||
|
|
||||||
val topLevelScopeDepth = 2
|
val topLevelScopeDepth = 2
|
||||||
var returnType: LLVMVariable? = null
|
var returnType: LLVMVariable? = null
|
||||||
var wasReturnOnTopLevel = false
|
|
||||||
|
|
||||||
fun evaluateCodeBlock(expr: PsiElement?,
|
fun evaluateCodeBlock(expr: PsiElement?,
|
||||||
startLabel: LLVMLabel? = null,
|
startLabel: LLVMLabel? = null,
|
||||||
@@ -57,7 +56,6 @@ abstract class BlockCodegen(val state: TranslationState,
|
|||||||
else -> codeBuilder.addAnyReturn(result.type, result.toString())
|
else -> codeBuilder.addAnyReturn(result.type, result.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
wasReturnOnTopLevel = true
|
|
||||||
}
|
}
|
||||||
codeBuilder.addUnconditionalJump(nextIterationLabel ?: return)
|
codeBuilder.addUnconditionalJump(nextIterationLabel ?: return)
|
||||||
}
|
}
|
||||||
@@ -1104,9 +1102,7 @@ abstract class BlockCodegen(val state: TranslationState,
|
|||||||
codeBuilder.addReturnOperator(retNativeValue)
|
codeBuilder.addReturnOperator(retNativeValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scopeDepth == topLevelScopeDepth + 2) {
|
|
||||||
wasReturnOnTopLevel = true
|
|
||||||
}
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ class FunctionCodegen(state: TranslationState,
|
|||||||
generateLoadArguments()
|
generateLoadArguments()
|
||||||
evaluateCodeBlock(function.bodyExpression, scopeDepth = topLevelScopeDepth, isBlock = function.hasBlockBody())
|
evaluateCodeBlock(function.bodyExpression, scopeDepth = topLevelScopeDepth, isBlock = function.hasBlockBody())
|
||||||
|
|
||||||
if (!wasReturnOnTopLevel)
|
if (returnType?.type is LLVMVoidType){
|
||||||
codeBuilder.addAnyReturn(returnType!!.type)
|
codeBuilder.addAnyReturn(LLVMVoidType())
|
||||||
|
}
|
||||||
codeBuilder.addEndExpression()
|
codeBuilder.addEndExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class LLVMBuilder(arm: Boolean = false) {
|
|||||||
addLLVMCodeToLocalPlace("{")
|
addLLVMCodeToLocalPlace("{")
|
||||||
|
|
||||||
fun addEndExpression() =
|
fun addEndExpression() =
|
||||||
addLLVMCodeToLocalPlace("}")
|
addLLVMCodeToLocalPlace("unreachable\n}")
|
||||||
|
|
||||||
fun addAssignment(lhs: LLVMVariable, rhs: LLVMNode) =
|
fun addAssignment(lhs: LLVMVariable, rhs: LLVMNode) =
|
||||||
addLLVMCodeToLocalPlace("$lhs = $rhs")
|
addLLVMCodeToLocalPlace("$lhs = $rhs")
|
||||||
|
|||||||
Reference in New Issue
Block a user