Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/TableGen.cpp
35258 views
//===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the main function for LLVM's TableGen.9//10//===----------------------------------------------------------------------===//1112#include "llvm/ADT/StringRef.h"13#include "llvm/Support/CommandLine.h"14#include "llvm/Support/InitLLVM.h"15#include "llvm/Support/raw_ostream.h"16#include "llvm/TableGen/Main.h"17#include "llvm/TableGen/Record.h"18#include "llvm/TableGen/SetTheory.h"19#include "llvm/TableGen/TableGenBackend.h"20#include <cassert>21#include <string>22#include <vector>2324using namespace llvm;2526namespace llvm {27cl::opt<bool> EmitLongStrLiterals(28"long-string-literals",29cl::desc("when emitting large string tables, prefer string literals over "30"comma-separated char literals. This can be a readability and "31"compile-time performance win, but upsets some compilers"),32cl::Hidden, cl::init(true));33} // end namespace llvm3435namespace {3637cl::OptionCategory PrintEnumsCat("Options for -print-enums");38cl::opt<std::string> Class("class", cl::desc("Print Enum list for this class"),39cl::value_desc("class name"),40cl::cat(PrintEnumsCat));4142void PrintRecords(RecordKeeper &Records, raw_ostream &OS) {43OS << Records; // No argument, dump all contents44}4546void PrintEnums(RecordKeeper &Records, raw_ostream &OS) {47for (Record *Rec : Records.getAllDerivedDefinitions(Class))48OS << Rec->getName() << ", ";49OS << "\n";50}5152void PrintSets(RecordKeeper &Records, raw_ostream &OS) {53SetTheory Sets;54Sets.addFieldExpander("Set", "Elements");55for (Record *Rec : Records.getAllDerivedDefinitions("Set")) {56OS << Rec->getName() << " = [";57const std::vector<Record *> *Elts = Sets.expand(Rec);58assert(Elts && "Couldn't expand Set instance");59for (Record *Elt : *Elts)60OS << ' ' << Elt->getName();61OS << " ]\n";62}63}6465TableGen::Emitter::Opt X[] = {66{"print-records", PrintRecords, "Print all records to stdout (default)",67true},68{"print-detailed-records", EmitDetailedRecords,69"Print full details of all records to stdout"},70{"null-backend", [](RecordKeeper &Records, raw_ostream &OS) {},71"Do nothing after parsing (useful for timing)"},72{"dump-json", EmitJSON, "Dump all records as machine-readable JSON"},73{"print-enums", PrintEnums, "Print enum values for a class"},74{"print-sets", PrintSets, "Print expanded sets for testing DAG exprs"},75};7677} // namespace7879int main(int argc, char **argv) {80InitLLVM X(argc, argv);81cl::ParseCommandLineOptions(argc, argv);8283return TableGenMain(argv[0]);84}8586#ifndef __has_feature87#define __has_feature(x) 088#endif8990#if __has_feature(address_sanitizer) || \91(defined(__SANITIZE_ADDRESS__) && defined(__GNUC__)) || \92__has_feature(leak_sanitizer)9394#include <sanitizer/lsan_interface.h>95// Disable LeakSanitizer for this binary as it has too many leaks that are not96// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .97LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }9899#endif100101102