xref: /freebsd/contrib/llvm-project/lldb/utils/TableGen/LLDBTableGen.cpp (revision 9dba64be9536c28e4800e06512b7f29b43ade345)
1*9dba64beSDimitry Andric //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
9*9dba64beSDimitry Andric // This file contains the main function for LLDB's TableGen.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "LLDBTableGenBackends.h" // Declares all backends.
140b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
150b57cec5SDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
160b57cec5SDimitry Andric #include "llvm/Support/Signals.h"
170b57cec5SDimitry Andric #include "llvm/TableGen/Error.h"
180b57cec5SDimitry Andric #include "llvm/TableGen/Main.h"
190b57cec5SDimitry Andric #include "llvm/TableGen/Record.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric using namespace llvm;
220b57cec5SDimitry Andric using namespace lldb_private;
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric enum ActionType {
250b57cec5SDimitry Andric   PrintRecords,
260b57cec5SDimitry Andric   DumpJSON,
270b57cec5SDimitry Andric   GenOptionDefs,
28*9dba64beSDimitry Andric   GenPropertyDefs,
29*9dba64beSDimitry Andric   GenPropertyEnumDefs,
300b57cec5SDimitry Andric };
310b57cec5SDimitry Andric 
32*9dba64beSDimitry Andric static cl::opt<ActionType> Action(
33*9dba64beSDimitry Andric     cl::desc("Action to perform:"),
340b57cec5SDimitry Andric     cl::values(clEnumValN(PrintRecords, "print-records",
350b57cec5SDimitry Andric                           "Print all records to stdout (default)"),
360b57cec5SDimitry Andric                clEnumValN(DumpJSON, "dump-json",
370b57cec5SDimitry Andric                           "Dump all records as machine-readable JSON"),
380b57cec5SDimitry Andric                clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
39*9dba64beSDimitry Andric                           "Generate lldb option definitions"),
40*9dba64beSDimitry Andric                clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
41*9dba64beSDimitry Andric                           "Generate lldb property definitions"),
42*9dba64beSDimitry Andric                clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
43*9dba64beSDimitry Andric                           "Generate lldb property enum definitions")));
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
460b57cec5SDimitry Andric   switch (Action) {
470b57cec5SDimitry Andric   case PrintRecords:
480b57cec5SDimitry Andric     OS << Records; // No argument, dump all contents
490b57cec5SDimitry Andric     break;
500b57cec5SDimitry Andric   case DumpJSON:
510b57cec5SDimitry Andric     EmitJSON(Records, OS);
520b57cec5SDimitry Andric     break;
530b57cec5SDimitry Andric   case GenOptionDefs:
540b57cec5SDimitry Andric     EmitOptionDefs(Records, OS);
550b57cec5SDimitry Andric     break;
56*9dba64beSDimitry Andric   case GenPropertyDefs:
57*9dba64beSDimitry Andric     EmitPropertyDefs(Records, OS);
58*9dba64beSDimitry Andric     break;
59*9dba64beSDimitry Andric   case GenPropertyEnumDefs:
60*9dba64beSDimitry Andric     EmitPropertyEnumDefs(Records, OS);
61*9dba64beSDimitry Andric     break;
620b57cec5SDimitry Andric   }
630b57cec5SDimitry Andric   return false;
640b57cec5SDimitry Andric }
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric int main(int argc, char **argv) {
670b57cec5SDimitry Andric   sys::PrintStackTraceOnErrorSignal(argv[0]);
680b57cec5SDimitry Andric   PrettyStackTraceProgram X(argc, argv);
690b57cec5SDimitry Andric   cl::ParseCommandLineOptions(argc, argv);
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   llvm_shutdown_obj Y;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   return TableGenMain(argv[0], &LLDBTableGenMain);
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric #ifdef __has_feature
770b57cec5SDimitry Andric #if __has_feature(address_sanitizer)
780b57cec5SDimitry Andric #include <sanitizer/lsan_interface.h>
790b57cec5SDimitry Andric // Disable LeakSanitizer for this binary as it has too many leaks that are not
800b57cec5SDimitry Andric // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
810b57cec5SDimitry Andric int __lsan_is_turned_off() { return 1; }
820b57cec5SDimitry Andric #endif // __has_feature(address_sanitizer)
830b57cec5SDimitry Andric #endif // defined(__has_feature)
84