Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/scala/chisel3/util/experimental/Inline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ trait InlineInstance { self: BaseModule =>
.map(chisel3.experimental.annotate(_))
}

/** Inlines all instances of a module. If this module dedups with any other
* module, instances of that other module will also be inlined.
*/
trait InlineInstanceAllowDedup { self: BaseModule =>
chisel3.experimental.annotate(
new ChiselAnnotation {
def toFirrtl: Annotation = InlineAnnotation(self.toNamed)
}
)
}

/** Flattens an instance of a module
*
* @example {{{
Expand Down
59 changes: 59 additions & 0 deletions src/test/scala/chiselTests/InlineSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0

package chiselTests

import chisel3._
import circt.stage.ChiselStage
import org.scalatest.matchers.should.Matchers
import chiselTests.{ChiselFlatSpec, MatchesAndOmits}
import chisel3.util.experimental.{InlineInstance, InlineInstanceAllowDedup}

class InlineInstanceSpec extends ChiselFlatSpec with MatchesAndOmits {
class ModuleA extends RawModule {
val w = dontTouch(WireInit(false.B))
}

class ModuleB extends RawModule with InlineInstance {
val w = dontTouch(WireInit(false.B))
}

class TopModule extends RawModule {
val a = Module(new ModuleA)
val b = Module(new ModuleB)
}

"InlineInstanceAllowDedup" should "Inline any module that dedups with a module marked inline" in {
val verilog = ChiselStage.emitSystemVerilog(new TopModule)
matchesAndOmits(verilog)(
"module TopModule()",
"module ModuleA();"
)(
"module ModuleB()"
)
}
}

class InlineInstanceAllowDedupSpec extends ChiselFlatSpec with MatchesAndOmits {
class ModuleA extends RawModule {
val w = dontTouch(WireInit(false.B))
}

class ModuleB extends RawModule with InlineInstanceAllowDedup {
val w = dontTouch(WireInit(false.B))
}

class TopModule extends RawModule {
val a = Module(new ModuleA)
val b = Module(new ModuleB)
}

"InlineInstanceAllowDedup" should "Inline any module that dedups with a module marked inline" in {
val verilog = ChiselStage.emitSystemVerilog(new TopModule)
matchesAndOmits(verilog)(
"module TopModule()"
)(
"module ModuleA()",
"module ModuleB()"
)
}
}