19870f6adSJonas Devlieghere //===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
293f50594SJonas Devlieghere //
393f50594SJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
493f50594SJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information.
593f50594SJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
693f50594SJonas Devlieghere //
793f50594SJonas Devlieghere //===----------------------------------------------------------------------===//
893f50594SJonas Devlieghere //
99870f6adSJonas Devlieghere // This file contains the main function for LLDB's TableGen.
1093f50594SJonas Devlieghere //
1193f50594SJonas Devlieghere //===----------------------------------------------------------------------===//
1293f50594SJonas Devlieghere
1393f50594SJonas Devlieghere #include "LLDBTableGenBackends.h" // Declares all backends.
1493f50594SJonas Devlieghere #include "llvm/Support/CommandLine.h"
1593f50594SJonas Devlieghere #include "llvm/Support/PrettyStackTrace.h"
1693f50594SJonas Devlieghere #include "llvm/Support/Signals.h"
1793f50594SJonas Devlieghere #include "llvm/TableGen/Error.h"
1893f50594SJonas Devlieghere #include "llvm/TableGen/Main.h"
1993f50594SJonas Devlieghere #include "llvm/TableGen/Record.h"
2093f50594SJonas Devlieghere
2193f50594SJonas Devlieghere using namespace llvm;
2293f50594SJonas Devlieghere using namespace lldb_private;
2393f50594SJonas Devlieghere
2493f50594SJonas Devlieghere enum ActionType {
2593f50594SJonas Devlieghere PrintRecords,
2693f50594SJonas Devlieghere DumpJSON,
2793f50594SJonas Devlieghere GenOptionDefs,
28*971f9ca6SJonas Devlieghere GenPropertyDefs,
29*971f9ca6SJonas Devlieghere GenPropertyEnumDefs,
3093f50594SJonas Devlieghere };
3193f50594SJonas Devlieghere
32*971f9ca6SJonas Devlieghere static cl::opt<ActionType> Action(
33*971f9ca6SJonas Devlieghere cl::desc("Action to perform:"),
3493f50594SJonas Devlieghere cl::values(clEnumValN(PrintRecords, "print-records",
3593f50594SJonas Devlieghere "Print all records to stdout (default)"),
3693f50594SJonas Devlieghere clEnumValN(DumpJSON, "dump-json",
3793f50594SJonas Devlieghere "Dump all records as machine-readable JSON"),
3893f50594SJonas Devlieghere clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
39*971f9ca6SJonas Devlieghere "Generate lldb option definitions"),
40*971f9ca6SJonas Devlieghere clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
41*971f9ca6SJonas Devlieghere "Generate lldb property definitions"),
42*971f9ca6SJonas Devlieghere clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
43*971f9ca6SJonas Devlieghere "Generate lldb property enum definitions")));
4493f50594SJonas Devlieghere
LLDBTableGenMain(raw_ostream & OS,RecordKeeper & Records)4593f50594SJonas Devlieghere static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
4693f50594SJonas Devlieghere switch (Action) {
4793f50594SJonas Devlieghere case PrintRecords:
4893f50594SJonas Devlieghere OS << Records; // No argument, dump all contents
4993f50594SJonas Devlieghere break;
5093f50594SJonas Devlieghere case DumpJSON:
5193f50594SJonas Devlieghere EmitJSON(Records, OS);
5293f50594SJonas Devlieghere break;
5393f50594SJonas Devlieghere case GenOptionDefs:
5493f50594SJonas Devlieghere EmitOptionDefs(Records, OS);
5593f50594SJonas Devlieghere break;
56*971f9ca6SJonas Devlieghere case GenPropertyDefs:
57*971f9ca6SJonas Devlieghere EmitPropertyDefs(Records, OS);
58*971f9ca6SJonas Devlieghere break;
59*971f9ca6SJonas Devlieghere case GenPropertyEnumDefs:
60*971f9ca6SJonas Devlieghere EmitPropertyEnumDefs(Records, OS);
61*971f9ca6SJonas Devlieghere break;
6293f50594SJonas Devlieghere }
6393f50594SJonas Devlieghere return false;
6493f50594SJonas Devlieghere }
6593f50594SJonas Devlieghere
main(int argc,char ** argv)6693f50594SJonas Devlieghere int main(int argc, char **argv) {
6793f50594SJonas Devlieghere sys::PrintStackTraceOnErrorSignal(argv[0]);
6893f50594SJonas Devlieghere PrettyStackTraceProgram X(argc, argv);
6993f50594SJonas Devlieghere cl::ParseCommandLineOptions(argc, argv);
7093f50594SJonas Devlieghere
7193f50594SJonas Devlieghere llvm_shutdown_obj Y;
7293f50594SJonas Devlieghere
7393f50594SJonas Devlieghere return TableGenMain(argv[0], &LLDBTableGenMain);
7493f50594SJonas Devlieghere }
7593f50594SJonas Devlieghere
7693f50594SJonas Devlieghere #ifdef __has_feature
7793f50594SJonas Devlieghere #if __has_feature(address_sanitizer)
7893f50594SJonas Devlieghere #include <sanitizer/lsan_interface.h>
7993f50594SJonas Devlieghere // Disable LeakSanitizer for this binary as it has too many leaks that are not
8093f50594SJonas Devlieghere // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()8193f50594SJonas Devlieghere int __lsan_is_turned_off() { return 1; }
8293f50594SJonas Devlieghere #endif // __has_feature(address_sanitizer)
8393f50594SJonas Devlieghere #endif // defined(__has_feature)
84