Use CLI compiler arguments directly in PhaseConfig creation
This commit is contained in:
+3
-3
@@ -57,7 +57,7 @@ typealias AnyNamedPhase = NamedCompilerPhase<*, *, *>
|
||||
enum class BeforeOrAfter { BEFORE, AFTER }
|
||||
|
||||
interface PhaseDumperVerifier<in Context : CommonBackendContext, Data> {
|
||||
fun dump(phase: AnyNamedPhase, context: Context, data: Data, beforeOrAfter: BeforeOrAfter)
|
||||
fun dump(phase: AnyNamedPhase, phaseConfig: PhaseConfig, data: Data, beforeOrAfter: BeforeOrAfter)
|
||||
fun verify(context: Context, data: Data)
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ abstract class AbstractNamedPhaseWrapper<in Context : CommonBackendContext, Inpu
|
||||
}
|
||||
|
||||
private fun runBefore(phaseConfig: PhaseConfig, context: Context, input: Input) {
|
||||
checkAndRun(phaseConfig.toDumpStateBefore) { inputDumperVerifier.dump(this, context, input, BeforeOrAfter.BEFORE) }
|
||||
checkAndRun(phaseConfig.toDumpStateBefore) { inputDumperVerifier.dump(this, phaseConfig, input, BeforeOrAfter.BEFORE) }
|
||||
checkAndRun(phaseConfig.toValidateStateBefore) { inputDumperVerifier.verify(context, input) }
|
||||
if (phaseConfig.checkConditions) {
|
||||
for (pre in preconditions) pre(input)
|
||||
@@ -115,7 +115,7 @@ abstract class AbstractNamedPhaseWrapper<in Context : CommonBackendContext, Inpu
|
||||
}
|
||||
|
||||
private fun runAfter(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, output: Output) {
|
||||
checkAndRun(phaseConfig.toDumpStateAfter) { outputDumperVerifier.dump(this, context, output, BeforeOrAfter.AFTER) }
|
||||
checkAndRun(phaseConfig.toDumpStateAfter) { outputDumperVerifier.dump(this, phaseConfig, output, BeforeOrAfter.AFTER) }
|
||||
checkAndRun(phaseConfig.toValidateStateAfter) { outputDumperVerifier.verify(context, output) }
|
||||
if (phaseConfig.checkConditions) {
|
||||
for (post in postconditions) post(output)
|
||||
|
||||
+8
-9
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.common.phaser
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
@@ -14,15 +13,15 @@ import org.jetbrains.kotlin.ir.declarations.name
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
|
||||
abstract class IrPhaseDumperVerifier<in Context : CommonBackendContext, Data : IrElement>(
|
||||
val verifier: (Context, Data) -> Unit
|
||||
val verifier: (Context, Data) -> Unit
|
||||
) : PhaseDumperVerifier<Context, Data> {
|
||||
abstract fun Data.getElementName(): String
|
||||
|
||||
// TODO: use a proper logger.
|
||||
override fun dump(phase: AnyNamedPhase, context: Context, data: Data, beforeOrAfter: BeforeOrAfter) {
|
||||
override fun dump(phase: AnyNamedPhase, phaseConfig: PhaseConfig, data: Data, beforeOrAfter: BeforeOrAfter) {
|
||||
fun separator(title: String) = println("\n\n--- $title ----------------------\n")
|
||||
|
||||
if (!shouldBeDumped(context, data)) return
|
||||
if (!shouldBeDumped(phaseConfig, data)) return
|
||||
|
||||
val beforeOrAfterStr = beforeOrAfter.name.toLowerCase()
|
||||
val title = "IR for ${data.getElementName()} $beforeOrAfterStr ${phase.description}"
|
||||
@@ -32,22 +31,22 @@ abstract class IrPhaseDumperVerifier<in Context : CommonBackendContext, Data : I
|
||||
|
||||
override fun verify(context: Context, data: Data) = verifier(context, data)
|
||||
|
||||
private fun shouldBeDumped(context: Context, input: Data) =
|
||||
input.getElementName() !in context.configuration.get(CommonConfigurationKeys.EXCLUDED_ELEMENTS_FROM_DUMPING, emptySet())
|
||||
private fun shouldBeDumped(phaseConfig: PhaseConfig, input: Data) =
|
||||
input.getElementName() !in phaseConfig.namesOfElementsExcludedFromDumping
|
||||
}
|
||||
|
||||
class IrFileDumperVerifier<in Context : CommonBackendContext>(verifier: (Context, IrFile) -> Unit) :
|
||||
IrPhaseDumperVerifier<Context, IrFile>(verifier) {
|
||||
IrPhaseDumperVerifier<Context, IrFile>(verifier) {
|
||||
override fun IrFile.getElementName() = name
|
||||
}
|
||||
|
||||
class IrModuleDumperVerifier<in Context : CommonBackendContext>(verifier: (Context, IrModuleFragment) -> Unit) :
|
||||
IrPhaseDumperVerifier<Context, IrModuleFragment>(verifier) {
|
||||
IrPhaseDumperVerifier<Context, IrModuleFragment>(verifier) {
|
||||
override fun IrModuleFragment.getElementName() = name.asString()
|
||||
}
|
||||
|
||||
class EmptyDumperVerifier<in Context : CommonBackendContext, Data> : PhaseDumperVerifier<Context, Data> {
|
||||
override fun dump(phase: AnyNamedPhase, context: Context, data: Data, beforeOrAfter: BeforeOrAfter) {}
|
||||
override fun dump(phase: AnyNamedPhase, phaseConfig: PhaseConfig, data: Data, beforeOrAfter: BeforeOrAfter) {}
|
||||
override fun verify(context: Context, data: Data) {}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.backend.common.phaser
|
||||
|
||||
fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> =
|
||||
getNamedSubphases().fold(mutableMapOf()) { acc, (_, phase) ->
|
||||
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"}
|
||||
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'" }
|
||||
acc[phase.name] = phase
|
||||
acc
|
||||
}
|
||||
@@ -21,6 +21,7 @@ class PhaseConfig(
|
||||
val toDumpStateAfter: Set<AnyNamedPhase> = emptySet(),
|
||||
val toValidateStateBefore: Set<AnyNamedPhase> = emptySet(),
|
||||
val toValidateStateAfter: Set<AnyNamedPhase> = emptySet(),
|
||||
val namesOfElementsExcludedFromDumping: Set<String> = emptySet(),
|
||||
val needProfiling: Boolean = false,
|
||||
val checkConditions: Boolean = false,
|
||||
val checkStickyConditions: Boolean = false
|
||||
|
||||
@@ -44,12 +44,6 @@ class JvmBackendContext(
|
||||
|
||||
override val configuration get() = state.configuration
|
||||
|
||||
init {
|
||||
if (state.configuration.get(CommonConfigurationKeys.LIST_PHASES) == true) {
|
||||
phaseConfig.list()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getJvmInternalClass(name: String): ClassDescriptor {
|
||||
return getClass(FqName("kotlin.jvm.internal").child(Name.identifier(name)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user