Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Basic/TableGen.cpp
213799 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 global defintions (mostly command line parameters)9// shared between llvm-tblgen and llvm-min-tblgen.10//11//===----------------------------------------------------------------------===//1213#include "TableGen.h"14#include "llvm/ADT/StringRef.h"15#include "llvm/Support/CommandLine.h"16#include "llvm/Support/InitLLVM.h"17#include "llvm/Support/raw_ostream.h"18#include "llvm/TableGen/Main.h"19#include "llvm/TableGen/Record.h"20#include "llvm/TableGen/SetTheory.h"21#include "llvm/TableGen/TableGenBackend.h"22#include <cassert>23#include <string>24#include <vector>2526using namespace llvm;2728static cl::OptionCategory PrintEnumsCat("Options for -print-enums");29static cl::opt<std::string> Class("class",30cl::desc("Print Enum list for this class"),31cl::value_desc("class name"),32cl::cat(PrintEnumsCat));3334static void printRecords(const RecordKeeper &Records, raw_ostream &OS) {35OS << Records; // No argument, dump all contents36}3738static void printEnums(const RecordKeeper &Records, raw_ostream &OS) {39for (const Record *Rec : Records.getAllDerivedDefinitions(Class))40OS << Rec->getName() << ", ";41OS << "\n";42}4344static void printSets(const RecordKeeper &Records, raw_ostream &OS) {45SetTheory Sets;46Sets.addFieldExpander("Set", "Elements");47for (const Record *Rec : Records.getAllDerivedDefinitions("Set")) {48OS << Rec->getName() << " = [";49const std::vector<const Record *> *Elts = Sets.expand(Rec);50assert(Elts && "Couldn't expand Set instance");51for (const Record *Elt : *Elts)52OS << ' ' << Elt->getName();53OS << " ]\n";54}55}5657static TableGen::Emitter::Opt X[] = {58{"print-records", printRecords, "Print all records to stdout (default)",59true},60{"print-detailed-records", EmitDetailedRecords,61"Print full details of all records to stdout"},62{"null-backend", [](const RecordKeeper &Records, raw_ostream &OS) {},63"Do nothing after parsing (useful for timing)"},64{"dump-json", EmitJSON, "Dump all records as machine-readable JSON"},65{"print-enums", printEnums, "Print enum values for a class"},66{"print-sets", printSets, "Print expanded sets for testing DAG exprs"},67};6869int tblgen_main(int argc, char **argv) {70InitLLVM X(argc, argv);71cl::ParseCommandLineOptions(argc, argv);7273return TableGenMain(argv[0]);74}7576#ifndef __has_feature77#define __has_feature(x) 078#endif7980#if __has_feature(address_sanitizer) || \81(defined(__SANITIZE_ADDRESS__) && defined(__GNUC__)) || \82__has_feature(leak_sanitizer)8384#include <sanitizer/lsan_interface.h>85// Disable LeakSanitizer for this binary as it has too many leaks that are not86// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .87LLVM_ATTRIBUTE_USED int __lsan_is_turned_off() { return 1; }8889#endif909192