blob: 1ba7dfdad96236953525bc1272b5c0c7bd218b6c [file] [log] [blame]
Owen Andersond8c87882011-02-18 21:51:29 +00001//===------------ 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"
Owen Andersond8c87882011-02-18 21:51:29 +000019
Peter Collingbourne7c788882011-10-01 16:41:13 +000020#include "llvm/TableGen/TableGenBackend.h"
Owen Andersond8c87882011-02-18 21:51:29 +000021#include "llvm/Support/DataTypes.h"
22
23namespace llvm {
24
Owen Andersond1e38df2011-07-28 21:54:31 +000025struct EncodingField {
26 unsigned Base, Width, Offset;
27 EncodingField(unsigned B, unsigned W, unsigned O)
28 : Base(B), Width(W), Offset(O) { }
29};
30
Owen Andersond8c87882011-02-18 21:51:29 +000031struct OperandInfo {
Owen Andersond1e38df2011-07-28 21:54:31 +000032 std::vector<EncodingField> Fields;
Owen Andersond8c87882011-02-18 21:51:29 +000033 std::string Decoder;
34
Owen Andersond1e38df2011-07-28 21:54:31 +000035 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(); }
Owen Andersond8c87882011-02-18 21:51:29 +000048};
49
50class FixedLenDecoderEmitter : public TableGenBackend {
51public:
Owen Anderson83e3f672011-08-17 17:44:15 +000052 FixedLenDecoderEmitter(RecordKeeper &R,
James Molloya5d58562011-09-07 19:42:28 +000053 std::string PredicateNamespace,
Owen Anderson83e3f672011-08-17 17:44:15 +000054 std::string GPrefix = "if (",
Jim Grosbach9c826d22012-02-29 22:07:56 +000055 std::string GPostfix = " == MCDisassembler::Fail)"
56 " return MCDisassembler::Fail;",
Owen Anderson83e3f672011-08-17 17:44:15 +000057 std::string ROK = "MCDisassembler::Success",
58 std::string RFail = "MCDisassembler::Fail",
59 std::string L = "") :
Craig Topperc007ba82012-03-13 06:39:00 +000060 Target(R),
James Molloya5d58562011-09-07 19:42:28 +000061 PredicateNamespace(PredicateNamespace),
Owen Anderson83e3f672011-08-17 17:44:15 +000062 GuardPrefix(GPrefix), GuardPostfix(GPostfix),
63 ReturnOK(ROK), ReturnFail(RFail), Locals(L) {}
Owen Andersond8c87882011-02-18 21:51:29 +000064
65 // run - Output the code emitter
66 void run(raw_ostream &o);
67
68private:
Owen Andersond8c87882011-02-18 21:51:29 +000069 CodeGenTarget Target;
Owen Anderson83e3f672011-08-17 17:44:15 +000070public:
James Molloya5d58562011-09-07 19:42:28 +000071 std::string PredicateNamespace;
Owen Anderson83e3f672011-08-17 17:44:15 +000072 std::string GuardPrefix, GuardPostfix;
73 std::string ReturnOK, ReturnFail;
74 std::string Locals;
Owen Andersond8c87882011-02-18 21:51:29 +000075};
76
77} // end llvm namespace
78
79#endif