2011-10-01 18:41:13 +02:00
|
|
|
//===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 22:20:30 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:37:13 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 22:20:30 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-05 21:27:59 +02:00
|
|
|
//
|
2011-10-01 18:41:13 +02:00
|
|
|
// This file contains the main function for LLVM's TableGen.
|
2003-10-05 21:27:59 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-11 17:37:55 +02:00
|
|
|
#include "TableGenBackends.h" // Declares all backends.
|
2009-07-08 20:44:05 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/Signals.h"
|
2011-10-01 18:41:13 +02:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Main.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
2014-06-17 15:10:38 +02:00
|
|
|
#include "llvm/TableGen/SetTheory.h"
|
2011-10-01 18:41:13 +02:00
|
|
|
|
2004-08-01 05:55:39 +02:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
enum ActionType {
|
|
|
|
PrintRecords,
|
|
|
|
GenEmitter,
|
2011-06-27 20:32:37 +02:00
|
|
|
GenRegisterInfo,
|
2011-06-28 22:07:07 +02:00
|
|
|
GenInstrInfo,
|
|
|
|
GenAsmWriter,
|
|
|
|
GenAsmMatcher,
|
2009-11-25 03:13:23 +01:00
|
|
|
GenDisassembler,
|
2011-07-08 19:36:35 +02:00
|
|
|
GenPseudoLowering,
|
2007-02-27 23:08:27 +01:00
|
|
|
GenCallingConv,
|
2005-09-03 03:14:03 +02:00
|
|
|
GenDAGISel,
|
2011-12-01 22:10:21 +01:00
|
|
|
GenDFAPacketizer,
|
2008-08-13 22:19:35 +02:00
|
|
|
GenFastISel,
|
2005-10-21 21:05:19 +02:00
|
|
|
GenSubtarget,
|
2006-03-03 03:32:46 +01:00
|
|
|
GenIntrinsic,
|
2009-02-05 02:49:45 +01:00
|
|
|
GenTgtIntrinsic,
|
2011-06-04 06:11:37 +02:00
|
|
|
PrintEnums,
|
2012-12-05 01:29:32 +01:00
|
|
|
PrintSets,
|
2013-03-22 00:40:38 +01:00
|
|
|
GenOptParserDefs,
|
|
|
|
GenCTags
|
2003-10-05 21:27:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
cl::opt<ActionType>
|
|
|
|
Action(cl::desc("Action to perform:"),
|
|
|
|
cl::values(clEnumValN(PrintRecords, "print-records",
|
|
|
|
"Print all records to stdout (default)"),
|
|
|
|
clEnumValN(GenEmitter, "gen-emitter",
|
|
|
|
"Generate machine code emitter"),
|
2011-06-24 03:44:41 +02:00
|
|
|
clEnumValN(GenRegisterInfo, "gen-register-info",
|
2011-06-27 20:32:37 +02:00
|
|
|
"Generate registers and register classes info"),
|
2011-06-28 22:07:07 +02:00
|
|
|
clEnumValN(GenInstrInfo, "gen-instr-info",
|
2003-10-05 21:27:59 +02:00
|
|
|
"Generate instruction descriptions"),
|
2007-02-27 23:08:27 +01:00
|
|
|
clEnumValN(GenCallingConv, "gen-callingconv",
|
|
|
|
"Generate calling convention descriptions"),
|
2004-08-01 07:59:33 +02:00
|
|
|
clEnumValN(GenAsmWriter, "gen-asm-writer",
|
|
|
|
"Generate assembly writer"),
|
2009-11-25 03:13:23 +01:00
|
|
|
clEnumValN(GenDisassembler, "gen-disassembler",
|
|
|
|
"Generate disassembler"),
|
2011-07-08 19:36:35 +02:00
|
|
|
clEnumValN(GenPseudoLowering, "gen-pseudo-lowering",
|
|
|
|
"Generate pseudo instruction lowering"),
|
2009-07-11 21:39:44 +02:00
|
|
|
clEnumValN(GenAsmMatcher, "gen-asm-matcher",
|
|
|
|
"Generate assembly instruction matcher"),
|
2005-09-03 03:14:03 +02:00
|
|
|
clEnumValN(GenDAGISel, "gen-dag-isel",
|
|
|
|
"Generate a DAG instruction selector"),
|
2011-12-01 22:10:21 +01:00
|
|
|
clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer",
|
|
|
|
"Generate DFA Packetizer for VLIW targets"),
|
2008-08-13 22:19:35 +02:00
|
|
|
clEnumValN(GenFastISel, "gen-fast-isel",
|
|
|
|
"Generate a \"fast\" instruction selector"),
|
2005-10-21 21:05:19 +02:00
|
|
|
clEnumValN(GenSubtarget, "gen-subtarget",
|
|
|
|
"Generate subtarget enumerations"),
|
2006-03-03 03:32:46 +01:00
|
|
|
clEnumValN(GenIntrinsic, "gen-intrinsic",
|
|
|
|
"Generate intrinsic information"),
|
2009-02-05 02:49:45 +01:00
|
|
|
clEnumValN(GenTgtIntrinsic, "gen-tgt-intrinsic",
|
|
|
|
"Generate target intrinsic information"),
|
2003-10-05 21:27:59 +02:00
|
|
|
clEnumValN(PrintEnums, "print-enums",
|
|
|
|
"Print enum values for a class"),
|
2011-06-04 06:11:37 +02:00
|
|
|
clEnumValN(PrintSets, "print-sets",
|
|
|
|
"Print expanded sets for testing DAG exprs"),
|
2012-12-05 01:29:32 +01:00
|
|
|
clEnumValN(GenOptParserDefs, "gen-opt-parser-defs",
|
|
|
|
"Generate option definitions"),
|
2013-03-22 00:40:38 +01:00
|
|
|
clEnumValN(GenCTags, "gen-ctags",
|
|
|
|
"Generate ctags-compatible index"),
|
2004-07-16 02:02:21 +02:00
|
|
|
clEnumValEnd));
|
2003-10-05 21:27:59 +02:00
|
|
|
|
|
|
|
cl::opt<std::string>
|
|
|
|
Class("class", cl::desc("Print Enum list for this class"),
|
2011-12-20 03:50:00 +01:00
|
|
|
cl::value_desc("class name"));
|
2012-06-11 17:37:55 +02:00
|
|
|
|
2012-10-03 23:29:19 +02:00
|
|
|
bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
|
|
|
|
switch (Action) {
|
|
|
|
case PrintRecords:
|
|
|
|
OS << Records; // No argument, dump all contents
|
|
|
|
break;
|
|
|
|
case GenEmitter:
|
|
|
|
EmitCodeEmitter(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenRegisterInfo:
|
|
|
|
EmitRegisterInfo(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenInstrInfo:
|
|
|
|
EmitInstrInfo(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenCallingConv:
|
|
|
|
EmitCallingConv(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenAsmWriter:
|
|
|
|
EmitAsmWriter(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenAsmMatcher:
|
|
|
|
EmitAsmMatcher(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenDisassembler:
|
|
|
|
EmitDisassembler(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenPseudoLowering:
|
|
|
|
EmitPseudoLowering(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenDAGISel:
|
|
|
|
EmitDAGISel(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenDFAPacketizer:
|
|
|
|
EmitDFAPacketizer(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenFastISel:
|
|
|
|
EmitFastISel(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenSubtarget:
|
|
|
|
EmitSubtarget(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenIntrinsic:
|
|
|
|
EmitIntrinsics(Records, OS);
|
|
|
|
break;
|
|
|
|
case GenTgtIntrinsic:
|
|
|
|
EmitIntrinsics(Records, OS, true);
|
|
|
|
break;
|
2012-12-05 01:29:32 +01:00
|
|
|
case GenOptParserDefs:
|
|
|
|
EmitOptParser(Records, OS);
|
|
|
|
break;
|
2012-10-03 23:29:19 +02:00
|
|
|
case PrintEnums:
|
|
|
|
{
|
2014-12-11 08:04:54 +01:00
|
|
|
for (Record *Rec : Records.getAllDerivedDefinitions(Class))
|
|
|
|
OS << Rec->getName() << ", ";
|
2012-10-03 23:29:19 +02:00
|
|
|
OS << "\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PrintSets:
|
|
|
|
{
|
|
|
|
SetTheory Sets;
|
|
|
|
Sets.addFieldExpander("Set", "Elements");
|
2014-12-11 08:04:54 +01:00
|
|
|
for (Record *Rec : Records.getAllDerivedDefinitions("Set")) {
|
|
|
|
OS << Rec->getName() << " = [";
|
|
|
|
const std::vector<Record*> *Elts = Sets.expand(Rec);
|
2012-10-03 23:29:19 +02:00
|
|
|
assert(Elts && "Couldn't expand Set instance");
|
2014-12-11 08:04:54 +01:00
|
|
|
for (Record *Elt : *Elts)
|
|
|
|
OS << ' ' << Elt->getName();
|
2012-10-03 23:29:19 +02:00
|
|
|
OS << " ]\n";
|
2003-11-11 23:41:34 +01:00
|
|
|
}
|
2012-10-03 23:29:19 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-03-22 00:40:38 +01:00
|
|
|
case GenCTags:
|
|
|
|
EmitCTags(Records, OS);
|
|
|
|
break;
|
2012-10-03 23:29:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-20 03:50:00 +01:00
|
|
|
}
|
2011-10-01 18:41:13 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
2010-05-05 06:13:08 +02:00
|
|
|
|
2012-10-03 23:29:19 +02:00
|
|
|
return TableGenMain(argv[0], &LLVMTableGenMain);
|
2003-10-05 21:27:59 +02:00
|
|
|
}
|
2014-01-10 09:05:42 +01:00
|
|
|
|
2014-01-15 08:59:37 +01:00
|
|
|
#ifdef __has_feature
|
|
|
|
#if __has_feature(address_sanitizer)
|
|
|
|
#include <sanitizer/lsan_interface.h>
|
2014-01-10 09:05:42 +01:00
|
|
|
// Disable LeakSanitizer for this binary as it has too many leaks that are not
|
2014-01-15 08:59:37 +01:00
|
|
|
// very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
|
|
|
|
int __lsan_is_turned_off() { return 1; }
|
|
|
|
#endif // __has_feature(address_sanitizer)
|
|
|
|
#endif // defined(__has_feature)
|