2011-10-20 21:10:27 +00:00
|
|
|
//===- TableGen.cpp - Top-Level TableGen implementation for LLVM ----------===//
|
2009-06-02 17:52:33 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-10-20 21:10:27 +00:00
|
|
|
// This file contains the main function for LLVM's TableGen.
|
2009-06-02 17:52:33 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-08-15 19:34:23 +00:00
|
|
|
#include "TableGenBackends.h" // Declares all backends.
|
2009-10-14 17:57:32 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2016-01-06 20:01:02 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-10-14 17:57:32 +00:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/Support/Signals.h"
|
2011-10-20 21:10:27 +00:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Main.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
2014-11-24 09:08:18 +00:00
|
|
|
#include "llvm/TableGen/SetTheory.h"
|
2011-10-20 21:10:27 +00:00
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
enum ActionType {
|
|
|
|
PrintRecords,
|
|
|
|
GenEmitter,
|
2011-07-17 15:36:56 +00:00
|
|
|
GenRegisterInfo,
|
|
|
|
GenInstrInfo,
|
|
|
|
GenAsmWriter,
|
|
|
|
GenAsmMatcher,
|
2009-12-01 11:07:05 +00:00
|
|
|
GenDisassembler,
|
2011-07-17 15:36:56 +00:00
|
|
|
GenPseudoLowering,
|
2009-06-02 17:52:33 +00:00
|
|
|
GenCallingConv,
|
|
|
|
GenDAGISel,
|
2012-04-14 13:54:10 +00:00
|
|
|
GenDFAPacketizer,
|
2009-06-02 17:52:33 +00:00
|
|
|
GenFastISel,
|
|
|
|
GenSubtarget,
|
|
|
|
GenIntrinsic,
|
|
|
|
GenTgtIntrinsic,
|
2011-06-12 15:42:51 +00:00
|
|
|
PrintEnums,
|
2013-04-08 18:41:23 +00:00
|
|
|
PrintSets,
|
|
|
|
GenOptParserDefs,
|
2015-12-30 11:46:15 +00:00
|
|
|
GenCTags,
|
2016-07-23 20:41:05 +00:00
|
|
|
GenAttributes,
|
|
|
|
GenSearchableTables,
|
2017-01-02 19:17:04 +00:00
|
|
|
GenGlobalISel,
|
2009-06-02 17:52:33 +00: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-07-17 15:36:56 +00:00
|
|
|
clEnumValN(GenRegisterInfo, "gen-register-info",
|
|
|
|
"Generate registers and register classes info"),
|
|
|
|
clEnumValN(GenInstrInfo, "gen-instr-info",
|
2009-06-02 17:52:33 +00:00
|
|
|
"Generate instruction descriptions"),
|
|
|
|
clEnumValN(GenCallingConv, "gen-callingconv",
|
|
|
|
"Generate calling convention descriptions"),
|
|
|
|
clEnumValN(GenAsmWriter, "gen-asm-writer",
|
|
|
|
"Generate assembly writer"),
|
2009-12-01 11:07:05 +00:00
|
|
|
clEnumValN(GenDisassembler, "gen-disassembler",
|
|
|
|
"Generate disassembler"),
|
2011-07-17 15:36:56 +00:00
|
|
|
clEnumValN(GenPseudoLowering, "gen-pseudo-lowering",
|
|
|
|
"Generate pseudo instruction lowering"),
|
2009-10-14 17:57:32 +00:00
|
|
|
clEnumValN(GenAsmMatcher, "gen-asm-matcher",
|
|
|
|
"Generate assembly instruction matcher"),
|
2009-06-02 17:52:33 +00:00
|
|
|
clEnumValN(GenDAGISel, "gen-dag-isel",
|
|
|
|
"Generate a DAG instruction selector"),
|
2012-04-14 13:54:10 +00:00
|
|
|
clEnumValN(GenDFAPacketizer, "gen-dfa-packetizer",
|
|
|
|
"Generate DFA Packetizer for VLIW targets"),
|
2009-06-02 17:52:33 +00:00
|
|
|
clEnumValN(GenFastISel, "gen-fast-isel",
|
|
|
|
"Generate a \"fast\" instruction selector"),
|
|
|
|
clEnumValN(GenSubtarget, "gen-subtarget",
|
|
|
|
"Generate subtarget enumerations"),
|
|
|
|
clEnumValN(GenIntrinsic, "gen-intrinsic",
|
|
|
|
"Generate intrinsic information"),
|
|
|
|
clEnumValN(GenTgtIntrinsic, "gen-tgt-intrinsic",
|
|
|
|
"Generate target intrinsic information"),
|
|
|
|
clEnumValN(PrintEnums, "print-enums",
|
|
|
|
"Print enum values for a class"),
|
2011-06-12 15:42:51 +00:00
|
|
|
clEnumValN(PrintSets, "print-sets",
|
|
|
|
"Print expanded sets for testing DAG exprs"),
|
2013-04-08 18:41:23 +00:00
|
|
|
clEnumValN(GenOptParserDefs, "gen-opt-parser-defs",
|
|
|
|
"Generate option definitions"),
|
|
|
|
clEnumValN(GenCTags, "gen-ctags",
|
|
|
|
"Generate ctags-compatible index"),
|
2015-12-30 11:46:15 +00:00
|
|
|
clEnumValN(GenAttributes, "gen-attrs",
|
|
|
|
"Generate attributes"),
|
2016-07-23 20:41:05 +00:00
|
|
|
clEnumValN(GenSearchableTables, "gen-searchable-tables",
|
|
|
|
"Generate generic binary-searchable table"),
|
2017-01-02 19:17:04 +00:00
|
|
|
clEnumValN(GenGlobalISel, "gen-global-isel",
|
|
|
|
"Generate GlobalISel selector")));
|
2009-06-02 17:52:33 +00:00
|
|
|
|
|
|
|
cl::opt<std::string>
|
|
|
|
Class("class", cl::desc("Print Enum list for this class"),
|
2012-04-14 13:54:10 +00:00
|
|
|
cl::value_desc("class name"));
|
2012-08-15 19:34:23 +00:00
|
|
|
|
2012-12-02 13:10:19 +00: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;
|
2013-04-08 18:41:23 +00:00
|
|
|
case GenOptParserDefs:
|
|
|
|
EmitOptParser(Records, OS);
|
2012-12-02 13:10:19 +00:00
|
|
|
break;
|
|
|
|
case PrintEnums:
|
|
|
|
{
|
2015-01-18 16:17:27 +00:00
|
|
|
for (Record *Rec : Records.getAllDerivedDefinitions(Class))
|
|
|
|
OS << Rec->getName() << ", ";
|
2012-12-02 13:10:19 +00:00
|
|
|
OS << "\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PrintSets:
|
|
|
|
{
|
|
|
|
SetTheory Sets;
|
|
|
|
Sets.addFieldExpander("Set", "Elements");
|
2015-01-18 16:17:27 +00:00
|
|
|
for (Record *Rec : Records.getAllDerivedDefinitions("Set")) {
|
|
|
|
OS << Rec->getName() << " = [";
|
|
|
|
const std::vector<Record*> *Elts = Sets.expand(Rec);
|
2012-12-02 13:10:19 +00:00
|
|
|
assert(Elts && "Couldn't expand Set instance");
|
2015-01-18 16:17:27 +00:00
|
|
|
for (Record *Elt : *Elts)
|
|
|
|
OS << ' ' << Elt->getName();
|
2012-12-02 13:10:19 +00:00
|
|
|
OS << " ]\n";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2012-12-02 13:10:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-04-08 18:41:23 +00:00
|
|
|
case GenCTags:
|
|
|
|
EmitCTags(Records, OS);
|
|
|
|
break;
|
2015-12-30 11:46:15 +00:00
|
|
|
case GenAttributes:
|
|
|
|
EmitAttributes(Records, OS);
|
|
|
|
break;
|
2016-07-23 20:41:05 +00:00
|
|
|
case GenSearchableTables:
|
|
|
|
EmitSearchableTables(Records, OS);
|
|
|
|
break;
|
2017-01-02 19:17:04 +00:00
|
|
|
case GenGlobalISel:
|
|
|
|
EmitGlobalISel(Records, OS);
|
|
|
|
break;
|
2012-12-02 13:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-14 13:54:10 +00:00
|
|
|
}
|
2011-10-20 21:10:27 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2016-07-23 20:41:05 +00:00
|
|
|
sys::PrintStackTraceOnErrorSignal(argv[0]);
|
2011-10-20 21:10:27 +00:00
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
2010-05-27 15:15:58 +00:00
|
|
|
|
2016-01-06 20:01:02 +00:00
|
|
|
llvm_shutdown_obj Y;
|
|
|
|
|
2012-12-02 13:10:19 +00:00
|
|
|
return TableGenMain(argv[0], &LLVMTableGenMain);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
2014-11-24 09:08:18 +00:00
|
|
|
|
|
|
|
#ifdef __has_feature
|
|
|
|
#if __has_feature(address_sanitizer)
|
|
|
|
#include <sanitizer/lsan_interface.h>
|
|
|
|
// Disable LeakSanitizer for this binary as it has too many leaks that are not
|
|
|
|
// 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)
|