diff options
| author | chick | 2020-08-14 19:47:53 -0700 |
|---|---|---|
| committer | Jack Koenig | 2020-08-14 19:47:53 -0700 |
| commit | 6fc742bfaf5ee508a34189400a1a7dbffe3f1cac (patch) | |
| tree | 2ed103ee80b0fba613c88a66af854ae9952610ce /src/main/scala/tutorial/lesson1-circuit-traversal | |
| parent | b516293f703c4de86397862fee1897aded2ae140 (diff) | |
All of src/ formatted with scalafmt
Diffstat (limited to 'src/main/scala/tutorial/lesson1-circuit-traversal')
| -rw-r--r-- | src/main/scala/tutorial/lesson1-circuit-traversal/AnalyzeCircuit.scala | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/main/scala/tutorial/lesson1-circuit-traversal/AnalyzeCircuit.scala b/src/main/scala/tutorial/lesson1-circuit-traversal/AnalyzeCircuit.scala index 48427af8..72f50461 100644 --- a/src/main/scala/tutorial/lesson1-circuit-traversal/AnalyzeCircuit.scala +++ b/src/main/scala/tutorial/lesson1-circuit-traversal/AnalyzeCircuit.scala @@ -4,9 +4,9 @@ package tutorial package lesson1 // Compiler Infrastructure -import firrtl.{Transform, LowForm, CircuitState, Utils} +import firrtl.{CircuitState, LowForm, Transform, Utils} // Firrtl IR classes -import firrtl.ir.{DefModule, Statement, Expression, Mux} +import firrtl.ir.{DefModule, Expression, Mux, Statement} // Map functions import firrtl.Mappers._ // Scala's mutable collections @@ -26,11 +26,11 @@ class Ledger { private val modules = mutable.Set[String]() private val moduleMuxMap = mutable.Map[String, Int]() def foundMux(): Unit = moduleName match { - case None => sys.error("Module name not defined in Ledger!") + case None => sys.error("Module name not defined in Ledger!") case Some(name) => moduleMuxMap(name) = moduleMuxMap.getOrElse(name, 0) + 1 } def getModuleName: String = moduleName match { - case None => Utils.error("Module name not defined in Ledger!") + case None => Utils.error("Module name not defined in Ledger!") case Some(name) => name } def setModuleName(myName: String): Unit = { @@ -38,9 +38,9 @@ class Ledger { moduleName = Some(myName) } def serialize: String = { - modules map { myName => + modules.map { myName => s"$myName => ${moduleMuxMap.getOrElse(myName, 0)} muxes!" - } mkString "\n" + }.mkString("\n") } } @@ -68,8 +68,10 @@ class Ledger { * - https://github.com/ucb-bar/firrtl/wiki/Common-Pass-Idioms */ class AnalyzeCircuit extends Transform { + /** Requires the [[firrtl.ir.Circuit Circuit]] form to be "low" */ def inputForm = LowForm + /** Indicates the output [[firrtl.ir.Circuit Circuit]] form to be "low" */ def outputForm = LowForm @@ -88,7 +90,7 @@ class AnalyzeCircuit extends Transform { * - "map" - classic functional programming concept * - discard the returned new [[firrtl.ir.Circuit Circuit]] because circuit is unmodified */ - circuit map walkModule(ledger) + circuit.map(walkModule(ledger)) // Print our ledger println(ledger.serialize) @@ -106,7 +108,7 @@ class AnalyzeCircuit extends Transform { * - return the new [[firrtl.ir.DefModule DefModule]] (in this case, its identical to m) * - if m does not contain [[firrtl.ir.Statement Statement]], map returns m. */ - m map walkStatement(ledger) + m.map(walkStatement(ledger)) } /** Deeply visits every [[firrtl.ir.Statement Statement]] and [[firrtl.ir.Expression Expression]] in s. */ @@ -116,13 +118,13 @@ class AnalyzeCircuit extends Transform { * - discard the new [[firrtl.ir.Statement Statement]] (in this case, its identical to s) * - if s does not contain [[firrtl.ir.Expression Expression]], map returns s. */ - s map walkExpression(ledger) + s.map(walkExpression(ledger)) /* Execute the function walkStatement(ledger) on every [[firrtl.ir.Statement Statement]] in s. * - return the new [[firrtl.ir.Statement Statement]] (in this case, its identical to s) * - if s does not contain [[firrtl.ir.Statement Statement]], map returns s. */ - s map walkStatement(ledger) + s.map(walkStatement(ledger)) } /** Deeply visits every [[firrtl.ir.Expression Expression]] in e. @@ -135,7 +137,7 @@ class AnalyzeCircuit extends Transform { * - return the new [[firrtl.ir.Expression Expression]] (in this case, its identical to e) * - if s does not contain [[firrtl.ir.Expression Expression]], map returns e. */ - val visited = e map walkExpression(ledger) + val visited = e.map(walkExpression(ledger)) visited match { // If e is a [[firrtl.ir.Mux Mux]], increment our ledger and return e. |
