summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mc
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-11-07 17:59:05 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-11-07 17:59:05 +0000
commit45a753a49a046ec81fad5627402c28eb03b38db7 (patch)
treeb58d181c5b0565ca873fd235d2eadf4d0e8ea5d2 /llvm/tools/llvm-mc
parentc909c9918f15354122121b7e922b9278e9a46e6d (diff)
downloadbcm5719-llvm-45a753a49a046ec81fad5627402c28eb03b38db7.tar.gz
bcm5719-llvm-45a753a49a046ec81fad5627402c28eb03b38db7.zip
Use StringRefMemoryObject in llvm-mc. NFC.
llvm-svn: 221536
Diffstat (limited to 'llvm/tools/llvm-mc')
-rw-r--r--llvm/tools/llvm-mc/Disassembler.cpp44
1 files changed, 15 insertions, 29 deletions
diff --git a/llvm/tools/llvm-mc/Disassembler.cpp b/llvm/tools/llvm-mc/Disassembler.cpp
index 0ff73c5dd0f..2c560ba4bc3 100644
--- a/llvm/tools/llvm-mc/Disassembler.cpp
+++ b/llvm/tools/llvm-mc/Disassembler.cpp
@@ -22,33 +22,15 @@
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/MemoryObject.h"
+#include "llvm/Support/StringRefMemoryObject.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
-typedef std::vector<std::pair<unsigned char, const char*> > ByteArrayTy;
-
-namespace {
-class VectorMemoryObject : public MemoryObject {
-private:
- const ByteArrayTy &Bytes;
-public:
- VectorMemoryObject(const ByteArrayTy &bytes) : Bytes(bytes) {}
-
- uint64_t getBase() const override { return 0; }
- uint64_t getExtent() const override { return Bytes.size(); }
-
- int readByte(uint64_t Addr, uint8_t *Byte) const override {
- if (Addr >= getExtent())
- return -1;
- *Byte = Bytes[Addr].first;
- return 0;
- }
-};
-}
+typedef std::pair<std::vector<unsigned char>, std::vector<const char *>>
+ ByteArrayTy;
static bool PrintInsts(const MCDisassembler &DisAsm,
const ByteArrayTy &Bytes,
@@ -56,13 +38,14 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
MCStreamer &Streamer, bool InAtomicBlock,
const MCSubtargetInfo &STI) {
// Wrap the vector in a MemoryObject.
- VectorMemoryObject memoryObject(Bytes);
+ StringRef Data((const char*)Bytes.first.data(), Bytes.first.size());
+ StringRefMemoryObject memoryObject(Data);
// Disassemble it to strings.
uint64_t Size;
uint64_t Index;
- for (Index = 0; Index < Bytes.size(); Index += Size) {
+ for (Index = 0; Index < Bytes.first.size(); Index += Size) {
MCInst Inst;
MCDisassembler::DecodeStatus S;
@@ -70,7 +53,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
/*REMOVE*/ nulls(), nulls());
switch (S) {
case MCDisassembler::Fail:
- SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
+ SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]),
SourceMgr::DK_Warning,
"invalid instruction encoding");
// Don't try to resynchronise the stream in a block
@@ -83,7 +66,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
break;
case MCDisassembler::SoftFail:
- SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
+ SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]),
SourceMgr::DK_Warning,
"potentially undefined instruction encoding");
// Fall through
@@ -143,11 +126,13 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
SM.PrintMessage(SMLoc::getFromPointer(Value.data()), SourceMgr::DK_Error,
"invalid input token");
Str = Str.substr(Str.find('\n'));
- ByteArray.clear();
+ ByteArray.first.clear();
+ ByteArray.second.clear();
continue;
}
- ByteArray.push_back(std::make_pair((unsigned char)ByteVal, Value.data()));
+ ByteArray.first.push_back(ByteVal);
+ ByteArray.second.push_back(Value.data());
Str = Str.substr(Next);
}
@@ -195,7 +180,8 @@ int Disassembler::disassemble(const Target &T,
bool InAtomicBlock = false;
while (SkipToToken(Str)) {
- ByteArray.clear();
+ ByteArray.first.clear();
+ ByteArray.second.clear();
if (Str[0] == '[') {
if (InAtomicBlock) {
@@ -220,7 +206,7 @@ int Disassembler::disassemble(const Target &T,
// It's a real token, get the bytes and emit them
ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM);
- if (!ByteArray.empty())
+ if (!ByteArray.first.empty())
ErrorOccurred |= PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer,
InAtomicBlock, STI);
}
OpenPOWER on IntegriCloud