1 //===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===//
3 // This tablegen backend is responsible for emitting a description of the target
4 // instruction set for the code generator.
6 //===----------------------------------------------------------------------===//
8 #include "InstrSelectorEmitter.h"
11 NodeType::ArgResultTypes NodeType::Translate(Record *R) {
12 const std::string &Name = R->getName();
13 if (Name == "DNRT_void") return Void;
14 if (Name == "DNRT_val" || Name == "DNAT_val") return Val;
15 if (Name == "DNRT_arg0" || Name == "DNAT_arg0") return Arg0;
16 if (Name == "DNAT_ptr") return Ptr;
17 throw "Unknown DagNodeResult Type '" + Name + "'!";
21 /// ProcessNodeTypes - Process all of the node types in the current
22 /// RecordKeeper, turning them into the more accessible NodeTypes data
25 void InstrSelectorEmitter::ProcessNodeTypes() {
26 std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode");
28 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
29 Record *Node = Nodes[i];
31 // Translate the return type...
32 NodeType::ArgResultTypes RetTy =
33 NodeType::Translate(Node->getValueAsDef("RetType"));
35 // Translate the arguments...
36 ListInit *Args = Node->getValueAsListInit("ArgTypes");
37 std::vector<NodeType::ArgResultTypes> ArgTypes;
39 for (unsigned a = 0, e = Args->getSize(); a != e; ++a)
40 if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a)))
41 ArgTypes.push_back(NodeType::Translate(DI->getDef()));
43 throw "In node " + Node->getName() + ", argument is not a Def!";
45 // Add the node type mapping now...
46 NodeTypes[Node] = NodeType(RetTy, ArgTypes);
50 void InstrSelectorEmitter::run(std::ostream &OS) {
51 // Type-check all of the node types to ensure we "understand" them.