summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3
diff options
context:
space:
mode:
authorJack Koenig2017-05-10 12:09:59 -0700
committerGitHub2017-05-10 12:09:59 -0700
commit45e235a5948a1cd15b8ccb5f437dc6f2ff80cb96 (patch)
treee21826d7f231b3553a0d9001cdf987beded4c1d4 /chiselFrontend/src/main/scala/chisel3
parent9ad6c747ddcedb831dbfbcd970a46966f986b800 (diff)
Add implicit CompileOptions to Record and Bundle (#595)
Fixes #495 Helps distinguish between Records/Bundles defined in Chisel._ vs. chisel3._. Also override compilationOptions when bulk connecting Records/Bundles defined in Chisel._. This allows Records/Bundles defined in Chisel._ code to be correctly bulk connected in chisel3._ code.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala4
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala61
2 files changed, 40 insertions, 25 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index 6a4d8cff..3f81de9f 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -362,7 +362,7 @@ trait VecLike[T <: Data] extends collection.IndexedSeq[T] with HasId {
* Record should only be extended by libraries and fairly sophisticated generators.
* RTL writers should use [[Bundle]]. See [[Record#elements]] for an example.
*/
-abstract class Record extends Aggregate {
+abstract class Record(private[chisel3] implicit val compileOptions: CompileOptions) extends Aggregate {
/** The collection of [[Data]]
*
@@ -464,7 +464,7 @@ abstract class Record extends Aggregate {
* }
* }}}
*/
-class Bundle extends Record {
+class Bundle(implicit compileOptions: CompileOptions) extends Record {
override def className = "Bundle"
/** The collection of [[Data]]
diff --git a/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala b/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
index 4240a945..0e5d4e8b 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
@@ -80,35 +80,50 @@ object BiConnect {
}
}
}
- // Handle Record case
- case (left_r: Record, right_r: Record) => {
- // Verify right has no extra fields that left doesn't have
- for((field, right_sub) <- right_r.elements) {
- if(!left_r.elements.isDefinedAt(field)) {
- if (connectCompileOptions.connectFieldsMustMatch) {
- throw MissingLeftFieldException(field)
- }
- }
+ // Handle Records defined in Chisel._ code (change to NotStrict)
+ case (left_r: Record, right_r: Record) => (left_r.compileOptions, right_r.compileOptions) match {
+ case (ExplicitCompileOptions.NotStrict, _) =>
+ left_r.bulkConnect(right_r)(sourceInfo, ExplicitCompileOptions.NotStrict)
+ case (_, ExplicitCompileOptions.NotStrict) =>
+ left_r.bulkConnect(right_r)(sourceInfo, ExplicitCompileOptions.NotStrict)
+ case _ => recordConnect(sourceInfo, connectCompileOptions, left_r, right_r, context_mod)
+ }
+
+ // Left and right are different subtypes of Data so fail
+ case (left, right) => throw MismatchedException(left.toString, right.toString)
+ }
+
+ // Do connection of two Records
+ def recordConnect(sourceInfo: SourceInfo,
+ connectCompileOptions: CompileOptions,
+ left_r: Record,
+ right_r: Record,
+ context_mod: UserModule): Unit = {
+ // Verify right has no extra fields that left doesn't have
+ for((field, right_sub) <- right_r.elements) {
+ if(!left_r.elements.isDefinedAt(field)) {
+ if (connectCompileOptions.connectFieldsMustMatch) {
+ throw MissingLeftFieldException(field)
}
- // For each field in left, descend with right
- for((field, left_sub) <- left_r.elements) {
- try {
- right_r.elements.get(field) match {
- case Some(right_sub) => connect(sourceInfo, connectCompileOptions, left_sub, right_sub, context_mod)
- case None => {
- if (connectCompileOptions.connectFieldsMustMatch) {
- throw MissingRightFieldException(field)
- }
- }
+ }
+ }
+ // For each field in left, descend with right
+ for((field, left_sub) <- left_r.elements) {
+ try {
+ right_r.elements.get(field) match {
+ case Some(right_sub) => connect(sourceInfo, connectCompileOptions, left_sub, right_sub, context_mod)
+ case None => {
+ if (connectCompileOptions.connectFieldsMustMatch) {
+ throw MissingRightFieldException(field)
}
- } catch {
- case BiConnectException(message) => throw BiConnectException(s".$field$message")
}
}
+ } 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