1 //===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the main function for LLVM's TableGen.
12 //===----------------------------------------------------------------------===//
14 #include "TableGenBackends.h" // Declares all backends.
15 #include "SetTheory.h"
16 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Support/PrettyStackTrace.h"
18 #include "llvm/Support/Signals.h"
19 #include "llvm/TableGen/Error.h"
20 #include "llvm/TableGen/Main.h"
21 #include "llvm/TableGen/Record.h"
49 Action(cl::desc("Action to perform:"),
50 cl::values(clEnumValN(PrintRecords, "print-records",
51 "Print all records to stdout (default)"),
52 clEnumValN(GenEmitter, "gen-emitter",
53 "Generate machine code emitter"),
54 clEnumValN(GenRegisterInfo, "gen-register-info",
55 "Generate registers and register classes info"),
56 clEnumValN(GenInstrInfo, "gen-instr-info",
57 "Generate instruction descriptions"),
58 clEnumValN(GenCallingConv, "gen-callingconv",
59 "Generate calling convention descriptions"),
60 clEnumValN(GenAsmWriter, "gen-asm-writer",
61 "Generate assembly writer"),
62 clEnumValN(GenDisassembler, "gen-disassembler",
63 "Generate disassembler"),
64 clEnumValN(GenPseudoLowering, "gen-pseudo-lowering",
65 "Generate pseudo instruction lowering"),
66 clEnumValN(GenAsmMatcher, "gen-asm-matcher",
67 "Generate assembly instruction matcher"),
68 clEnumValN(GenDAGISel, "gen-dag-isel",
69 "Generate a DAG instruction selector"),
70 clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer",
71 "Generate DFA Packetizer for VLIW targets"),
72 clEnumValN(GenFastISel, "gen-fast-isel",
73 "Generate a \"fast\" instruction selector"),
74 clEnumValN(GenSubtarget, "gen-subtarget",
75 "Generate subtarget enumerations"),
76 clEnumValN(GenIntrinsic, "gen-intrinsic",
77 "Generate intrinsic information"),
78 clEnumValN(GenTgtIntrinsic, "gen-tgt-intrinsic",
79 "Generate target intrinsic information"),
80 clEnumValN(PrintEnums, "print-enums",
81 "Print enum values for a class"),
82 clEnumValN(PrintSets, "print-sets",
83 "Print expanded sets for testing DAG exprs"),
84 clEnumValN(GenOptParserDefs, "gen-opt-parser-defs",
85 "Generate option definitions"),
86 clEnumValN(GenCTags, "gen-ctags",
87 "Generate ctags-compatible index"),
91 Class("class", cl::desc("Print Enum list for this class"),
92 cl::value_desc("class name"));
94 bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
97 OS << Records; // No argument, dump all contents
100 EmitCodeEmitter(Records, OS);
102 case GenRegisterInfo:
103 EmitRegisterInfo(Records, OS);
106 EmitInstrInfo(Records, OS);
109 EmitCallingConv(Records, OS);
112 EmitAsmWriter(Records, OS);
115 EmitAsmMatcher(Records, OS);
117 case GenDisassembler:
118 EmitDisassembler(Records, OS);
120 case GenPseudoLowering:
121 EmitPseudoLowering(Records, OS);
124 EmitDAGISel(Records, OS);
126 case GenDFAPacketizer:
127 EmitDFAPacketizer(Records, OS);
130 EmitFastISel(Records, OS);
133 EmitSubtarget(Records, OS);
136 EmitIntrinsics(Records, OS);
138 case GenTgtIntrinsic:
139 EmitIntrinsics(Records, OS, true);
141 case GenOptParserDefs:
142 EmitOptParser(Records, OS);
146 std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
147 for (unsigned i = 0, e = Recs.size(); i != e; ++i)
148 OS << Recs[i]->getName() << ", ";
155 Sets.addFieldExpander("Set", "Elements");
156 std::vector<Record*> Recs = Records.getAllDerivedDefinitions("Set");
157 for (unsigned i = 0, e = Recs.size(); i != e; ++i) {
158 OS << Recs[i]->getName() << " = [";
159 const std::vector<Record*> *Elts = Sets.expand(Recs[i]);
160 assert(Elts && "Couldn't expand Set instance");
161 for (unsigned ei = 0, ee = Elts->size(); ei != ee; ++ei)
162 OS << ' ' << (*Elts)[ei]->getName();
168 EmitCTags(Records, OS);
176 int main(int argc, char **argv) {
177 sys::PrintStackTraceOnErrorSignal();
178 PrettyStackTraceProgram X(argc, argv);
179 cl::ParseCommandLineOptions(argc, argv);
181 return TableGenMain(argv[0], &LLVMTableGenMain);
185 // Disable LeakSanitizer for this binary as it has too many leaks that are not
186 // very interesting to fix. __lsan_is_turned_off is explained in
187 // compiler-rt/include/sanitizer/lsan_interface.h
188 int __lsan_is_turned_off() { return 1; }