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 
12 #include "PassDetails.h"
15 #include "llvm/Support/GraphWriter.h"
16 #include "llvm/Support/raw_ostream.h"
17 
18 using namespace circt;
19 using namespace hw;
20 
21 namespace {
22 struct PrintHWModuleGraphPass
23  : public PrintHWModuleGraphBase<PrintHWModuleGraphPass> {
24  PrintHWModuleGraphPass(raw_ostream &os) : os(os) {}
25  void runOnOperation() override {
26  getOperation().walk([&](hw::HWModuleOp module) {
27  // We don't really have any other way of forwarding draw arguments to the
28  // DOTGraphTraits for HWModule except through the module itself - as an
29  // attribute.
30  module->setAttr("dot_verboseEdges",
31  BoolAttr::get(module.getContext(), verboseEdges));
32 
33  llvm::WriteGraph(os, module, /*ShortNames=*/false);
34  });
35  }
36  raw_ostream &os;
37 };
38 } // end anonymous namespace
39 
40 std::unique_ptr<mlir::Pass> circt::hw::createPrintHWModuleGraphPass() {
41  return std::make_unique<PrintHWModuleGraphPass>(llvm::errs());
42 }
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