CIRCT  19.0.0git
PrintHWModuleGraph.cpp
Go to the documentation of this file.
1 //===- PrintHWModuleGraph.cpp - Print the instance graph --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===//
7 //
8 // Prints an HW module as a .dot graph.
9 //
10 //===----------------------------------------------------------------------===//
11 
13 #include "circt/Dialect/HW/HWOps.h"
15 #include "mlir/Pass/Pass.h"
16 #include "llvm/Support/GraphWriter.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 namespace circt {
20 namespace hw {
21 #define GEN_PASS_DEF_PRINTHWMODULEGRAPH
22 #include "circt/Dialect/HW/Passes.h.inc"
23 } // namespace hw
24 } // namespace circt
25 
26 using namespace circt;
27 using namespace hw;
28 
29 namespace {
30 struct PrintHWModuleGraphPass
31  : public circt::hw::impl::PrintHWModuleGraphBase<PrintHWModuleGraphPass> {
32  PrintHWModuleGraphPass(raw_ostream &os) : os(os) {}
33  void runOnOperation() override {
34  getOperation().walk([&](hw::HWModuleOp module) {
35  // We don't really have any other way of forwarding draw arguments to the
36  // DOTGraphTraits for HWModule except through the module itself - as an
37  // attribute.
38  module->setAttr("dot_verboseEdges",
39  BoolAttr::get(module.getContext(), verboseEdges));
40 
41  llvm::WriteGraph(os, module, /*ShortNames=*/false);
42  });
43  }
44  raw_ostream &os;
45 };
46 } // end anonymous namespace
47 
48 std::unique_ptr<mlir::Pass> circt::hw::createPrintHWModuleGraphPass() {
49  return std::make_unique<PrintHWModuleGraphPass>(llvm::errs());
50 }
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
std::unique_ptr< mlir::Pass > createPrintHWModuleGraphPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: hw.py:1