[K/N] Small refactoring (review fixes)
This commit is contained in:
+2
-2
@@ -469,7 +469,7 @@ private class ExportedElement(val kind: ElementKind,
|
||||
}
|
||||
builder.append(" } catch (...) {")
|
||||
builder.append(" SetCurrentFrame(reinterpret_cast<KObjHeader**>(frame));\n")
|
||||
builder.append(" HandleCurrentExceptionForCInterop();\n")
|
||||
builder.append(" HandleCurrentExceptionWhenLeavingKotlinCode();\n")
|
||||
builder.append(" } \n")
|
||||
|
||||
builder.append("}\n")
|
||||
@@ -936,7 +936,7 @@ internal class CAdapterGenerator(val context: Context) : DeclarationDescriptorVi
|
||||
|void Kotlin_initRuntimeIfNeeded();
|
||||
|void Kotlin_mm_switchThreadStateRunnable() RUNTIME_NOTHROW;
|
||||
|void Kotlin_mm_switchThreadStateNative() RUNTIME_NOTHROW;
|
||||
|void HandleCurrentExceptionForCInterop();
|
||||
|void HandleCurrentExceptionWhenLeavingKotlinCode();
|
||||
|
|
||||
|KObjHeader* CreateStringFromCString(const char*, KObjHeader**);
|
||||
|char* CreateCStringFromString(const KObjHeader*);
|
||||
|
||||
+6
-5
@@ -475,10 +475,12 @@ internal abstract class FunctionGenerationContext(
|
||||
private val entryBb = basicBlockInFunction("entry", startLocation)
|
||||
protected val cleanupLandingpad = basicBlockInFunction("cleanup_landingpad", endLocation)
|
||||
|
||||
protected open val needLeaveFrameInUnwindEpilogue: Boolean
|
||||
// Functions that can be exported and called not only from Kotlin code should have `LeaveFrame`
|
||||
// because there is no guarantee of catching Kotlin exception in Kotlin code.
|
||||
protected open val needLeaveFrame: Boolean
|
||||
get() = irFunction?.annotations?.hasAnnotation(RuntimeNames.exportForCppRuntime) == true
|
||||
|| forwardingForeignExceptionsTerminatedWith != null
|
||||
|| irFunction?.origin == CBridgeOrigin.C_TO_KOTLIN_BRIDGE
|
||||
|
||||
private var setCurrentFrameIsCalled: Boolean = false
|
||||
|
||||
val stackLocalsManager = StackLocalsManagerImpl(this, stackLocalsInitBb)
|
||||
@@ -1051,7 +1053,6 @@ internal abstract class FunctionGenerationContext(
|
||||
}
|
||||
|
||||
fun generateFrameCheck() {
|
||||
assert(slotsPhi != null)
|
||||
call(context.llvm.checkCurrentFrameFunction, listOf(slotsPhi!!))
|
||||
}
|
||||
|
||||
@@ -1426,7 +1427,7 @@ internal abstract class FunctionGenerationContext(
|
||||
}
|
||||
|
||||
internal fun epilogue() {
|
||||
val needLeaveFrameInUnwindEpilogue = this.needLeaveFrameInUnwindEpilogue
|
||||
val needLeaveFrameInUnwindEpilogue = this.needLeaveFrame
|
||||
|
||||
appendingTo(prologueBb) {
|
||||
val slots = if (needSlotsPhi || needLeaveFrameInUnwindEpilogue)
|
||||
@@ -1715,7 +1716,7 @@ internal abstract class FunctionGenerationContext(
|
||||
}
|
||||
|
||||
private fun releaseVars() {
|
||||
if (needLeaveFrameInUnwindEpilogue || needSlots) {
|
||||
if (needLeaveFrame || needSlots) {
|
||||
check(!forbidRuntime) { "Attempt to leave a frame where runtime usage is forbidden" }
|
||||
call(context.llvm.leaveFrameFunction,
|
||||
listOf(slotsPhi!!, Int32(vars.skipSlots).llvm, Int32(slotCount).llvm))
|
||||
|
||||
+3
-1
@@ -53,7 +53,9 @@ internal class ObjCExportFunctionGenerationContext(
|
||||
) : FunctionGenerationContext(builder) {
|
||||
private val objCExportCodegen = builder.objCExportCodegen
|
||||
|
||||
override val needLeaveFrameInUnwindEpilogue: Boolean
|
||||
// All generated bridges by ObjCExport should have `LeaveFrame`
|
||||
// because there is no guarantee of catching Kotlin exception in Kotlin code.
|
||||
override val needLeaveFrame: Boolean
|
||||
get() = true
|
||||
|
||||
// Note: we could generate single "epilogue" and make all [ret]s just branch to it (like [DefaultFunctionGenerationContext]),
|
||||
|
||||
Reference in New Issue
Block a user