Refine LLVM bitcode imports detection
Don't link native libraries if external function requires only library-stored bitcode
This commit is contained in:
committed by
SvyatoslavScherbina
parent
f8393819fc
commit
06f8864b69
+6
-3
@@ -27,7 +27,8 @@ class GlobalVariableStub(global: GlobalDecl, stubGenerator: StubGenerator) : Kot
|
||||
stubGenerator.simpleBridgeGenerator.kotlinToNative(
|
||||
nativeBacked = this,
|
||||
returnType = BridgedType.NATIVE_PTR,
|
||||
kotlinValues = emptyList()
|
||||
kotlinValues = emptyList(),
|
||||
independent = false
|
||||
) {
|
||||
"&${global.name}"
|
||||
}
|
||||
@@ -58,7 +59,8 @@ class GlobalVariableStub(global: GlobalDecl, stubGenerator: StubGenerator) : Kot
|
||||
getter = mirror.info.argFromBridged(stubGenerator.simpleBridgeGenerator.kotlinToNative(
|
||||
nativeBacked = this,
|
||||
returnType = mirror.info.bridgedType,
|
||||
kotlinValues = emptyList()
|
||||
kotlinValues = emptyList(),
|
||||
independent = false
|
||||
) {
|
||||
mirror.info.cToBridged(expr = global.name)
|
||||
}, kotlinScope, nativeBacked = this)
|
||||
@@ -71,7 +73,8 @@ class GlobalVariableStub(global: GlobalDecl, stubGenerator: StubGenerator) : Kot
|
||||
stubGenerator.simpleBridgeGenerator.kotlinToNative(
|
||||
nativeBacked = setterStub,
|
||||
returnType = BridgedType.VOID,
|
||||
kotlinValues = listOf(bridgedValue)
|
||||
kotlinValues = listOf(bridgedValue),
|
||||
independent = false
|
||||
) { nativeValues ->
|
||||
out("${global.name} = ${mirror.info.cFromBridged(
|
||||
nativeValues.single(),
|
||||
|
||||
+2
@@ -157,6 +157,8 @@ data class KotlinFunctionType(
|
||||
internal val cnamesStructsPackageName = "cnames.structs"
|
||||
|
||||
object KotlinTypes {
|
||||
val independent = Classifier.topLevel("kotlin.native.internal", "Independent")
|
||||
|
||||
val boolean by BuiltInType
|
||||
val byte by BuiltInType
|
||||
val short by BuiltInType
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ interface MappingBridgeGenerator {
|
||||
nativeBacked: NativeBacked,
|
||||
returnType: Type,
|
||||
kotlinValues: List<TypedKotlinValue>,
|
||||
independent: Boolean,
|
||||
block: NativeCodeBuilder.(nativeValues: List<NativeExpression>) -> NativeExpression
|
||||
): KotlinExpression
|
||||
|
||||
|
||||
+2
-1
@@ -35,6 +35,7 @@ class MappingBridgeGeneratorImpl(
|
||||
nativeBacked: NativeBacked,
|
||||
returnType: Type,
|
||||
kotlinValues: List<TypedKotlinValue>,
|
||||
independent: Boolean,
|
||||
block: NativeCodeBuilder.(nativeValues: List<NativeExpression>) -> NativeExpression
|
||||
): KotlinExpression {
|
||||
val bridgeArguments = mutableListOf<BridgeTypedKotlinValue>()
|
||||
@@ -70,7 +71,7 @@ class MappingBridgeGeneratorImpl(
|
||||
}
|
||||
|
||||
val callExpr = simpleBridgeGenerator.kotlinToNative(
|
||||
nativeBacked, bridgeReturnType, bridgeArguments
|
||||
nativeBacked, bridgeReturnType, bridgeArguments, independent
|
||||
) { bridgeNativeValues ->
|
||||
|
||||
val nativeValues = mutableListOf<String>()
|
||||
|
||||
+2
-1
@@ -307,7 +307,8 @@ sealed class TypeInfo {
|
||||
type.returnType,
|
||||
type.parameterTypes.mapIndexed { index, it ->
|
||||
TypedKotlinValue(it, "p$index")
|
||||
} + TypedKotlinValue(PointerType(VoidType), "interpretCPointer<COpaque>($kniBlockPtr)")
|
||||
} + TypedKotlinValue(PointerType(VoidType), "interpretCPointer<COpaque>($kniBlockPtr)"),
|
||||
independent = true
|
||||
|
||||
) { nativeValues ->
|
||||
val type = type
|
||||
|
||||
+5
-1
@@ -226,7 +226,11 @@ class ObjCMethodStub(private val stubGenerator: StubGenerator,
|
||||
bodyGenerator,
|
||||
this@ObjCMethodStub,
|
||||
returnType,
|
||||
nativeBridgeArguments
|
||||
nativeBridgeArguments,
|
||||
independent = when (container) {
|
||||
is ObjCClassOrProtocol -> true // Every proper instance has this method in its method table.
|
||||
is ObjCCategory -> false // Method is contributed by native dependency.
|
||||
}
|
||||
) { nativeValues ->
|
||||
val messengerParameterTypes = mutableListOf<String>()
|
||||
messengerParameterTypes.add("void*")
|
||||
|
||||
+1
@@ -60,6 +60,7 @@ interface SimpleBridgeGenerator {
|
||||
nativeBacked: NativeBacked,
|
||||
returnType: BridgedType,
|
||||
kotlinValues: List<BridgeTypedKotlinValue>,
|
||||
independent: Boolean,
|
||||
block: NativeCodeBuilder.(nativeValues: List<NativeExpression>) -> NativeExpression
|
||||
): KotlinExpression
|
||||
|
||||
|
||||
+3
-1
@@ -71,7 +71,8 @@ class SimpleBridgeGeneratorImpl(
|
||||
nativeBacked: NativeBacked,
|
||||
returnType: BridgedType,
|
||||
kotlinValues: List<BridgeTypedKotlinValue>,
|
||||
block: NativeCodeBuilder.(arguments: List<NativeExpression>) -> NativeExpression
|
||||
independent: Boolean,
|
||||
block: NativeCodeBuilder.(nativeValues: List<NativeExpression>) -> NativeExpression
|
||||
): KotlinExpression {
|
||||
|
||||
val kotlinLines = mutableListOf<String>()
|
||||
@@ -116,6 +117,7 @@ class SimpleBridgeGeneratorImpl(
|
||||
}
|
||||
KotlinPlatform.NATIVE -> {
|
||||
val functionName = pkgName.replace(INVALID_CLANG_IDENTIFIER_REGEX, "_") + "_$kotlinFunctionName"
|
||||
if (independent) kotlinLines.add("@" + topLevelKotlinScope.reference(KotlinTypes.independent))
|
||||
kotlinLines.add("@SymbolName(${functionName.quoteAsKotlinLiteral()})")
|
||||
"$cReturnType $functionName ($joinedCParameters)"
|
||||
}
|
||||
|
||||
+2
-1
@@ -660,7 +660,8 @@ class StubGenerator(
|
||||
bodyGenerator,
|
||||
this,
|
||||
func.returnType,
|
||||
bridgeArguments
|
||||
bridgeArguments,
|
||||
independent = false
|
||||
) { nativeValues ->
|
||||
"${func.name}(${nativeValues.joinToString()})"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user