xref: /openbsd-src/gnu/llvm/lldb/utils/TableGen/LLDBTableGen.cpp (revision 061da546b983eb767bad15e67af1174fb0bcf31c)
1*061da546Spatrick //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
2*061da546Spatrick //
3*061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5*061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*061da546Spatrick //
7*061da546Spatrick //===----------------------------------------------------------------------===//
8*061da546Spatrick //
9*061da546Spatrick // This file contains the main function for LLDB's TableGen.
10*061da546Spatrick //
11*061da546Spatrick //===----------------------------------------------------------------------===//
12*061da546Spatrick 
13*061da546Spatrick #include "LLDBTableGenBackends.h" // Declares all backends.
14*061da546Spatrick #include "llvm/Support/CommandLine.h"
15*061da546Spatrick #include "llvm/Support/PrettyStackTrace.h"
16*061da546Spatrick #include "llvm/Support/Signals.h"
17*061da546Spatrick #include "llvm/TableGen/Error.h"
18*061da546Spatrick #include "llvm/TableGen/Main.h"
19*061da546Spatrick #include "llvm/TableGen/Record.h"
20*061da546Spatrick 
21*061da546Spatrick using namespace llvm;
22*061da546Spatrick using namespace lldb_private;
23*061da546Spatrick 
24*061da546Spatrick enum ActionType {
25*061da546Spatrick   PrintRecords,
26*061da546Spatrick   DumpJSON,
27*061da546Spatrick   GenOptionDefs,
28*061da546Spatrick   GenPropertyDefs,
29*061da546Spatrick   GenPropertyEnumDefs,
30*061da546Spatrick };
31*061da546Spatrick 
32*061da546Spatrick static cl::opt<ActionType> Action(
33*061da546Spatrick     cl::desc("Action to perform:"),
34*061da546Spatrick     cl::values(clEnumValN(PrintRecords, "print-records",
35*061da546Spatrick                           "Print all records to stdout (default)"),
36*061da546Spatrick                clEnumValN(DumpJSON, "dump-json",
37*061da546Spatrick                           "Dump all records as machine-readable JSON"),
38*061da546Spatrick                clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
39*061da546Spatrick                           "Generate lldb option definitions"),
40*061da546Spatrick                clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
41*061da546Spatrick                           "Generate lldb property definitions"),
42*061da546Spatrick                clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
43*061da546Spatrick                           "Generate lldb property enum definitions")));
44*061da546Spatrick 
LLDBTableGenMain(raw_ostream & OS,RecordKeeper & Records)45*061da546Spatrick static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
46*061da546Spatrick   switch (Action) {
47*061da546Spatrick   case PrintRecords:
48*061da546Spatrick     OS << Records; // No argument, dump all contents
49*061da546Spatrick     break;
50*061da546Spatrick   case DumpJSON:
51*061da546Spatrick     EmitJSON(Records, OS);
52*061da546Spatrick     break;
53*061da546Spatrick   case GenOptionDefs:
54*061da546Spatrick     EmitOptionDefs(Records, OS);
55*061da546Spatrick     break;
56*061da546Spatrick   case GenPropertyDefs:
57*061da546Spatrick     EmitPropertyDefs(Records, OS);
58*061da546Spatrick     break;
59*061da546Spatrick   case GenPropertyEnumDefs:
60*061da546Spatrick     EmitPropertyEnumDefs(Records, OS);
61*061da546Spatrick     break;
62*061da546Spatrick   }
63*061da546Spatrick   return false;
64*061da546Spatrick }
65*061da546Spatrick 
main(int argc,char ** argv)66*061da546Spatrick int main(int argc, char **argv) {
67*061da546Spatrick   sys::PrintStackTraceOnErrorSignal(argv[0]);
68*061da546Spatrick   PrettyStackTraceProgram X(argc, argv);
69*061da546Spatrick   cl::ParseCommandLineOptions(argc, argv);
70*061da546Spatrick 
71*061da546Spatrick   llvm_shutdown_obj Y;
72*061da546Spatrick 
73*061da546Spatrick   return TableGenMain(argv[0], &LLDBTableGenMain);
74*061da546Spatrick }
75*061da546Spatrick 
76*061da546Spatrick #ifdef __has_feature
77*061da546Spatrick #if __has_feature(address_sanitizer)
78*061da546Spatrick #include <sanitizer/lsan_interface.h>
79*061da546Spatrick // Disable LeakSanitizer for this binary as it has too many leaks that are not
80*061da546Spatrick // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()81*061da546Spatrick int __lsan_is_turned_off() { return 1; }
82*061da546Spatrick #endif // __has_feature(address_sanitizer)
83*061da546Spatrick #endif // defined(__has_feature)
84