[Interop] Perform enum and struct generation before linkage
This process may generate symbols that should be bound. Thus, we need to perform it before linkage. Also replace unsafe `irCall` with proper one.
This commit is contained in:
committed by
Sergey Bogolepov
parent
3db0cc689c
commit
5887bd54a9
+5
-4
@@ -208,6 +208,11 @@ internal val psiToIrPhase = konanUnitPhase(
|
|||||||
config.configuration.languageVersionSettings
|
config.configuration.languageVersionSettings
|
||||||
)
|
)
|
||||||
val irProviderForCEnumsAndCStructs = IrProviderForCEnumAndCStructStubs(generatorContext, interopBuiltIns, symbols)
|
val irProviderForCEnumsAndCStructs = IrProviderForCEnumAndCStructStubs(generatorContext, interopBuiltIns, symbols)
|
||||||
|
// We need to run `buildAllEnumsAndStructsFrom` before `generateModuleFragment` because it adds references to symbolTable
|
||||||
|
// that should be bound.
|
||||||
|
modulesWithoutDCE
|
||||||
|
.filter(ModuleDescriptor::isFromInteropLibrary)
|
||||||
|
.forEach(irProviderForCEnumsAndCStructs::buildAllEnumsAndStructsFrom)
|
||||||
val irProviderForInteropStubs = IrProviderForInteropStubs(irProviderForCEnumsAndCStructs::canHandleSymbol)
|
val irProviderForInteropStubs = IrProviderForInteropStubs(irProviderForCEnumsAndCStructs::canHandleSymbol)
|
||||||
val irProviders = listOf(
|
val irProviders = listOf(
|
||||||
irProviderForCEnumsAndCStructs,
|
irProviderForCEnumsAndCStructs,
|
||||||
@@ -235,10 +240,6 @@ internal val psiToIrPhase = konanUnitPhase(
|
|||||||
if (this.stdlibModule in modulesWithoutDCE) {
|
if (this.stdlibModule in modulesWithoutDCE) {
|
||||||
functionIrClassFactory.buildAllClasses()
|
functionIrClassFactory.buildAllClasses()
|
||||||
}
|
}
|
||||||
modulesWithoutDCE
|
|
||||||
.filter(ModuleDescriptor::isFromInteropLibrary)
|
|
||||||
.forEach(irProviderForCEnumsAndCStructs::buildAllEnumsAndStructsFrom)
|
|
||||||
|
|
||||||
irModule = module
|
irModule = module
|
||||||
irModules = deserializer.modules.filterValues { llvmModuleSpecification.containsModule(it) }
|
irModules = deserializer.modules.filterValues { llvmModuleSpecification.containsModule(it) }
|
||||||
ir.symbols = symbols
|
ir.symbols = symbols
|
||||||
|
|||||||
+5
-6
@@ -54,23 +54,22 @@ internal class CEnumByValueFunctionGenerator(
|
|||||||
val values = irTemporaryVar(irCall(valuesIrFunctionSymbol))
|
val values = irTemporaryVar(irCall(valuesIrFunctionSymbol))
|
||||||
val inductionVariable = irTemporaryVar(irInt(0))
|
val inductionVariable = irTemporaryVar(irInt(0))
|
||||||
val arrayClass = values.type.classOrNull!!
|
val arrayClass = values.type.classOrNull!!
|
||||||
val valuesSize = irCall(symbols.arraySize.getValue(arrayClass)).also { irCall ->
|
val valuesSize = irCall(symbols.arraySize.getValue(arrayClass), irBuiltIns.intType).also { irCall ->
|
||||||
irCall.dispatchReceiver = irGet(values)
|
irCall.dispatchReceiver = irGet(values)
|
||||||
}
|
}
|
||||||
val getElementFn = symbols.arrayGet.getValue(arrayClass)
|
val getElementFn = symbols.arrayGet.getValue(arrayClass)
|
||||||
val plusFun = symbols.intPlusInt
|
val plusFun = symbols.intPlusInt
|
||||||
val lessFunctionSymbol = irBuiltIns.lessFunByOperandType.getValue(irBuiltIns.intClass)
|
val lessFunctionSymbol = irBuiltIns.lessFunByOperandType.getValue(irBuiltIns.intClass)
|
||||||
+irWhile().also { loop ->
|
+irWhile().also { loop ->
|
||||||
loop.condition = irCall(lessFunctionSymbol).also { irCall ->
|
loop.condition = irCall(lessFunctionSymbol, irBuiltIns.booleanType).also { irCall ->
|
||||||
irCall.putValueArgument(0, irGet(inductionVariable))
|
irCall.putValueArgument(0, irGet(inductionVariable))
|
||||||
irCall.putValueArgument(1, valuesSize)
|
irCall.putValueArgument(1, valuesSize)
|
||||||
}
|
}
|
||||||
loop.body = irBlock {
|
loop.body = irBlock {
|
||||||
val untypedEntry = irCall(getElementFn).also { irCall ->
|
val entry = irTemporaryVar(irCall(getElementFn, byValueIrFunction.returnType).also { irCall ->
|
||||||
irCall.dispatchReceiver = irGet(values)
|
irCall.dispatchReceiver = irGet(values)
|
||||||
irCall.putValueArgument(0, irGet(inductionVariable))
|
irCall.putValueArgument(0, irGet(inductionVariable))
|
||||||
}
|
})
|
||||||
val entry = irTemporaryVar(irImplicitCast(untypedEntry, byValueIrFunction.returnType))
|
|
||||||
val valueGetter = entry.type.getClass()!!.getPropertyGetter("value")!!
|
val valueGetter = entry.type.getClass()!!.getPropertyGetter("value")!!
|
||||||
val entryValue = irGet(irValueParameter.type, irGet(entry), valueGetter)
|
val entryValue = irGet(irValueParameter.type, irGet(entry), valueGetter)
|
||||||
+irIfThenElse(
|
+irIfThenElse(
|
||||||
@@ -87,7 +86,7 @@ internal class CEnumByValueFunctionGenerator(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+irCall(symbols.ThrowNullPointerException)
|
+irCall(symbols.ThrowNullPointerException, irBuiltIns.nothingType)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return byValueIrFunction
|
return byValueIrFunction
|
||||||
|
|||||||
Reference in New Issue
Block a user