From 87551bf5f56d52198efaabdeb69dcd15fb230954 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Tue, 21 Aug 2018 14:32:13 -0400 Subject: Add FlattenInstance API This adds a new trait, FlattenInstance, to chisel3.util.experimental. When mixed into a module or a specific instance this trait will "flatten", i.e., "inline that module and all of its submodules". This includes testing (additions to InlineSpec) and ScalaDoc documentation. Signed-off-by: Schuyler Eldridge --- .../scala/chisel3/util/experimental/Inline.scala | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/main') diff --git a/src/main/scala/chisel3/util/experimental/Inline.scala b/src/main/scala/chisel3/util/experimental/Inline.scala index 4039f3ed..8ec5219b 100644 --- a/src/main/scala/chisel3/util/experimental/Inline.scala +++ b/src/main/scala/chisel3/util/experimental/Inline.scala @@ -48,3 +48,38 @@ trait InlineInstance { self: BaseModule => def toFirrtl: Annotation = NoDedupAnnotation(self.toNamed) }) .map(chisel3.experimental.annotate(_)) } + +/** Flattens an instance of a module + * + * @example {{{ + * trait Internals { this: Module => + * val io = IO(new Bundle{ val a = Input(Bool()) }) + * } + * class Foo extends Module with Internals with FlattenInstance + * class Bar extends Module with Internals { + * val baz = Module(new Baz) + * baz.io.a := io.a + * } + * class Baz extends Module with Internals + * /* The resulting instances will be: + * - Top + * - Top.x + * - Top.y + * - Top.z + * - Top.z.baz */ + * class Top extends Module with Internals { + * val x = Module(new Foo) // x will be flattened + * val y = Module(new Bar with FlattenInstance) // y will also be flattened + * val z = Module(new Bar) // z will not be flattened + * Seq(x, y, z).map(_.io.a := io.a) + * } + * }}} + */ +trait FlattenInstance { self: BaseModule => + Seq(new ChiselAnnotation with RunFirrtlTransform { + def toFirrtl: Annotation = FlattenAnnotation(self.toNamed) + def transformClass: Class[_ <: Transform] = classOf[Flatten] }, + new ChiselAnnotation { + def toFirrtl: Annotation = NoDedupAnnotation(self.toNamed) }) + .map(chisel3.experimental.annotate(_)) +} -- cgit v1.2.3