blob: 522cd11aaffdf29e1ce09e52db1cf3e11e591e20 [file] [log] [blame]
Chris Lattnerfaca5ab2003-08-06 05:42:05 +00001//===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===//
2//
3// This tablegen backend is responsible for emitting a description of the target
4// instruction set for the code generator.
5//
6//===----------------------------------------------------------------------===//
7
8#include "InstrSelectorEmitter.h"
9#include "Record.h"
10
11NodeType::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 + "'!";
18}
19
20
21/// ProcessNodeTypes - Process all of the node types in the current
22/// RecordKeeper, turning them into the more accessible NodeTypes data
23/// structure.
24///
25void InstrSelectorEmitter::ProcessNodeTypes() {
26 std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode");
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000027 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
28 Record *Node = Nodes[i];
29
30 // Translate the return type...
31 NodeType::ArgResultTypes RetTy =
32 NodeType::Translate(Node->getValueAsDef("RetType"));
33
34 // Translate the arguments...
35 ListInit *Args = Node->getValueAsListInit("ArgTypes");
36 std::vector<NodeType::ArgResultTypes> ArgTypes;
37
Chris Lattner2787d1a2003-08-06 06:16:35 +000038 for (unsigned a = 0, e = Args->getSize(); a != e; ++a) {
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000039 if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a)))
40 ArgTypes.push_back(NodeType::Translate(DI->getDef()));
41 else
42 throw "In node " + Node->getName() + ", argument is not a Def!";
43
Chris Lattner2787d1a2003-08-06 06:16:35 +000044 if (a == 0 && ArgTypes.back() == NodeType::Arg0)
45 throw "In node " + Node->getName() + ", arg 0 cannot have type 'arg0'!";
46 if (ArgTypes.back() == NodeType::Void)
47 throw "In node " + Node->getName() + ", args cannot be void type!";
48 }
49 if (RetTy == NodeType::Arg0 && Args->getSize() == 0)
50 throw "In node " + Node->getName() +
51 ", invalid return type for nullary node!";
52
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000053 // Add the node type mapping now...
54 NodeTypes[Node] = NodeType(RetTy, ArgTypes);
55 }
56}
57
Chris Lattner2787d1a2003-08-06 06:16:35 +000058/// ProcessInstructionPatterns - Read in all subclasses of Instruction, and
59/// process those with a useful Pattern field.
60///
61void InstrSelectorEmitter::ProcessInstructionPatterns() {
62 std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
63 for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
64 Record *Inst = Insts[i];
65 if (DagInit *PatternInit =
66 dynamic_cast<DagInit*>(Inst->getValueInit("Pattern"))) {
67
68 }
69 }
70}
71
72
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000073void InstrSelectorEmitter::run(std::ostream &OS) {
74 // Type-check all of the node types to ensure we "understand" them.
75 ProcessNodeTypes();
76
Chris Lattner2787d1a2003-08-06 06:16:35 +000077 // Read all of the instruction patterns in...
78 ProcessInstructionPatterns();
79
80 // Read all of the Expander patterns in...
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000081
82}