summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
diff options
context:
space:
mode:
authorAndrew Waterman2016-08-31 19:23:11 -0700
committerAndrew Waterman2016-08-31 19:23:58 -0700
commit3442fac58a99551ca9e25dbc2c363c866c40e3cf (patch)
tree2f5b74bb83c3e2caba64cb42dc90c6e88b7408c9 /chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
parente2c76e1b752cb332d6c3b23dd224db14951c7e72 (diff)
Check that Vecs have homogeneous types
Vec[Element] can have heterogeneous widths. Vec[Aggregate] cannot (but possibly could relax this by stripping widths from constituent Elements and relying on width inference).
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala17
1 files changed, 15 insertions, 2 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index 82c6097f..e6ecff91 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -48,8 +48,21 @@ object Vec {
// with apply(Seq) after type erasure. Workarounds by either introducing a
// DummyImplicit or additional type parameter will break some code.
require(!elts.isEmpty)
- val width = elts.map(_.width).reduce(_ max _)
- val vec = Wire(new Vec(elts.head.cloneTypeWidth(width), elts.length))
+ def gen = elts.head match {
+ case e: Element =>
+ // Vec[Element] must have homogeneous types, but may differ in width
+ for (elt <- elts.tail)
+ require(e.getClass == elt.getClass,
+ s"can't create Vec of heterogeneous types ${e.getClass} and ${elt.getClass}")
+ val maxWidth = elts.map(_.width).reduce(_ max _)
+ elts.head.cloneTypeWidth(maxWidth)
+ case a: Aggregate =>
+ // Vec[Aggregate] must be homogeneous in type and width
+ for (elt <- elts.tail)
+ require(Mux.typesCompatible(a, elt), s"can't create Vec of heterogeneous types ${a.getClass} and ${elt.getClass}")
+ elts.head.cloneType
+ }
+ val vec = Wire(new Vec(gen, elts.length))
for ((v, e) <- vec zip elts)
v := e
vec