aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/WIR.scala
diff options
context:
space:
mode:
authorazidar2016-02-04 18:02:13 -0800
committerazidar2016-02-09 18:57:07 -0800
commitbf900917c50a440632dbcaae17bcfe9613d14452 (patch)
tree09ca1e2b58bbfc7b32cfe88f1a5cbc70e954027f /src/main/scala/firrtl/WIR.scala
parent69f0ac34b9fd81b9bca932d32b01c522781a64f6 (diff)
Added Lower Types.
Diffstat (limited to 'src/main/scala/firrtl/WIR.scala')
-rw-r--r--src/main/scala/firrtl/WIR.scala101
1 files changed, 99 insertions, 2 deletions
diff --git a/src/main/scala/firrtl/WIR.scala b/src/main/scala/firrtl/WIR.scala
index 35fcb93a..26e3a131 100644
--- a/src/main/scala/firrtl/WIR.scala
+++ b/src/main/scala/firrtl/WIR.scala
@@ -69,6 +69,103 @@ case class MinusWidth(arg1:Width,arg2:Width) extends Width
case class MaxWidth(args:Seq[Width]) extends Width
case class MinWidth(args:Seq[Width]) extends Width
case class ExpWidth(arg1:Width) extends Width
-//case class IntWidth(width: BigInt) extends Width
-//case object UnknownWidth extends Width
+
+class WrappedType (val t:Type) {
+ def wt (tx:Type) = new WrappedType(tx)
+ override def equals (o:Any) : Boolean = {
+ o match {
+ case (t2:WrappedType) => {
+ (t,t2.t) match {
+ case (t1:UIntType,t2:UIntType) => true
+ case (t1:SIntType,t2:SIntType) => true
+ case (t1:ClockType,t2:ClockType) => true
+ case (t1:VectorType,t2:VectorType) => (wt(t1.tpe) == wt(t2.tpe) && t1.size == t2.size)
+ case (t1:BundleType,t2:BundleType) => {
+ var ret = true
+ (t1.fields,t2.fields).zipped.foreach{ (f1,f2) => {
+ if (f1.flip != f2.flip) ret = false
+ if (f1.name != f2.name) ret = false
+ if (wt(f1.tpe) != wt(f2.tpe)) ret = false
+ }}
+ ret
+ }
+ case (t1,t2) => false
+ }
+ }
+ case _ => false
+ }
+ }
+}
+class WrappedWidth (val w:Width) {
+ override def toString = {
+ w match {
+ case (w:VarWidth) => w.name
+ case (w:MaxWidth) => "max(" + w.args.map(_.toString).reduce(_ + _) + ")"
+ case (w:MinWidth) => "min(" + w.args.map(_.toString).reduce(_ + _) + ")"
+ case (w:PlusWidth) => "(" + w.arg1 + " + " + w.arg2 + ")"
+ case (w:MinusWidth) => "(" + w.arg1 + " - " + w.arg2 + ")"
+ case (w:ExpWidth) => "exp(" + w.arg1 + ")"
+ case (w:IntWidth) => w.width.toString
+ case (w:UnknownWidth) => "?"
+ }
+ }
+ def eq (w1:Width,w2:Width) : Boolean = {
+ (new WrappedWidth(w1)) == (new WrappedWidth(w2))
+ }
+ override def equals (o:Any) : Boolean = {
+ o match {
+ case (w2:WrappedWidth) => {
+ (w,w2.w) match {
+ case (w1:VarWidth,w2:VarWidth) => w1.name.equals(w2.name)
+ case (w1:MaxWidth,w2:MaxWidth) => {
+ var ret = true
+ if (w1.args.size != w2.args.size) ret = false
+ else {
+ for (a1 <- w1.args) {
+ var found = false
+ for (a2 <- w2.args) { if (eq(a1,a2)) found = true }
+ if (found == false) ret = false
+ }
+ }
+ ret
+ }
+ case (w1:MinWidth,w2:MinWidth) => {
+ var ret = true
+ if (w1.args.size != w2.args.size) ret = false
+ else {
+ for (a1 <- w1.args) {
+ var found = false
+ for (a2 <- w2.args) { if (eq(a1,a2)) found = true }
+ if (found == false) ret = false
+ }
+ }
+ ret
+ }
+ case (w1:IntWidth,w2:IntWidth) => w1.width == w2.width
+ case (w1:PlusWidth,w2:PlusWidth) =>
+ (w1.arg1 == w2.arg1 && w1.arg2 == w2.arg2) || (w1.arg1 == w2.arg2 && w1.arg2 == w2.arg1)
+ case (w1:MinusWidth,w2:MinusWidth) =>
+ (w1.arg1 == w2.arg1 && w1.arg2 == w2.arg2) || (w1.arg1 == w2.arg2 && w1.arg2 == w2.arg1)
+ case (w1:ExpWidth,w2:ExpWidth) => w1.arg1 == w2.arg1
+ case (w1:UnknownWidth,w2:UnknownWidth) => true
+ case (w1,w2) => false
+ }
+ }
+ case _ => false
+ }
+ }
+}
+
+trait Constraint
+class WGeq(val loc:Width,val exp:Width) extends Constraint {
+ override def toString = {
+ val wloc = new WrappedWidth(loc)
+ val wexp = new WrappedWidth(exp)
+ wloc.toString + " >= " + wexp.toString
+ }
+}
+object WGeq {
+ def apply (loc:Width,exp:Width) = new WGeq(loc,exp)
+}
+