1 //===------------ FixedLenDecoderEmitter.h - Decoder Generator --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // It contains the tablegen backend that emits the decoder functions for
11 // targets with fixed length instruction set.
13 //===----------------------------------------------------------------------===//
15 #ifndef FixedLenDECODEREMITTER_H
16 #define FixedLenDECODEREMITTER_H
18 #include "CodeGenTarget.h"
20 #include "llvm/TableGen/TableGenBackend.h"
21 #include "llvm/Support/DataTypes.h"
25 struct EncodingField {
26 unsigned Base, Width, Offset;
27 EncodingField(unsigned B, unsigned W, unsigned O)
28 : Base(B), Width(W), Offset(O) { }
32 std::vector<EncodingField> Fields;
35 OperandInfo(std::string D)
38 void addField(unsigned Base, unsigned Width, unsigned Offset) {
39 Fields.push_back(EncodingField(Base, Width, Offset));
42 unsigned numFields() { return Fields.size(); }
44 typedef std::vector<EncodingField>::iterator iterator;
46 iterator begin() { return Fields.begin(); }
47 iterator end() { return Fields.end(); }
50 class FixedLenDecoderEmitter : public TableGenBackend {
52 FixedLenDecoderEmitter(RecordKeeper &R,
53 std::string PredicateNamespace,
54 std::string GPrefix = "if (",
55 std::string GPostfix = " == MCDisassembler::Fail) return MCDisassembler::Fail;",
56 std::string ROK = "MCDisassembler::Success",
57 std::string RFail = "MCDisassembler::Fail",
59 Records(R), Target(R),
60 NumberedInstructions(Target.getInstructionsByEnumValue()),
61 PredicateNamespace(PredicateNamespace),
62 GuardPrefix(GPrefix), GuardPostfix(GPostfix),
63 ReturnOK(ROK), ReturnFail(RFail), Locals(L) {}
65 // run - Output the code emitter
66 void run(raw_ostream &o);
69 RecordKeeper &Records;
71 std::vector<const CodeGenInstruction*> NumberedInstructions;
72 std::vector<unsigned> Opcodes;
73 std::map<unsigned, std::vector<OperandInfo> > Operands;
75 std::string PredicateNamespace;
76 std::string GuardPrefix, GuardPostfix;
77 std::string ReturnOK, ReturnFail;
81 } // end llvm namespace