Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/utils/TableGen/TableGen.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
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
// This file contains the main function for Clang's TableGen.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "TableGenBackends.h" // Declares all backends.
14
#include "ASTTableGen.h"
15
#include "llvm/Support/CommandLine.h"
16
#include "llvm/Support/PrettyStackTrace.h"
17
#include "llvm/Support/Signals.h"
18
#include "llvm/TableGen/Error.h"
19
#include "llvm/TableGen/Main.h"
20
#include "llvm/TableGen/Record.h"
21
22
using namespace llvm;
23
using namespace clang;
24
25
enum ActionType {
26
  PrintRecords,
27
  DumpJSON,
28
  GenClangAttrClasses,
29
  GenClangAttrParserStringSwitches,
30
  GenClangAttrSubjectMatchRulesParserStringSwitches,
31
  GenClangAttrImpl,
32
  GenClangAttrList,
33
  GenClangAttrSubjectMatchRuleList,
34
  GenClangAttrPCHRead,
35
  GenClangAttrPCHWrite,
36
  GenClangAttrHasAttributeImpl,
37
  GenClangAttrSpellingListIndex,
38
  GenClangAttrASTVisitor,
39
  GenClangAttrTemplateInstantiate,
40
  GenClangAttrParsedAttrList,
41
  GenClangAttrParsedAttrImpl,
42
  GenClangAttrParsedAttrKinds,
43
  GenClangAttrTextNodeDump,
44
  GenClangAttrNodeTraverse,
45
  GenClangBasicReader,
46
  GenClangBasicWriter,
47
  GenClangDiagsDefs,
48
  GenClangDiagGroups,
49
  GenClangDiagsIndexName,
50
  GenClangCommentNodes,
51
  GenClangDeclNodes,
52
  GenClangStmtNodes,
53
  GenClangTypeNodes,
54
  GenClangTypeReader,
55
  GenClangTypeWriter,
56
  GenClangOpcodes,
57
  GenClangSACheckers,
58
  GenClangCommentHTMLTags,
59
  GenClangCommentHTMLTagsProperties,
60
  GenClangCommentHTMLNamedCharacterReferences,
61
  GenClangCommentCommandInfo,
62
  GenClangCommentCommandList,
63
  GenClangOpenCLBuiltins,
64
  GenArmNeon,
65
  GenArmFP16,
66
  GenArmNeonSema,
67
  GenArmNeonTest,
68
  GenArmMveHeader,
69
  GenArmMveBuiltinDef,
70
  GenArmMveBuiltinSema,
71
  GenArmMveBuiltinCG,
72
  GenArmMveBuiltinAliases,
73
  GenAttrDocs,
74
  GenDiagDocs,
75
  GenOptDocs,
76
  GenDataCollectors,
77
  GenTestPragmaAttributeSupportedAttributes
78
};
79
80
namespace {
81
cl::opt<ActionType> Action(
82
    cl::desc("Action to perform:"),
83
    cl::values(
84
        clEnumValN(PrintRecords, "print-records",
85
                   "Print all records to stdout (default)"),
86
        clEnumValN(DumpJSON, "dump-json",
87
                   "Dump all records as machine-readable JSON"),
88
        clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
89
                   "Generate clang attribute clases"),
90
        clEnumValN(GenClangAttrParserStringSwitches,
91
                   "gen-clang-attr-parser-string-switches",
92
                   "Generate all parser-related attribute string switches"),
93
        clEnumValN(GenClangAttrSubjectMatchRulesParserStringSwitches,
94
                   "gen-clang-attr-subject-match-rules-parser-string-switches",
95
                   "Generate all parser-related attribute subject match rule"
96
                   "string switches"),
97
        clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl",
98
                   "Generate clang attribute implementations"),
99
        clEnumValN(GenClangAttrList, "gen-clang-attr-list",
100
                   "Generate a clang attribute list"),
101
        clEnumValN(GenClangAttrSubjectMatchRuleList,
102
                   "gen-clang-attr-subject-match-rule-list",
103
                   "Generate a clang attribute subject match rule list"),
104
        clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read",
105
                   "Generate clang PCH attribute reader"),
106
        clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
107
                   "Generate clang PCH attribute writer"),
108
        clEnumValN(GenClangAttrHasAttributeImpl,
109
                   "gen-clang-attr-has-attribute-impl",
110
                   "Generate a clang attribute spelling list"),
111
        clEnumValN(GenClangAttrSpellingListIndex,
112
                   "gen-clang-attr-spelling-index",
113
                   "Generate a clang attribute spelling index"),
114
        clEnumValN(GenClangAttrASTVisitor, "gen-clang-attr-ast-visitor",
115
                   "Generate a recursive AST visitor for clang attributes"),
116
        clEnumValN(GenClangAttrTemplateInstantiate,
117
                   "gen-clang-attr-template-instantiate",
118
                   "Generate a clang template instantiate code"),
119
        clEnumValN(GenClangAttrParsedAttrList,
120
                   "gen-clang-attr-parsed-attr-list",
121
                   "Generate a clang parsed attribute list"),
122
        clEnumValN(GenClangAttrParsedAttrImpl,
123
                   "gen-clang-attr-parsed-attr-impl",
124
                   "Generate the clang parsed attribute helpers"),
125
        clEnumValN(GenClangAttrParsedAttrKinds,
126
                   "gen-clang-attr-parsed-attr-kinds",
127
                   "Generate a clang parsed attribute kinds"),
128
        clEnumValN(GenClangAttrTextNodeDump, "gen-clang-attr-text-node-dump",
129
                   "Generate clang attribute text node dumper"),
130
        clEnumValN(GenClangAttrNodeTraverse, "gen-clang-attr-node-traverse",
131
                   "Generate clang attribute traverser"),
132
        clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
133
                   "Generate Clang diagnostics definitions"),
134
        clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
135
                   "Generate Clang diagnostic groups"),
136
        clEnumValN(GenClangDiagsIndexName, "gen-clang-diags-index-name",
137
                   "Generate Clang diagnostic name index"),
138
        clEnumValN(GenClangBasicReader, "gen-clang-basic-reader",
139
                   "Generate Clang BasicReader classes"),
140
        clEnumValN(GenClangBasicWriter, "gen-clang-basic-writer",
141
                   "Generate Clang BasicWriter classes"),
142
        clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes",
143
                   "Generate Clang AST comment nodes"),
144
        clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
145
                   "Generate Clang AST declaration nodes"),
146
        clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
147
                   "Generate Clang AST statement nodes"),
148
        clEnumValN(GenClangTypeNodes, "gen-clang-type-nodes",
149
                   "Generate Clang AST type nodes"),
150
        clEnumValN(GenClangTypeReader, "gen-clang-type-reader",
151
                   "Generate Clang AbstractTypeReader class"),
152
        clEnumValN(GenClangTypeWriter, "gen-clang-type-writer",
153
                   "Generate Clang AbstractTypeWriter class"),
154
        clEnumValN(GenClangOpcodes, "gen-clang-opcodes",
155
                   "Generate Clang constexpr interpreter opcodes"),
156
        clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
157
                   "Generate Clang Static Analyzer checkers"),
158
        clEnumValN(GenClangCommentHTMLTags, "gen-clang-comment-html-tags",
159
                   "Generate efficient matchers for HTML tag "
160
                   "names that are used in documentation comments"),
161
        clEnumValN(GenClangCommentHTMLTagsProperties,
162
                   "gen-clang-comment-html-tags-properties",
163
                   "Generate efficient matchers for HTML tag "
164
                   "properties"),
165
        clEnumValN(GenClangCommentHTMLNamedCharacterReferences,
166
                   "gen-clang-comment-html-named-character-references",
167
                   "Generate function to translate named character "
168
                   "references to UTF-8 sequences"),
169
        clEnumValN(GenClangCommentCommandInfo, "gen-clang-comment-command-info",
170
                   "Generate command properties for commands that "
171
                   "are used in documentation comments"),
172
        clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list",
173
                   "Generate list of commands that are used in "
174
                   "documentation comments"),
175
        clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins",
176
                   "Generate OpenCL builtin declaration handlers"),
177
        clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
178
        clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for clang"),
179
        clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
180
                   "Generate ARM NEON sema support for clang"),
181
        clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
182
                   "Generate ARM NEON tests for clang"),
183
        clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
184
                   "Generate arm_mve.h for clang"),
185
        clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
186
                   "Generate ARM MVE builtin definitions for clang"),
187
        clEnumValN(GenArmMveBuiltinSema, "gen-arm-mve-builtin-sema",
188
                   "Generate ARM MVE builtin sema checks for clang"),
189
        clEnumValN(GenArmMveBuiltinCG, "gen-arm-mve-builtin-codegen",
190
                   "Generate ARM MVE builtin code-generator for clang"),
191
        clEnumValN(GenArmMveBuiltinAliases, "gen-arm-mve-builtin-aliases",
192
                   "Generate list of valid ARM MVE builtin aliases for clang"),
193
        clEnumValN(GenAttrDocs, "gen-attr-docs",
194
                   "Generate attribute documentation"),
195
        clEnumValN(GenDiagDocs, "gen-diag-docs",
196
                   "Generate diagnostic documentation"),
197
        clEnumValN(GenOptDocs, "gen-opt-docs", "Generate option documentation"),
198
        clEnumValN(GenDataCollectors, "gen-clang-data-collectors",
199
                   "Generate data collectors for AST nodes"),
200
        clEnumValN(GenTestPragmaAttributeSupportedAttributes,
201
                   "gen-clang-test-pragma-attribute-supported-attributes",
202
                   "Generate a list of attributes supported by #pragma clang "
203
                   "attribute for testing purposes")));
204
205
cl::opt<std::string>
206
ClangComponent("clang-component",
207
               cl::desc("Only use warnings from specified component"),
208
               cl::value_desc("component"), cl::Hidden);
209
210
5
bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
211
5
  switch (Action) {
212
0
  case PrintRecords:
213
0
    OS << Records;           // No argument, dump all contents
214
0
    break;
215
0
  case DumpJSON:
216
0
    EmitJSON(Records, OS);
217
0
    break;
218
0
  case GenClangAttrClasses:
219
0
    EmitClangAttrClass(Records, OS);
220
0
    break;
221
0
  case GenClangAttrParserStringSwitches:
222
0
    EmitClangAttrParserStringSwitches(Records, OS);
223
0
    break;
224
0
  case GenClangAttrSubjectMatchRulesParserStringSwitches:
225
0
    EmitClangAttrSubjectMatchRulesParserStringSwitches(Records, OS);
226
0
    break;
227
0
  case GenClangAttrImpl:
228
0
    EmitClangAttrImpl(Records, OS);
229
0
    break;
230
0
  case GenClangAttrList:
231
0
    EmitClangAttrList(Records, OS);
232
0
    break;
233
0
  case GenClangAttrSubjectMatchRuleList:
234
0
    EmitClangAttrSubjectMatchRuleList(Records, OS);
235
0
    break;
236
0
  case GenClangAttrPCHRead:
237
0
    EmitClangAttrPCHRead(Records, OS);
238
0
    break;
239
0
  case GenClangAttrPCHWrite:
240
0
    EmitClangAttrPCHWrite(Records, OS);
241
0
    break;
242
0
  case GenClangAttrHasAttributeImpl:
243
0
    EmitClangAttrHasAttrImpl(Records, OS);
244
0
    break;
245
0
  case GenClangAttrSpellingListIndex:
246
0
    EmitClangAttrSpellingListIndex(Records, OS);
247
0
    break;
248
0
  case GenClangAttrASTVisitor:
249
0
    EmitClangAttrASTVisitor(Records, OS);
250
0
    break;
251
0
  case GenClangAttrTemplateInstantiate:
252
0
    EmitClangAttrTemplateInstantiate(Records, OS);
253
0
    break;
254
0
  case GenClangAttrParsedAttrList:
255
0
    EmitClangAttrParsedAttrList(Records, OS);
256
0
    break;
257
0
  case GenClangAttrParsedAttrImpl:
258
0
    EmitClangAttrParsedAttrImpl(Records, OS);
259
0
    break;
260
0
  case GenClangAttrParsedAttrKinds:
261
0
    EmitClangAttrParsedAttrKinds(Records, OS);
262
0
    break;
263
0
  case GenClangAttrTextNodeDump:
264
0
    EmitClangAttrTextNodeDump(Records, OS);
265
0
    break;
266
0
  case GenClangAttrNodeTraverse:
267
0
    EmitClangAttrNodeTraverse(Records, OS);
268
0
    break;
269
1
  case GenClangDiagsDefs:
270
1
    EmitClangDiagsDefs(Records, OS, ClangComponent);
271
1
    break;
272
2
  case GenClangDiagGroups:
273
2
    EmitClangDiagGroups(Records, OS);
274
2
    break;
275
0
  case GenClangDiagsIndexName:
276
0
    EmitClangDiagsIndexName(Records, OS);
277
0
    break;
278
0
  case GenClangCommentNodes:
279
0
    EmitClangASTNodes(Records, OS, CommentNodeClassName, "");
280
0
    break;
281
0
  case GenClangDeclNodes:
282
0
    EmitClangASTNodes(Records, OS, DeclNodeClassName, "Decl");
283
0
    EmitClangDeclContext(Records, OS);
284
0
    break;
285
0
  case GenClangStmtNodes:
286
0
    EmitClangASTNodes(Records, OS, StmtNodeClassName, "");
287
0
    break;
288
0
  case GenClangTypeNodes:
289
0
    EmitClangTypeNodes(Records, OS);
290
0
    break;
291
0
  case GenClangTypeReader:
292
0
    EmitClangTypeReader(Records, OS);
293
0
    break;
294
0
  case GenClangTypeWriter:
295
0
    EmitClangTypeWriter(Records, OS);
296
0
    break;
297
0
  case GenClangBasicReader:
298
0
    EmitClangBasicReader(Records, OS);
299
0
    break;
300
0
  case GenClangBasicWriter:
301
0
    EmitClangBasicWriter(Records, OS);
302
0
    break;
303
0
  case GenClangOpcodes:
304
0
    EmitClangOpcodes(Records, OS);
305
0
    break;
306
0
  case GenClangSACheckers:
307
0
    EmitClangSACheckers(Records, OS);
308
0
    break;
309
0
  case GenClangCommentHTMLTags:
310
0
    EmitClangCommentHTMLTags(Records, OS);
311
0
    break;
312
0
  case GenClangCommentHTMLTagsProperties:
313
0
    EmitClangCommentHTMLTagsProperties(Records, OS);
314
0
    break;
315
0
  case GenClangCommentHTMLNamedCharacterReferences:
316
0
    EmitClangCommentHTMLNamedCharacterReferences(Records, OS);
317
0
    break;
318
0
  case GenClangCommentCommandInfo:
319
0
    EmitClangCommentCommandInfo(Records, OS);
320
0
    break;
321
0
  case GenClangCommentCommandList:
322
0
    EmitClangCommentCommandList(Records, OS);
323
0
    break;
324
0
  case GenClangOpenCLBuiltins:
325
0
    EmitClangOpenCLBuiltins(Records, OS);
326
0
    break;
327
0
  case GenArmNeon:
328
0
    EmitNeon(Records, OS);
329
0
    break;
330
0
  case GenArmFP16:
331
0
    EmitFP16(Records, OS);
332
0
    break;
333
0
  case GenArmNeonSema:
334
0
    EmitNeonSema(Records, OS);
335
0
    break;
336
0
  case GenArmNeonTest:
337
0
    EmitNeonTest(Records, OS);
338
0
    break;
339
0
  case GenArmMveHeader:
340
0
    EmitMveHeader(Records, OS);
341
0
    break;
342
0
  case GenArmMveBuiltinDef:
343
0
    EmitMveBuiltinDef(Records, OS);
344
0
    break;
345
0
  case GenArmMveBuiltinSema:
346
0
    EmitMveBuiltinSema(Records, OS);
347
0
    break;
348
0
  case GenArmMveBuiltinCG:
349
0
    EmitMveBuiltinCG(Records, OS);
350
0
    break;
351
0
  case GenArmMveBuiltinAliases:
352
0
    EmitMveBuiltinAliases(Records, OS);
353
0
    break;
354
0
  case GenAttrDocs:
355
0
    EmitClangAttrDocs(Records, OS);
356
0
    break;
357
1
  case GenDiagDocs:
358
1
    EmitClangDiagDocs(Records, OS);
359
1
    break;
360
0
  case GenOptDocs:
361
0
    EmitClangOptDocs(Records, OS);
362
0
    break;
363
0
  case GenDataCollectors:
364
0
    EmitClangDataCollectors(Records, OS);
365
0
    break;
366
1
  case GenTestPragmaAttributeSupportedAttributes:
367
1
    EmitTestPragmaAttributeSupportedAttributes(Records, OS);
368
1
    break;
369
5
  }
370
5
371
5
  return false;
372
5
}
373
}
374
375
10.8k
int main(int argc, char **argv) {
376
10.8k
  sys::PrintStackTraceOnErrorSignal(argv[0]);
377
10.8k
  PrettyStackTraceProgram X(argc, argv);
378
10.8k
  cl::ParseCommandLineOptions(argc, argv);
379
10.8k
380
10.8k
  llvm_shutdown_obj Y;
381
10.8k
382
10.8k
  return TableGenMain(argv[0], &ClangTableGenMain);
383
10.8k
}
384
385
#ifdef __has_feature
386
#if __has_feature(address_sanitizer)
387
#include <sanitizer/lsan_interface.h>
388
// Disable LeakSanitizer for this binary as it has too many leaks that are not
389
// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
390
int __lsan_is_turned_off() { return 1; }
391
#endif  // __has_feature(address_sanitizer)
392
#endif  // defined(__has_feature)