blob: 941763eb03c96c333e682260997d8b41e92d48ac [file] [log] [blame]
Chris Lattnerfaca5ab2003-08-06 05:42:05 +00001//===- 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
15struct NodeType {
16 enum ArgResultTypes {
17 // Both argument and return types...
18 Val, // A non-void type
19 Arg0, // Value matches the type of Arg0
Chris Lattner2787d1a2003-08-06 06:16:35 +000020 Ptr, // Tree node is the type of the target pointer
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000021
22 // Return types
23 Void, // Tree node always returns void
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000024 };
25
26 ArgResultTypes ResultType;
27 std::vector<ArgResultTypes> ArgTypes;
28
29 NodeType(ArgResultTypes RT, std::vector<ArgResultTypes> &AT) : ResultType(RT){
30 AT.swap(ArgTypes);
31 }
32
33 NodeType() : ResultType(Val) {}
34 NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){}
35
36 static ArgResultTypes Translate(Record *R);
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000037};
38
39class InstrSelectorEmitter : public TableGenBackend {
40 RecordKeeper &Records;
41
42 std::map<Record*, NodeType> NodeTypes;
43public:
44 InstrSelectorEmitter(RecordKeeper &R) : Records(R) {}
45
46 // run - Output the instruction set description, returning true on failure.
47 void run(std::ostream &OS);
48
49private:
50 // ProcessNodeTypes - Process all of the node types in the current
51 // RecordKeeper, turning them into the more accessible NodeTypes data
52 // structure.
53 void ProcessNodeTypes();
Chris Lattner2787d1a2003-08-06 06:16:35 +000054
55 // ProcessInstructionPatterns - Read in all subclasses of Instruction, and
56 // process those with a useful Pattern field.
57 void ProcessInstructionPatterns();
Chris Lattnerfaca5ab2003-08-06 05:42:05 +000058};
59
60#endif