15
15
#ifndef LLVM_UTILS_TABLEGEN_SEQUENCETOOFFSETTABLE_H
16
16
#define LLVM_UTILS_TABLEGEN_SEQUENCETOOFFSETTABLE_H
17
17
18
- #include " llvm/Support/CommandLine.h"
19
18
#include " llvm/Support/raw_ostream.h"
20
19
#include < algorithm>
21
20
#include < cassert>
24
23
#include < map>
25
24
26
25
namespace llvm {
27
- extern llvm::cl::opt<bool > EmitLongStrLiterals;
28
-
29
- // Helper function for SequenceToOffsetTable<string>.
30
- static inline void printStrLitEscChar (raw_ostream &OS, char C) {
31
- const char *Escapes[] = {
32
- " \\ 000" , " \\ 001" , " \\ 002" , " \\ 003" , " \\ 004" , " \\ 005" , " \\ 006" , " \\ 007" ,
33
- " \\ 010" , " \\ t" , " \\ n" , " \\ 013" , " \\ 014" , " \\ r" , " \\ 016" , " \\ 017" ,
34
- " \\ 020" , " \\ 021" , " \\ 022" , " \\ 023" , " \\ 024" , " \\ 025" , " \\ 026" , " \\ 027" ,
35
- " \\ 030" , " \\ 031" , " \\ 032" , " \\ 033" , " \\ 034" , " \\ 035" , " \\ 036" , " \\ 037" ,
36
- " " , " !" , " \\\" " , " #" , " $" , " %" , " &" , " '" ,
37
- " (" , " )" , " *" , " +" , " ," , " -" , " ." , " /" ,
38
- " 0" , " 1" , " 2" , " 3" , " 4" , " 5" , " 6" , " 7" ,
39
- " 8" , " 9" , " :" , " ;" , " <" , " =" , " >" , " ?" ,
40
- " @" , " A" , " B" , " C" , " D" , " E" , " F" , " G" ,
41
- " H" , " I" , " J" , " K" , " L" , " M" , " N" , " O" ,
42
- " P" , " Q" , " R" , " S" , " T" , " U" , " V" , " W" ,
43
- " X" , " Y" , " Z" , " [" , " \\\\ " , " ]" , " ^" , " _" ,
44
- " `" , " a" , " b" , " c" , " d" , " e" , " f" , " g" ,
45
- " h" , " i" , " j" , " k" , " l" , " m" , " n" , " o" ,
46
- " p" , " q" , " r" , " s" , " t" , " u" , " v" , " w" ,
47
- " x" , " y" , " z" , " {" , " |" , " }" , " ~" , " \\ 177" ,
48
- " \\ 200" , " \\ 201" , " \\ 202" , " \\ 203" , " \\ 204" , " \\ 205" , " \\ 206" , " \\ 207" ,
49
- " \\ 210" , " \\ 211" , " \\ 212" , " \\ 213" , " \\ 214" , " \\ 215" , " \\ 216" , " \\ 217" ,
50
- " \\ 220" , " \\ 221" , " \\ 222" , " \\ 223" , " \\ 224" , " \\ 225" , " \\ 226" , " \\ 227" ,
51
- " \\ 230" , " \\ 231" , " \\ 232" , " \\ 233" , " \\ 234" , " \\ 235" , " \\ 236" , " \\ 237" ,
52
- " \\ 240" , " \\ 241" , " \\ 242" , " \\ 243" , " \\ 244" , " \\ 245" , " \\ 246" , " \\ 247" ,
53
- " \\ 250" , " \\ 251" , " \\ 252" , " \\ 253" , " \\ 254" , " \\ 255" , " \\ 256" , " \\ 257" ,
54
- " \\ 260" , " \\ 261" , " \\ 262" , " \\ 263" , " \\ 264" , " \\ 265" , " \\ 266" , " \\ 267" ,
55
- " \\ 270" , " \\ 271" , " \\ 272" , " \\ 273" , " \\ 274" , " \\ 275" , " \\ 276" , " \\ 277" ,
56
- " \\ 300" , " \\ 301" , " \\ 302" , " \\ 303" , " \\ 304" , " \\ 305" , " \\ 306" , " \\ 307" ,
57
- " \\ 310" , " \\ 311" , " \\ 312" , " \\ 313" , " \\ 314" , " \\ 315" , " \\ 316" , " \\ 317" ,
58
- " \\ 320" , " \\ 321" , " \\ 322" , " \\ 323" , " \\ 324" , " \\ 325" , " \\ 326" , " \\ 327" ,
59
- " \\ 330" , " \\ 331" , " \\ 332" , " \\ 333" , " \\ 334" , " \\ 335" , " \\ 336" , " \\ 337" ,
60
- " \\ 340" , " \\ 341" , " \\ 342" , " \\ 343" , " \\ 344" , " \\ 345" , " \\ 346" , " \\ 347" ,
61
- " \\ 350" , " \\ 351" , " \\ 352" , " \\ 353" , " \\ 354" , " \\ 355" , " \\ 356" , " \\ 357" ,
62
- " \\ 360" , " \\ 361" , " \\ 362" , " \\ 363" , " \\ 364" , " \\ 365" , " \\ 366" , " \\ 367" ,
63
- " \\ 370" , " \\ 371" , " \\ 372" , " \\ 373" , " \\ 374" , " \\ 375" , " \\ 376" , " \\ 377" };
64
-
65
- static_assert (sizeof Escapes / sizeof Escapes[0 ] ==
66
- std::numeric_limits<unsigned char >::max () + 1 ,
67
- " unsupported character type" );
68
- OS << Escapes[static_cast <unsigned char >(C)];
69
- }
70
-
71
- static inline void printChar (raw_ostream &OS, char C) {
72
- unsigned char UC (C);
73
- if (isalnum (UC) || ispunct (UC)) {
74
- OS << ' \' ' ;
75
- if (C == ' \\ ' || C == ' \' ' )
76
- OS << ' \\ ' ;
77
- OS << C << ' \' ' ;
78
- } else {
79
- OS << unsigned (UC);
80
- }
81
- }
82
26
83
27
// / SequenceToOffsetTable - Collect a number of terminated sequences of T.
84
28
// / Compute the layout of a table that contains all the sequences, possibly by
@@ -164,24 +108,6 @@ class SequenceToOffsetTable {
164
108
return I->second + (I->first .size () - Seq.size ());
165
109
}
166
110
167
- // / `emit_string_literals` - Print out the table as the body of an array
168
- // / initializer, where each element is a C string literal terminated by
169
- // / `Term`. Calls the the given `Print` function to format individual
170
- // / elements.
171
- void emit_string_literals (raw_ostream &OS) const {
172
- assert (Entries && " Call layout() before emit_string_literals()" );
173
- if (!EmitLongStrLiterals) {
174
- return emit (OS, printChar, " 0" );
175
- }
176
- for (auto I : Seqs) {
177
- OS << " /* " << I.second << " */ \" " ;
178
- for (auto C: I.first ) {
179
- printStrLitEscChar (OS, C);
180
- }
181
- OS << " \\ 0\"\n " ;
182
- }
183
- }
184
-
185
111
// / emit - Print out the table as the body of an array initializer.
186
112
// / Use the Print function to print elements.
187
113
void emit (raw_ostream &OS,
@@ -201,6 +127,19 @@ class SequenceToOffsetTable {
201
127
}
202
128
};
203
129
130
+ // Helper function for SequenceToOffsetTable<string>.
131
+ static inline void printChar (raw_ostream &OS, char C) {
132
+ unsigned char UC (C);
133
+ if (isalnum (UC) || ispunct (UC)) {
134
+ OS << ' \' ' ;
135
+ if (C == ' \\ ' || C == ' \' ' )
136
+ OS << ' \\ ' ;
137
+ OS << C << ' \' ' ;
138
+ } else {
139
+ OS << unsigned (UC);
140
+ }
141
+ }
142
+
204
143
} // end namespace llvm
205
144
206
145
#endif
0 commit comments