summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/Aggregate.scala
diff options
context:
space:
mode:
authoranniej-sifive2021-08-04 12:11:58 -0700
committerGitHub2021-08-04 19:11:58 +0000
commit5a9b6487fbc5ccf0243f9755ee3cd88ec6036e2c (patch)
treeb760b1e6a98f5dca1ac20965ce3de3dbfea49342 /core/src/main/scala/chisel3/Aggregate.scala
parentda923f317ff325a93cee6289552ccfa413c35f98 (diff)
Added VecInit factory methods (fill,iterate) (#2059)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'core/src/main/scala/chisel3/Aggregate.scala')
-rw-r--r--core/src/main/scala/chisel3/Aggregate.scala30
1 files changed, 29 insertions, 1 deletions
diff --git a/core/src/main/scala/chisel3/Aggregate.scala b/core/src/main/scala/chisel3/Aggregate.scala
index 45ecec36..3a766628 100644
--- a/core/src/main/scala/chisel3/Aggregate.scala
+++ b/core/src/main/scala/chisel3/Aggregate.scala
@@ -590,6 +590,33 @@ object VecInit extends SourceInfoDoc {
/** @group SourceInfoTransformMacro */
def do_tabulate[T <: Data](n: Int)(gen: (Int) => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
apply((0 until n).map(i => gen(i)))
+
+ /** Creates a new [[Vec]] of length `n` composed of the result of the given
+ * function applied to an element of data type T.
+ *
+ * @param n number of elements in the vector
+ * @param gen function that takes in an element T and returns an output
+ * element of the same type
+ */
+ def fill[T <: Data](n: Int)(gen: => T): Vec[T] = macro VecTransform.fill
+
+ /** @group SourceInfoTransformMacro */
+ def do_fill[T <: Data](n: Int)(gen: => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
+ apply(Seq.fill(n)(gen))
+
+ /** Creates a new [[Vec]] of length `n` composed of the result of the given
+ * function applied to an element of data type T.
+ *
+ * @param start First element in the Vec
+ * @param len Lenth of elements in the Vec
+ * @param f Function that applies the element T from previous index and returns the output
+ * element to the next index
+ */
+ def iterate[T <: Data](start: T, len: Int)(f: (T) => T): Vec[T] = macro VecTransform.iterate
+
+ /** @group SourceInfoTransformMacro */
+ def do_iterate[T <: Data](start: T, len: Int)(f: (T) => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Vec[T] =
+ apply(Seq.iterate(start, len)(f))
}
/** A trait for [[Vec]]s containing common hardware generators for collection
@@ -964,7 +991,7 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record {
getBundleField(m) match {
case Some(d: Data) =>
requireIsChiselType(d)
-
+
if (nameMap contains m.getName) {
require(nameMap(m.getName) eq d)
} else {
@@ -1268,3 +1295,4 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record {
*/
override def toPrintable: Printable = toPrintableHelper(elements.toList.reverse)
}
+