mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
If you thought that it didn't make sense for the disassembler
to not produce caret diagnostics, you were right! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91895 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2adbef06a6
commit
c3de94fabf
@ -23,8 +23,7 @@
|
|||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/MemoryObject.h"
|
#include "llvm/Support/MemoryObject.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -47,9 +46,7 @@ public:
|
|||||||
int readByte(uint64_t addr, uint8_t *byte) const {
|
int readByte(uint64_t addr, uint8_t *byte) const {
|
||||||
if (addr > getExtent())
|
if (addr > getExtent())
|
||||||
return -1;
|
return -1;
|
||||||
else
|
|
||||||
*byte = Bytes[addr];
|
*byte = Bytes[addr];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -58,26 +55,19 @@ void printInst(const llvm::MCDisassembler &disassembler,
|
|||||||
llvm::MCInstPrinter &instPrinter,
|
llvm::MCInstPrinter &instPrinter,
|
||||||
const std::vector<unsigned char> &bytes) {
|
const std::vector<unsigned char> &bytes) {
|
||||||
// Wrap the vector in a MemoryObject.
|
// Wrap the vector in a MemoryObject.
|
||||||
|
|
||||||
VectorMemoryObject memoryObject(bytes);
|
VectorMemoryObject memoryObject(bytes);
|
||||||
|
|
||||||
// Disassemble it.
|
// Disassemble it.
|
||||||
|
|
||||||
MCInst inst;
|
MCInst inst;
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
|
|
||||||
std::string verboseOStr;
|
std::string verboseOStr;
|
||||||
llvm::raw_string_ostream verboseOS(verboseOStr);
|
llvm::raw_string_ostream verboseOS(verboseOStr);
|
||||||
|
|
||||||
if (disassembler.getInstruction(inst,
|
if (disassembler.getInstruction(inst, size, memoryObject, 0, verboseOS)) {
|
||||||
size,
|
|
||||||
memoryObject,
|
|
||||||
0,
|
|
||||||
verboseOS)) {
|
|
||||||
instPrinter.printInst(&inst);
|
instPrinter.printInst(&inst);
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
errs() << "error: invalid instruction" << "\n";
|
errs() << "error: invalid instruction" << "\n";
|
||||||
errs() << "Diagnostic log:" << "\n";
|
errs() << "Diagnostic log:" << "\n";
|
||||||
errs() << verboseOStr.c_str() << "\n";
|
errs() << verboseOStr.c_str() << "\n";
|
||||||
@ -108,11 +98,13 @@ int HexDisassembler::disassemble(const Target &T, const std::string &Triple,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SourceMgr SourceManager;
|
||||||
|
SourceManager.AddNewSourceBuffer(&Buffer, SMLoc());
|
||||||
|
|
||||||
// Convert the input to a vector for disassembly.
|
// Convert the input to a vector for disassembly.
|
||||||
std::vector<unsigned char> ByteArray;
|
std::vector<unsigned char> ByteArray;
|
||||||
|
|
||||||
StringRef Str = Buffer.getBuffer();
|
StringRef Str = Buffer.getBuffer();
|
||||||
|
|
||||||
while (!Str.empty()) {
|
while (!Str.empty()) {
|
||||||
// Strip horizontal whitespace.
|
// Strip horizontal whitespace.
|
||||||
if (size_t Pos = Str.find_first_not_of(" \t\r")) {
|
if (size_t Pos = Str.find_first_not_of(" \t\r")) {
|
||||||
@ -148,11 +140,15 @@ int HexDisassembler::disassemble(const Target &T, const std::string &Triple,
|
|||||||
// Convert to a byte and add to the byte vector.
|
// Convert to a byte and add to the byte vector.
|
||||||
unsigned ByteVal;
|
unsigned ByteVal;
|
||||||
if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
|
if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
|
||||||
errs() << "warning: invalid input token '" << Value << "' of length "
|
// If we have an error, print it and skip to the end of line.
|
||||||
<< Next << "\n";
|
SourceManager.PrintMessage(SMLoc::getFromPointer(Value.data()),
|
||||||
} else {
|
"invalid input token", "error");
|
||||||
ByteArray.push_back((unsigned char)ByteVal);
|
Str = Str.substr(Str.find('\n'));
|
||||||
|
ByteArray.clear();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteArray.push_back((unsigned char)ByteVal);
|
||||||
Str = Str.substr(Next);
|
Str = Str.substr(Next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user