Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,46 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
//
//===----------------------------------------------------------------------===//

template <typename InsnType>
DecodeStatus AMDGPUDisassembler::tryDecodeInst(const uint8_t *Table, MCInst &MI,
InsnType Inst, uint64_t Address,
raw_ostream &Comments) const {
assert(MI.getOpcode() == 0);
assert(MI.getNumOperands() == 0);
MCInst TmpInst;
HasLiteral = false;
const auto SavedBytes = Bytes;

SmallString<64> LocalComments;
raw_svector_ostream LocalCommentStream(LocalComments);
CommentStream = &LocalCommentStream;

DecodeStatus Res =
decodeInstruction(Table, TmpInst, Inst, Address, this, STI);

CommentStream = nullptr;

if (Res != MCDisassembler::Fail) {
MI = TmpInst;
Comments << LocalComments;
return MCDisassembler::Success;
}
Bytes = SavedBytes;
return MCDisassembler::Fail;
}

template <typename InsnType>
DecodeStatus
AMDGPUDisassembler::tryDecodeInst(const uint8_t *Table1, const uint8_t *Table2,
MCInst &MI, InsnType Inst, uint64_t Address,
raw_ostream &Comments) const {
for (const uint8_t *T : {Table1, Table2}) {
if (DecodeStatus Res = tryDecodeInst(T, MI, Inst, Address, Comments))
return Res;
}
return MCDisassembler::Fail;
}

template <typename T> static inline T eatBytes(ArrayRef<uint8_t>& Bytes) {
assert(Bytes.size() >= sizeof(T));
const auto Res =
Expand Down
34 changes: 2 additions & 32 deletions llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,41 +130,11 @@ class AMDGPUDisassembler : public MCDisassembler {

template <typename InsnType>
DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, InsnType Inst,
uint64_t Address, raw_ostream &Comments) const {
assert(MI.getOpcode() == 0);
assert(MI.getNumOperands() == 0);
MCInst TmpInst;
HasLiteral = false;
const auto SavedBytes = Bytes;

SmallString<64> LocalComments;
raw_svector_ostream LocalCommentStream(LocalComments);
CommentStream = &LocalCommentStream;

DecodeStatus Res =
decodeInstruction(Table, TmpInst, Inst, Address, this, STI);

CommentStream = nullptr;

if (Res != Fail) {
MI = TmpInst;
Comments << LocalComments;
return MCDisassembler::Success;
}
Bytes = SavedBytes;
return MCDisassembler::Fail;
}

uint64_t Address, raw_ostream &Comments) const;
template <typename InsnType>
DecodeStatus tryDecodeInst(const uint8_t *Table1, const uint8_t *Table2,
MCInst &MI, InsnType Inst, uint64_t Address,
raw_ostream &Comments) const {
for (const uint8_t *T : {Table1, Table2}) {
if (DecodeStatus Res = tryDecodeInst(T, MI, Inst, Address, Comments))
return Res;
}
return MCDisassembler::Fail;
}
raw_ostream &Comments) const;

Expected<bool> onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
ArrayRef<uint8_t> Bytes,
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ void DecoderEmitter::run(raw_ostream &o) {
#include "llvm/TargetParser/SubtargetFeature.h"
#include <assert.h>

namespace llvm {
namespace {
)";

emitFieldFromInstruction(OS);
Expand Down Expand Up @@ -2561,7 +2561,7 @@ namespace llvm {
// Emit the main entry point for the decoder, decodeInstruction().
emitDecodeInstruction(OS, IsVarLenInst);

OS << "\n} // end namespace llvm\n";
OS << "\n} // namespace\n";
}

void llvm::EmitDecoder(const RecordKeeper &RK, raw_ostream &OS,
Expand Down
Loading