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 "AsmMatcherEmitter.h"
15 #include "AsmWriterEmitter.h"
16 #include "CallingConvEmitter.h"
17 #include "CodeEmitterGen.h"
18 #include "DAGISelEmitter.h"
19 #include "DFAPacketizerEmitter.h"
20 #include "DisassemblerEmitter.h"
21 #include "EDEmitter.h"
22 #include "FastISelEmitter.h"
23 #include "InstrInfoEmitter.h"
24 #include "IntrinsicEmitter.h"
25 #include "PseudoLoweringEmitter.h"
26 #include "RegisterInfoEmitter.h"
27 #include "SubtargetEmitter.h"
28 #include "SetTheory.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/PrettyStackTrace.h"
32 #include "llvm/Support/Signals.h"
33 #include "llvm/TableGen/Error.h"
34 #include "llvm/TableGen/Main.h"
35 #include "llvm/TableGen/Record.h"
36 #include "llvm/TableGen/TableGenAction.h"
63 Action(cl::desc("Action to perform:"),
64 cl::values(clEnumValN(PrintRecords, "print-records",
65 "Print all records to stdout (default)"),
66 clEnumValN(GenEmitter, "gen-emitter",
67 "Generate machine code emitter"),
68 clEnumValN(GenRegisterInfo, "gen-register-info",
69 "Generate registers and register classes info"),
70 clEnumValN(GenInstrInfo, "gen-instr-info",
71 "Generate instruction descriptions"),
72 clEnumValN(GenCallingConv, "gen-callingconv",
73 "Generate calling convention descriptions"),
74 clEnumValN(GenAsmWriter, "gen-asm-writer",
75 "Generate assembly writer"),
76 clEnumValN(GenDisassembler, "gen-disassembler",
77 "Generate disassembler"),
78 clEnumValN(GenPseudoLowering, "gen-pseudo-lowering",
79 "Generate pseudo instruction lowering"),
80 clEnumValN(GenAsmMatcher, "gen-asm-matcher",
81 "Generate assembly instruction matcher"),
82 clEnumValN(GenDAGISel, "gen-dag-isel",
83 "Generate a DAG instruction selector"),
84 clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer",
85 "Generate DFA Packetizer for VLIW targets"),
86 clEnumValN(GenFastISel, "gen-fast-isel",
87 "Generate a \"fast\" instruction selector"),
88 clEnumValN(GenSubtarget, "gen-subtarget",
89 "Generate subtarget enumerations"),
90 clEnumValN(GenIntrinsic, "gen-intrinsic",
91 "Generate intrinsic information"),
92 clEnumValN(GenTgtIntrinsic, "gen-tgt-intrinsic",
93 "Generate target intrinsic information"),
94 clEnumValN(GenEDInfo, "gen-enhanced-disassembly-info",
95 "Generate enhanced disassembly info"),
96 clEnumValN(PrintEnums, "print-enums",
97 "Print enum values for a class"),
98 clEnumValN(PrintSets, "print-sets",
99 "Print expanded sets for testing DAG exprs"),
103 Class("class", cl::desc("Print Enum list for this class"),
104 cl::value_desc("class name"));
107 class LLVMTableGenAction : public TableGenAction {
109 bool operator()(raw_ostream &OS, RecordKeeper &Records) {
112 OS << Records; // No argument, dump all contents
115 CodeEmitterGen(Records).run(OS);
117 case GenRegisterInfo:
118 RegisterInfoEmitter(Records).run(OS);
121 InstrInfoEmitter(Records).run(OS);
124 CallingConvEmitter(Records).run(OS);
127 AsmWriterEmitter(Records).run(OS);
130 AsmMatcherEmitter(Records).run(OS);
132 case GenDisassembler:
133 DisassemblerEmitter(Records).run(OS);
135 case GenPseudoLowering:
136 PseudoLoweringEmitter(Records).run(OS);
139 DAGISelEmitter(Records).run(OS);
141 case GenDFAPacketizer:
142 DFAGen(Records).run(OS);
145 FastISelEmitter(Records).run(OS);
148 SubtargetEmitter(Records).run(OS);
151 IntrinsicEmitter(Records).run(OS);
153 case GenTgtIntrinsic:
154 IntrinsicEmitter(Records, true).run(OS);
157 EDEmitter(Records).run(OS);
161 std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
162 for (unsigned i = 0, e = Recs.size(); i != e; ++i)
163 OS << Recs[i]->getName() << ", ";
170 Sets.addFieldExpander("Set", "Elements");
171 std::vector<Record*> Recs = Records.getAllDerivedDefinitions("Set");
172 for (unsigned i = 0, e = Recs.size(); i != e; ++i) {
173 OS << Recs[i]->getName() << " = [";
174 const std::vector<Record*> *Elts = Sets.expand(Recs[i]);
175 assert(Elts && "Couldn't expand Set instance");
176 for (unsigned ei = 0, ee = Elts->size(); ei != ee; ++ei)
177 OS << ' ' << (*Elts)[ei]->getName();
183 assert(1 && "Invalid Action");
191 int main(int argc, char **argv) {
192 sys::PrintStackTraceOnErrorSignal();
193 PrettyStackTraceProgram X(argc, argv);
194 cl::ParseCommandLineOptions(argc, argv);
196 LLVMTableGenAction Action;
197 return TableGenMain(argv[0], Action);