CIRCT  19.0.0git
Debug.cpp
Go to the documentation of this file.
1 //===- Debug.cpp - Debug Utilities ------------------------------*- 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 //
9 // Utilities related to generating run-time debug information.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "circt/Support/Debug.h"
14 
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/Debug.h"
17 
18 llvm::raw_ostream &circt::debugHeader(llvm::StringRef str, int width) {
19  auto &dbgStream = llvm::dbgs();
20  dbgStream << "===- " << str << " ";
21  width -= 6 + str.size();
22  if (width > 3) {
23  dbgStream << std::string(width - 3, '-');
24  width = 3;
25  }
26  if (width > 0)
27  dbgStream << std::string(width, '=');
28  return dbgStream;
29 }
30 
31 llvm::raw_ostream &circt::debugPassHeader(const mlir::Pass *pass, int width) {
32  return debugHeader((llvm::Twine("Running ") + pass->getName()).str());
33 }
34 
35 llvm::raw_ostream &circt::debugFooter(int width) {
36  auto &dbgStream = llvm::dbgs();
37  if (width > 3) {
38  int startWidth = std::min(width - 3, 3);
39  dbgStream << std::string(startWidth, '=');
40  width -= startWidth;
41  }
42  if (width > 3) {
43  dbgStream << std::string(width - 3, '-');
44  width = 3;
45  }
46  if (width > 0)
47  dbgStream << std::string(width, '=');
48  return dbgStream;
49 }
int32_t width
Definition: FIRRTL.cpp:36
llvm::raw_ostream & debugHeader(llvm::StringRef str, int width=80)
Write a "header"-like string to the debug stream with a certain width.
Definition: Debug.cpp:18
llvm::raw_ostream & debugPassHeader(const mlir::Pass *pass, int width=80)
Write a boilerplate header for a pass to the debug stream.
Definition: Debug.cpp:31
llvm::raw_ostream & debugFooter(int width=80)
Write a boilerplate footer to the debug stream to indicate that a pass has ended.
Definition: Debug.cpp:35