JVM_IR: incorporate validation into jvmPhases
This commit is contained in:
+18
-1
@@ -5,6 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.phaser
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CheckDeclarationParentsVisitor
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.IrValidator
|
||||
import org.jetbrains.kotlin.backend.common.IrValidatorConfig
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
@@ -117,4 +121,17 @@ fun <Data, Context> dumpToStdout(
|
||||
println()
|
||||
}
|
||||
|
||||
val defaultDumper = makeDumpAction(dumpToStdout(::dumpIrElement) + dumpToFile("ir", ::dumpIrElement))
|
||||
val defaultDumper = makeDumpAction(dumpToStdout(::dumpIrElement) + dumpToFile("ir", ::dumpIrElement))
|
||||
|
||||
fun <Fragment : IrElement> validationCallback(context: CommonBackendContext, fragment: Fragment) {
|
||||
val validatorConfig = IrValidatorConfig(
|
||||
abortOnError = true,
|
||||
ensureAllNodesAreDifferent = true,
|
||||
checkTypes = false,
|
||||
checkDescriptors = false
|
||||
)
|
||||
fragment.accept(IrValidator(context, validatorConfig), null)
|
||||
fragment.accept(CheckDeclarationParentsVisitor, null)
|
||||
}
|
||||
|
||||
val validationAction = makeVerifyAction(::validationCallback)
|
||||
|
||||
+37
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.common.phaser
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
|
||||
@@ -54,7 +55,7 @@ fun <Context : CommonBackendContext> namedIrModulePhase(
|
||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrModuleFragment>> = lower.stickyPostconditions,
|
||||
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper),
|
||||
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper, validationAction),
|
||||
nlevels: Int = 1
|
||||
) = SameTypeNamedPhaseWrapper(
|
||||
name,
|
||||
@@ -76,7 +77,7 @@ fun <Context : CommonBackendContext> namedIrFilePhase(
|
||||
preconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
postconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrFile>> = lower.stickyPostconditions,
|
||||
actions: Set<Action<IrFile, Context>> = setOf(defaultDumper),
|
||||
actions: Set<Action<IrFile, Context>> = setOf(defaultDumper, validationAction),
|
||||
nlevels: Int = 1
|
||||
) = SameTypeNamedPhaseWrapper(
|
||||
name,
|
||||
@@ -90,6 +91,38 @@ fun <Context : CommonBackendContext> namedIrFilePhase(
|
||||
nlevels
|
||||
)
|
||||
|
||||
fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
|
||||
op: (Context, Element) -> Unit,
|
||||
description: String,
|
||||
name: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
preconditions: Set<Checker<Element>> = emptySet(),
|
||||
postconditions: Set<Checker<Element>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<Element>> = emptySet(),
|
||||
actions: Set<Action<Element, Context>> = setOf(defaultDumper, validationAction),
|
||||
nlevels: Int = 1
|
||||
) = SameTypeNamedPhaseWrapper(
|
||||
name,
|
||||
description,
|
||||
prerequisite,
|
||||
preconditions = preconditions,
|
||||
postconditions = postconditions,
|
||||
stickyPostconditions = stickyPostconditions,
|
||||
actions = actions,
|
||||
nlevels = nlevels,
|
||||
lower = object : SameTypeCompilerPhase<Context, Element> {
|
||||
override fun invoke(
|
||||
phaseConfig: PhaseConfig,
|
||||
phaserState: PhaserState<Element>,
|
||||
context: Context,
|
||||
input: Element
|
||||
): Element {
|
||||
op(context, input)
|
||||
return input
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
fun <Context : CommonBackendContext> namedUnitPhase(
|
||||
name: String,
|
||||
description: String,
|
||||
@@ -160,7 +193,7 @@ fun <Context : CommonBackendContext> makeIrFilePhase(
|
||||
preconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
postconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
actions: Set<Action<IrFile, Context>> = setOf(defaultDumper)
|
||||
actions: Set<Action<IrFile, Context>> = setOf(defaultDumper, validationAction)
|
||||
) = namedIrFilePhase(
|
||||
name, description, prerequisite,
|
||||
preconditions = preconditions,
|
||||
@@ -184,7 +217,7 @@ fun <Context : CommonBackendContext> makeIrModulePhase(
|
||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper)
|
||||
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper, validationAction)
|
||||
) = namedIrModulePhase(
|
||||
name, description, prerequisite,
|
||||
preconditions=preconditions,
|
||||
|
||||
Reference in New Issue
Block a user