backend: do not refer phases by name

also transform KonanPhase to enum
This commit is contained in:
Svyatoslav Scherbina
2016-12-22 17:04:37 +07:00
committed by SvyatoslavScherbina
parent b6561b13a4
commit 4acb0774cf
4 changed files with 29 additions and 31 deletions
@@ -60,15 +60,15 @@ public fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEn
context.irModule = module context.irModule = module
val phaser = PhaseManager(context) val phaser = PhaseManager(context)
phaser.phase("Optimizer") { phaser.phase(KonanPhase.OPTIMIZER) {
KonanLower(context).lower(module) KonanLower(context).lower(module)
} }
phaser.phase("Bitcode") { phaser.phase(KonanPhase.BITCODE) {
emitLLVM(context) emitLLVM(context)
} }
phaser.phase("Linker") { phaser.phase(KonanPhase.LINKER) {
//TODO: We don't have it yet. //TODO: We don't have it yet.
// invokeLinker() // invokeLinker()
} }
@@ -17,20 +17,20 @@ internal class KonanLower(val context: Context) {
fun lower(irFile: IrFile) { fun lower(irFile: IrFile) {
val phaser = PhaseManager(context) val phaser = PhaseManager(context)
phaser.phase("Lower_builtin_operators") { phaser.phase(KonanPhase.LOWER_BUILTIN_OPERATORS) {
BuiltinOperatorLowering(context).runOnFilePostfix(irFile) BuiltinOperatorLowering(context).runOnFilePostfix(irFile)
} }
phaser.phase("Lower_shared_variables") { phaser.phase(KonanPhase.LOWER_SHARED_VARIABLES) {
SharedVariablesLowering(context).runOnFilePostfix(irFile) SharedVariablesLowering(context).runOnFilePostfix(irFile)
} }
phaser.phase("Lower_local_functions") { phaser.phase(KonanPhase.LOWER_LOCAL_FUNCTIONS) {
LocalFunctionsLowering(context).runOnFilePostfix(irFile) LocalFunctionsLowering(context).runOnFilePostfix(irFile)
} }
phaser.phase("Lower_callables") { phaser.phase(KonanPhase.LOWER_CALLABLES) {
CallableReferenceLowering(context).runOnFilePostfix(irFile) CallableReferenceLowering(context).runOnFilePostfix(irFile)
} }
phaser.phase("Autobox") { phaser.phase(KonanPhase.AUTOBOX) {
Autoboxing(context).lower(irFile) Autoboxing(context).lower(irFile)
} }
} }
@@ -2,26 +2,26 @@ package org.jetbrains.kotlin.backend.konan
import org.jetbrains.kotlin.backend.konan.Context import org.jetbrains.kotlin.backend.konan.Context
class KonanPhase (val description: String, enum class KonanPhase(val description: String,
var enabled: Boolean = true, var verbose: Boolean = false) { var enabled: Boolean = true, var verbose: Boolean = false) {
BACKEND("All backend"), // TODO: it is unused
OPTIMIZER("IR Optimizer"),
LOWER_BUILTIN_OPERATORS("BuiltIn Operators Lowering"),
LOWER_SHARED_VARIABLES("Shared Variable Lowering"),
LOWER_LOCAL_FUNCTIONS("Local Function Lowering"),
LOWER_CALLABLES("Callable references Lowering"),
AUTOBOX("Autoboxing of primitive types"),
LOWER("IR Lowering"), // TODO: it is unused
BITCODE("LLVM BitCode Generation"),
RTTI("RTTI Generation"),
CODEGEN("Code Generation"),
METADATOR("Metadata Generation"),
LINKER("Link Stage");
} }
object KonanPhases { object KonanPhases {
val phases = mapOf<String, KonanPhase> ( val phases = KonanPhase.values().associate { it.name to it }
"Backend" to KonanPhase("All backend"),
"Optimizer" to KonanPhase("IR Optimizer"),
"Lower_builtin_operators" to KonanPhase("BuiltIn Operators Lowering"),
"Lower_shared_variables" to KonanPhase("Shared Variable Lowering"),
"Lower_local_functions" to KonanPhase("Local Function Lowering"),
"Lower_callables" to KonanPhase("Callable references Lowering"),
"Autobox" to KonanPhase("Autoboxing of primitive types"),
"Lower" to KonanPhase("IR Lowering"),
"Bitcode" to KonanPhase("LLVM BitCode Generation"),
"RTTI" to KonanPhase("RTTI Generation"),
"Codegen" to KonanPhase("Code Generation"),
"Metadator" to KonanPhase("Metadata Generation"),
"Linker" to KonanPhase("Link Stage")
)
fun config(config: KonanConfig) { fun config(config: KonanConfig) {
val disabled = config.configuration.get(KonanConfigKeys.DISABLED_PHASES) val disabled = config.configuration.get(KonanConfigKeys.DISABLED_PHASES)
@@ -46,10 +46,8 @@ object KonanPhases {
internal class PhaseManager(val context: Context) { internal class PhaseManager(val context: Context) {
internal fun phase(shortName: String, body: () -> Unit) { internal fun phase(phase: KonanPhase, body: () -> Unit) {
val phase = KonanPhases.phases[shortName]
if (phase == null) throw Error("Unknown backend phase: $shortName")
if (!phase .enabled) return if (!phase .enabled) return
val savePhase = context.phase val savePhase = context.phase
@@ -39,15 +39,15 @@ internal fun emitLLVM(context: Context) {
val phaser = PhaseManager(context) val phaser = PhaseManager(context)
phaser.phase("RTTI") { phaser.phase(KonanPhase.RTTI) {
irModule.acceptVoid(RTTIGeneratorVisitor(context)) irModule.acceptVoid(RTTIGeneratorVisitor(context))
} }
phaser.phase("Codegen") { phaser.phase(KonanPhase.CODEGEN) {
irModule.acceptVoid(CodeGeneratorVisitor(context)) irModule.acceptVoid(CodeGeneratorVisitor(context))
} }
phaser.phase("Metadator") { phaser.phase(KonanPhase.METADATOR) {
irModule.acceptVoid(MetadatorVisitor(context)) irModule.acceptVoid(MetadatorVisitor(context))
} }