CIRCT 20.0.0git
Loading...
Searching...
No Matches
PrettyPrinterHelpers.cpp
Go to the documentation of this file.
1//===- PrettyPrinterHelpers.cpp - Pretty printing helpers -----------------===//
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// Helper classes for using PrettyPrinter.
10//
11//===----------------------------------------------------------------------===//
12
14
15#include "llvm/ADT/SmallString.h"
16#include "llvm/Support/raw_ostream.h"
17#include <array>
18
19namespace circt {
20namespace pretty {
21
22//===----------------------------------------------------------------------===//
23// Convenience builders.
24//===----------------------------------------------------------------------===//
25
26void TokenStringSaver::clear() { alloc.Reset(); }
27
28/// Add multiple non-breaking spaces as a single token.
29void detail::emitNBSP(unsigned n, llvm::function_ref<void(Token)> add) {
30 static const std::array<char, 128> spaces = ([]() constexpr {
31 std::array<char, 128> s = {};
32 for (auto &c : s)
33 c = ' ';
34 return s;
35 })();
36
37 const auto size = spaces.size();
38 if (n <= size) {
39 if (n != 0)
40 add(StringToken({spaces.data(), n}));
41 return;
42 }
43 while (n) {
44 auto chunk = std::min<uint32_t>(n, size);
45 add(StringToken({spaces.data(), chunk}));
46 n -= chunk;
47 }
48}
49
50} // end namespace pretty
51} // end namespace circt
void clear() override
PrettyPrinter::Listener::clear – indicates no external refs.
void emitNBSP(unsigned n, llvm::function_ref< void(Token)> add)
Add multiple non-breaking spaces as a single token.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.