2011-02-20 12:57:14 +00: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"
|
|
|
|
|
2011-10-20 21:10:27 +00:00
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2011-02-20 12:57:14 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2011-10-20 21:10:27 +00:00
|
|
|
struct EncodingField {
|
|
|
|
unsigned Base, Width, Offset;
|
|
|
|
EncodingField(unsigned B, unsigned W, unsigned O)
|
|
|
|
: Base(B), Width(W), Offset(O) { }
|
|
|
|
};
|
|
|
|
|
2011-02-20 12:57:14 +00:00
|
|
|
struct OperandInfo {
|
2011-10-20 21:10:27 +00:00
|
|
|
std::vector<EncodingField> Fields;
|
2011-02-20 12:57:14 +00:00
|
|
|
std::string Decoder;
|
|
|
|
|
2011-10-20 21:10:27 +00:00
|
|
|
OperandInfo(std::string D)
|
|
|
|
: Decoder(D) { }
|
|
|
|
|
|
|
|
void addField(unsigned Base, unsigned Width, unsigned Offset) {
|
|
|
|
Fields.push_back(EncodingField(Base, Width, Offset));
|
|
|
|
}
|
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
unsigned numFields() const { return Fields.size(); }
|
2011-10-20 21:10:27 +00:00
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
typedef std::vector<EncodingField>::const_iterator const_iterator;
|
2011-10-20 21:10:27 +00:00
|
|
|
|
2012-04-14 13:54:10 +00:00
|
|
|
const_iterator begin() const { return Fields.begin(); }
|
|
|
|
const_iterator end() const { return Fields.end(); }
|
2011-02-20 12:57:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FixedLenDecoderEmitter : public TableGenBackend {
|
|
|
|
public:
|
2011-10-20 21:10:27 +00:00
|
|
|
FixedLenDecoderEmitter(RecordKeeper &R,
|
|
|
|
std::string PredicateNamespace,
|
|
|
|
std::string GPrefix = "if (",
|
2012-04-14 13:54:10 +00:00
|
|
|
std::string GPostfix = " == MCDisassembler::Fail)"
|
|
|
|
" return MCDisassembler::Fail;",
|
2011-10-20 21:10:27 +00:00
|
|
|
std::string ROK = "MCDisassembler::Success",
|
|
|
|
std::string RFail = "MCDisassembler::Fail",
|
|
|
|
std::string L = "") :
|
2012-04-14 13:54:10 +00:00
|
|
|
Target(R),
|
2011-10-20 21:10:27 +00:00
|
|
|
PredicateNamespace(PredicateNamespace),
|
|
|
|
GuardPrefix(GPrefix), GuardPostfix(GPostfix),
|
|
|
|
ReturnOK(ROK), ReturnFail(RFail), Locals(L) {}
|
2011-02-20 12:57:14 +00:00
|
|
|
|
|
|
|
// run - Output the code emitter
|
|
|
|
void run(raw_ostream &o);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CodeGenTarget Target;
|
2011-10-20 21:10:27 +00:00
|
|
|
public:
|
|
|
|
std::string PredicateNamespace;
|
|
|
|
std::string GuardPrefix, GuardPostfix;
|
|
|
|
std::string ReturnOK, ReturnFail;
|
|
|
|
std::string Locals;
|
2011-02-20 12:57:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|