diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/IR.scala | 10 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Serialize.scala | 8 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 102 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Visitor.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/Checks.scala | 14 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/ExpandWhens.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/Passes.scala | 44 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/Uniquify.scala | 14 |
8 files changed, 99 insertions, 97 deletions
diff --git a/src/main/scala/firrtl/IR.scala b/src/main/scala/firrtl/IR.scala index 08be0fe8..0f4630b8 100644 --- a/src/main/scala/firrtl/IR.scala +++ b/src/main/scala/firrtl/IR.scala @@ -147,11 +147,13 @@ trait Width extends AST { case class IntWidth(width: BigInt) extends Width case class UnknownWidth() extends Width -trait Flip extends AST -case object DEFAULT extends Flip -case object REVERSE extends Flip +/** Orientation of [[Field]] */ +abstract class Orientation extends AST +case object Default extends Orientation +case object Flip extends Orientation -case class Field(name: String, flip: Flip, tpe: Type) extends AST with HasName +/** Field of [[BundleType]] */ +case class Field(name: String, flip: Orientation, tpe: Type) extends AST with HasName abstract class Type extends AST abstract class GroundType extends Type { diff --git a/src/main/scala/firrtl/Serialize.scala b/src/main/scala/firrtl/Serialize.scala index e46ce111..c8ea9e0f 100644 --- a/src/main/scala/firrtl/Serialize.scala +++ b/src/main/scala/firrtl/Serialize.scala @@ -38,7 +38,7 @@ private object Serialize { case r: Expression => ser.serialize(r) case r: Stmt => ser.serialize(r) case r: Width => ser.serialize(r) - case r: Flip => ser.serialize(r) + case r: Orientation => ser.serialize(r) case r: Field => ser.serialize(r) case r: Type => ser.serialize(r) case r: Direction => ser.serialize(r) @@ -169,10 +169,10 @@ class Serialize { } } - def serialize(f: Flip): String = { + def serialize(f: Orientation): String = { f match { - case REVERSE => "flip " - case DEFAULT => "" + case Flip => "flip " + case Default => "" } } diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index a85dedb5..9d8b9360 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -147,7 +147,7 @@ object Utils extends LazyLogging { } } } - def get_flip (t:Type, i:Int, f:Flip) : Flip = { + def get_flip (t:Type, i:Int, f:Orientation) : Orientation = { if (i >= get_size(t)) error("Shouldn't be here") val x = t match { case (t:UIntType) => f @@ -155,7 +155,7 @@ object Utils extends LazyLogging { case ClockType => f case (t:BundleType) => { var n = i - var ret:Option[Flip] = None + var ret:Option[Orientation] = None t.fields.foreach { x => { if (n < get_size(x.tpe)) { ret match { @@ -164,11 +164,11 @@ object Utils extends LazyLogging { } } else { n = n - get_size(x.tpe) } }} - ret.asInstanceOf[Some[Flip]].get + ret.asInstanceOf[Some[Orientation]].get } case (t:VectorType) => { var n = i - var ret:Option[Flip] = None + var ret:Option[Orientation] = None for (j <- 0 until t.size) { if (n < get_size(t.tpe)) { ret = Some(get_flip(t.tpe,n,f)) @@ -176,7 +176,7 @@ object Utils extends LazyLogging { n = n - get_size(t.tpe) } } - ret.asInstanceOf[Some[Flip]].get + ret.asInstanceOf[Some[Orientation]].get } } x @@ -302,7 +302,7 @@ object Utils extends LazyLogging { case (t) => 1 } } - def get_valid_points (t1:Type,t2:Type,flip1:Flip,flip2:Flip) : Seq[(Int,Int)] = { + def get_valid_points (t1:Type, t2:Type, flip1:Orientation, flip2:Orientation) : Seq[(Int,Int)] = { //;println_all(["Inside with t1:" t1 ",t2:" t2 ",f1:" flip1 ",f2:" flip2]) (t1,t2) match { case (t1:UIntType,t2:UIntType) => if (flip1 == flip2) Seq((0, 0)) else Seq() @@ -360,10 +360,10 @@ object Utils extends LazyLogging { case Input => Output } } - def swap (f:Flip) : Flip = { + def swap (f:Orientation) : Orientation = { f match { - case DEFAULT => REVERSE - case REVERSE => DEFAULT + case Default => Flip + case Flip => Default } } def to_dir (g:Gender) : Direction = { @@ -378,25 +378,25 @@ object Utils extends LazyLogging { case Output => FEMALE } } - def toGender(f: Flip): Gender = f match { - case DEFAULT => FEMALE - case REVERSE => MALE + def toGender(f: Orientation): Gender = f match { + case Default => FEMALE + case Flip => MALE } - def toFlip(g: Gender): Flip = g match { - case MALE => REVERSE - case FEMALE => DEFAULT + def toFlip(g: Gender): Orientation = g match { + case MALE => Flip + case FEMALE => Default } - def field_flip (v:Type,s:String) : Flip = { + def field_flip (v:Type,s:String) : Orientation = { v match { case v:BundleType => { val ft = v.fields.find {p => p.name == s} ft match { case ft:Some[Field] => ft.get.flip - case ft => DEFAULT + case ft => Default } } - case v => DEFAULT + case v => Default } } def get_field (v:Type,s:String) : Field = { @@ -405,17 +405,17 @@ object Utils extends LazyLogging { val ft = v.fields.find {p => p.name == s} ft match { case ft:Some[Field] => ft.get - case ft => error("Shouldn't be here"); Field("blah",DEFAULT,UnknownType) + case ft => error("Shouldn't be here"); Field("blah",Default,UnknownType) } } - case v => error("Shouldn't be here"); Field("blah",DEFAULT,UnknownType) + case v => error("Shouldn't be here"); Field("blah",Default,UnknownType) } } - def times (flip:Flip,d:Direction) : Direction = times(flip, d) - def times (d:Direction,flip:Flip) : Direction = { + def times (flip:Orientation, d:Direction) : Direction = times(flip, d) + def times (d:Direction,flip:Orientation) : Direction = { flip match { - case DEFAULT => d - case REVERSE => swap(d) + case Default => d + case Flip => swap(d) } } def times (g: Gender, d: Direction): Direction = times(d, g) @@ -424,17 +424,17 @@ object Utils extends LazyLogging { case MALE => swap(d) // MALE == INPUT == REVERSE } - def times (g:Gender,flip:Flip) : Gender = times(flip, g) - def times (flip:Flip,g:Gender) : Gender = { + def times (g:Gender,flip:Orientation) : Gender = times(flip, g) + def times (flip:Orientation, g:Gender) : Gender = { flip match { - case DEFAULT => g - case REVERSE => swap(g) + case Default => g + case Flip => swap(g) } } - def times (f1:Flip,f2:Flip) : Flip = { + def times (f1:Orientation, f2:Orientation) : Orientation = { f2 match { - case DEFAULT => f1 - case REVERSE => swap(f1) + case Default => f1 + case Flip => swap(f1) } } @@ -525,22 +525,22 @@ object Utils extends LazyLogging { case s:DefNode => tpe(s.value) case s:DefMemory => { val depth = s.depth - val addr = Field("addr",DEFAULT,UIntType(IntWidth(scala.math.max(ceil_log2(depth), 1)))) - val en = Field("en",DEFAULT,BoolType()) - val clk = Field("clk",DEFAULT,ClockType) - val def_data = Field("data",DEFAULT,s.data_type) - val rev_data = Field("data",REVERSE,s.data_type) - val mask = Field("mask",DEFAULT,create_mask(s.data_type)) - val wmode = Field("wmode",DEFAULT,UIntType(IntWidth(1))) - val rdata = Field("rdata",REVERSE,s.data_type) + val addr = Field("addr",Default,UIntType(IntWidth(scala.math.max(ceil_log2(depth), 1)))) + val en = Field("en",Default,BoolType()) + val clk = Field("clk",Default,ClockType) + val def_data = Field("data",Default,s.data_type) + val rev_data = Field("data",Flip,s.data_type) + val mask = Field("mask",Default,create_mask(s.data_type)) + val wmode = Field("wmode",Default,UIntType(IntWidth(1))) + val rdata = Field("rdata",Flip,s.data_type) val read_type = BundleType(Seq(rev_data,addr,en,clk)) val write_type = BundleType(Seq(def_data,mask,addr,en,clk)) val readwrite_type = BundleType(Seq(wmode,rdata,def_data,mask,addr,en,clk)) val mem_fields = ArrayBuffer[Field]() - s.readers.foreach {x => mem_fields += Field(x,REVERSE,read_type)} - s.writers.foreach {x => mem_fields += Field(x,REVERSE,write_type)} - s.readwriters.foreach {x => mem_fields += Field(x,REVERSE,readwrite_type)} + s.readers.foreach {x => mem_fields += Field(x,Flip,read_type)} + s.writers.foreach {x => mem_fields += Field(x,Flip,write_type)} + s.readwriters.foreach {x => mem_fields += Field(x,Flip,readwrite_type)} BundleType(mem_fields) } case s:DefInstance => UnknownType @@ -742,18 +742,18 @@ object Utils extends LazyLogging { } } - implicit class FlipUtils(f: Flip) { - def flip(): Flip = { + implicit class FlipUtils(f: Orientation) { + def flip(): Orientation = { f match { - case REVERSE => DEFAULT - case DEFAULT => REVERSE + case Flip => Default + case Default => Flip } } def toDirection(): Direction = { f match { - case DEFAULT => Output - case REVERSE => Input + case Default => Output + case Flip => Input } } } @@ -788,10 +788,10 @@ object Utils extends LazyLogging { } implicit class DirectionUtils(d: Direction) { - def toFlip(): Flip = { + def toFlip(): Orientation = { d match { - case Input => REVERSE - case Output => DEFAULT + case Input => Flip + case Output => Default } } } diff --git a/src/main/scala/firrtl/Visitor.scala b/src/main/scala/firrtl/Visitor.scala index 39e5c876..e17f0213 100644 --- a/src/main/scala/firrtl/Visitor.scala +++ b/src/main/scala/firrtl/Visitor.scala @@ -139,7 +139,7 @@ class Visitor(infoMode: InfoMode) extends FIRRTLBaseVisitor[AST] } private def visitField[AST](ctx: FIRRTLParser.FieldContext): Field = { - val flip = if(ctx.getChild(0).getText == "flip") REVERSE else DEFAULT + val flip = if(ctx.getChild(0).getText == "flip") Flip else Default Field((ctx.id.getText), flip, visitType(ctx.`type`)) } diff --git a/src/main/scala/firrtl/passes/Checks.scala b/src/main/scala/firrtl/passes/Checks.scala index 88ba6ab2..0857382b 100644 --- a/src/main/scala/firrtl/passes/Checks.scala +++ b/src/main/scala/firrtl/passes/Checks.scala @@ -69,7 +69,7 @@ object CheckHighForm extends Pass with LazyLogging { t map (findFlip) match { case t: BundleType => { for (f <- t.fields) { - if (f.flip == REVERSE) has = true + if (f.flip == Flip) has = true } t } @@ -366,7 +366,7 @@ object CheckTypes extends Pass with LazyLogging { case (t:BundleType) => { var p = true for (x <- t.fields ) { - if (x.flip == REVERSE) p = false + if (x.flip == Flip) p = false if (!passive(x.tpe)) p = false } p @@ -420,7 +420,7 @@ object CheckTypes extends Pass with LazyLogging { e } - def bulk_equals (t1: Type, t2: Type, flip1: Flip, flip2: Flip): Boolean = { + def bulk_equals (t1: Type, t2: Type, flip1: Orientation, flip2: Orientation): Boolean = { //;println_all(["Inside with t1:" t1 ",t2:" t2 ",f1:" flip1 ",f2:" flip2]) (t1,t2) match { case (ClockType, ClockType) => flip1 == flip2 @@ -448,7 +448,7 @@ object CheckTypes extends Pass with LazyLogging { s map (check_types_e(get_info(s))) match { case (s:Connect) => if (wt(tpe(s.loc)) != wt(tpe(s.exp))) errors.append(new InvalidConnect(s.info, s.loc.serialize, s.exp.serialize)) case (s:DefRegister) => if (wt(s.tpe) != wt(tpe(s.init))) errors.append(new InvalidRegInit(s.info)) - case (s:BulkConnect) => if (!bulk_equals(tpe(s.loc),tpe(s.exp),DEFAULT,DEFAULT) ) errors.append(new InvalidConnect(s.info, s.loc.serialize, s.exp.serialize)) + case (s:BulkConnect) => if (!bulk_equals(tpe(s.loc),tpe(s.exp),Default,Default) ) errors.append(new InvalidConnect(s.info, s.loc.serialize, s.exp.serialize)) case (s:Stop) => { if (wt(tpe(s.clk)) != wt(ClockType) ) errors.append(new ReqClk(s.info)) if (wt(tpe(s.en)) != wt(ut()) ) errors.append(new EnNotUInt(s.info)) @@ -517,7 +517,7 @@ object CheckGenders extends Pass { val kindx = get_kind(e) def flipQ (t:Type) : Boolean = { var fQ = false - def flip_rec (t:Type,f:Flip) : Type = { + def flip_rec (t:Type,f:Orientation) : Type = { (t) match { case (t:BundleType) => { for (field <- t.fields) { @@ -525,11 +525,11 @@ object CheckGenders extends Pass { } } case (t:VectorType) => flip_rec(t.tpe,f) - case (t) => if (f == REVERSE) fQ = true + case (t) => if (f == Flip) fQ = true } t } - flip_rec(t,DEFAULT) + flip_rec(t,Default) fQ } diff --git a/src/main/scala/firrtl/passes/ExpandWhens.scala b/src/main/scala/firrtl/passes/ExpandWhens.scala index d68b1eaa..1dac5e17 100644 --- a/src/main/scala/firrtl/passes/ExpandWhens.scala +++ b/src/main/scala/firrtl/passes/ExpandWhens.scala @@ -59,7 +59,7 @@ object ExpandWhens extends Pass { hashx } private def getFemaleRefs(n: String, t: Type, g: Gender): Seq[Expression] = { - def getGender(t: Type, i: Int, g: Gender): Gender = times(g, get_flip(t, i, DEFAULT)) + def getGender(t: Type, i: Int, g: Gender): Gender = times(g, get_flip(t, i, Default)) val exps = create_exps(WRef(n, t, ExpKind(), g)) val expsx = ArrayBuffer[Expression]() for (j <- 0 until exps.size) { diff --git a/src/main/scala/firrtl/passes/Passes.scala b/src/main/scala/firrtl/passes/Passes.scala index f9a79f54..0243c6cd 100644 --- a/src/main/scala/firrtl/passes/Passes.scala +++ b/src/main/scala/firrtl/passes/Passes.scala @@ -254,8 +254,8 @@ object ResolveGenders extends Pass { case e:WSubField => { val expx = field_flip(tpe(e.exp),e.name) match { - case DEFAULT => resolve_e(g)(e.exp) - case REVERSE => resolve_e(swap(g))(e.exp) + case Default => resolve_e(g)(e.exp) + case Flip => resolve_e(swap(g))(e.exp) } WSubField(expx,e.name,e.tpe,g) } @@ -542,7 +542,7 @@ object InferWidths extends Pass { def run (c:Circuit): Circuit = { val v = ArrayBuffer[WGeq]() def constrain (w1:Width,w2:Width) : Unit = v += WGeq(w1,w2) - def get_constraints_t (t1:Type,t2:Type,f:Flip) : Unit = { + def get_constraints_t (t1:Type,t2:Type,f:Orientation) : Unit = { (t1,t2) match { case (t1:UIntType,t2:UIntType) => constrain(t1.width,t2.width) case (t1:SIntType,t2:SIntType) => constrain(t1.width,t2.width) @@ -566,23 +566,23 @@ object InferWidths extends Pass { for (i <- 0 until n) { val locx = ce_loc(i) val expx = ce_exp(i) - get_flip(tpe(s.loc),i,DEFAULT) match { - case DEFAULT => constrain(width_BANG(locx),width_BANG(expx)) - case REVERSE => constrain(width_BANG(expx),width_BANG(locx)) }} + get_flip(tpe(s.loc),i,Default) match { + case Default => constrain(width_BANG(locx),width_BANG(expx)) + case Flip => constrain(width_BANG(expx),width_BANG(locx)) }} s } case (s:BulkConnect) => { - val ls = get_valid_points(tpe(s.loc),tpe(s.exp),DEFAULT,DEFAULT) + val ls = get_valid_points(tpe(s.loc),tpe(s.exp),Default,Default) for (x <- ls) { val locx = create_exps(s.loc)(x._1) val expx = create_exps(s.exp)(x._2) - get_flip(tpe(s.loc),x._1,DEFAULT) match { - case DEFAULT => constrain(width_BANG(locx),width_BANG(expx)) - case REVERSE => constrain(width_BANG(expx),width_BANG(locx)) }} + get_flip(tpe(s.loc),x._1,Default) match { + case Default => constrain(width_BANG(locx),width_BANG(expx)) + case Flip => constrain(width_BANG(expx),width_BANG(locx)) }} s } case (s:DefRegister) => { constrain(width_BANG(s.reset),ONE) constrain(ONE,width_BANG(s.reset)) - get_constraints_t(s.tpe,tpe(s.init),DEFAULT) + get_constraints_t(s.tpe,tpe(s.init),Default) s } case (s:Conditionally) => { v += WGeq(width_BANG(s.pred),ONE) @@ -708,25 +708,25 @@ object ExpandConnects extends Pass { for (i <- 0 until n) { val locx = locs(i) val expx = exps(i) - val sx = get_flip(tpe(s.loc),i,DEFAULT) match { - case DEFAULT => Connect(s.info,locx,expx) - case REVERSE => Connect(s.info,expx,locx) + val sx = get_flip(tpe(s.loc),i,Default) match { + case Default => Connect(s.info,locx,expx) + case Flip => Connect(s.info,expx,locx) } connects += sx } Begin(connects) } case (s:BulkConnect) => { - val ls = get_valid_points(tpe(s.loc),tpe(s.exp),DEFAULT,DEFAULT) + val ls = get_valid_points(tpe(s.loc),tpe(s.exp),Default,Default) val connects = ArrayBuffer[Stmt]() val locs = create_exps(s.loc) val exps = create_exps(s.exp) ls.foreach { x => { val locx = locs(x._1) val expx = exps(x._2) - val sx = get_flip(tpe(s.loc),x._1,DEFAULT) match { - case DEFAULT => Connect(s.info,locx,expx) - case REVERSE => Connect(s.info,expx,locx) + val sx = get_flip(tpe(s.loc),x._1,Default) match { + case Default => Connect(s.info,locx,expx) + case Flip => Connect(s.info,expx,locx) } connects += sx }} @@ -1037,9 +1037,9 @@ object CInferTypes extends Pass { } def to_field (p:Port) : Field = { - if (p.direction == Output) Field(p.name,DEFAULT,p.tpe) - else if (p.direction == Input) Field(p.name,REVERSE,p.tpe) - else error("Shouldn't be here"); Field(p.name,REVERSE,p.tpe) + if (p.direction == Output) Field(p.name,Default,p.tpe) + else if (p.direction == Input) Field(p.name,Flip,p.tpe) + else error("Shouldn't be here"); Field(p.name,Flip,p.tpe) } def module_type (m:DefModule) : Type = BundleType(m.ports.map(p => to_field(p))) def field_type (v:Type,s:String) : Type = { @@ -1405,7 +1405,7 @@ object RemoveCHIRRTL extends Pass { val rocx = remove_chirrtl_e(MALE)(s.exp) stmts += BulkConnect(s.info,locx,rocx) if (has_write_mport != false) { - val ls = get_valid_points(tpe(s.loc),tpe(s.exp),DEFAULT,DEFAULT) + val ls = get_valid_points(tpe(s.loc),tpe(s.exp),Default,Default) val locs = create_exps(get_mask(s.loc)) for (x <- ls ) { val locx = locs(x._1) diff --git a/src/main/scala/firrtl/passes/Uniquify.scala b/src/main/scala/firrtl/passes/Uniquify.scala index 9f28f3fa..d0442f37 100644 --- a/src/main/scala/firrtl/passes/Uniquify.scala +++ b/src/main/scala/firrtl/passes/Uniquify.scala @@ -223,25 +223,25 @@ object Uniquify extends Pass { def stmtToType(s: Stmt)(implicit sinfo: Info, mname: String): BundleType = { // Recursive helper def recStmtToType(s: Stmt): Seq[Field] = s match { - case s: DefWire => Seq(Field(s.name, DEFAULT, s.tpe)) - case s: DefRegister => Seq(Field(s.name, DEFAULT, s.tpe)) - case s: WDefInstance => Seq(Field(s.name, DEFAULT, s.tpe)) + case s: DefWire => Seq(Field(s.name, Default, s.tpe)) + case s: DefRegister => Seq(Field(s.name, Default, s.tpe)) + case s: WDefInstance => Seq(Field(s.name, Default, s.tpe)) case s: DefMemory => s.data_type match { case (_: UIntType | _: SIntType) => - Seq(Field(s.name, DEFAULT, get_type(s))) + Seq(Field(s.name, Default, get_type(s))) case tpe: BundleType => val newFields = tpe.fields map ( f => DefMemory(s.info, f.name, f.tpe, s.depth, s.write_latency, s.read_latency, s.readers, s.writers, s.readwriters) ) flatMap (recStmtToType) - Seq(Field(s.name, DEFAULT, BundleType(newFields))) + Seq(Field(s.name, Default, BundleType(newFields))) case tpe: VectorType => val newFields = (0 until tpe.size) map ( i => s.copy(name = i.toString, data_type = tpe.tpe) ) flatMap (recStmtToType) - Seq(Field(s.name, DEFAULT, BundleType(newFields))) + Seq(Field(s.name, Default, BundleType(newFields))) } - case s: DefNode => Seq(Field(s.name, DEFAULT, get_type(s))) + case s: DefNode => Seq(Field(s.name, Default, get_type(s))) case s: Conditionally => recStmtToType(s.conseq) ++ recStmtToType(s.alt) case s: Begin => (s.stmts map (recStmtToType)).flatten case s => Seq() |
