-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Public trait to create public FIRRTL modules (#3813)
Add a new trait, `Public`, which can be used to emit FIRRTL modules which have the public keyword. This is a weak form of "public modules" that we want to support for FIRRTL 4.0.0. This does not allow for multiple, disjoint instance graphs to be contained in a circuit, nor does it remove the "main module" from the circuit. However, it provides a mechanism for plucking modules out of a circuit later and working with them. This is self-typed on `RawModule` to prevent mix-in to an external module. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com> Co-authored-by: Jack Koenig <koenig@sifive.com>
- Loading branch information
1 parent
cba3158
commit 1f05995
Showing
13 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chisel3 | ||
|
||
/** A trait that can be mixed into a Chisel module to indicate that a module has external users. | ||
* | ||
* This will result in a public FIRRTL module being produced. | ||
*/ | ||
trait Public { this: RawModule => | ||
|
||
override private[chisel3] def _isPublic = isPublic | ||
|
||
/** Is this module public? | ||
* | ||
* Users can override this if they need more control over when outputs of this Module should | ||
* be considered public | ||
*/ | ||
def isPublic: Boolean = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chiselTests | ||
|
||
import chisel3._ | ||
import circt.stage.ChiselStage | ||
|
||
class PublicModuleSpec extends ChiselFlatSpec with MatchesAndOmits { | ||
|
||
class Qux extends RawModule | ||
|
||
class Baz extends RawModule with Public { | ||
val qux = Module(new Qux) | ||
override def isPublic = false | ||
} | ||
|
||
class Bar extends RawModule with Public { | ||
val baz = Module(new Baz) | ||
} | ||
|
||
class Foo extends RawModule { | ||
val bar = Module(new Bar) | ||
} | ||
|
||
val chirrtl = ChiselStage.emitCHIRRTL(new Foo) | ||
|
||
"the main module" should "be implicitly public" in { | ||
chirrtl should include("public module Foo") | ||
} | ||
|
||
"non-main modules" should "be implicitly private" in { | ||
matchesAndOmits(chirrtl)("module Qux")("public module Qux") | ||
} | ||
|
||
behavior.of("the Public trait") | ||
|
||
it should "cause a module that mixes it in to be public" in { | ||
chirrtl should include("public module Bar") | ||
} | ||
|
||
it should "allow making a module that mixes it in private via an override" in { | ||
matchesAndOmits(chirrtl)("module Baz")("public module Baz") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters