xref: /freebsd/contrib/llvm-project/lldb/utils/TableGen/LLDBTableGen.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
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 LLDB's TableGen.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LLDBTableGenBackends.h" // Declares all backends.
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/ManagedStatic.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 lldb_private;
24 
25 enum ActionType {
26   PrintRecords,
27   DumpJSON,
28   GenOptionDefs,
29   GenPropertyDefs,
30   GenPropertyEnumDefs,
31 };
32 
33 static cl::opt<ActionType> Action(
34     cl::desc("Action to perform:"),
35     cl::values(clEnumValN(PrintRecords, "print-records",
36                           "Print all records to stdout (default)"),
37                clEnumValN(DumpJSON, "dump-json",
38                           "Dump all records as machine-readable JSON"),
39                clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
40                           "Generate lldb option definitions"),
41                clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
42                           "Generate lldb property definitions"),
43                clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
44                           "Generate lldb property enum definitions")));
45 
LLDBTableGenMain(raw_ostream & OS,RecordKeeper & Records)46 static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
47   switch (Action) {
48   case PrintRecords:
49     OS << Records; // No argument, dump all contents
50     break;
51   case DumpJSON:
52     EmitJSON(Records, OS);
53     break;
54   case GenOptionDefs:
55     EmitOptionDefs(Records, OS);
56     break;
57   case GenPropertyDefs:
58     EmitPropertyDefs(Records, OS);
59     break;
60   case GenPropertyEnumDefs:
61     EmitPropertyEnumDefs(Records, OS);
62     break;
63   }
64   return false;
65 }
66 
main(int argc,char ** argv)67 int main(int argc, char **argv) {
68   sys::PrintStackTraceOnErrorSignal(argv[0]);
69   PrettyStackTraceProgram X(argc, argv);
70   cl::ParseCommandLineOptions(argc, argv);
71   llvm_shutdown_obj Y;
72 
73   return TableGenMain(argv[0], &LLDBTableGenMain);
74 }
75 
76 #ifdef __has_feature
77 #if __has_feature(address_sanitizer)
78 #include <sanitizer/lsan_interface.h>
79 // Disable LeakSanitizer for this binary as it has too many leaks that are not
80 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()81 int __lsan_is_turned_off() { return 1; }
82 #endif // __has_feature(address_sanitizer)
83 #endif // defined(__has_feature)
84