Add explicit phase dependency mechanism. (#313)
This commit is contained in:
+6
@@ -76,6 +76,12 @@ public fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEn
|
||||
phaser.phase(KonanPhase.BITCODE) {
|
||||
emitLLVM(context)
|
||||
}
|
||||
// We always verify bitcode to prevent hard to debug bugs.
|
||||
context.verifyBitCode()
|
||||
|
||||
if (context.shouldPrintBitCode()) {
|
||||
context.printBitCode()
|
||||
}
|
||||
}
|
||||
|
||||
phaser.phase(KonanPhase.LINKER) {
|
||||
|
||||
+29
-23
@@ -1,37 +1,40 @@
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
|
||||
enum class KonanPhase(val description: String,
|
||||
val prerequisite: Set<KonanPhase> = setOf<KonanPhase>(),
|
||||
var enabled: Boolean = true, var verbose: Boolean = false) {
|
||||
|
||||
/* */ FRONTEND("Frontend builds AST"),
|
||||
/* */ PSI_TO_IR("Psi to IR conversion"),
|
||||
/* */ BACKEND("All backend"),
|
||||
/* ... */ LOWER("IR Lowering"),
|
||||
/* ... ... */ LOWER_BUILTIN_OPERATORS("BuiltIn Operators Lowering"),
|
||||
/* ... ... */ LOWER_VARARG("Vararg lowering"),
|
||||
/* ... ... */ LOWER_DEFAULT_PARAMETER_EXTENT("Default Parameter Extent Lowering"),
|
||||
/* ... ... */ LOWER_TYPE_OPERATORS("Type operators lowering"),
|
||||
/* ... ... */ LOWER_SHARED_VARIABLES("Shared Variable Lowering"),
|
||||
/* ... ... */ LOWER_LOCAL_FUNCTIONS("Local Function Lowering"),
|
||||
/* ... ... */ LOWER_CALLABLES("Callable references Lowering"),
|
||||
/* ... */ LOWER("IR Lowering"),
|
||||
/* ... ... */ LOWER_INLINE("Functions inlining"),
|
||||
/* ... ... */ LOWER_INTEROP("Interop lowering"),
|
||||
/* ... ... */ AUTOBOX("Autoboxing of primitive types"),
|
||||
/* ... ... */ LOWER_SHARED_VARIABLES("Shared Variable Lowering"),
|
||||
/* ... ... */ LOWER_ENUMS("Enum classes lowering"),
|
||||
/* ... ... */ LOWER_INNER_CLASSES("Inner classes lowering"),
|
||||
/* ... ... */ LOWER_STRING_CONCAT("String concatenation lowering"),
|
||||
/* ... ... */ LOWER_INITIALIZERS("Initializers lowering"),
|
||||
/* ... ... */ BRIDGES_BUILDING("Bridges building"),
|
||||
/* ... ... */ LOWER_DELEGATION("Delegation lowering"),
|
||||
/* ... ... */ LOWER_TAILREC("tailrec lowering"),
|
||||
/* ... ... */ LOWER_INITIALIZERS("Initializers lowering", setOf(LOWER_ENUMS)),
|
||||
/* ... ... */ LOWER_CALLABLES("Callable references Lowering", setOf(
|
||||
LOWER_INTEROP, LOWER_INITIALIZERS, LOWER_DELEGATION)),
|
||||
/* ... ... */ LOWER_VARARG("Vararg lowering", setOf(LOWER_CALLABLES)),
|
||||
/* ... ... */ LOWER_LOCAL_FUNCTIONS("Local Function Lowering", setOf(LOWER_INITIALIZERS)),
|
||||
/* ... ... */ LOWER_TAILREC("tailrec lowering", setOf(LOWER_LOCAL_FUNCTIONS)),
|
||||
/* ... ... */ LOWER_DEFAULT_PARAMETER_EXTENT("Default Parameter Extent Lowering", setOf(
|
||||
LOWER_TAILREC, LOWER_ENUMS)),
|
||||
/* ... ... */ LOWER_INNER_CLASSES("Inner classes lowering", setOf(LOWER_DEFAULT_PARAMETER_EXTENT)),
|
||||
/* ... ... */ LOWER_BUILTIN_OPERATORS("BuiltIn Operators Lowering", setOf(
|
||||
LOWER_DEFAULT_PARAMETER_EXTENT)),
|
||||
/* ... ... */ LOWER_TYPE_OPERATORS("Type operators lowering"),
|
||||
/* ... ... */ BRIDGES_BUILDING("Bridges building"),
|
||||
/* ... ... */ LOWER_STRING_CONCAT("String concatenation lowering"),
|
||||
/* ... ... */ AUTOBOX("Autoboxing of primitive types", setOf(BRIDGES_BUILDING)),
|
||||
/* ... */ BITCODE("LLVM BitCode Generation"),
|
||||
/* ... ... */ RTTI("RTTI Generation"),
|
||||
/* ... ... */ CODEGEN("Code Generation"),
|
||||
/* ... ... */ METADATOR("Metadata Generation"),
|
||||
/* */ LINKER("Link Stage");
|
||||
/* */ LINKER("Link Stage")
|
||||
}
|
||||
|
||||
object KonanPhases {
|
||||
@@ -73,9 +76,18 @@ object KonanPhases {
|
||||
|
||||
internal class PhaseManager(val context: Context) {
|
||||
|
||||
val previousPhases = mutableSetOf<KonanPhase>()
|
||||
|
||||
internal fun phase(phase: KonanPhase, body: () -> Unit) {
|
||||
|
||||
if (!phase .enabled) return
|
||||
if (!phase.enabled) return
|
||||
|
||||
phase.prerequisite.forEach {
|
||||
if (!previousPhases.contains(it))
|
||||
throw Error("$phase requires $it")
|
||||
}
|
||||
|
||||
previousPhases.add(phase)
|
||||
|
||||
val savePhase = context.phase
|
||||
context.phase = phase
|
||||
@@ -93,18 +105,12 @@ internal class PhaseManager(val context: Context) {
|
||||
verifyIr()
|
||||
}
|
||||
|
||||
// We always verify bitcode to prevent hard to debug bugs.
|
||||
verifyBitCode()
|
||||
|
||||
if (shouldPrintDescriptors()) {
|
||||
printDescriptors()
|
||||
}
|
||||
if (shouldPrintIr()) {
|
||||
printIr()
|
||||
}
|
||||
if (shouldPrintBitCode()) {
|
||||
printBitCode()
|
||||
}
|
||||
}
|
||||
|
||||
context.depth --
|
||||
|
||||
Reference in New Issue
Block a user