[K/N] Enable dynamic and static output for dynamic driver

This commit is contained in:
Sergey Bogolepov
2022-12-15 16:32:05 +02:00
committed by Space Team
parent 2e5981eb94
commit 7706ad8cb3
@@ -26,6 +26,8 @@ internal class DynamicCompilerDriver : CompilerDriver() {
CompilerOutputKind.DYNAMIC_CACHE,
CompilerOutputKind.STATIC_CACHE,
CompilerOutputKind.FRAMEWORK,
CompilerOutputKind.DYNAMIC,
CompilerOutputKind.STATIC,
)
}
@@ -35,8 +37,8 @@ internal class DynamicCompilerDriver : CompilerDriver() {
PhaseEngine.startTopLevel(config) { engine ->
when (config.produce) {
CompilerOutputKind.PROGRAM -> produceBinary(engine, config, environment)
CompilerOutputKind.DYNAMIC -> error("Dynamic compiler driver does not support `dynamic` output yet.")
CompilerOutputKind.STATIC -> error("Dynamic compiler driver does not support `static` output yet.")
CompilerOutputKind.DYNAMIC -> produceCLibrary(engine, config, environment)
CompilerOutputKind.STATIC -> produceCLibrary(engine, config, environment)
CompilerOutputKind.FRAMEWORK -> produceObjCFramework(engine, config, environment)
CompilerOutputKind.LIBRARY -> produceKlib(engine, config, environment)
CompilerOutputKind.BITCODE -> error("Dynamic compiler driver does not support `bitcode` output yet.")
@@ -72,6 +74,17 @@ internal class DynamicCompilerDriver : CompilerDriver() {
engine.runBackend(backendContext)
}
private fun produceCLibrary(engine: PhaseEngine<PhaseContext>, config: KonanConfig, environment: KotlinCoreEnvironment) {
val frontendOutput = engine.runFrontend(config, environment) ?: return
val (psiToIrOutput, cAdapterElements) = engine.runPsiToIr(frontendOutput, isProducingLibrary = false) {
it.runPhase(BuildCExports, frontendOutput)
}
val backendContext = createBackendContext(config, frontendOutput, psiToIrOutput) {
it.cAdapterExportedElements = cAdapterElements
}
engine.runBackend(backendContext)
}
private fun produceKlib(engine: PhaseEngine<PhaseContext>, config: KonanConfig, environment: KotlinCoreEnvironment) {
val frontendOutput = engine.runFrontend(config, environment) ?: return
val psiToIrOutput = if (config.metadataKlib) {