-
Notifications
You must be signed in to change notification settings - Fork 647
Implement module prefix API #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
700f18c
b5180f0
374aafb
bad9f00
6a22f97
86eb496
4a0fb28
f8f335f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ package chiselTests | |
| import chisel3._ | ||
| import chisel3.experimental.DataMirror | ||
| import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage, NoRunFirrtlCompilerAnnotation} | ||
| import chisel3.util.HasBlackBoxInline | ||
| import firrtl.annotations.NoTargetAnnotation | ||
| import firrtl.options.Unserializable | ||
|
|
||
|
|
@@ -200,4 +201,84 @@ class ModuleSpec extends ChiselPropSpec with Utils { | |
| val s = Source.fromFile("generated/PlusOne.v").mkString("") | ||
| assert(s.contains("assign io_out = io_in + 32'h1")) | ||
| } | ||
|
|
||
| property("withModulePrefix should prefix modules within it") { | ||
| val m = elaborateAndGetModule(new Module { | ||
| val child = withModulePrefix("Foo") { | ||
| Module(new chisel3.Module { | ||
| Module.currentModulePrefix should be ("Foo") | ||
|
|
||
| override val desiredName = "Module" | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| m.child.name should be ("FooModule") | ||
| } | ||
|
|
||
| property("withModulePrefix should support nested module prefixing") { | ||
| val m = elaborateAndGetModule(new Module { | ||
| val child = withModulePrefix("Foo") { | ||
| Module(new chisel3.Module { | ||
| Module.currentModulePrefix should be ("Foo") | ||
|
|
||
| val nestedChild = withModulePrefix("Bar") { | ||
| Module(new chisel3.Module { | ||
| Module.currentModulePrefix should be ("FooBar") | ||
|
|
||
| override val desiredName = "Module" | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| m.child.nestedChild.name should be ("FooBarModule") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please add a test which includes a And also please add a test for blackbox/inline black box, which should NOT get prefixes applied
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed with all of the tests. I'll note that prefixing of |
||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is a generator, people may want to have generated prefixes, including empty ones. I believe this works but can you add a test showing that an empty prefix ( |
||
|
|
||
| property("withModulePrefix should not prefix if given an empty argument") { | ||
| val m = elaborateAndGetModule(new Module { | ||
| val child = withModulePrefix("") { | ||
| Module(new chisel3.Module { | ||
| Module.currentModulePrefix should be ("") | ||
| override val desiredName = "NoPrefixModule" | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| m.child.name should be ("NoPrefixModule") | ||
| } | ||
|
|
||
| property("withModulePrefix should not prefix blackboxes") { | ||
| val m = elaborateAndGetModule(new Module { | ||
| val bb = withModulePrefix("Foo") { | ||
| Module(new BlackBox { | ||
| val io = IO(new Bundle { }) | ||
| override val desiredName = "BlackBox" | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| m.bb.name should be ("BlackBox") | ||
| } | ||
|
|
||
| property("withModulePrefix should not prefix inlined blackboxes") { | ||
| val m = elaborateAndGetModule(new Module { | ||
| val bb = withModulePrefix("Foo") { | ||
| Module(new BlackBox with HasBlackBoxInline { | ||
| val io = IO(new Bundle { }) | ||
| override val desiredName = "InlineBlackBox" | ||
|
|
||
| setInline("InlineBlackBox.v", | ||
| s""" | ||
| |module InlineBlackBox (); | ||
| | | ||
| |endmodule | ||
| """.stripMargin) | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| m.bb.name should be ("InlineBlackBox") | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.