diff options
| author | jackkoenig | 2016-04-28 13:46:29 -0700 |
|---|---|---|
| committer | jackkoenig | 2016-05-03 16:56:52 -0700 |
| commit | c32b1d4a13bb0f1c35f1f4e074f4740a32755258 (patch) | |
| tree | 8ca484e85069c03d2096a0840ed37ef4f1a418ed /src | |
| parent | b60752795ea894c4152dfd5bd8069712d8541419 (diff) | |
Make style and spacing of Check Initialization more idiomatic Scala
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/passes/CheckInitialization.scala | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/main/scala/firrtl/passes/CheckInitialization.scala b/src/main/scala/firrtl/passes/CheckInitialization.scala index 3c0688a4..0982fdb6 100644 --- a/src/main/scala/firrtl/passes/CheckInitialization.scala +++ b/src/main/scala/firrtl/passes/CheckInitialization.scala @@ -31,56 +31,56 @@ import firrtl._ import firrtl.Utils._ import firrtl.Mappers._ -// Datastructures -import scala.collection.mutable.ArrayBuffer - -object CheckInitialization extends Pass with StanzaPass { - def name = "Check Initialization" - var mname = "" - class RefNotInitialized (info:Info, name:String) extends PassException(s"${info} : [module ${mname} Reference ${name} is not fully initialized.") - def run (c:Circuit): Circuit = { - val errors = ArrayBuffer[PassException]() - def check_init_m (m:InModule) : Unit = { - def get_name (e:Expression) : String = { - (e) match { - case (e:WRef) => e.name - case (e:WSubField) => get_name(e.exp) + "." + e.name - case (e:WSubIndex) => get_name(e.exp) + "[" + e.value + "]" - case (e) => error("Shouldn't be here"); "" - } - } - def has_voidQ (e:Expression) : Boolean = { - var void = false - def has_void (e:Expression) : Expression = { - (e) match { - case (e:WVoid) => void = true; e - case (e) => e map (has_void) - } - } - has_void(e) - void - } - def check_init_s (s:Stmt) : Stmt = { - (s) match { - case (s:Connect) => { - if (has_voidQ(s.exp)) errors += new RefNotInitialized(s.info,get_name(s.loc)) - s - } - case (s) => s map (check_init_s) - } - } - check_init_s(m.body) +object CheckInitialization extends Pass { + def name = "Check Initialization" + var mname = "" + class RefNotInitialized(info: Info, name: String) extends PassException(s"$info : [module $mname] Reference $name is not fully initialized.") + def run(c: Circuit): Circuit = { + val errors = collection.mutable.ArrayBuffer[PassException]() + def checkInitM(m: InModule): Unit = { + def getName(e: Expression): String = { + e match { + case e: WRef => e.name + case e: WSubField => getName(e.exp) + "." + e.name + case e: WSubIndex => getName(e.exp) + "[" + e.value + "]" + case e => + error("Shouldn't be here") + "" + } + } + def hasVoidQ(e: Expression): Boolean = { + var void = false + def hasVoid(e: Expression): Expression = { + e match { + case e: WVoid => + void = true + e + case e => e map hasVoid + } + } + hasVoid(e) + void } - - for (m <- c.modules) { - mname = m.name - (m) match { - case (m:InModule) => check_init_m(m) - case (m) => false - } + def checkInitS(s: Stmt): Stmt = { + s match { + case s: Connect => + if (hasVoidQ(s.exp)) errors += new RefNotInitialized(s.info, getName(s.loc)) + s + case s => s map checkInitS + } + } + checkInitS(m.body) + } + + c.modules foreach { m => + mname = m.name + m match { + case m: InModule => checkInitM(m) + case m => false } + } if (errors.nonEmpty) throw new PassExceptions(errors) c - } + } } |
