|
1 | | -//===- Debug.cpp - Debug Utilities ------------------------------*- C++ -*-===// |
| 1 | +//===----------------------------------------------------------------------===// |
2 | 2 | // |
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | 4 | // See https://llvm.org/LICENSE.txt for license information. |
|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | #include "circt/Support/Debug.h" |
14 | | - |
15 | 14 | #include "llvm/ADT/Twine.h" |
16 | 15 | #include "llvm/Support/Debug.h" |
17 | 16 |
|
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; |
| 17 | +llvm::raw_ostream &circt::debugHeader(const llvm::Twine &str, unsigned width) { |
| 18 | + auto &os = llvm::dbgs(); |
| 19 | + auto start = os.tell(); |
| 20 | + os << "===- " << str << " "; |
| 21 | + auto endAct = os.tell() + 4; // 4 for "-===" |
| 22 | + auto endExp = start + width; |
| 23 | + while (endAct < endExp) { |
| 24 | + os << '-'; |
| 25 | + ++endAct; |
25 | 26 | } |
26 | | - if (width > 0) |
27 | | - dbgStream << std::string(width, '='); |
28 | | - return dbgStream; |
| 27 | + os << "-==="; |
| 28 | + return os; |
29 | 29 | } |
30 | 30 |
|
31 | | -llvm::raw_ostream &circt::debugPassHeader(const mlir::Pass *pass, int width) { |
32 | | - return debugHeader((llvm::Twine("Running ") + pass->getName()).str()); |
| 31 | +llvm::raw_ostream &circt::debugPassHeader(const mlir::Pass *pass, |
| 32 | + unsigned width) { |
| 33 | + return debugHeader(llvm::Twine("Running ") + pass->getName()); |
33 | 34 | } |
34 | 35 |
|
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; |
| 36 | +llvm::raw_ostream &circt::debugFooter(unsigned width) { |
| 37 | + auto &os = llvm::dbgs(); |
| 38 | + auto start = os.tell(); |
| 39 | + os << "==="; |
| 40 | + auto endAct = os.tell() + 3; // 3 for trailing "===" |
| 41 | + auto endExp = start + width; |
| 42 | + while (endAct < endExp) { |
| 43 | + os << '-'; |
| 44 | + ++endAct; |
45 | 45 | } |
46 | | - if (width > 0) |
47 | | - dbgStream << std::string(width, '='); |
48 | | - return dbgStream; |
| 46 | + os << "==="; |
| 47 | + return os; |
49 | 48 | } |
0 commit comments