diff options
| author | Jack Koenig | 2018-08-23 11:41:06 -0700 |
|---|---|---|
| committer | GitHub | 2018-08-23 11:41:06 -0700 |
| commit | 52daa373e7c6601b7461e8bf400b8957080ca110 (patch) | |
| tree | 9e7464dc06123b102045ed04136666efd0308ae8 /src/main/scala/chisel3 | |
| parent | b72f5b8a250547766b89fc9f91eb7076ad8223a8 (diff) | |
| parent | 87551bf5f56d52198efaabdeb69dcd15fb230954 (diff) | |
Merge pull request #838 from seldridge/issue-602
Add instance inline API
Diffstat (limited to 'src/main/scala/chisel3')
| -rw-r--r-- | src/main/scala/chisel3/util/experimental/Inline.scala | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/util/experimental/Inline.scala b/src/main/scala/chisel3/util/experimental/Inline.scala new file mode 100644 index 00000000..8ec5219b --- /dev/null +++ b/src/main/scala/chisel3/util/experimental/Inline.scala @@ -0,0 +1,85 @@ +// See LICENSE for license details. + +package chisel3.util.experimental + +import chisel3._ +import chisel3.internal.InstanceId +import chisel3.experimental.{BaseModule, ChiselAnnotation, RunFirrtlTransform} +import firrtl.Transform +import firrtl.passes.{InlineAnnotation, InlineInstances} +import firrtl.transforms.{NoDedupAnnotation, FlattenAnnotation, Flatten} +import firrtl.annotations.{CircuitName, ModuleName, ComponentName, Annotation} + +/** Inlines an instance of a module + * + * @example {{{ + * trait Internals { this: Module => + * val io = IO(new Bundle{ val a = Input(Bool()) }) + * } + * class Sub extends Module with Internals + * trait HasSub { this: Module with Internals => + * val sub = Module(new Sub) + * sub.io.a := io.a + * } + * /* InlineInstance is mixed directly into Foo's definition. Every instance + * * of this will be inlined. */ + * class Foo extends Module with Internals with InlineInstance with HasSub + * /* Bar will, by default, not be inlined */ + * class Bar extends Module with Internals with HasSub + * /* The resulting instances will be: + * - Top + * - Top.x$sub + * - Top.y$sub + * - Top.z + * - Top.z.sub */ + * class Top extends Module with Internals { + * val x = Module(new Foo) // x will be inlined + * val y = Module(new Bar with InlineInstance) // y will also be inlined + * val z = Module(new Bar) // z will not be inlined + * Seq(x, y, z).map(_.io.a := io.a) + * } + * }}} + */ +trait InlineInstance { self: BaseModule => + Seq(new ChiselAnnotation with RunFirrtlTransform { + def toFirrtl: Annotation = InlineAnnotation(self.toNamed) + def transformClass: Class[_ <: Transform] = classOf[InlineInstances] }, + new ChiselAnnotation { + 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(_)) +} |
