mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-05 15:42:24 +00:00
971f9ca612
Property definitions are currently defined in a PropertyDefinition array and have a corresponding enum to index in this array. Unfortunately this is quite error prone. Indeed, just today we found an incorrect merge where a discrepancy between the order of the enum values and their definition caused the test suite to fail spectacularly. Tablegen can streamline the process of generating the property definition table while at the same time guaranteeing that the enums stay in sync. That's exactly what this patch does. It adds a new tablegen file for the properties, building on top of the infrastructure that Raphael added recently for the command options. It also introduces two new tablegen backends: one for the property definitions and one for their corresponding enums. It might be worth mentioning that I generated most of the tablegen definitions from the existing property definitions, by adding a dump method to the struct. This seems both more efficient and less error prone that copying everything over by hand. Only Enum properties needed manual fixup for the EnumValues and DefaultEnumValue fields. Differential revision: https://reviews.llvm.org/D65185 llvm-svn: 367058
84 lines
2.7 KiB
C++
84 lines
2.7 KiB
C++
//===- LLDBTableGen.cpp - Top-Level TableGen implementation for LLDB ------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains the main function for LLDB's TableGen.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "LLDBTableGenBackends.h" // Declares all backends.
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
#include "llvm/Support/Signals.h"
|
|
#include "llvm/TableGen/Error.h"
|
|
#include "llvm/TableGen/Main.h"
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
using namespace llvm;
|
|
using namespace lldb_private;
|
|
|
|
enum ActionType {
|
|
PrintRecords,
|
|
DumpJSON,
|
|
GenOptionDefs,
|
|
GenPropertyDefs,
|
|
GenPropertyEnumDefs,
|
|
};
|
|
|
|
static cl::opt<ActionType> Action(
|
|
cl::desc("Action to perform:"),
|
|
cl::values(clEnumValN(PrintRecords, "print-records",
|
|
"Print all records to stdout (default)"),
|
|
clEnumValN(DumpJSON, "dump-json",
|
|
"Dump all records as machine-readable JSON"),
|
|
clEnumValN(GenOptionDefs, "gen-lldb-option-defs",
|
|
"Generate lldb option definitions"),
|
|
clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
|
|
"Generate lldb property definitions"),
|
|
clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
|
|
"Generate lldb property enum definitions")));
|
|
|
|
static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
|
|
switch (Action) {
|
|
case PrintRecords:
|
|
OS << Records; // No argument, dump all contents
|
|
break;
|
|
case DumpJSON:
|
|
EmitJSON(Records, OS);
|
|
break;
|
|
case GenOptionDefs:
|
|
EmitOptionDefs(Records, OS);
|
|
break;
|
|
case GenPropertyDefs:
|
|
EmitPropertyDefs(Records, OS);
|
|
break;
|
|
case GenPropertyEnumDefs:
|
|
EmitPropertyEnumDefs(Records, OS);
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
sys::PrintStackTraceOnErrorSignal(argv[0]);
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
llvm_shutdown_obj Y;
|
|
|
|
return TableGenMain(argv[0], &LLDBTableGenMain);
|
|
}
|
|
|
|
#ifdef __has_feature
|
|
#if __has_feature(address_sanitizer)
|
|
#include <sanitizer/lsan_interface.h>
|
|
// Disable LeakSanitizer for this binary as it has too many leaks that are not
|
|
// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
|
|
int __lsan_is_turned_off() { return 1; }
|
|
#endif // __has_feature(address_sanitizer)
|
|
#endif // defined(__has_feature)
|