diff options
| author | azidar | 2016-02-04 18:02:13 -0800 |
|---|---|---|
| committer | azidar | 2016-02-09 18:57:07 -0800 |
| commit | bf900917c50a440632dbcaae17bcfe9613d14452 (patch) | |
| tree | 09ca1e2b58bbfc7b32cfe88f1a5cbc70e954027f /src/main/scala/firrtl/Utils.scala | |
| parent | 69f0ac34b9fd81b9bca932d32b01c522781a64f6 (diff) | |
Added Lower Types.
Diffstat (limited to 'src/main/scala/firrtl/Utils.scala')
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 406e393c..b9fb49c6 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -27,7 +27,11 @@ object Utils { import scala.reflect._ def as[O: ClassTag]: Option[O] = x match { case o: O => Some(o) - case _ => None } } + case _ => None } + def typeof[O: ClassTag]: Boolean = x match { + case o: O => true + case _ => false } + } implicit def toWrappedExpression (x:Expression) = new WrappedExpression(x) def ceil_log2(x: BigInt): BigInt = (x-1).bitLength def ceil_log2(x: Int): Int = scala.math.ceil(scala.math.log(x) / scala.math.log(2)).toInt @@ -182,7 +186,9 @@ object Utils { case (w1,w2) => MaxWidth(Seq(w1,w2)) } } - if (equals(t1,t2)) { + val wt1 = new WrappedType(t1) + val wt2 = new WrappedType(t2) + if (wt1 == wt2) { (t1,t2) match { case (t1:UIntType,t2:UIntType) => UIntType(wmax(t1.width,t2.width)) case (t1:SIntType,t2:SIntType) => SIntType(wmax(t1.width,t2.width)) @@ -340,6 +346,12 @@ object Utils { case REVERSE => DEFAULT } } + def to_dir (g:Gender) : Direction = { + g match { + case MALE => INPUT + case FEMALE => OUTPUT + } + } def to_gender (d:Direction) : Gender = { d match { case INPUT => MALE @@ -414,10 +426,10 @@ object Utils { } def gender (e:Expression) : Gender = { e match { - case e:WRef => gender(e) - case e:WSubField => gender(e) - case e:WSubIndex => gender(e) - case e:WSubAccess => gender(e) + case e:WRef => e.gender + case e:WSubField => e.gender + case e:WSubIndex => e.gender + case e:WSubAccess => e.gender case e:PrimOp => MALE case e:UIntValue => MALE case e:SIntValue => MALE @@ -608,6 +620,29 @@ object Utils { case w => w } } + def stMap (f: String => String, c:Stmt) : Stmt = { + c match { + case (c:DefWire) => DefWire(c.info,f(c.name),c.tpe) + case (c:DefPoison) => DefPoison(c.info,f(c.name),c.tpe) + case (c:DefRegister) => DefRegister(c.info,f(c.name), c.tpe, c.clock, c.reset, c.init) + case (c:DefMemory) => DefMemory(c.info,f(c.name), c.data_type, c.depth, c.write_latency, c.read_latency, c.readers, c.writers, c.readwriters) + case (c:DefNode) => DefNode(c.info,f(c.name),c.value) + case (c:DefInstance) => DefInstance(c.info,f(c.name), c.module) + case (c) => c + } + } + def mapr (f: Width => Width, t:Type) : Type = { + def apply_t (t:Type) : Type = wMap(f,tMap(apply_t _,t)) + apply_t(t) + } + def mapr (f: Width => Width, s:Stmt) : Stmt = { + def apply_t (t:Type) : Type = mapr(f,t) + def apply_e (e:Expression) : Expression = + wMap(f,tMap(apply_t _,eMap(apply_e _,e))) + def apply_s (s:Stmt) : Stmt = + tMap(apply_t _,eMap(apply_e _,sMap(apply_s _,s))) + apply_s(s) + } val ONE = IntWidth(1) //def digits (s:String) : Boolean { // val digits = "0123456789" @@ -803,6 +838,7 @@ object Utils { val s = w match { case w:UnknownWidth => "" //"?" case w: IntWidth => s"<${w.width.toString}>" + case w: VarWidth => s"<${w.name}>" } s + debug(w) } |
