2011-02-18 22:51:29 +01:00
|
|
|
//===------------ FixedLenDecoderEmitter.h - Decoder Generator --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// It contains the tablegen backend that emits the decoder functions for
|
|
|
|
// targets with fixed length instruction set.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef FixedLenDECODEREMITTER_H
|
|
|
|
#define FixedLenDECODEREMITTER_H
|
|
|
|
|
|
|
|
#include "CodeGenTarget.h"
|
|
|
|
#include "TableGenBackend.h"
|
|
|
|
|
|
|
|
#include "llvm/Support/DataTypes.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2011-07-28 23:54:31 +02:00
|
|
|
struct EncodingField {
|
|
|
|
unsigned Base, Width, Offset;
|
|
|
|
EncodingField(unsigned B, unsigned W, unsigned O)
|
|
|
|
: Base(B), Width(W), Offset(O) { }
|
|
|
|
};
|
|
|
|
|
2011-02-18 22:51:29 +01:00
|
|
|
struct OperandInfo {
|
2011-07-28 23:54:31 +02:00
|
|
|
std::vector<EncodingField> Fields;
|
2011-02-18 22:51:29 +01:00
|
|
|
std::string Decoder;
|
|
|
|
|
2011-07-28 23:54:31 +02:00
|
|
|
OperandInfo(std::string D)
|
|
|
|
: Decoder(D) { }
|
|
|
|
|
|
|
|
void addField(unsigned Base, unsigned Width, unsigned Offset) {
|
|
|
|
Fields.push_back(EncodingField(Base, Width, Offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned numFields() { return Fields.size(); }
|
|
|
|
|
|
|
|
typedef std::vector<EncodingField>::iterator iterator;
|
|
|
|
|
|
|
|
iterator begin() { return Fields.begin(); }
|
|
|
|
iterator end() { return Fields.end(); }
|
2011-02-18 22:51:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class FixedLenDecoderEmitter : public TableGenBackend {
|
|
|
|
public:
|
2011-08-17 19:44:15 +02:00
|
|
|
FixedLenDecoderEmitter(RecordKeeper &R,
|
2011-09-07 21:42:28 +02:00
|
|
|
std::string PredicateNamespace,
|
2011-08-17 19:44:15 +02:00
|
|
|
std::string GPrefix = "if (",
|
|
|
|
std::string GPostfix = " == MCDisassembler::Fail) return MCDisassembler::Fail;",
|
|
|
|
std::string ROK = "MCDisassembler::Success",
|
|
|
|
std::string RFail = "MCDisassembler::Fail",
|
|
|
|
std::string L = "") :
|
2011-02-18 22:51:29 +01:00
|
|
|
Records(R), Target(R),
|
2011-08-17 19:44:15 +02:00
|
|
|
NumberedInstructions(Target.getInstructionsByEnumValue()),
|
2011-09-07 21:42:28 +02:00
|
|
|
PredicateNamespace(PredicateNamespace),
|
2011-08-17 19:44:15 +02:00
|
|
|
GuardPrefix(GPrefix), GuardPostfix(GPostfix),
|
|
|
|
ReturnOK(ROK), ReturnFail(RFail), Locals(L) {}
|
2011-02-18 22:51:29 +01:00
|
|
|
|
|
|
|
// run - Output the code emitter
|
|
|
|
void run(raw_ostream &o);
|
|
|
|
|
|
|
|
private:
|
|
|
|
RecordKeeper &Records;
|
|
|
|
CodeGenTarget Target;
|
|
|
|
std::vector<const CodeGenInstruction*> NumberedInstructions;
|
|
|
|
std::vector<unsigned> Opcodes;
|
|
|
|
std::map<unsigned, std::vector<OperandInfo> > Operands;
|
2011-08-17 19:44:15 +02:00
|
|
|
public:
|
2011-09-07 21:42:28 +02:00
|
|
|
std::string PredicateNamespace;
|
2011-08-17 19:44:15 +02:00
|
|
|
std::string GuardPrefix, GuardPostfix;
|
|
|
|
std::string ReturnOK, ReturnFail;
|
|
|
|
std::string Locals;
|
2011-02-18 22:51:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|