summaryrefslogtreecommitdiff
path: root/chiselFrontend/src
diff options
context:
space:
mode:
authorEdward Wang2018-07-08 02:36:18 -0700
committeredwardcwang2018-08-22 11:55:38 -0700
commit02d6fbbacaf5da2080dd406b98cddbdab2ab5cb1 (patch)
tree096fad5b80f2f7f8cd2e79526cd37111e326942b /chiselFrontend/src
parent3679e80c72e67c7c1b09a8f3f5315bc4d3e8d9ab (diff)
Warn user that using Seq for hardware construction in Bundle is not supported
Diffstat (limited to 'chiselFrontend/src')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala36
1 files changed, 29 insertions, 7 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index 3dbce379..cfb9810c 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -539,18 +539,40 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record {
val nameMap = LinkedHashMap[String, Data]()
val seen = HashSet[Data]()
for (m <- getPublicFields(classOf[Bundle])) {
- getBundleField(m) foreach { d =>
- if (nameMap contains m.getName) {
- require(nameMap(m.getName) eq d)
- } else if (!seen(d)) {
- nameMap(m.getName) = d
- seen += d
- }
+ getBundleField(m) match {
+ case Some(d: Data) =>
+ if (nameMap contains m.getName) {
+ require(nameMap(m.getName) eq d)
+ } else if (!seen(d)) {
+ nameMap(m.getName) = d
+ seen += d
+ }
+ case None =>
+ if (!ignoreSeq) {
+ m.invoke(this) match {
+ case s: scala.collection.Seq[Any] if s.nonEmpty => s.head match {
+ // Ignore empty Seq()
+ case d: Data => throwException("Public Seq members cannot be used to define Bundle elements " +
+ s"(found public Seq member '${m.getName}'). " +
+ "Either use a Vec() if all elements are of the same type, or HeterogeneousVec() if the elements " +
+ "are of different types. If this Seq member is not intended to construct RTL, override ignoreSeq " +
+ "to be true.")
+ case _ => // don't care about non-Data Seq
+ }
+ case _ => // not a Seq
+ }
+ }
}
}
ListMap(nameMap.toSeq sortWith { case ((an, a), (bn, b)) => (a._id > b._id) || ((a eq b) && (an > bn)) }: _*)
}
+ /**
+ * Override this to be true to avoid raising an error/exception when a Seq is a public member of the bundle.
+ * This is useful if you have public Seq fields in the Bundle that are unrelated to hardware construction.
+ */
+ def ignoreSeq: Boolean = false
+
/** Returns a field's contained user-defined Bundle element if it appears to
* be one, otherwise returns None.
*/