[K/N] Extract C header generation to a separate phase
This commit is contained in:
committed by
Space Team
parent
818b738921
commit
8516ae2b72
+9
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.driver.phases
|
package org.jetbrains.kotlin.backend.konan.driver.phases
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
|
||||||
|
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterApiExporter
|
||||||
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterExportedElements
|
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterExportedElements
|
||||||
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterGenerator
|
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterGenerator
|
||||||
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterTypeTranslator
|
import org.jetbrains.kotlin.backend.konan.cexport.CAdapterTypeTranslator
|
||||||
@@ -16,4 +18,11 @@ internal val BuildCExports = createSimpleNamedCompilerPhase<PsiToIrContext, Fron
|
|||||||
val prefix = context.config.fullExportedNamePrefix.replace("-|\\.".toRegex(), "_")
|
val prefix = context.config.fullExportedNamePrefix.replace("-|\\.".toRegex(), "_")
|
||||||
val typeTranslator = CAdapterTypeTranslator(prefix, context.builtIns)
|
val typeTranslator = CAdapterTypeTranslator(prefix, context.builtIns)
|
||||||
CAdapterGenerator(context, typeTranslator).buildExports(input.moduleDescriptor)
|
CAdapterGenerator(context, typeTranslator).buildExports(input.moduleDescriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal val CExportGenerateApiPhase = createSimpleNamedCompilerPhase<NativeGenerationState, Unit>(
|
||||||
|
name = "CExportGenerateApi",
|
||||||
|
description = "Create C header for the exported API",
|
||||||
|
) { context, _ ->
|
||||||
|
CAdapterApiExporter(context, context.context.cAdapterExportedElements!!).makeGlobalStruct()
|
||||||
}
|
}
|
||||||
+4
@@ -173,10 +173,14 @@ internal fun PhaseEngine<NativeGenerationState>.runBackendCodegen(module: IrModu
|
|||||||
}
|
}
|
||||||
mergeDependencies(module, dependenciesToCompile)
|
mergeDependencies(module, dependenciesToCompile)
|
||||||
runCodegen(module)
|
runCodegen(module)
|
||||||
|
if (context.config.produce.isNativeLibrary) {
|
||||||
|
runPhase(CExportGenerateApiPhase)
|
||||||
|
}
|
||||||
runPhase(CStubsPhase)
|
runPhase(CStubsPhase)
|
||||||
// TODO: Consider extracting llvmModule and friends from nativeGenerationState and pass them explicitly.
|
// TODO: Consider extracting llvmModule and friends from nativeGenerationState and pass them explicitly.
|
||||||
// Motivation: possibility to run LTO on bitcode level after separate IR compilation.
|
// Motivation: possibility to run LTO on bitcode level after separate IR compilation.
|
||||||
val llvmModule = context.llvm.module
|
val llvmModule = context.llvm.module
|
||||||
|
// TODO: Consider dropping these in favor of proper phases dumping and validation.
|
||||||
if (context.config.needCompilerVerification || context.config.configuration.getBoolean(KonanConfigKeys.VERIFY_BITCODE)) {
|
if (context.config.needCompilerVerification || context.config.configuration.getBoolean(KonanConfigKeys.VERIFY_BITCODE)) {
|
||||||
runPhase(VerifyBitcodePhase, llvmModule)
|
runPhase(VerifyBitcodePhase, llvmModule)
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -347,8 +347,6 @@ internal class CodeGeneratorVisitor(
|
|||||||
}
|
}
|
||||||
private fun appendCAdapters(elements: CAdapterExportedElements) {
|
private fun appendCAdapters(elements: CAdapterExportedElements) {
|
||||||
CAdapterCodegen(codegen, generationState).buildAllAdaptersRecursively(elements)
|
CAdapterCodegen(codegen, generationState).buildAllAdaptersRecursively(elements)
|
||||||
// TODO: It is not a part of IrToBitcode. Maybe move it somewhere?
|
|
||||||
CAdapterApiExporter(generationState, elements).makeGlobalStruct()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FunctionGenerationContext.initThreadLocalField(irField: IrField) {
|
private fun FunctionGenerationContext.initThreadLocalField(irField: IrField) {
|
||||||
|
|||||||
Reference in New Issue
Block a user