summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Lawson2016-07-06 10:01:23 -0700
committerJim Lawson2016-07-18 15:17:56 -0700
commitc5f9ea3133ef363ff8944e17d94fea79767b6bed (patch)
treecc80a6df1eb58f0feaf9f138eb7fe261ccda4ea2
parent53813f61b7dfe246d214ab966739d01c65c8ecb0 (diff)
Rename "Chisel" to "chisel3" (only git mv).
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala (renamed from chiselFrontend/src/main/scala/Chisel/Aggregate.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Assert.scala (renamed from chiselFrontend/src/main/scala/Chisel/Assert.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala190
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Binder.scala64
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Binding.scala179
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Bits.scala (renamed from chiselFrontend/src/main/scala/Chisel/Bits.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala (renamed from chiselFrontend/src/main/scala/Chisel/BlackBox.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala (renamed from chiselFrontend/src/main/scala/Chisel/Data.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Mem.scala (renamed from chiselFrontend/src/main/scala/Chisel/Mem.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Module.scala (renamed from chiselFrontend/src/main/scala/Chisel/Module.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala172
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Printf.scala (renamed from chiselFrontend/src/main/scala/Chisel/Printf.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Reg.scala (renamed from chiselFrontend/src/main/scala/Chisel/Reg.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala (renamed from chiselFrontend/src/main/scala/Chisel/SeqUtils.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/When.scala (renamed from chiselFrontend/src/main/scala/Chisel/When.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Builder.scala (renamed from chiselFrontend/src/main/scala/Chisel/internal/Builder.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Error.scala (renamed from chiselFrontend/src/main/scala/Chisel/internal/Error.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala (renamed from chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala)0
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala (renamed from chiselFrontend/src/main/scala/Chisel/internal/firrtl/IR.scala)0
-rw-r--r--coreMacros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala (renamed from coreMacros/src/main/scala/Chisel/internal/sourceinfo/SourceInfoTransform.scala)0
-rw-r--r--src/main/scala/chisel3/Driver.scala (renamed from src/main/scala/Chisel/Driver.scala)0
-rw-r--r--src/main/scala/chisel3/compatibility/FileSystemUtilities.scala (renamed from src/main/scala/Chisel/FileSystemUtilities.scala)0
-rw-r--r--src/main/scala/chisel3/compatibility/Main.scala (renamed from src/main/scala/Chisel/Main.scala)0
-rw-r--r--src/main/scala/chisel3/compatibility/throwException.scala (renamed from src/main/scala/Chisel/throwException.scala)0
-rw-r--r--src/main/scala/chisel3/internal/firrtl/Emitter.scala (renamed from src/main/scala/Chisel/internal/firrtl/Emitter.scala)0
-rw-r--r--src/main/scala/chisel3/package.scala (renamed from src/main/scala/Chisel/package.scala)0
-rw-r--r--src/main/scala/chisel3/testers/BasicTester.scala (renamed from src/main/scala/Chisel/testers/BasicTester.scala)0
-rw-r--r--src/main/scala/chisel3/testers/TesterDriver.scala (renamed from src/main/scala/Chisel/testers/TesterDriver.scala)0
-rw-r--r--src/main/scala/chisel3/util/Arbiter.scala (renamed from src/main/scala/Chisel/util/Arbiter.scala)0
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala (renamed from src/main/scala/Chisel/BitPat.scala)0
-rw-r--r--src/main/scala/chisel3/util/Bitwise.scala (renamed from src/main/scala/Chisel/util/Bitwise.scala)0
-rw-r--r--src/main/scala/chisel3/util/Cat.scala (renamed from src/main/scala/Chisel/util/Cat.scala)0
-rw-r--r--src/main/scala/chisel3/util/CircuitMath.scala (renamed from src/main/scala/Chisel/util/CircuitMath.scala)0
-rw-r--r--src/main/scala/chisel3/util/Conditional.scala (renamed from src/main/scala/Chisel/util/Conditional.scala)0
-rw-r--r--src/main/scala/chisel3/util/Counter.scala (renamed from src/main/scala/Chisel/util/Counter.scala)0
-rw-r--r--src/main/scala/chisel3/util/Decoupled.scala (renamed from src/main/scala/Chisel/util/Decoupled.scala)0
-rw-r--r--src/main/scala/chisel3/util/Enum.scala (renamed from src/main/scala/Chisel/util/Enum.scala)0
-rw-r--r--src/main/scala/chisel3/util/ImplicitConversions.scala (renamed from src/main/scala/Chisel/ImplicitConversions.scala)0
-rw-r--r--src/main/scala/chisel3/util/LFSR.scala (renamed from src/main/scala/Chisel/util/LFSR.scala)0
-rw-r--r--src/main/scala/chisel3/util/Lookup.scala (renamed from src/main/scala/Chisel/util/Lookup.scala)0
-rw-r--r--src/main/scala/chisel3/util/Math.scala (renamed from src/main/scala/Chisel/util/Math.scala)0
-rw-r--r--src/main/scala/chisel3/util/Mux.scala (renamed from src/main/scala/Chisel/util/Mux.scala)0
-rw-r--r--src/main/scala/chisel3/util/OneHot.scala (renamed from src/main/scala/Chisel/util/OneHot.scala)0
-rw-r--r--src/main/scala/chisel3/util/Reg.scala (renamed from src/main/scala/Chisel/util/Reg.scala)0
-rw-r--r--src/main/scala/chisel3/util/TransitName.scala (renamed from src/main/scala/Chisel/util/TransitName.scala)0
-rw-r--r--src/main/scala/chisel3/util/Valid.scala (renamed from src/main/scala/Chisel/util/Valid.scala)0
46 files changed, 605 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/Chisel/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index 1eef5d69..1eef5d69 100644
--- a/chiselFrontend/src/main/scala/Chisel/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/Assert.scala b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
index c086f014..c086f014 100644
--- a/chiselFrontend/src/main/scala/Chisel/Assert.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
diff --git a/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala b/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
new file mode 100644
index 00000000..42d85bfb
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
@@ -0,0 +1,190 @@
+package Chisel
+
+import internal.Builder.pushCommand
+import internal.firrtl.Connect
+import scala.language.experimental.macros
+import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
+
+/**
+* BiConnect.connect executes a bidirectional connection element-wise.
+*
+* Note that the arguments are left and right (not source and sink) so the
+* intent is for the operation to be commutative.
+*
+* The connect operation will recurse down the left Data (with the right Data).
+* An exception will be thrown if a movement through the left cannot be matched
+* in the right (or if the right side has extra fields).
+*
+* See elemConnect for details on how the root connections are issued.
+*
+*/
+
+object BiConnect {
+ // These are all the possible exceptions that can be thrown.
+ case class BiConnectException(message: String) extends Exception(message)
+ // These are from element-level connection
+ def BothDriversException =
+ BiConnectException(": Both Left and Right are drivers")
+ def NeitherDriverException =
+ BiConnectException(": Neither Left nor Right is a driver")
+ def UnknownDriverException =
+ BiConnectException(": Locally unclear whether Left or Right (both internal)")
+ def UnknownRelationException =
+ BiConnectException(": Left or Right unavailable to current module.")
+ // These are when recursing down aggregate types
+ def MismatchedVecException =
+ BiConnectException(": Left and Right are different length Vecs.")
+ def MissingLeftFieldException(field: String) =
+ BiConnectException(s".$field: Left Bundle missing field ($field).")
+ def MissingRightFieldException(field: String) =
+ BiConnectException(s": Right Bundle missing field ($field).")
+ def MismatchedException(left: String, right: String) =
+ BiConnectException(s": Left ($left) and Right ($right) have different types.")
+
+ /** This function is what recursively tries to connect a left and right together
+ *
+ * There is some cleverness in the use of internal try-catch to catch exceptions
+ * during the recursive decent and then rethrow them with extra information added.
+ * This gives the user a 'path' to where in the connections things went wrong.
+ */
+ def connect(sourceInfo: SourceInfo, left: Data, right: Data, context_mod: Module): Unit =
+ (left, right) match {
+ // Handle element case (root case)
+ case (left_e: Element, right_e: Element) => {
+ elemConnect(sourceInfo, left_e, right_e, context_mod)
+ // TODO(twigg): Verify the element-level classes are connectable
+ }
+ // Handle Vec case
+ case (left_v: Vec[Data @unchecked], right_v: Vec[Data @unchecked]) => {
+ if(left_v.length != right_v.length) { throw MismatchedVecException }
+ for(idx <- 0 until left_v.length) {
+ try {
+ connect(sourceInfo, left_v(idx), right_v(idx), context_mod)
+ } catch {
+ case BiConnectException(message) => throw BiConnectException(s"($idx)$message")
+ }
+ }
+ }
+ // Handle Bundle case
+ case (left_b: Bundle, right_b: Bundle) => {
+ // Verify right has no extra fields that left doesn't have
+ for((field, right_sub) <- right_b.elements) {
+ if(!left_b.elements.isDefinedAt(field)) throw MissingLeftFieldException(field)
+ }
+ // For each field in left, descend with right
+ for((field, left_sub) <- left_b.elements) {
+ try {
+ right_b.elements.get(field) match {
+ case Some(right_sub) => connect(sourceInfo, left_sub, right_sub, context_mod)
+ case None => throw MissingRightFieldException(field)
+ }
+ } catch {
+ case BiConnectException(message) => throw BiConnectException(s".$field$message")
+ }
+ }
+ }
+ // Left and right are different subtypes of Data so fail
+ case (left, right) => throw MismatchedException(left.toString, right.toString)
+ }
+
+ // These functions (finally) issue the connection operation
+ // Issue with right as sink, left as source
+ private def issueConnectL2R(left: Element, right: Element)(implicit sourceInfo: SourceInfo): Unit = {
+ pushCommand(Connect(sourceInfo, right.lref, left.ref))
+ }
+ // Issue with left as sink, right as source
+ private def issueConnectR2L(left: Element, right: Element)(implicit sourceInfo: SourceInfo): Unit = {
+ pushCommand(Connect(sourceInfo, left.lref, right.ref))
+ }
+
+ // This function checks if element-level connection operation allowed.
+ // Then it either issues it or throws the appropriate exception.
+ def elemConnect(implicit sourceInfo: SourceInfo, left: Element, right: Element, context_mod: Module): Unit = {
+ import Direction.{Input, Output} // Using extensively so import these
+ // If left or right have no location, assume in context module
+ // This can occur if one of them is a literal, unbound will error previously
+ val left_mod: Module = left.binding.location.getOrElse(context_mod)
+ val right_mod: Module = right.binding.location.getOrElse(context_mod)
+
+ val left_direction: Option[Direction] = left.binding.direction
+ val right_direction: Option[Direction] = right.binding.direction
+ // None means internal
+
+ // CASE: Context is same module as left node and right node is in a child module
+ if( (left_mod == context_mod) &&
+ (right_mod._parent.map(_ == context_mod).getOrElse(false)) ) {
+ // Thus, right node better be a port node and thus have a direction hint
+ (left_direction, right_direction) match {
+ // CURRENT MOD CHILD MOD
+ case (Some(Input), Some(Input)) => issueConnectL2R(left, right)
+ case (None, Some(Input)) => issueConnectL2R(left, right)
+
+ case (Some(Output), Some(Output)) => issueConnectR2L(left, right)
+ case (None, Some(Output)) => issueConnectR2L(left, right)
+
+ case (Some(Input), Some(Output)) => throw BothDriversException
+ case (Some(Output), Some(Input)) => throw NeitherDriverException
+ case (_, None) => throw UnknownRelationException
+ }
+ }
+
+ // CASE: Context is same module as right node and left node is in child module
+ else if( (right_mod == context_mod) &&
+ (left_mod._parent.map(_ == context_mod).getOrElse(false)) ) {
+ // Thus, left node better be a port node and thus have a direction hint
+ (left_direction, right_direction) match {
+ // CHILD MOD CURRENT MOD
+ case (Some(Input), Some(Input)) => issueConnectR2L(left, right)
+ case (Some(Input), None) => issueConnectR2L(left, right)
+
+ case (Some(Output), Some(Output)) => issueConnectL2R(left, right)
+ case (Some(Output), None) => issueConnectL2R(left, right)
+
+ case (Some(Input), Some(Output)) => throw NeitherDriverException
+ case (Some(Output), Some(Input)) => throw BothDriversException
+ case (None, _) => throw UnknownRelationException
+ }
+ }
+
+ // CASE: Context is same module that both left node and right node are in
+ else if( (context_mod == left_mod) && (context_mod == right_mod) ) {
+ (left_direction, right_direction) match {
+ // CURRENT MOD CURRENT MOD
+ case (Some(Input), Some(Output)) => issueConnectL2R(left, right)
+ case (Some(Input), None) => issueConnectL2R(left, right)
+ case (None, Some(Output)) => issueConnectL2R(left, right)
+
+ case (Some(Output), Some(Input)) => issueConnectR2L(left, right)
+ case (Some(Output), None) => issueConnectR2L(left, right)
+ case (None, Some(Input)) => issueConnectR2L(left, right)
+
+ case (Some(Input), Some(Input)) => throw BothDriversException
+ case (Some(Output), Some(Output)) => throw NeitherDriverException
+ case (None, None) => throw UnknownDriverException
+ }
+ }
+
+ // CASE: Context is the parent module of both the module containing left node
+ // and the module containing right node
+ // Note: This includes case when left and right in same module but in parent
+ else if( (left_mod._parent.map(_ == context_mod).getOrElse(false)) &&
+ (right_mod._parent.map(_ == context_mod).getOrElse(false))
+ ) {
+ // Thus both nodes must be ports and have a direction hint
+ (left_direction, right_direction) match {
+ // CHILD MOD CHILD MOD
+ case (Some(Input), Some(Output)) => issueConnectR2L(left, right)
+ case (Some(Output), Some(Input)) => issueConnectL2R(left, right)
+
+ case (Some(Input), Some(Input)) => throw NeitherDriverException
+ case (Some(Output), Some(Output)) => throw BothDriversException
+ case (_, None) => throw UnknownRelationException
+ case (None, _) => throw UnknownRelationException
+ }
+ }
+
+ // Not quite sure where left and right are compared to current module
+ // so just error out
+ else throw UnknownRelationException
+ }
+}
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Binder.scala b/chiselFrontend/src/main/scala/chisel3/core/Binder.scala
new file mode 100644
index 00000000..ca074527
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/core/Binder.scala
@@ -0,0 +1,64 @@
+package Chisel
+
+/**
+* A Binder is a function from UnboundBinding to some Binding.
+*
+* These are used exclusively by Binding.bind and sealed in order to keep
+* all of them in one place. There are two flavors of Binders:
+* Non-terminal (returns another UnboundBinding): These are used to reformat an
+* UnboundBinding (like setting direction) before it is terminally bound.
+* Terminal (returns any other Binding): Due to the nature of Bindings, once a
+* Data is bound to anything but an UnboundBinding, it is forever locked to
+* being that type (as it now represents something in the hardware graph).
+*
+* Note that some Binders require extra arguments to be constructed, like the
+* enclosing Module.
+*/
+
+sealed trait Binder[Out <: Binding] extends Function1[UnboundBinding, Out]{
+ def apply(in: UnboundBinding): Out
+}
+
+// THE NON-TERMINAL BINDERS
+// These 'rebind' to another unbound node of different direction!
+case object InputBinder extends Binder[UnboundBinding] {
+ def apply(in: UnboundBinding) = UnboundBinding(Some(Direction.Input))
+}
+case object OutputBinder extends Binder[UnboundBinding] {
+ def apply(in: UnboundBinding) = UnboundBinding(Some(Direction.Output))
+}
+case object FlippedBinder extends Binder[UnboundBinding] {
+ def apply(in: UnboundBinding) = UnboundBinding(in.direction.map(_.flip))
+ // TODO(twigg): flipping a None should probably be a warning/error
+}
+// The need for this should be transient.
+case object NoDirectionBinder extends Binder[UnboundBinding] {
+ def apply(in: UnboundBinding) = UnboundBinding(None)
+}
+
+// THE TERMINAL BINDERS
+case object LitBinder extends Binder[LitBinding] {
+ def apply(in: UnboundBinding) = LitBinding()
+}
+
+case class MemoryPortBinder(enclosure: Module) extends Binder[MemoryPortBinding] {
+ def apply(in: UnboundBinding) = MemoryPortBinding(enclosure)
+}
+
+case class OpBinder(enclosure: Module) extends Binder[OpBinding] {
+ def apply(in: UnboundBinding) = OpBinding(enclosure)
+}
+
+// Notice how PortBinder uses the direction of the UnboundNode
+case class PortBinder(enclosure: Module) extends Binder[PortBinding] {
+ def apply(in: UnboundBinding) = PortBinding(enclosure, in.direction)
+}
+
+case class RegBinder(enclosure: Module) extends Binder[RegBinding] {
+ def apply(in: UnboundBinding) = RegBinding(enclosure)
+}
+
+case class WireBinder(enclosure: Module) extends Binder[WireBinding] {
+ def apply(in: UnboundBinding) = WireBinding(enclosure)
+}
+
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Binding.scala b/chiselFrontend/src/main/scala/chisel3/core/Binding.scala
new file mode 100644
index 00000000..949ac9cd
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/core/Binding.scala
@@ -0,0 +1,179 @@
+package Chisel
+
+/**
+ * The purpose of a Binding is to indicate what type of hardware 'entity' a
+ * specific Data's leaf Elements is actually bound to. All Data starts as being
+ * Unbound (and the whole point of cloneType is to return an unbound version).
+ * Then, specific API calls take a Data, and return a bound version (either by
+ * binding the original model or cloneType then binding the clone). For example,
+ * Reg[T<:Data](...) returns a T bound to RegBinding.
+ *
+ * It is considered invariant that all Elements of a single Data are bound to
+ * the same concrete type of Binding.
+ *
+ * These bindings can be checked (e.g. checkSynthesizable) to make sure certain
+ * operations are valid. For example, arithemetic operations or connections can
+ * only be executed between synthesizable nodes. These checks are to avoid
+ * undefined reference errors.
+ *
+ * Bindings can carry information about the particular element in the graph it
+ * represents like:
+ * - For ports (and unbound), the 'direction'
+ * - For (relevant) synthesizable nodes, the enclosing Module
+ *
+ * TODO(twigg): Enrich the bindings to carry more information like the hosting
+ * module (when applicable), direction (when applicable), literal info (when
+ * applicable). Can ensure applicable data only stored on relevant nodes. e.g.
+ * literal info on LitBinding, direction info on UnboundBinding and PortBinding,
+ * etc.
+ *
+ * TODO(twigg): Currently, bindings only apply at the Element level and an
+ * Aggregate is considered bound via its elements. May be appropriate to allow
+ * Aggregates to be bound along with the Elements. However, certain literal and
+ * port direction information doesn't quite make sense in aggregates. This would
+ * elegantly handle the empty Vec or Bundle problem though.
+ *
+ * TODO(twigg): Binding is currently done via allElements. It may be more
+ * elegant if this was instead done as a more explicit tree walk as that allows
+ * for better errors.
+ */
+
+object Binding {
+ // Two bindings are 'compatible' if they are the same type.
+ // Check currently kind of weird: just ensures same class
+ private def compatible(a: Binding, b: Binding): Boolean = a.getClass == b.getClass
+ private def compatible(nodes: Seq[Binding]): Boolean =
+ if(nodes.size > 1)
+ (for((a,b) <- nodes zip nodes.tail) yield compatible(a,b))
+ .fold(true)(_&&_)
+ else true
+
+ case class BindingException(message: String) extends Exception(message)
+ def AlreadyBoundException(binding: String) = BindingException(s": Already bound to $binding")
+ def NotSynthesizableException = BindingException(s": Not bound to synthesizable node, currently only Type description")
+
+ // This recursively walks down the Data tree to look at all the leaf 'Element's
+ // Will build up an error string in case something goes wrong
+ // TODO(twigg): Make member function of Data.
+ // Allows oddities like sample_element to be better hidden
+ private def walkToBinding(target: Data, checker: Element=>Unit): Unit = target match {
+ case (element: Element) => checker(element)
+ case (vec: Vec[Data @unchecked]) => {
+ try walkToBinding(vec.sample_element, checker)
+ catch {
+ case BindingException(message) => throw BindingException(s"(*)$message")
+ }
+ for(idx <- 0 until vec.length) {
+ try walkToBinding(vec(idx), checker)
+ catch {
+ case BindingException(message) => throw BindingException(s"($idx)$message")
+ }
+ }
+ }
+ case (bundle: Bundle) => {
+ for((field, subelem) <- bundle.elements) {
+ try walkToBinding(subelem, checker)
+ catch {
+ case BindingException(message) => throw BindingException(s".$field$message")
+ }
+ }
+ }
+ }
+
+ // Use walkToBinding to actually rebind the node type
+ def bind[T<:Data](target: T, binder: Binder[_<:Binding], error_prelude: String): target.type = {
+ try walkToBinding(
+ target,
+ element => element.binding match {
+ case unbound @ UnboundBinding(_) => {
+ element.binding = binder(unbound)
+ }
+ case binding => throw AlreadyBoundException(binding.toString)
+ }
+ )
+ catch {
+ case BindingException(message) => throw BindingException(s"$error_prelude$message")
+ }
+ target
+ }
+
+ // Excepts if any root element is already bound
+ def checkUnbound(target: Data, error_prelude: String): Unit = {
+ try walkToBinding(
+ target,
+ element => element.binding match {
+ case unbound @ UnboundBinding(_) => {}
+ case binding => throw AlreadyBoundException(binding.toString)
+ }
+ )
+ catch {
+ case BindingException(message) => throw BindingException(s"$error_prelude$message")
+ }
+ }
+
+ // Excepts if any root element is unbound and thus not on the hardware graph
+ def checkSynthesizable(target: Data, error_prelude: String): Unit =
+ try walkToBinding(
+ target,
+ element => element.binding match {
+ case SynthesizableBinding() => {} // OK
+ case binding => throw NotSynthesizableException
+ }
+ )
+ catch {
+ case BindingException(message) => throw BindingException(s"$error_prelude$message")
+ }
+}
+
+// Location refers to 'where' in the Module hierarchy this lives
+sealed trait Binding {
+ def location: Option[Module]
+ def direction: Option[Direction]
+}
+
+// Constrained-ness refers to whether 'bound by Module boundaries'
+// An unconstrained binding, like a literal, can be read by everyone
+sealed trait UnconstrainedBinding extends Binding {
+ def location = None
+}
+// A constrained binding can only be read/written by specific modules
+// Location will track where this Module is
+sealed trait ConstrainedBinding extends Binding {
+ def enclosure: Module
+ def location = Some(enclosure)
+}
+
+// An undirectioned binding means the element represents an internal node
+// with no meaningful concept of a direction
+sealed trait UndirectionedBinding extends Binding { def direction = None }
+
+// This is the default binding, represents data not yet positioned in the graph
+case class UnboundBinding(direction: Option[Direction])
+ extends Binding with UnconstrainedBinding
+
+
+// A synthesizable binding is 'bound into' the hardware graph
+object SynthesizableBinding {
+ def unapply(target: Binding): Boolean = target.isInstanceOf[SynthesizableBinding]
+ // Type check OK because Binding and SynthesizableBinding is sealed
+}
+sealed trait SynthesizableBinding extends Binding
+case class LitBinding() // will eventually have literal info
+ extends SynthesizableBinding with UnconstrainedBinding with UndirectionedBinding
+
+case class MemoryPortBinding(enclosure: Module)
+ extends SynthesizableBinding with ConstrainedBinding with UndirectionedBinding
+
+// TODO(twigg): Ops between unenclosed nodes can also be unenclosed
+// However, Chisel currently binds all op results to a module
+case class OpBinding(enclosure: Module)
+ extends SynthesizableBinding with ConstrainedBinding with UndirectionedBinding
+
+case class PortBinding(enclosure: Module, direction: Option[Direction])
+ extends SynthesizableBinding with ConstrainedBinding
+
+case class RegBinding(enclosure: Module)
+ extends SynthesizableBinding with ConstrainedBinding with UndirectionedBinding
+
+case class WireBinding(enclosure: Module)
+ extends SynthesizableBinding with ConstrainedBinding with UndirectionedBinding
diff --git a/chiselFrontend/src/main/scala/Chisel/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
index bc8cc8e2..bc8cc8e2 100644
--- a/chiselFrontend/src/main/scala/Chisel/Bits.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/BlackBox.scala b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
index b634f021..b634f021 100644
--- a/chiselFrontend/src/main/scala/Chisel/BlackBox.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index d16843f7..d16843f7 100644
--- a/chiselFrontend/src/main/scala/Chisel/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/Mem.scala b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
index e34d5499..e34d5499 100644
--- a/chiselFrontend/src/main/scala/Chisel/Mem.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Mem.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
index e2101538..e2101538 100644
--- a/chiselFrontend/src/main/scala/Chisel/Module.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
diff --git a/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala b/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala
new file mode 100644
index 00000000..27da965b
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala
@@ -0,0 +1,172 @@
+package Chisel
+
+import internal.Builder.pushCommand
+import internal.firrtl.Connect
+import scala.language.experimental.macros
+import internal.sourceinfo.{SourceInfo, DeprecatedSourceInfo, UnlocatableSourceInfo, WireTransform, SourceInfoTransform}
+
+/**
+* MonoConnect.connect executes a mono-directional connection element-wise.
+*
+* Note that this isn't commutative. There is an explicit source and sink
+* already determined before this function is called.
+*
+* The connect operation will recurse down the left Data (with the right Data).
+* An exception will be thrown if a movement through the left cannot be matched
+* in the right. The right side is allowed to have extra Bundle fields.
+* Vecs must still be exactly the same size.
+*
+* See elemConnect for details on how the root connections are issued.
+*
+* Note that a valid sink must be writable so, one of these must hold:
+* - Is an internal writable node (Reg or Wire)
+* - Is an output of the current module
+* - Is an input of a submodule of the current module
+*
+* Note that a valid source must be readable so, one of these must hold:
+* - Is an internal readable node (Reg, Wire, Op)
+* - Is a literal
+* - Is a port of the current module or submodule of the current module
+*/
+
+object MonoConnect {
+ // These are all the possible exceptions that can be thrown.
+ case class MonoConnectException(message: String) extends Exception(message)
+ // These are from element-level connection
+ def UnreadableSourceException =
+ MonoConnectException(": Source is unreadable from current module.")
+ def UnwritableSinkException =
+ MonoConnectException(": Sink is unwriteable by current module.")
+ def UnknownRelationException =
+ MonoConnectException(": Sink or source unavailable to current module.")
+ // These are when recursing down aggregate types
+ def MismatchedVecException =
+ MonoConnectException(": Sink and Source are different length Vecs.")
+ def MissingFieldException(field: String) =
+ MonoConnectException(s": Source Bundle missing field ($field).")
+ def MismatchedException(sink: String, source: String) =
+ MonoConnectException(s": Sink ($sink) and Source ($source) have different types.")
+
+ /** This function is what recursively tries to connect a sink and source together
+ *
+ * There is some cleverness in the use of internal try-catch to catch exceptions
+ * during the recursive decent and then rethrow them with extra information added.
+ * This gives the user a 'path' to where in the connections things went wrong.
+ */
+ def connect(sourceInfo: SourceInfo, sink: Data, source: Data, context_mod: Module): Unit =
+ (sink, source) match {
+ // Handle element case (root case)
+ case (sink_e: Element, source_e: Element) => {
+ elemConnect(sourceInfo, sink_e, source_e, context_mod)
+ // TODO(twigg): Verify the element-level classes are connectable
+ }
+ // Handle Vec case
+ case (sink_v: Vec[Data @unchecked], source_v: Vec[Data @unchecked]) => {
+ if(sink_v.length != source_v.length) { throw MismatchedVecException }
+ for(idx <- 0 until sink_v.length) {
+ try {
+ connect(sourceInfo, sink_v(idx), source_v(idx), context_mod)
+ } catch {
+ case MonoConnectException(message) => throw MonoConnectException(s"($idx)$message")
+ }
+ }
+ }
+ // Handle Bundle case
+ case (sink_b: Bundle, source_b: Bundle) => {
+ // For each field, descend with right
+ for((field, sink_sub) <- sink_b.elements) {
+ try {
+ source_b.elements.get(field) match {
+ case Some(source_sub) => connect(sourceInfo, sink_sub, source_sub, context_mod)
+ case None => throw MissingFieldException(field)
+ }
+ } catch {
+ case MonoConnectException(message) => throw MonoConnectException(s".$field$message")
+ }
+ }
+ }
+ // Sink and source are different subtypes of data so fail
+ case (sink, source) => throw MismatchedException(sink.toString, source.toString)
+ }
+
+ // This function (finally) issues the connection operation
+ private def issueConnect(sink: Element, source: Element)(implicit sourceInfo: SourceInfo): Unit = {
+ pushCommand(Connect(sourceInfo, sink.lref, source.ref))
+ }
+
+ // This function checks if element-level connection operation allowed.
+ // Then it either issues it or throws the appropriate exception.
+ def elemConnect(implicit sourceInfo: SourceInfo, sink: Element, source: Element, context_mod: Module): Unit = {
+ import Direction.{Input, Output} // Using extensively so import these
+ // If source has no location, assume in context module
+ // This can occur if is a literal, unbound will error previously
+ val sink_mod: Module = sink.binding.location.getOrElse(throw UnwritableSinkException)
+ val source_mod: Module = source.binding.location.getOrElse(context_mod)
+
+ val sink_direction: Option[Direction] = sink.binding.direction
+ val source_direction: Option[Direction] = source.binding.direction
+ // None means internal
+
+ // CASE: Context is same module that both left node and right node are in
+ if( (context_mod == sink_mod) && (context_mod == source_mod) ) {
+ (sink_direction, source_direction) match {
+ // SINK SOURCE
+ // CURRENT MOD CURRENT MOD
+ case (Some(Output), _) => issueConnect(sink, source)
+ case (None, _) => issueConnect(sink, source)
+ case (Some(Input), _) => throw UnwritableSinkException
+ }
+ }
+
+ // CASE: Context is same module as sink node and right node is in a child module
+ else if( (sink_mod == context_mod) &&
+ (source_mod._parent.map(_ == context_mod).getOrElse(false)) ) {
+ // Thus, right node better be a port node and thus have a direction
+ (sink_direction, source_direction) match {
+ // SINK SOURCE
+ // CURRENT MOD CHILD MOD
+ case (None, Some(Output)) => issueConnect(sink, source)
+ case (None, Some(Input)) => issueConnect(sink, source)
+ case (Some(Output), Some(Output)) => issueConnect(sink, source)
+ case (Some(Output), Some(Input)) => issueConnect(sink, source)
+ case (_, None) => throw UnreadableSourceException
+ case (Some(Input), _) => throw UnwritableSinkException
+ }
+ }
+
+ // CASE: Context is same module as source node and sink node is in child module
+ else if( (source_mod == context_mod) &&
+ (sink_mod._parent.map(_ == context_mod).getOrElse(false)) ) {
+ // Thus, left node better be a port node and thus have a direction
+ (sink_direction, source_direction) match {
+ // SINK SOURCE
+ // CHILD MOD CURRENT MOD
+ case (Some(Input), _) => issueConnect(sink, source)
+ case (Some(Output), _) => throw UnwritableSinkException
+ case (None, _) => throw UnwritableSinkException
+ }
+ }
+
+ // CASE: Context is the parent module of both the module containing sink node
+ // and the module containing source node
+ // Note: This includes case when sink and source in same module but in parent
+ else if( (sink_mod._parent.map(_ == context_mod).getOrElse(false)) &&
+ (source_mod._parent.map(_ == context_mod).getOrElse(false))
+ ) {
+ // Thus both nodes must be ports and have a direction
+ (sink_direction, source_direction) match {
+ // SINK SOURCE
+ // CHILD MOD CHILD MOD
+ case (Some(Input), Some(Input)) => issueConnect(sink, source)
+ case (Some(Input), Some(Output)) => issueConnect(sink, source)
+ case (Some(Output), _) => throw UnwritableSinkException
+ case (_, None) => throw UnreadableSourceException
+ case (None, _) => throw UnwritableSinkException
+ }
+ }
+
+ // Not quite sure where left and right are compared to current module
+ // so just error out
+ else throw UnknownRelationException
+ }
+}
diff --git a/chiselFrontend/src/main/scala/Chisel/Printf.scala b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
index f068f637..f068f637 100644
--- a/chiselFrontend/src/main/scala/Chisel/Printf.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/Reg.scala b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
index c8faa5c9..c8faa5c9 100644
--- a/chiselFrontend/src/main/scala/Chisel/Reg.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Reg.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/SeqUtils.scala b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
index 9a15fd5f..9a15fd5f 100644
--- a/chiselFrontend/src/main/scala/Chisel/SeqUtils.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/SeqUtils.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/When.scala b/chiselFrontend/src/main/scala/chisel3/core/When.scala
index 90b3d1a5..90b3d1a5 100644
--- a/chiselFrontend/src/main/scala/Chisel/When.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/When.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
index d0e28b7c..d0e28b7c 100644
--- a/chiselFrontend/src/main/scala/Chisel/internal/Builder.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/internal/Error.scala b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
index 6c4c0880..6c4c0880 100644
--- a/chiselFrontend/src/main/scala/Chisel/internal/Error.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
index 66bfc7a4..66bfc7a4 100644
--- a/chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
diff --git a/chiselFrontend/src/main/scala/Chisel/internal/firrtl/IR.scala b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
index 62784cee..62784cee 100644
--- a/chiselFrontend/src/main/scala/Chisel/internal/firrtl/IR.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/firrtl/IR.scala
diff --git a/coreMacros/src/main/scala/Chisel/internal/sourceinfo/SourceInfoTransform.scala b/coreMacros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala
index 82ad5b9e..82ad5b9e 100644
--- a/coreMacros/src/main/scala/Chisel/internal/sourceinfo/SourceInfoTransform.scala
+++ b/coreMacros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala
diff --git a/src/main/scala/Chisel/Driver.scala b/src/main/scala/chisel3/Driver.scala
index 02204684..02204684 100644
--- a/src/main/scala/Chisel/Driver.scala
+++ b/src/main/scala/chisel3/Driver.scala
diff --git a/src/main/scala/Chisel/FileSystemUtilities.scala b/src/main/scala/chisel3/compatibility/FileSystemUtilities.scala
index 575ae138..575ae138 100644
--- a/src/main/scala/Chisel/FileSystemUtilities.scala
+++ b/src/main/scala/chisel3/compatibility/FileSystemUtilities.scala
diff --git a/src/main/scala/Chisel/Main.scala b/src/main/scala/chisel3/compatibility/Main.scala
index a72debc3..a72debc3 100644
--- a/src/main/scala/Chisel/Main.scala
+++ b/src/main/scala/chisel3/compatibility/Main.scala
diff --git a/src/main/scala/Chisel/throwException.scala b/src/main/scala/chisel3/compatibility/throwException.scala
index 702884aa..702884aa 100644
--- a/src/main/scala/Chisel/throwException.scala
+++ b/src/main/scala/chisel3/compatibility/throwException.scala
diff --git a/src/main/scala/Chisel/internal/firrtl/Emitter.scala b/src/main/scala/chisel3/internal/firrtl/Emitter.scala
index 7ca3268a..7ca3268a 100644
--- a/src/main/scala/Chisel/internal/firrtl/Emitter.scala
+++ b/src/main/scala/chisel3/internal/firrtl/Emitter.scala
diff --git a/src/main/scala/Chisel/package.scala b/src/main/scala/chisel3/package.scala
index f05e8b5d..f05e8b5d 100644
--- a/src/main/scala/Chisel/package.scala
+++ b/src/main/scala/chisel3/package.scala
diff --git a/src/main/scala/Chisel/testers/BasicTester.scala b/src/main/scala/chisel3/testers/BasicTester.scala
index b8c1494a..b8c1494a 100644
--- a/src/main/scala/Chisel/testers/BasicTester.scala
+++ b/src/main/scala/chisel3/testers/BasicTester.scala
diff --git a/src/main/scala/Chisel/testers/TesterDriver.scala b/src/main/scala/chisel3/testers/TesterDriver.scala
index a56bb8b7..a56bb8b7 100644
--- a/src/main/scala/Chisel/testers/TesterDriver.scala
+++ b/src/main/scala/chisel3/testers/TesterDriver.scala
diff --git a/src/main/scala/Chisel/util/Arbiter.scala b/src/main/scala/chisel3/util/Arbiter.scala
index 16ae9be5..16ae9be5 100644
--- a/src/main/scala/Chisel/util/Arbiter.scala
+++ b/src/main/scala/chisel3/util/Arbiter.scala
diff --git a/src/main/scala/Chisel/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 96206f63..96206f63 100644
--- a/src/main/scala/Chisel/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
diff --git a/src/main/scala/Chisel/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala
index 239a295e..239a295e 100644
--- a/src/main/scala/Chisel/util/Bitwise.scala
+++ b/src/main/scala/chisel3/util/Bitwise.scala
diff --git a/src/main/scala/Chisel/util/Cat.scala b/src/main/scala/chisel3/util/Cat.scala
index dd706e62..dd706e62 100644
--- a/src/main/scala/Chisel/util/Cat.scala
+++ b/src/main/scala/chisel3/util/Cat.scala
diff --git a/src/main/scala/Chisel/util/CircuitMath.scala b/src/main/scala/chisel3/util/CircuitMath.scala
index 06cab903..06cab903 100644
--- a/src/main/scala/Chisel/util/CircuitMath.scala
+++ b/src/main/scala/chisel3/util/CircuitMath.scala
diff --git a/src/main/scala/Chisel/util/Conditional.scala b/src/main/scala/chisel3/util/Conditional.scala
index 9cab25ef..9cab25ef 100644
--- a/src/main/scala/Chisel/util/Conditional.scala
+++ b/src/main/scala/chisel3/util/Conditional.scala
diff --git a/src/main/scala/Chisel/util/Counter.scala b/src/main/scala/chisel3/util/Counter.scala
index 872e830a..872e830a 100644
--- a/src/main/scala/Chisel/util/Counter.scala
+++ b/src/main/scala/chisel3/util/Counter.scala
diff --git a/src/main/scala/Chisel/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala
index 8e045855..8e045855 100644
--- a/src/main/scala/Chisel/util/Decoupled.scala
+++ b/src/main/scala/chisel3/util/Decoupled.scala
diff --git a/src/main/scala/Chisel/util/Enum.scala b/src/main/scala/chisel3/util/Enum.scala
index 20057197..20057197 100644
--- a/src/main/scala/Chisel/util/Enum.scala
+++ b/src/main/scala/chisel3/util/Enum.scala
diff --git a/src/main/scala/Chisel/ImplicitConversions.scala b/src/main/scala/chisel3/util/ImplicitConversions.scala
index 6a230022..6a230022 100644
--- a/src/main/scala/Chisel/ImplicitConversions.scala
+++ b/src/main/scala/chisel3/util/ImplicitConversions.scala
diff --git a/src/main/scala/Chisel/util/LFSR.scala b/src/main/scala/chisel3/util/LFSR.scala
index 839b1d1f..839b1d1f 100644
--- a/src/main/scala/Chisel/util/LFSR.scala
+++ b/src/main/scala/chisel3/util/LFSR.scala
diff --git a/src/main/scala/Chisel/util/Lookup.scala b/src/main/scala/chisel3/util/Lookup.scala
index 54922fc4..54922fc4 100644
--- a/src/main/scala/Chisel/util/Lookup.scala
+++ b/src/main/scala/chisel3/util/Lookup.scala
diff --git a/src/main/scala/Chisel/util/Math.scala b/src/main/scala/chisel3/util/Math.scala
index 5f8212d8..5f8212d8 100644
--- a/src/main/scala/Chisel/util/Math.scala
+++ b/src/main/scala/chisel3/util/Math.scala
diff --git a/src/main/scala/Chisel/util/Mux.scala b/src/main/scala/chisel3/util/Mux.scala
index 9d92321a..9d92321a 100644
--- a/src/main/scala/Chisel/util/Mux.scala
+++ b/src/main/scala/chisel3/util/Mux.scala
diff --git a/src/main/scala/Chisel/util/OneHot.scala b/src/main/scala/chisel3/util/OneHot.scala
index 73f27403..73f27403 100644
--- a/src/main/scala/Chisel/util/OneHot.scala
+++ b/src/main/scala/chisel3/util/OneHot.scala
diff --git a/src/main/scala/Chisel/util/Reg.scala b/src/main/scala/chisel3/util/Reg.scala
index 6584a4bf..6584a4bf 100644
--- a/src/main/scala/Chisel/util/Reg.scala
+++ b/src/main/scala/chisel3/util/Reg.scala
diff --git a/src/main/scala/Chisel/util/TransitName.scala b/src/main/scala/chisel3/util/TransitName.scala
index ec5a11cc..ec5a11cc 100644
--- a/src/main/scala/Chisel/util/TransitName.scala
+++ b/src/main/scala/chisel3/util/TransitName.scala
diff --git a/src/main/scala/Chisel/util/Valid.scala b/src/main/scala/chisel3/util/Valid.scala
index 9e2202bb..9e2202bb 100644
--- a/src/main/scala/Chisel/util/Valid.scala
+++ b/src/main/scala/chisel3/util/Valid.scala