CLI loading of compiler ir generation plugins
(cherry picked from commit b0fdfae2ce3aaa9bb5790b9c8ac8d507f2df4235)
This commit is contained in:
committed by
Vasily Levchenko
parent
b49e7c067f
commit
6064cc9a34
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.konan.KonanVersion
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
@@ -59,6 +60,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
val pluginLoadResult =
|
||||
PluginCliParser.loadPluginsSafe(arguments.pluginClasspaths, arguments.pluginOptions, configuration)
|
||||
if (pluginLoadResult != ExitCode.OK) return pluginLoadResult
|
||||
|
||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
|
||||
configuration, EnvironmentConfigFiles.NATIVE_CONFIG_FILES)
|
||||
val project = environment.project
|
||||
@@ -138,7 +143,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
// TODO: Collect all the explicit file names into an object
|
||||
// and teach the compiler to work with temporaries and -save-temps.
|
||||
|
||||
arguments.outputName ?.let { put(OUTPUT, it) }
|
||||
arguments.outputName ?.let { put(OUTPUT, it) }
|
||||
val outputKind = CompilerOutputKind.valueOf(
|
||||
(arguments.produce ?: "program").toUpperCase())
|
||||
put(PRODUCE, outputKind)
|
||||
|
||||
+8
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ModuleIndex
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.emitLLVM
|
||||
@@ -81,12 +82,18 @@ fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEnvironme
|
||||
|
||||
// validateIrModule(context, module)
|
||||
}
|
||||
phaser.phase(KonanPhase.IR_GENERATOR_PLUGINS) {
|
||||
val extensions = IrGenerationExtension.getInstances(context.config.project)
|
||||
extensions.forEach { extension ->
|
||||
context.irModule!!.files.forEach { irFile -> extension.generate(irFile, context, bindingContext) }
|
||||
}
|
||||
}
|
||||
phaser.phase(KonanPhase.GEN_SYNTHETIC_FIELDS) {
|
||||
markBackingFields(context)
|
||||
}
|
||||
phaser.phase(KonanPhase.SERIALIZER) {
|
||||
val serializer = KonanSerializationUtil(context, context.config.configuration.get(CommonConfigurationKeys.METADATA_VERSION)!!)
|
||||
context.serializedLinkData =
|
||||
context.serializedLinkData =
|
||||
serializer.serializeModule(context.moduleDescriptor)
|
||||
}
|
||||
phaser.phase(KonanPhase.BACKEND) {
|
||||
|
||||
+4
-3
@@ -25,6 +25,7 @@ enum class KonanPhase(val description: String,
|
||||
var verbose: Boolean = false) {
|
||||
/* */ FRONTEND("Frontend builds AST"),
|
||||
/* */ PSI_TO_IR("Psi to IR conversion"),
|
||||
/* */ IR_GENERATOR_PLUGINS("Plugged-in ir generators"),
|
||||
/* */ GEN_SYNTHETIC_FIELDS("Generate synthetic fields"),
|
||||
/* */ SERIALIZER("Serialize descriptor tree and inline IR bodies", GEN_SYNTHETIC_FIELDS),
|
||||
/* */ BACKEND("All backend"),
|
||||
@@ -86,10 +87,10 @@ object KonanPhases {
|
||||
}
|
||||
|
||||
fun config(config: KonanConfig) {
|
||||
with (config.configuration) { with (KonanConfigKeys) {
|
||||
with (config.configuration) { with (KonanConfigKeys) {
|
||||
|
||||
// Don't serialize anything to a final executable.
|
||||
KonanPhase.SERIALIZER.enabled =
|
||||
KonanPhase.SERIALIZER.enabled =
|
||||
(config.produce == CompilerOutputKind.LIBRARY)
|
||||
KonanPhase.LINK_STAGE.enabled = config.produce.isNativeBinary
|
||||
|
||||
@@ -110,7 +111,7 @@ object KonanPhases {
|
||||
phases.forEach { key, phase ->
|
||||
val enabled = if (phase.enabled) "(Enabled)" else ""
|
||||
val verbose = if (phase.verbose) "(Verbose)" else ""
|
||||
|
||||
|
||||
println(String.format("%1$-30s%2$-30s%3$-10s", "${key}:", phase.description, "$enabled $verbose"))
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -125,6 +125,8 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
|
||||
|
||||
val entryPoint = findMainEntryPoint(context)?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
|
||||
override val externalSymbolTable = lazySymbolTable
|
||||
|
||||
val nothing = symbolTable.referenceClass(builtIns.nothing)
|
||||
val throwable = symbolTable.referenceClass(builtIns.throwable)
|
||||
val string = symbolTable.referenceClass(builtIns.string)
|
||||
|
||||
Reference in New Issue
Block a user