Skip to content

Commit

Permalink
Merge pull request #1426 from freechipsproject/1412-2
Browse files Browse the repository at this point in the history
Fix Double Elaboration Backportably
  • Loading branch information
seldridge authored May 6, 2020
2 parents 33cfe81 + 5e2ca44 commit e7b8e6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/main/scala/chisel3/stage/ChiselStage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class ChiselStage extends Stage with PreservesAll[Phase] {

val targets: Seq[Dependency[Phase]] =
Seq( Dependency[chisel3.stage.phases.Checks],
Dependency[chisel3.stage.phases.Elaborate],
Dependency[chisel3.stage.phases.AddImplicitOutputFile],
Dependency[chisel3.stage.phases.AddImplicitOutputAnnotationFile],
Dependency[chisel3.stage.phases.MaybeAspectPhase],
Dependency[chisel3.stage.phases.Emitter],
Dependency[chisel3.stage.phases.Convert],
Dependency[chisel3.stage.phases.MaybeFirrtlStage] )

final lazy val phaseManager = new PhaseManager(targets) {
override val wrappers = Seq( (a: Phase) => DeletedWrapper(a) )
}

def run(annotations: AnnotationSeq): AnnotationSeq = try {
new PhaseManager(targets) { override val wrappers = Seq( (a: Phase) => DeletedWrapper(a) ) }
.transformOrder
.map(firrtl.options.phases.DeletedWrapper(_))
.foldLeft(annotations)( (a, f) => f.transform(a) )
phaseManager.transform(annotations)
} catch {
case ce: ChiselException =>
val stackTrace = if (!view[ChiselOptions](annotations).printFullStackTrace) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/scala/chisel3/stage/phases/Emitter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ class Emitter extends Phase {
Dependency[AddImplicitOutputAnnotationFile],
Dependency[MaybeAspectPhase] )

override def invalidates(phase: Phase): Boolean = phase match {
case _: Elaborate => true
case _ => false
}
override def optionalPrerequisiteOf = Seq(Dependency[Convert])

override def invalidates(phase: Phase): Boolean = false

def transform(annotations: AnnotationSeq): AnnotationSeq = {
val copts = view[ChiselOptions](annotations)
Expand Down
13 changes: 13 additions & 0 deletions src/test/scala/chiselTests/stage/ChiselStageSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import chisel3.stage.ChiselStage
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import firrtl.options.Dependency

object ChiselStageSpec {

class Foo extends MultiIOModule {
Expand Down Expand Up @@ -57,4 +59,15 @@ class ChiselStageSpec extends AnyFlatSpec with Matchers {
ChiselStage.convert(new Foo)
}

behavior of "ChiselStage phase ordering"

it should "only run elaboration once" in new ChiselStageFixture {
info("Phase order is:\n" + stage.phaseManager.prettyPrint(" "))

val order = stage.phaseManager.flattenedTransformOrder.map(Dependency.fromTransform)

info("Elaborate only runs once")
exactly (1, order) should be (Dependency[chisel3.stage.phases.Elaborate])
}

}

0 comments on commit e7b8e6e

Please sign in to comment.