aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Waterman2016-04-21 14:29:44 -0700
committerjackkoenig2016-04-21 15:54:02 -0700
commitec32c852b57a42c7741f8ae27d59c21fcdb86a82 (patch)
tree1ade1c970813a59007313f9d8a109311d3e683d9 /src
parentd2268e388c16481b3716619f2f27e88909f37914 (diff)
Avoid Lint errors connecting wide signals to narrow ones
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/Compiler.scala2
-rw-r--r--src/main/scala/firrtl/passes/Passes.scala20
2 files changed, 20 insertions, 2 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala
index 69450a67..fda4b7e3 100644
--- a/src/main/scala/firrtl/Compiler.scala
+++ b/src/main/scala/firrtl/Compiler.scala
@@ -73,11 +73,11 @@ object VerilogCompiler extends Compiler {
RemoveAccesses,
ExpandWhens,
CheckInitialization,
- Legalize,
ResolveKinds,
InferTypes,
ResolveGenders,
InferWidths,
+ Legalize,
LowerTypes,
ResolveKinds,
InferTypes,
diff --git a/src/main/scala/firrtl/passes/Passes.scala b/src/main/scala/firrtl/passes/Passes.scala
index f7526897..bfe2a3cc 100644
--- a/src/main/scala/firrtl/passes/Passes.scala
+++ b/src/main/scala/firrtl/passes/Passes.scala
@@ -1159,6 +1159,18 @@ object Legalize extends Pass {
}
case _ => e
}
+ def legalizeConnect(c: Connect): Stmt = {
+ val t = tpe(c.loc)
+ val w = long_BANG(t)
+ if (w >= long_BANG(tpe(c.exp))) c
+ else {
+ val newType = t match {
+ case _: UIntType => UIntType(IntWidth(w))
+ case _: SIntType => SIntType(IntWidth(w))
+ }
+ Connect(c.info, c.loc, DoPrim(BITS_SELECT_OP, Seq(c.exp), Seq(w-1, 0), newType))
+ }
+ }
def run (c: Circuit): Circuit = {
def legalizeE (e: Expression): Expression = {
e map (legalizeE) match {
@@ -1166,7 +1178,13 @@ object Legalize extends Pass {
case e => e
}
}
- def legalizeS (s: Stmt): Stmt = s map (legalizeS) map (legalizeE)
+ def legalizeS (s: Stmt): Stmt = {
+ val legalizedStmt = s match {
+ case c: Connect => legalizeConnect(c)
+ case _ => s
+ }
+ legalizedStmt map legalizeS map legalizeE
+ }
def legalizeM (m: Module): Module = m map (legalizeS)
Circuit(c.info, c.modules.map(legalizeM), c.main)
}