18 #include "mlir/IR/Builders.h"
19 #include "mlir/Pass/Pass.h"
20 #include "llvm/Support/Path.h"
21 #include "llvm/Support/Process.h"
25 #define GEN_PASS_DEF_SVTRACEIVERILOG
26 #include "circt/Dialect/SV/SVPasses.h.inc"
30 using namespace circt;
40 struct SVTraceIVerilogPass
41 :
public circt::sv::impl::SVTraceIVerilogBase<SVTraceIVerilogPass> {
42 void runOnOperation()
override;
47 void SVTraceIVerilogPass::runOnOperation() {
48 mlir::ModuleOp mod = getOperation();
51 auto &graph = getAnalysis<InstanceGraph>();
52 auto topLevelNodes = graph.getInferredTopLevelNodes();
53 if (failed(topLevelNodes) || topLevelNodes->size() != 1) {
54 mod.emitError(
"Expected exactly one top level node");
55 return signalPassFailure();
58 dyn_cast_or_null<hw::HWModuleOp>(*topLevelNodes->front()->getModule());
60 mod.emitError(
"top module is not a HWModuleOp");
61 return signalPassFailure();
63 targetModuleName.setValue(top.getName().str());
67 if (!targetModuleName.empty() &&
68 hwmod.getName() != targetModuleName.getValue())
70 OpBuilder builder(hwmod.getBodyBlock(), hwmod.getBodyBlock()->begin());
71 std::string traceMacro;
72 llvm::raw_string_ostream ss(traceMacro);
73 auto modName = hwmod.getName();
74 ss <<
"initial begin\n $dumpfile (\"" << directoryName.getValue()
75 << modName <<
".vcd\");\n $dumpvars (0, " << modName
77 builder.create<sv::VerbatimOp>(hwmod.getLoc(), ss.str());
82 return std::make_unique<SVTraceIVerilogPass>();
std::unique_ptr< mlir::Pass > createSVTraceIVerilogPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.