Skip to content

Commit 2f23702

Browse files
author
Oron Port
committed
Improve stage runner and match handling logic
- Update `MatchToIf` to nullify `DropUnreferencedAnons` stage - Modify `StageRunner` to pass done stages to single stage runner - Enhance stage execution tracking and dependency management
1 parent 4d37499 commit 2f23702

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

compiler/stages/src/main/scala/dfhdl/compiler/stages/MatchToIf.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import dfhdl.internals.*
1919
*/
2020
case object MatchToIf extends Stage:
2121
override def dependencies: List[Stage] = List(DropBinds)
22-
override def nullifies: Set[Stage] = Set(DFHDLUniqueNames)
22+
override def nullifies: Set[Stage] = Set(DFHDLUniqueNames, DropUnreferencedAnons)
2323
def matchFilter(mh: DFMatchHeader)(using getSet: MemberGetSet, co: CompilerOptions): Boolean =
2424
def composedPatternRemoval = mh.selectorRef.get.dfType match
2525
case _: ComposedDFType => true

compiler/stages/src/main/scala/dfhdl/compiler/stages/StageRunner.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ class StageRunner(using co: CompilerOptions, po: PrinterOptions) extends LogSupp
1717
logger.setLogLevel(LogLevel.INFO)
1818
def logWarn(): Unit =
1919
logger.setLogLevel(LogLevel.WARN)
20-
private def runSingleStage(stage: Stage)(designDB: DB): DB =
20+
private def runSingleStage(stage: Stage, done: Set[Stage])(designDB: DB): DB =
2121
info(s"Running stage ${stage.typeName}....")
2222
val ret = stage.transform(designDB)(using designDB.getSet)
2323
info(s"Finished stage ${stage.typeName}")
2424
if (
2525
logger.getLogLevel >= LogLevel.DEBUG && stage != SanityCheck &&
2626
!stage.isInstanceOf[NoCheckStage]
2727
)
28-
if (stage.nullifies.contains(DropUnreferencedAnons))
28+
if (!done.contains(DropUnreferencedAnons))
2929
ret.dropUnreferencedAnons.sanityCheck
3030
else
3131
ret.sanityCheck
@@ -52,10 +52,12 @@ class StageRunner(using co: CompilerOptions, po: PrinterOptions) extends LogSupp
5252
else if (done.contains(head)) run(next, done)(designDB)
5353
// all the dependencies of head are done, so we can run the head stage
5454
else if ((head.depSet -- done).isEmpty)
55-
// running the stage
56-
val resultDB = runSingleStage(head)(designDB)
5755
// the stage is done, so we add it to the done set and remove the nullified stages
58-
run(next, done + head -- head.nullifies)(resultDB)
56+
val updatedDone = done + head -- head.nullifies
57+
// running the stage (updatedDone set is given only for tracing purposes)
58+
val resultDB = runSingleStage(head, updatedDone)(designDB)
59+
// running the next stage
60+
run(next, updatedDone)(resultDB)
5961
// still need to wait for dependencies, so we add them to the deps queue in a sorted order
6062
// (this is just to preserve consistency in compilation order).
6163
else run(head.dependencies ++ deps, done)(designDB)

0 commit comments

Comments
 (0)