[AVX] Unique BitInit
[oota-llvm.git] / utils / TableGen / FixedLenDecoderEmitter.h
1 //===------------ FixedLenDecoderEmitter.h - Decoder Generator --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // It contains the tablegen backend that emits the decoder functions for
11 // targets with fixed length instruction set.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef FixedLenDECODEREMITTER_H
16 #define FixedLenDECODEREMITTER_H
17
18 #include "CodeGenTarget.h"
19 #include "TableGenBackend.h"
20
21 #include "llvm/Support/DataTypes.h"
22
23 namespace llvm {
24
25 struct EncodingField {
26   unsigned Base, Width, Offset;
27   EncodingField(unsigned B, unsigned W, unsigned O)
28     : Base(B), Width(W), Offset(O) { }
29 };
30
31 struct OperandInfo {
32   std::vector<EncodingField> Fields;
33   std::string Decoder;
34
35   OperandInfo(std::string D)
36     : Decoder(D) { }
37
38   void addField(unsigned Base, unsigned Width, unsigned Offset) {
39     Fields.push_back(EncodingField(Base, Width, Offset));
40   }
41
42   unsigned numFields() { return Fields.size(); }
43
44   typedef std::vector<EncodingField>::iterator iterator;
45
46   iterator begin() { return Fields.begin(); }
47   iterator end()   { return Fields.end();   }
48 };
49
50 class FixedLenDecoderEmitter : public TableGenBackend {
51 public:
52   FixedLenDecoderEmitter(RecordKeeper &R) :
53     Records(R), Target(R),
54     NumberedInstructions(Target.getInstructionsByEnumValue()) {}
55
56   // run - Output the code emitter
57   void run(raw_ostream &o);
58
59 private:
60   RecordKeeper &Records;
61   CodeGenTarget Target;
62   std::vector<const CodeGenInstruction*> NumberedInstructions;
63   std::vector<unsigned> Opcodes;
64   std::map<unsigned, std::vector<OperandInfo> > Operands;
65
66 };
67
68 } // end llvm namespace
69
70 #endif