2011-10-01 16:41:13 +00:00
|
|
|
//===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 20:20:30 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 20:20:30 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-08-01 04:39:05 +00:00
|
|
|
//
|
2011-10-01 16:41:13 +00:00
|
|
|
// This file contains the main function for LLVM's TableGen.
|
2003-08-01 04:39:05 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-18 21:29:51 +00:00
|
|
|
#include "AsmMatcherEmitter.h"
|
|
|
|
#include "AsmWriterEmitter.h"
|
2007-02-27 22:08:27 +00:00
|
|
|
#include "CallingConvEmitter.h"
|
2003-05-24 00:17:12 +00:00
|
|
|
#include "CodeEmitterGen.h"
|
2005-09-03 01:14:03 +00:00
|
|
|
#include "DAGISelEmitter.h"
|
2011-12-01 21:10:21 +00:00
|
|
|
#include "DFAPacketizerEmitter.h"
|
2009-11-25 02:13:23 +00:00
|
|
|
#include "DisassemblerEmitter.h"
|
2010-01-29 00:21:04 +00:00
|
|
|
#include "EDEmitter.h"
|
2008-08-13 20:19:35 +00:00
|
|
|
#include "FastISelEmitter.h"
|
2009-11-18 21:29:51 +00:00
|
|
|
#include "InstrInfoEmitter.h"
|
2006-03-03 02:32:46 +00:00
|
|
|
#include "IntrinsicEmitter.h"
|
2011-07-08 17:36:35 +00:00
|
|
|
#include "PseudoLoweringEmitter.h"
|
2009-11-18 21:29:51 +00:00
|
|
|
#include "RegisterInfoEmitter.h"
|
|
|
|
#include "SubtargetEmitter.h"
|
2011-06-04 04:11:37 +00:00
|
|
|
#include "SetTheory.h"
|
2011-10-01 16:41:13 +00:00
|
|
|
|
2009-07-08 18:44:05 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Signals.h"
|
2011-10-01 16:41:13 +00:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Main.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/TableGenAction.h"
|
|
|
|
|
2004-08-01 03:55:39 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2003-06-03 04:56:29 +00:00
|
|
|
enum ActionType {
|
|
|
|
PrintRecords,
|
|
|
|
GenEmitter,
|
2011-06-27 18:32:37 +00:00
|
|
|
GenRegisterInfo,
|
2011-06-28 20:07:07 +00:00
|
|
|
GenInstrInfo,
|
|
|
|
GenAsmWriter,
|
|
|
|
GenAsmMatcher,
|
2009-11-25 02:13:23 +00:00
|
|
|
GenDisassembler,
|
2011-07-08 17:36:35 +00:00
|
|
|
GenPseudoLowering,
|
2007-02-27 22:08:27 +00:00
|
|
|
GenCallingConv,
|
2005-09-03 01:14:03 +00:00
|
|
|
GenDAGISel,
|
2011-12-01 21:10:21 +00:00
|
|
|
GenDFAPacketizer,
|
2008-08-13 20:19:35 +00:00
|
|
|
GenFastISel,
|
2005-10-21 19:05:19 +00:00
|
|
|
GenSubtarget,
|
2006-03-03 02:32:46 +00:00
|
|
|
GenIntrinsic,
|
2009-02-05 01:49:45 +00:00
|
|
|
GenTgtIntrinsic,
|
2010-07-20 19:45:21 +00:00
|
|
|
GenEDInfo,
|
2011-06-04 04:11:37 +00:00
|
|
|
PrintEnums,
|
|
|
|
PrintSets
|
2003-06-03 04:56:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
cl::opt<ActionType>
|
|
|
|
Action(cl::desc("Action to perform:"),
|
|
|
|
cl::values(clEnumValN(PrintRecords, "print-records",
|
2003-06-03 05:07:28 +00:00
|
|
|
"Print all records to stdout (default)"),
|
2003-06-03 04:56:29 +00:00
|
|
|
clEnumValN(GenEmitter, "gen-emitter",
|
|
|
|
"Generate machine code emitter"),
|
2011-06-24 01:44:41 +00:00
|
|
|
clEnumValN(GenRegisterInfo, "gen-register-info",
|
2011-06-27 18:32:37 +00:00
|
|
|
"Generate registers and register classes info"),
|
2011-06-28 20:07:07 +00:00
|
|
|
clEnumValN(GenInstrInfo, "gen-instr-info",
|
2003-08-03 21:58:28 +00:00
|
|
|
"Generate instruction descriptions"),
|
2007-02-27 22:08:27 +00:00
|
|
|
clEnumValN(GenCallingConv, "gen-callingconv",
|
|
|
|
"Generate calling convention descriptions"),
|
2004-08-01 05:59:33 +00:00
|
|
|
clEnumValN(GenAsmWriter, "gen-asm-writer",
|
|
|
|
"Generate assembly writer"),
|
2009-11-25 02:13:23 +00:00
|
|
|
clEnumValN(GenDisassembler, "gen-disassembler",
|
|
|
|
"Generate disassembler"),
|
2011-07-08 17:36:35 +00:00
|
|
|
clEnumValN(GenPseudoLowering, "gen-pseudo-lowering",
|
|
|
|
"Generate pseudo instruction lowering"),
|
2009-07-11 19:39:44 +00:00
|
|
|
clEnumValN(GenAsmMatcher, "gen-asm-matcher",
|
|
|
|
"Generate assembly instruction matcher"),
|
2005-09-03 01:14:03 +00:00
|
|
|
clEnumValN(GenDAGISel, "gen-dag-isel",
|
|
|
|
"Generate a DAG instruction selector"),
|
2011-12-01 21:10:21 +00:00
|
|
|
clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer",
|
|
|
|
"Generate DFA Packetizer for VLIW targets"),
|
2008-08-13 20:19:35 +00:00
|
|
|
clEnumValN(GenFastISel, "gen-fast-isel",
|
|
|
|
"Generate a \"fast\" instruction selector"),
|
2005-10-21 19:05:19 +00:00
|
|
|
clEnumValN(GenSubtarget, "gen-subtarget",
|
|
|
|
"Generate subtarget enumerations"),
|
2006-03-03 02:32:46 +00:00
|
|
|
clEnumValN(GenIntrinsic, "gen-intrinsic",
|
|
|
|
"Generate intrinsic information"),
|
2009-02-05 01:49:45 +00:00
|
|
|
clEnumValN(GenTgtIntrinsic, "gen-tgt-intrinsic",
|
|
|
|
"Generate target intrinsic information"),
|
2010-01-29 00:21:04 +00:00
|
|
|
clEnumValN(GenEDInfo, "gen-enhanced-disassembly-info",
|
|
|
|
"Generate enhanced disassembly info"),
|
2003-06-03 04:56:29 +00:00
|
|
|
clEnumValN(PrintEnums, "print-enums",
|
|
|
|
"Print enum values for a class"),
|
2011-06-04 04:11:37 +00:00
|
|
|
clEnumValN(PrintSets, "print-sets",
|
|
|
|
"Print expanded sets for testing DAG exprs"),
|
2004-07-16 00:02:21 +00:00
|
|
|
clEnumValEnd));
|
2003-06-03 04:56:29 +00:00
|
|
|
|
|
|
|
cl::opt<std::string>
|
2003-06-03 05:07:28 +00:00
|
|
|
Class("class", cl::desc("Print Enum list for this class"),
|
2011-12-20 02:50:00 +00:00
|
|
|
cl::value_desc("class name"));
|
|
|
|
|
|
|
|
class LLVMTableGenAction : public TableGenAction {
|
|
|
|
public:
|
|
|
|
bool operator()(raw_ostream &OS, RecordKeeper &Records) {
|
|
|
|
switch (Action) {
|
|
|
|
case PrintRecords:
|
|
|
|
OS << Records; // No argument, dump all contents
|
|
|
|
break;
|
|
|
|
case GenEmitter:
|
|
|
|
CodeEmitterGen(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenRegisterInfo:
|
|
|
|
RegisterInfoEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenInstrInfo:
|
|
|
|
InstrInfoEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenCallingConv:
|
|
|
|
CallingConvEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenAsmWriter:
|
|
|
|
AsmWriterEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenAsmMatcher:
|
|
|
|
AsmMatcherEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenDisassembler:
|
|
|
|
DisassemblerEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenPseudoLowering:
|
|
|
|
PseudoLoweringEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenDAGISel:
|
|
|
|
DAGISelEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenDFAPacketizer:
|
|
|
|
DFAGen(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenFastISel:
|
|
|
|
FastISelEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenSubtarget:
|
|
|
|
SubtargetEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenIntrinsic:
|
|
|
|
IntrinsicEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case GenTgtIntrinsic:
|
|
|
|
IntrinsicEmitter(Records, true).run(OS);
|
|
|
|
break;
|
|
|
|
case GenEDInfo:
|
|
|
|
EDEmitter(Records).run(OS);
|
|
|
|
break;
|
|
|
|
case PrintEnums:
|
|
|
|
{
|
|
|
|
std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
|
|
|
|
for (unsigned i = 0, e = Recs.size(); i != e; ++i)
|
|
|
|
OS << Recs[i]->getName() << ", ";
|
|
|
|
OS << "\n";
|
|
|
|
break;
|
2011-06-04 04:11:37 +00:00
|
|
|
}
|
2011-12-20 02:50:00 +00:00
|
|
|
case PrintSets:
|
|
|
|
{
|
|
|
|
SetTheory Sets;
|
|
|
|
Sets.addFieldExpander("Set", "Elements");
|
|
|
|
std::vector<Record*> Recs = Records.getAllDerivedDefinitions("Set");
|
|
|
|
for (unsigned i = 0, e = Recs.size(); i != e; ++i) {
|
|
|
|
OS << Recs[i]->getName() << " = [";
|
|
|
|
const std::vector<Record*> *Elts = Sets.expand(Recs[i]);
|
|
|
|
assert(Elts && "Couldn't expand Set instance");
|
|
|
|
for (unsigned ei = 0, ee = Elts->size(); ei != ee; ++ei)
|
|
|
|
OS << ' ' << (*Elts)[ei]->getName();
|
|
|
|
OS << " ]\n";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2003-11-11 22:41:34 +00:00
|
|
|
}
|
2011-12-20 02:50:00 +00:00
|
|
|
};
|
|
|
|
}
|
2011-10-01 16:41:13 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
2010-05-05 04:13:08 +00:00
|
|
|
|
2011-10-01 16:41:13 +00:00
|
|
|
LLVMTableGenAction Action;
|
|
|
|
return TableGenMain(argv[0], Action);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|