[firtool] Add -grand-central-instantiate-companion

Add an option that will cause Grand Central companion modules to not be
bound in (they are directly instantiated) and interfaces are no longer
emitted.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
This commit is contained in:
Schuyler Eldridge 2023-01-27 15:48:22 -05:00
parent acb8ba5c61
commit c9f7723269
No known key found for this signature in database
GPG Key ID: 50C5E9936AAD536D
2 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,59 @@
; RUN: firtool %s --grand-central-instantiate-companion | FileCheck %s --check-prefix CHECK
circuit Foo : %[[
{
"class": "sifive.enterprise.grandcentral.GrandCentralView$SerializedViewAnnotation",
"name": "bar_view",
"companion": "~Foo|Companion",
"parent": "~Foo|Foo",
"view": {
"class": "sifive.enterprise.grandcentral.AugmentedBundleType",
"defName": "Bar_View",
"elements": [
{
"name": "bar_in",
"description": "bar in",
"tpe": {
"class": "sifive.enterprise.grandcentral.AugmentedGroundType",
"ref": {
"circuit": "Foo",
"module": "Foo",
"path": [],
"ref": "a",
"component": []
},
"tpe": {
"class": "sifive.enterprise.grandcentral.GrandCentralView$UnknownGroundType$"
}
}
}
]
}
},
{
"class": "sifive.enterprise.grandcentral.ExtractGrandCentralAnnotation",
"directory": "Wire/firrtl/gct",
"filename": "Wire/firrtl/bindings.sv"
}
]]
module Companion :
input clock: Clock
input a: UInt<1>
assert(clock, a, UInt<1>(1), "hello")
module Foo :
input clock: Clock
wire a: UInt<1>
a is invalid
inst companion of Companion
companion.clock <= clock
companion.a <= a
; CHECK: module Foo
; CHECK-NOT: endmodule
; CHECK-NOT: emitted as a bind statement
; CHECK: Companion companion
; CHECK: endmodule

View File

@ -303,6 +303,15 @@ static cl::opt<bool>
cl::desc("Disable the Grand Central passes"),
cl::init(false), cl::Hidden, cl::cat(mainCategory));
static cl::opt<bool> grandCentralInstantiateCompanionOnly(
"grand-central-instantiate-companion",
cl::desc(
"Run Grand Central in a mode where the companion module is "
"instantiated and not bound in and the interface is dropped. This is "
"intended for situations where there is useful assertion logic inside "
"the companion, but you don't care about the actual interface."),
cl::init(false), cl::Hidden, cl::cat(mainCategory));
static cl::opt<bool> exportModuleHierarchy(
"export-module-hierarchy",
cl::desc("Export module and instance hierarchy as JSON"), cl::init(false),
@ -753,7 +762,8 @@ static LogicalResult processBuffer(
// certain black boxes should be placed. Note: all Grand Central Taps related
// collateral is resolved entirely by LowerAnnotations.
if (!disableGrandCentral)
pm.addNestedPass<firrtl::CircuitOp>(firrtl::createGrandCentralPass());
pm.addNestedPass<firrtl::CircuitOp>(
firrtl::createGrandCentralPass(grandCentralInstantiateCompanionOnly));
// Read black box source files into the IR.
StringRef blackBoxRoot = blackBoxRootPath.empty()