Skip to content
Snippets Groups Projects
  • Etienne Kneuss's avatar
    554d6e66
    Refactor Phases/Pipelines · 554d6e66
    Etienne Kneuss authored
    1) run's prototype follows apply's prototype: (ctx, v) instead of
    (ctx)(v)
    
    2) run() returns a possibly updated context. SimpleLeonPhase defines
    apply and returns the same context.
    554d6e66
    History
    Refactor Phases/Pipelines
    Etienne Kneuss authored
    1) run's prototype follows apply's prototype: (ctx, v) instead of
    (ctx)(v)
    
    2) run() returns a possibly updated context. SimpleLeonPhase defines
    apply and returns the same context.
LeonPhase.scala 1.07 KiB
/* Copyright 2009-2015 EPFL, Lausanne */

package leon

import purescala.Definitions.Program

trait LeonPhase[-F, +T] extends Pipeline[F, T] with LeonComponent {

  // def run(ac: LeonContext)(v: F): T
}

trait SimpleLeonPhase[-F, +T] extends LeonPhase[F, T] {
  def apply(ctx: LeonContext, v: F): T

  def run(ctx: LeonContext, v: F): (LeonContext, T) = (ctx, apply(ctx, v))
}

abstract class TransformationPhase extends LeonPhase[Program, Program] {
  def apply(ctx: LeonContext, p: Program): Program

  override def run(ctx: LeonContext, p: Program) = {
    ctx.reporter.debug("Running transformation phase: " + name)(utils.DebugSectionLeon)
    (ctx, apply(ctx, p))
  }
}

abstract class UnitPhase[T] extends LeonPhase[T, T] {
  def apply(ctx: LeonContext, p: T): Unit

  override def run(ctx: LeonContext, p: T) = {
    ctx.reporter.debug("Running unit phase phase: " + name)(utils.DebugSectionLeon)
    apply(ctx, p)
    (ctx, p)
  }
}

case class NoopPhase[T]() extends LeonPhase[T, T] {
  val name = "noop"
  val description = "no-op"
  override def run(ctx: LeonContext, v: T) = (ctx, v)
}