backend: improve Nothing type handling

This commit is contained in:
Svyatoslav Scherbina
2016-12-19 16:33:17 +07:00
committed by SvyatoslavScherbina
parent 44f2036506
commit 61c28db886
2 changed files with 11 additions and 7 deletions
@@ -272,16 +272,16 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
fun evaluateBreak(destination: IrBreak): LLVMValueRef? {
fun evaluateBreak(destination: IrBreak): LLVMValueRef {
currentCodeContext.genBreak(destination)
return null
return codegen.kNothingFakeValue
}
//-------------------------------------------------------------------------//
fun evaluateContinue(destination: IrContinue): LLVMValueRef? {
fun evaluateContinue(destination: IrContinue): LLVMValueRef {
currentCodeContext.genContinue(destination)
return null
return codegen.kNothingFakeValue
}
//-------------------------------------------------------------------------//
@@ -860,10 +860,10 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateThrow(tmpVariableName: String, expression: IrThrow): LLVMValueRef? {
private fun evaluateThrow(tmpVariableName: String, expression: IrThrow): LLVMValueRef {
val exception = evaluateExpression(codegen.newVar(), expression.value)!!
currentCodeContext.genThrow(exception)
return null
return codegen.kNothingFakeValue
}
//-------------------------------------------------------------------------//
@@ -1516,7 +1516,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
}
currentCodeContext.genReturn(expression.returnTarget, ret)
return null
return codegen.kNothingFakeValue
}
//-------------------------------------------------------------------------//
@@ -128,6 +128,10 @@ internal val kImmInt64One = Int64(1).llvm
internal val ContextUtils.kNullObjHeaderPtr: LLVMValueRef
get() = LLVMConstNull(this.kObjHeaderPtr)!!
// Nothing type has no values, but we do generate unreachable code and thus need some fake value:
internal val ContextUtils.kNothingFakeValue: LLVMValueRef
get() = LLVMGetUndef(kObjHeaderPtr)!!
internal fun pointerType(pointeeType: LLVMTypeRef) = LLVMPointerType(pointeeType, 0)!!
internal fun structType(vararg types: LLVMTypeRef): LLVMTypeRef = structType(types.toList())