summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/CustomBundle.scala
diff options
context:
space:
mode:
authorLeway Colin2021-07-15 07:22:20 +0800
committerGitHub2021-07-14 16:22:20 -0700
commite6c902eaf6f63413ff8f3b12ad8993cf34447413 (patch)
tree051779057f56faf67185b2c360f4e1368f591606 /src/test/scala/chiselTests/CustomBundle.scala
parent695864f5716626a15a7798dae048d8301940a2db (diff)
Fix Cat rename signal (#2011)
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/test/scala/chiselTests/CustomBundle.scala')
-rw-r--r--src/test/scala/chiselTests/CustomBundle.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/CustomBundle.scala b/src/test/scala/chiselTests/CustomBundle.scala
new file mode 100644
index 00000000..b04dcc59
--- /dev/null
+++ b/src/test/scala/chiselTests/CustomBundle.scala
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package chiselTests
+
+import chisel3._
+import chisel3.experimental.{DataMirror, requireIsChiselType}
+import scala.collection.immutable.ListMap
+
+// An example of how Record might be extended
+// In this case, CustomBundle is a Record constructed from a Tuple of (String, Data)
+// it is a possible implementation of a programmatic "Bundle"
+// (and can by connected to MyBundle below)
+final class CustomBundle(elts: (String, Data)*) extends Record {
+ val elements = ListMap(elts map { case (field, elt) =>
+ requireIsChiselType(elt)
+ field -> elt
+ }: _*)
+ def apply(elt: String): Data = elements(elt)
+ override def cloneType: this.type = {
+ val cloned = elts.map { case (n, d) => n -> DataMirror.internal.chiselTypeClone(d) }
+ (new CustomBundle(cloned: _*)).asInstanceOf[this.type]
+ }
+}
+