summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/internal
diff options
context:
space:
mode:
authorJim Lawson2016-12-12 09:14:33 -0800
committerGitHub2016-12-12 09:14:33 -0800
commitb581a24728bfba0c39ed2c032fd86f628a1e1a50 (patch)
treef625219f936d39e760192aa69df17e776b95dd56 /chiselFrontend/src/main/scala/chisel3/internal
parent0bd9ae059368570dc72f25f7939afa5cfe5fd06e (diff)
parentad53161bbb9f67e16b88ca7a508a537f88d77e05 (diff)
Merge branch 'master' into buildinfousepackageaspath
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/internal')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala19
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala62
2 files changed, 71 insertions, 10 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index 028ce628..7a77763b 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
@@ -108,23 +108,23 @@ private[chisel3] trait HasId extends InstanceId {
private[chisel3] def getRef: Arg = _ref.get
// Implementation of public methods.
- def instanceName = _parent match {
+ def instanceName: String = _parent match {
case Some(p) => p._component match {
case Some(c) => getRef fullName c
case None => throwException("signalName/pathName should be called after circuit elaboration")
}
case None => throwException("this cannot happen")
}
- def pathName = _parent match {
+ def pathName: String = _parent match {
case None => instanceName
case Some(p) => s"${p.pathName}.$instanceName"
}
- def parentPathName = _parent match {
+ def parentPathName: String = _parent match {
case Some(p) => p.pathName
case None => throwException(s"$instanceName doesn't have a parent")
}
- def parentModName = _parent match {
- case Some(p) => p.modName
+ def parentModName: String = _parent match {
+ case Some(p) => p.name
case None => throwException(s"$instanceName doesn't have a parent")
}
@@ -145,6 +145,7 @@ private[chisel3] class DynamicContext() {
val idGen = new IdGen
val globalNamespace = new Namespace(None, Set())
val components = ArrayBuffer[Component]()
+ val annotations = ArrayBuffer[ChiselAnnotation]()
var currentModule: Option[Module] = None
// Set by object Module.apply before calling class Module constructor
// Used to distinguish between no Module() wrapping, multiple wrappings, and rewrapping
@@ -161,6 +162,7 @@ private[chisel3] object Builder {
def idGen: IdGen = dynamicContext.idGen
def globalNamespace: Namespace = dynamicContext.globalNamespace
def components: ArrayBuffer[Component] = dynamicContext.components
+ def annotations: ArrayBuffer[ChiselAnnotation] = dynamicContext.annotations
def currentModule: Option[Module] = dynamicContext.currentModule
def currentModule_=(target: Option[Module]): Unit = {
@@ -181,7 +183,10 @@ private[chisel3] object Builder {
// TODO(twigg): Ideally, binding checks and new bindings would all occur here
// However, rest of frontend can't support this yet.
def pushCommand[T <: Command](c: T): T = {
- forcedModule._commands += c
+ forcedModule match {
+ case _: BlackBox => throwException("Cannot add hardware to a BlackBox")
+ case m => m._commands += c
+ }
c
}
def pushOp[T <: Data](cmd: DefPrim[T]): T = {
@@ -203,7 +208,7 @@ private[chisel3] object Builder {
errors.checkpoint()
errors.info("Done elaborating.")
- Circuit(components.last.name, components)
+ Circuit(components.last.name, components, annotations.map(_.toFirrtl))
}
}
}
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
index 0f866c27..50400034 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
@@ -7,6 +7,8 @@ import core._
import chisel3.internal._
import chisel3.internal.sourceinfo.{SourceInfo, NoSourceInfo}
+import _root_.firrtl.annotations.Annotation
+
case class PrimOp(val name: String) {
override def toString: String = name
}
@@ -64,7 +66,7 @@ abstract class LitArg(val num: BigInt, widthArg: Width) extends Arg {
protected def minWidth: Int
if (forcedWidth) {
require(widthArg.get >= minWidth,
- s"The literal value ${num} was elaborated with a specificed width of ${widthArg.get} bits, but at least ${minWidth} bits are required.")
+ s"The literal value ${num} was elaborated with a specified width of ${widthArg.get} bits, but at least ${minWidth} bits are required.")
}
}
@@ -109,6 +111,54 @@ case class Index(imm: Arg, value: Arg) extends Arg {
override def fullName(ctx: Component): String = s"${imm.fullName(ctx)}[${value.fullName(ctx)}]"
}
+sealed trait Bound
+sealed trait NumericBound[T] extends Bound {
+ val value: T
+}
+sealed case class Open[T](value: T) extends NumericBound[T]
+sealed case class Closed[T](value: T) extends NumericBound[T]
+
+sealed trait Range {
+ val min: Bound
+ val max: Bound
+ def getWidth: Width
+}
+
+sealed trait KnownIntRange extends Range {
+ val min: NumericBound[Int]
+ val max: NumericBound[Int]
+
+ require( (min, max) match {
+ case (Open(low_val), Open(high_val)) => low_val < high_val - 1
+ case (Closed(low_val), Open(high_val)) => low_val < high_val
+ case (Open(low_val), Closed(high_val)) => low_val < high_val
+ case (Closed(low_val), Closed(high_val)) => low_val <= high_val
+ })
+}
+
+sealed case class KnownUIntRange(min: NumericBound[Int], max: NumericBound[Int]) extends KnownIntRange {
+ require (min.value >= 0)
+
+ def getWidth: Width = max match {
+ case Open(v) => Width(BigInt(v - 1).bitLength.max(1))
+ case Closed(v) => Width(BigInt(v).bitLength.max(1))
+ }
+}
+
+sealed case class KnownSIntRange(min: NumericBound[Int], max: NumericBound[Int]) extends KnownIntRange {
+
+ val maxWidth = max match {
+ case Open(v) => Width(BigInt(v - 1).bitLength + 1)
+ case Closed(v) => Width(BigInt(v).bitLength + 1)
+ }
+ val minWidth = min match {
+ case Open(v) => Width(BigInt(v + 1).bitLength + 1)
+ case Closed(v) => Width(BigInt(v).bitLength + 1)
+ }
+ def getWidth: Width = maxWidth.max(minWidth)
+
+}
+
object Width {
def apply(x: Int): Width = KnownWidth(x)
def apply(): Width = UnknownWidth()
@@ -215,8 +265,14 @@ case class Connect(sourceInfo: SourceInfo, loc: Node, exp: Arg) extends Command
case class BulkConnect(sourceInfo: SourceInfo, loc1: Node, loc2: Node) extends Command
case class ConnectInit(sourceInfo: SourceInfo, loc: Node, exp: Arg) extends Command
case class Stop(sourceInfo: SourceInfo, clock: Arg, ret: Int) extends Command
-case class Component(id: Module, name: String, ports: Seq[Port], commands: Seq[Command]) extends Arg
case class Port(id: Data, dir: Direction)
case class Printf(sourceInfo: SourceInfo, clock: Arg, pable: Printable) extends Command
+abstract class Component extends Arg {
+ def id: Module
+ def name: String
+ def ports: Seq[Port]
+}
+case class DefModule(id: Module, name: String, ports: Seq[Port], commands: Seq[Command]) extends Component
+case class DefBlackBox(id: Module, name: String, ports: Seq[Port], params: Map[String, Param]) extends Component
-case class Circuit(name: String, components: Seq[Component])
+case class Circuit(name: String, components: Seq[Component], annotations: Seq[Annotation] = Seq.empty)