aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/Basic/TableGen.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 17:16:04 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 17:16:04 +0900
commit0aa930a41f2d1ebf1fa90ec42da8f96d15a4dcbb (patch)
tree6a77b463f700e090df586672c26b9fe765fd115b /llvm/utils/TableGen/Basic/TableGen.cpp
parentec6892d1c979ce0b84c86918d5cdbb03037b409a (diff)
parent6d16b1c5c468a79ecf867293023c89ac518ecdda (diff)
downloadllvm-users/chapuni/cov/single/nextcount-base.zip
llvm-users/chapuni/cov/single/nextcount-base.tar.gz
llvm-users/chapuni/cov/single/nextcount-base.tar.bz2
Merge branch 'users/chapuni/cov/single/pair' into users/chapuni/cov/single/nextcount-baseusers/chapuni/cov/single/nextcount-base
Diffstat (limited to 'llvm/utils/TableGen/Basic/TableGen.cpp')
-rw-r--r--llvm/utils/TableGen/Basic/TableGen.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/Basic/TableGen.cpp b/llvm/utils/TableGen/Basic/TableGen.cpp
new file mode 100644
index 0000000..80ac93f
--- /dev/null
+++ b/llvm/utils/TableGen/Basic/TableGen.cpp
@@ -0,0 +1,99 @@
+//===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
+//
+// 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 global defintions (mostly command line parameters)
+// shared between llvm-tblgen and llvm-min-tblgen.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TableGen.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/TableGen/Main.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/SetTheory.h"
+#include "llvm/TableGen/TableGenBackend.h"
+#include <cassert>
+#include <string>
+#include <vector>
+
+using namespace llvm;
+
+namespace llvm {
+cl::opt<bool> EmitLongStrLiterals(
+ "long-string-literals",
+ cl::desc("when emitting large string tables, prefer string literals over "
+ "comma-separated char literals. This can be a readability and "
+ "compile-time performance win, but upsets some compilers"),
+ cl::Hidden, cl::init(true));
+} // end namespace llvm
+
+static cl::OptionCategory PrintEnumsCat("Options for -print-enums");
+static cl::opt<std::string> Class("class",
+ cl::desc("Print Enum list for this class"),
+ cl::value_desc("class name"),
+ cl::cat(PrintEnumsCat));
+
+static void printRecords(const RecordKeeper &Records, raw_ostream &OS) {
+ OS << Records; // No argument, dump all contents
+}
+
+static void printEnums(const RecordKeeper &Records, raw_ostream &OS) {
+ for (const Record *Rec : Records.getAllDerivedDefinitions(Class))
+ OS << Rec->getName() << ", ";
+ OS << "\n";
+}
+
+static void printSets(const RecordKeeper &Records, raw_ostream &OS) {
+ SetTheory Sets;
+ Sets.addFieldExpander("Set", "Elements");
+ for (const Record *Rec : Records.getAllDerivedDefinitions("Set")) {
+ OS << Rec->getName() << " = [";
+ const std::vector<const Record *> *Elts = Sets.expand(Rec);
+ assert(Elts && "Couldn't expand Set instance");
+ for (const Record *Elt : *Elts)
+ OS << ' ' << Elt->getName();
+ OS << " ]\n";
+ }
+}
+
+static TableGen::Emitter::Opt X[] = {
+ {"print-records", printRecords, "Print all records to stdout (default)",
+ true},
+ {"print-detailed-records", EmitDetailedRecords,
+ "Print full details of all records to stdout"},
+ {"null-backend", [](const RecordKeeper &Records, raw_ostream &OS) {},
+ "Do nothing after parsing (useful for timing)"},
+ {"dump-json", EmitJSON, "Dump all records as machine-readable JSON"},
+ {"print-enums", printEnums, "Print enum values for a class"},
+ {"print-sets", printSets, "Print expanded sets for testing DAG exprs"},
+};
+
+int tblgen_main(int argc, char **argv) {
+ InitLLVM X(argc, argv);
+ cl::ParseCommandLineOptions(argc, argv);
+
+ return TableGenMain(argv[0]);
+}
+
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+#if __has_feature(address_sanitizer) || \
+ (defined(__SANITIZE_ADDRESS__) && defined(__GNUC__)) || \
+ __has_feature(leak_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 .
+LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }
+
+#endif