[Native] Move createSimpleNamedCompilerPhase into common.phaser.PhaseBuilders
This is needed to be able to reuse these functions for other backends.
This commit is contained in:
+47
@@ -7,6 +7,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.LoggingContext
|
||||
import org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
@@ -47,6 +48,52 @@ infix fun <Context : CommonBackendContext, Input, Mid, Output> CompilerPhase<Con
|
||||
return CompositePhase(if (this is CompositePhase<Context, *, *>) phases + unsafeOther else listOf(unsafeThis, unsafeOther))
|
||||
}
|
||||
|
||||
fun <Context : LoggingContext, Input, Output> createSimpleNamedCompilerPhase(
|
||||
name: String,
|
||||
description: String,
|
||||
preactions: Set<Action<Input, Context>> = emptySet(),
|
||||
postactions: Set<Action<Output, Context>> = emptySet(),
|
||||
prerequisite: Set<AbstractNamedCompilerPhase<*, *, *>> = emptySet(),
|
||||
outputIfNotEnabled: (PhaseConfigurationService, PhaserState<Input>, Context, Input) -> Output,
|
||||
op: (Context, Input) -> Output
|
||||
): SimpleNamedCompilerPhase<Context, Input, Output> = object : SimpleNamedCompilerPhase<Context, Input, Output>(
|
||||
name,
|
||||
description,
|
||||
preactions = preactions,
|
||||
postactions = postactions.map { f ->
|
||||
fun(actionState: ActionState, data: Pair<Input, Output>, context: Context) = f(actionState, data.second, context)
|
||||
}.toSet(),
|
||||
prerequisite = prerequisite,
|
||||
) {
|
||||
override fun outputIfNotEnabled(phaseConfig: PhaseConfigurationService, phaserState: PhaserState<Input>, context: Context, input: Input): Output =
|
||||
outputIfNotEnabled(phaseConfig, phaserState, context, input)
|
||||
|
||||
override fun phaseBody(context: Context, input: Input): Output =
|
||||
op(context, input)
|
||||
}
|
||||
|
||||
fun <Context : LoggingContext, Input> createSimpleNamedCompilerPhase(
|
||||
name: String,
|
||||
description: String,
|
||||
preactions: Set<Action<Input, Context>> = emptySet(),
|
||||
postactions: Set<Action<Input, Context>> = emptySet(),
|
||||
prerequisite: Set<AbstractNamedCompilerPhase<*, *, *>> = emptySet(),
|
||||
op: (Context, Input) -> Unit
|
||||
): SimpleNamedCompilerPhase<Context, Input, Unit> = object : SimpleNamedCompilerPhase<Context, Input, Unit>(
|
||||
name,
|
||||
description,
|
||||
preactions = preactions,
|
||||
postactions = postactions.map { f ->
|
||||
fun(actionState: ActionState, data: Pair<Input, Unit>, context: Context) = f(actionState, data.first, context)
|
||||
}.toSet(),
|
||||
prerequisite = prerequisite,
|
||||
) {
|
||||
override fun outputIfNotEnabled(phaseConfig: PhaseConfigurationService, phaserState: PhaserState<Input>, context: Context, input: Input) {}
|
||||
|
||||
override fun phaseBody(context: Context, input: Input): Unit =
|
||||
op(context, input)
|
||||
}
|
||||
|
||||
fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
|
||||
op: (Context, Element) -> Unit,
|
||||
name: String,
|
||||
|
||||
Reference in New Issue
Block a user