Skip to content
Snippets Groups Projects
Commit 4d88b0c9 authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Pipeline.when optionally applies a pipeline

parent 5f9356bf
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,6 @@ package leon ...@@ -5,7 +5,6 @@ package leon
import purescala.Definitions.Program import purescala.Definitions.Program
trait LeonPhase[-F, +T] extends Pipeline[F, T] with LeonComponent { trait LeonPhase[-F, +T] extends Pipeline[F, T] with LeonComponent {
// def run(ac: LeonContext)(v: F): T // def run(ac: LeonContext)(v: F): T
} }
...@@ -22,6 +21,7 @@ abstract class TransformationPhase extends LeonPhase[Program, Program] { ...@@ -22,6 +21,7 @@ abstract class TransformationPhase extends LeonPhase[Program, Program] {
ctx.reporter.debug("Running transformation phase: " + name)(utils.DebugSectionLeon) ctx.reporter.debug("Running transformation phase: " + name)(utils.DebugSectionLeon)
(ctx, apply(ctx, p)) (ctx, apply(ctx, p))
} }
} }
abstract class UnitPhase[T] extends LeonPhase[T, T] { abstract class UnitPhase[T] extends LeonPhase[T, T] {
......
...@@ -195,7 +195,7 @@ object Main { ...@@ -195,7 +195,7 @@ object Main {
val verification = val verification =
VerificationPhase andThen VerificationPhase andThen
(if (xlangF) FixReportLabels else NoopPhase[VerificationReport]()) andThen FixReportLabels.when(xlangF) andThen
PrintReportPhase PrintReportPhase
val termination = TerminationPhase andThen PrintReportPhase val termination = TerminationPhase andThen PrintReportPhase
......
...@@ -13,6 +13,12 @@ abstract class Pipeline[-F, +T] { ...@@ -13,6 +13,12 @@ abstract class Pipeline[-F, +T] {
} }
} }
def when[F2 <: F, T2 >: T](cond: Boolean)(implicit tps: F2 =:= T2): Pipeline[F2, T2] = {
if (cond) this else new Pipeline[F2, T2] {
def run(ctx: LeonContext, v: F2): (LeonContext, T2) = (ctx, v)
}
}
def run(ctx: LeonContext, v: F): (LeonContext, T) def run(ctx: LeonContext, v: F): (LeonContext, T)
} }
......
...@@ -16,44 +16,28 @@ class PreprocessingPhase(desugarXLang: Boolean = false, genc: Boolean = false) e ...@@ -16,44 +16,28 @@ class PreprocessingPhase(desugarXLang: Boolean = false, genc: Boolean = false) e
override def run(ctx: LeonContext, p: Program): (LeonContext, Program) = { override def run(ctx: LeonContext, p: Program): (LeonContext, Program) = {
def debugTrees(title: String): LeonPhase[Program, Program] = { def debugTrees(title: String) =
if (ctx.reporter.isDebugEnabled(DebugSectionTrees)) { PrintTreePhase(title).when(ctx.reporter.isDebugEnabled(DebugSectionTrees))
PrintTreePhase(title)
} else {
NoopPhase[Program]()
}
}
val checkX = if (desugarXLang) {
NoopPhase[Program]()
} else {
NoXLangFeaturesChecking
}
val pipeBegin = val pipeBegin =
debugTrees("Program after extraction") andThen debugTrees("Program after extraction") andThen
checkX andThen NoXLangFeaturesChecking.when(!desugarXLang) andThen
MethodLifting andThen MethodLifting andThen
TypingPhase andThen TypingPhase andThen
synthesis.ConversionPhase andThen synthesis.ConversionPhase andThen
InliningPhase InliningPhase
val pipeX = if (!genc && desugarXLang) { // Do not desugar xlang when generating C code
// Do not desugar when generating C code val pipeX = (
XLangDesugaringPhase andThen XLangDesugaringPhase andThen
debugTrees("Program after xlang desugaring") debugTrees("Program after xlang desugaring")
} else { ) when (!genc && desugarXLang)
NoopPhase[Program]()
}
def pipeEnd = if (genc) { def pipeEnd = (
// No InjectAsserts, FunctionClosure and AdaptationPhase phases
NoopPhase[Program]()
} else {
InjectAsserts andThen InjectAsserts andThen
FunctionClosure andThen FunctionClosure andThen
AdaptationPhase AdaptationPhase
} ) when (!genc)
val phases = val phases =
pipeBegin andThen pipeBegin andThen
......
...@@ -37,9 +37,9 @@ trait VerificationSuite extends LeonRegressionSuite { ...@@ -37,9 +37,9 @@ trait VerificationSuite extends LeonRegressionSuite {
new PreprocessingPhase(desugarXLang) new PreprocessingPhase(desugarXLang)
val analysis = val analysis =
(if (isabelle) AdaptationPhase else NoopPhase[Program]) andThen AdaptationPhase.when(isabelle) andThen
VerificationPhase andThen VerificationPhase andThen
(if (desugarXLang) FixReportLabels else NoopPhase[VerificationReport]) FixReportLabels.when(desugarXLang)
val ctx = createLeonContext(files:_*).copy(reporter = new TestErrorReporter) val ctx = createLeonContext(files:_*).copy(reporter = new TestErrorReporter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment