16 #include "mlir/IR/Builders.h"
17 #include "mlir/Pass/Pass.h"
21 #define GEN_PASS_DEF_HWSTUBEXTERNALMODULES
22 #include "circt/Dialect/SV/SVPasses.h.inc"
26 using namespace circt;
32 struct HWStubExternalModulesPass
33 :
public circt::sv::impl::HWStubExternalModulesBase<
34 HWStubExternalModulesPass> {
35 void runOnOperation()
override;
39 void HWStubExternalModulesPass::runOnOperation() {
40 auto topModule = getOperation().getBody();
41 OpBuilder builder(topModule->getParentOp()->getContext());
42 builder.setInsertionPointToEnd(topModule);
44 for (
auto &op : llvm::make_early_inc_range(*topModule))
45 if (
auto module = dyn_cast<hw::HWModuleExternOp>(op)) {
46 hw::ModulePortInfo ports(module.getPortList());
47 auto nameAttr = module.getNameAttr();
49 module.getLoc(), nameAttr, ports, module.getParameters());
50 auto outputOp = newModule.getBodyBlock()->getTerminator();
51 OpBuilder innerBuilder(outputOp);
52 SmallVector<Value, 8> outputs;
54 for (
auto &p : ports.getOutputs()) {
56 innerBuilder.create<sv::ConstantXOp>(outputOp->getLoc(), p.
type));
58 outputOp->setOperands(outputs);
66 return std::make_unique<HWStubExternalModulesPass>();
std::unique_ptr< mlir::Pass > createHWStubExternalModulesPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.