diff --git a/test/Dialect/FIRRTL/SFCTests/GrandCentralInterfaces/InstantiateCompanionOnly.fir b/test/Dialect/FIRRTL/SFCTests/GrandCentralInterfaces/InstantiateCompanionOnly.fir new file mode 100644 index 0000000000..866d2764e8 --- /dev/null +++ b/test/Dialect/FIRRTL/SFCTests/GrandCentralInterfaces/InstantiateCompanionOnly.fir @@ -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 diff --git a/tools/firtool/firtool.cpp b/tools/firtool/firtool.cpp index 96a1852a60..eea4f88770 100644 --- a/tools/firtool/firtool.cpp +++ b/tools/firtool/firtool.cpp @@ -303,6 +303,15 @@ static cl::opt cl::desc("Disable the Grand Central passes"), cl::init(false), cl::Hidden, cl::cat(mainCategory)); +static cl::opt 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 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::createGrandCentralPass()); + pm.addNestedPass( + firrtl::createGrandCentralPass(grandCentralInstantiateCompanionOnly)); // Read black box source files into the IR. StringRef blackBoxRoot = blackBoxRootPath.empty()