Initial support for an instruction selector emitter
[oota-llvm.git] / support / tools / TableGen / InstrSelectorEmitter.h
1 //===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===//
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 #ifndef INSTRSELECTOR_EMITTER_H
9 #define INSTRSELECTOR_EMITTER_H
10
11 #include "TableGenBackend.h"
12 #include <vector>
13 #include <map>
14
15 struct NodeType {
16   enum ArgResultTypes {
17     // Both argument and return types...
18     Val,            // A non-void type
19     Arg0,           // Value matches the type of Arg0
20
21     // Return types
22     Void,           // Tree node always returns void
23
24     // Argument types
25     Ptr,            // Tree node is the target argument type
26   };
27
28   ArgResultTypes ResultType;
29   std::vector<ArgResultTypes> ArgTypes;
30
31   NodeType(ArgResultTypes RT, std::vector<ArgResultTypes> &AT) : ResultType(RT){
32     AT.swap(ArgTypes);
33   }
34
35   NodeType() : ResultType(Val) {}
36   NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){}
37
38   static ArgResultTypes Translate(Record *R);
39
40 };
41
42 class InstrSelectorEmitter : public TableGenBackend {
43   RecordKeeper &Records;
44
45   std::map<Record*, NodeType> NodeTypes;
46 public:
47   InstrSelectorEmitter(RecordKeeper &R) : Records(R) {}
48   
49   // run - Output the instruction set description, returning true on failure.
50   void run(std::ostream &OS);
51
52 private:
53   // ProcessNodeTypes - Process all of the node types in the current
54   // RecordKeeper, turning them into the more accessible NodeTypes data
55   // structure.
56   void ProcessNodeTypes();
57 };
58
59 #endif