LLVM: lib/TableGen/StringToOffsetTable.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14
15using namespace llvm;
16
18 auto [II, Inserted] = StringOffset.insert({Str, size()});
19 if (Inserted) {
20
21 AggregateString.append(Str.begin(), Str.end());
22 if (AppendZero)
23 AggregateString += '\0';
24 }
25
26 return II->second;
27}
28
30 const Twine &Name) const {
31
32
33 if (!AppendZero)
34 PrintFatalError("llvm::StringTable requires null terminated strings");
35
37#ifdef __GNUC__
38#pragma GCC diagnostic push
39#pragma GCC diagnostic ignored "-Woverlength-strings"
40#endif
41{} constexpr char {}{}Storage[] =)",
42 ClassPrefix.empty() ? "static" : "",
43 UsePrefixForStorageMember ? ClassPrefix : "", Name);
44
45
46
47
48
49
50 bool UseChars = && AggregateString.size() > (64 * 1024);
51 OS << (UseChars ? "{\n" : "\n");
52
55
56
57
58 assert(Strings.front().empty() && "Expected empty initial string!");
60 "Expected empty string at the end due to terminators!");
63 OS << LineSep << " ";
64
65 if (!UseChars) {
66 OS << "\"";
68 OS << "\\0\"";
69 continue;
70 }
71
73 for (char C : Str) {
74 OS << CharSep << "'";
76 OS << "'";
77 }
78 OS << CharSep << "'\\0'";
79 }
80 OS << LineSep << (UseChars ? "};" : " ;");
81
83#ifdef __GNUC__
84#pragma GCC diagnostic pop
85#endif
86
87{1} llvm::StringTable
88{2}{0} = {0}Storage;
89)",
90 Name, ClassPrefix.empty() ? "static constexpr" : "const",
91 ClassPrefix);
92}
93
95
98
99 O << " \"";
100 unsigned CharsPrinted = 0;
101 for (unsigned i = 0, e = EscapedStr.size(); i != e; ++i) {
102 if (CharsPrinted > 70) {
103 O << "\"\n \"";
104 CharsPrinted = 0;
105 }
106 O << EscapedStr[i];
107 ++CharsPrinted;
108
109
110 if (EscapedStr[i] != '\\')
111 continue;
112
113 assert(i + 1 < EscapedStr.size() && "Incomplete escape sequence!");
114 if (isDigit(EscapedStr[i + 1])) {
116 "Expected 3 digit octal escape!");
117 O << EscapedStr[++i];
118 O << EscapedStr[++i];
119 O << EscapedStr[++i];
120 CharsPrinted += 3;
121 } else {
122 O << EscapedStr[++i];
123 ++CharsPrinted;
124 }
125 }
126 O << "\"";
127}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t IntrinsicInst * II
A helper class to return the specified delimiter string after the first invocation of operator String...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
unsigned GetOrAddStringOffset(StringRef Str)
Definition StringToOffsetTable.cpp:17
void EmitStringTableDef(raw_ostream &OS, const Twine &Name) const
Definition StringToOffsetTable.cpp:29
void EmitString(raw_ostream &O) const
Definition StringToOffsetTable.cpp:82
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
A raw_ostream that writes to an SmallVector or SmallString.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
void PrintFatalError(const Twine &Msg)
cl::opt< bool > EmitLongStrLiterals
Controls emitting large character arrays as strings or character arrays.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...