diff options
| author | Jack | 2016-05-09 17:31:14 -0700 |
|---|---|---|
| committer | Jack Koenig | 2016-06-10 16:32:37 -0700 |
| commit | 1eb8be78938721dd0d609f684c159bc1d1ddcfd6 (patch) | |
| tree | 55e66afc08893ae8bb105340d7fc2af49122c5a5 /src | |
| parent | cd0973b58c70f5b1e91f1d9a2abdf99a30f3f669 (diff) | |
API Cleanup - Width
Add simple documentation
trait Width -> abstract class Width
case class UnknownWidth -> case object UnknownWidth
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/Emitter.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/firrtl/IR.scala | 15 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Serialize.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 8 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Visitor.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/firrtl/WIR.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/Checks.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/Passes.scala | 2 |
8 files changed, 21 insertions, 20 deletions
diff --git a/src/main/scala/firrtl/Emitter.scala b/src/main/scala/firrtl/Emitter.scala index 1455b912..7af2017c 100644 --- a/src/main/scala/firrtl/Emitter.scala +++ b/src/main/scala/firrtl/Emitter.scala @@ -56,7 +56,7 @@ object FIRRTLEmitter extends Emitter { case class VIndent() case object VRandom extends Expression { - def tpe = UIntType(UnknownWidth()) + def tpe = UIntType(UnknownWidth) } class VerilogEmitter extends Emitter { val tab = " " diff --git a/src/main/scala/firrtl/IR.scala b/src/main/scala/firrtl/IR.scala index 0f4630b8..e11c2334 100644 --- a/src/main/scala/firrtl/IR.scala +++ b/src/main/scala/firrtl/IR.scala @@ -126,26 +126,27 @@ case class Stop(info: Info, ret: Int, clk: Expression, en: Expression) extends S case class Print(info: Info, string: StringLit, args: Seq[Expression], clk: Expression, en: Expression) extends Stmt with HasInfo case class Empty() extends Stmt -trait Width extends AST { +abstract class Width extends AST { def +(x: Width): Width = (this, x) match { case (a: IntWidth, b: IntWidth) => IntWidth(a.width + b.width) - case _ => UnknownWidth() + case _ => UnknownWidth } def -(x: Width): Width = (this, x) match { case (a: IntWidth, b: IntWidth) => IntWidth(a.width - b.width) - case _ => UnknownWidth() + case _ => UnknownWidth } def max(x: Width): Width = (this, x) match { case (a: IntWidth, b: IntWidth) => IntWidth(a.width max b.width) - case _ => UnknownWidth() + case _ => UnknownWidth } def min(x: Width): Width = (this, x) match { case (a: IntWidth, b: IntWidth) => IntWidth(a.width min b.width) - case _ => UnknownWidth() + case _ => UnknownWidth } } -case class IntWidth(width: BigInt) extends Width -case class UnknownWidth() extends Width +/** Positive Integer Bit Width of a [[GroundType]] */ +case class IntWidth(width: BigInt) extends Width +case object UnknownWidth extends Width /** Orientation of [[Field]] */ abstract class Orientation extends AST diff --git a/src/main/scala/firrtl/Serialize.scala b/src/main/scala/firrtl/Serialize.scala index c8ea9e0f..e81ecba9 100644 --- a/src/main/scala/firrtl/Serialize.scala +++ b/src/main/scala/firrtl/Serialize.scala @@ -163,7 +163,7 @@ class Serialize { def serialize(w: Width): String = { w match { - case w:UnknownWidth => "" + case UnknownWidth => "" case w: IntWidth => s"<${w.width.toString}>" case w: VarWidth => s"<${w.name}>" } diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 9d8b9360..408359f0 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -204,8 +204,8 @@ object Utils extends LazyLogging { def mux_type (t1:Type,t2:Type) : Type = { if (wt(t1) == wt(t2)) { (t1,t2) match { - case (t1:UIntType,t2:UIntType) => UIntType(UnknownWidth()) - case (t1:SIntType,t2:SIntType) => SIntType(UnknownWidth()) + case (t1:UIntType,t2:UIntType) => UIntType(UnknownWidth) + case (t1:SIntType,t2:SIntType) => SIntType(UnknownWidth) case (t1:VectorType,t2:VectorType) => VectorType(mux_type(t1.tpe,t2.tpe),t1.size) case (t1:BundleType,t2:BundleType) => BundleType((t1.fields,t2.fields).zipped.map((f1,f2) => { @@ -781,8 +781,8 @@ object Utils extends LazyLogging { def wipeWidth(): Type = t match { - case t: UIntType => UIntType(UnknownWidth()) - case t: SIntType => SIntType(UnknownWidth()) + case t: UIntType => UIntType(UnknownWidth) + case t: SIntType => SIntType(UnknownWidth) case _ => t } } diff --git a/src/main/scala/firrtl/Visitor.scala b/src/main/scala/firrtl/Visitor.scala index e17f0213..ff1f9a49 100644 --- a/src/main/scala/firrtl/Visitor.scala +++ b/src/main/scala/firrtl/Visitor.scala @@ -128,9 +128,9 @@ class Visitor(infoMode: InfoMode) extends FIRRTLBaseVisitor[AST] case term: TerminalNode => term.getText match { case "UInt" => if (ctx.getChildCount > 1) UIntType(IntWidth(string2BigInt(ctx.IntLit.getText))) - else UIntType( UnknownWidth() ) + else UIntType( UnknownWidth ) case "SInt" => if (ctx.getChildCount > 1) SIntType(IntWidth(string2BigInt(ctx.IntLit.getText))) - else SIntType( UnknownWidth() ) + else SIntType( UnknownWidth ) case "Clock" => ClockType case "{" => BundleType(ctx.field.map(visitField)) } diff --git a/src/main/scala/firrtl/WIR.scala b/src/main/scala/firrtl/WIR.scala index d38efc35..dca1cdff 100644 --- a/src/main/scala/firrtl/WIR.scala +++ b/src/main/scala/firrtl/WIR.scala @@ -161,7 +161,7 @@ class WrappedWidth (val w:Width) { case (w:MinusWidth) => "(" + w.arg1 + " - " + w.arg2 + ")" case (w:ExpWidth) => "exp(" + w.arg1 + ")" case (w:IntWidth) => w.width.toString - case (w:UnknownWidth) => "?" + case UnknownWidth => "?" } } def ww (w:Width) : WrappedWidth = new WrappedWidth(w) @@ -200,7 +200,7 @@ class WrappedWidth (val w:Width) { case (w1:MinusWidth,w2:MinusWidth) => (ww(w1.arg1) == ww(w2.arg1) && ww(w1.arg2) == ww(w2.arg2)) || (ww(w1.arg1) == ww(w2.arg2) && ww(w1.arg2) == ww(w2.arg1)) case (w1:ExpWidth,w2:ExpWidth) => ww(w1.arg1) == ww(w2.arg1) - case (w1:UnknownWidth,w2:UnknownWidth) => true + case (UnknownWidth, UnknownWidth) => true case (w1,w2) => false } } diff --git a/src/main/scala/firrtl/passes/Checks.scala b/src/main/scala/firrtl/passes/Checks.scala index 0857382b..a88ad051 100644 --- a/src/main/scala/firrtl/passes/Checks.scala +++ b/src/main/scala/firrtl/passes/Checks.scala @@ -290,8 +290,8 @@ object CheckTypes extends Pass with LazyLogging { class ValidIfPassiveTypes(info:Info) extends PassException(s"${info}: [module ${mname}] Must validif a passive type.") class ValidIfCondUInt(info:Info) extends PassException(s"${info}: [module ${mname}] A validif condition must be of type UInt.") //;---------------- Helper Functions -------------- - def ut () : UIntType = UIntType(UnknownWidth()) - def st () : SIntType = SIntType(UnknownWidth()) + def ut () : UIntType = UIntType(UnknownWidth) + def st () : SIntType = SIntType(UnknownWidth) def check_types_primop (e:DoPrim, errors:Errors, info:Info) : Unit = { def all_same_type (ls:Seq[Expression]) : Unit = { diff --git a/src/main/scala/firrtl/passes/Passes.scala b/src/main/scala/firrtl/passes/Passes.scala index 0243c6cd..42b51268 100644 --- a/src/main/scala/firrtl/passes/Passes.scala +++ b/src/main/scala/firrtl/passes/Passes.scala @@ -159,7 +159,7 @@ object InferTypes extends Pass { } def remove_unknowns_w (w:Width)(implicit namespace: Namespace):Width = { w match { - case w:UnknownWidth => VarWidth(namespace.newName("w")) + case UnknownWidth => VarWidth(namespace.newName("w")) case w => w } } |
