summaryrefslogtreecommitdiff
path: root/tools/llvm-mc/Disassembler.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2010-02-03 03:46:41 +0000
committerSean Callanan <scallanan@apple.com>2010-02-03 03:46:41 +0000
commit2e235a826d2f65a064b2a39b27c775d0adf8b7c3 (patch)
treed6f8cbf7c58bbf5e6e26760002cb71058def2ef4 /tools/llvm-mc/Disassembler.cpp
parent281d051921be84e2f790dd567958cd200b28e2dd (diff)
downloadllvm-2e235a826d2f65a064b2a39b27c775d0adf8b7c3.tar.gz
llvm-2e235a826d2f65a064b2a39b27c775d0adf8b7c3.tar.bz2
llvm-2e235a826d2f65a064b2a39b27c775d0adf8b7c3.tar.xz
Fixed the disassembler so it accepts multiple
instructions on a single line. Also made it a bit more forgiving when it reports errors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95197 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/Disassembler.cpp')
-rw-r--r--tools/llvm-mc/Disassembler.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp
index 5fde71238d..dbfe7a5d06 100644
--- a/tools/llvm-mc/Disassembler.cpp
+++ b/tools/llvm-mc/Disassembler.cpp
@@ -47,32 +47,30 @@ public:
};
}
-static bool PrintInst(const llvm::MCDisassembler &DisAsm,
+static bool PrintInsts(const llvm::MCDisassembler &DisAsm,
llvm::MCInstPrinter &Printer, const ByteArrayTy &Bytes,
SourceMgr &SM) {
// Wrap the vector in a MemoryObject.
VectorMemoryObject memoryObject(Bytes);
- // Disassemble it to a string and get the size of the instruction.
- MCInst Inst;
+ // Disassemble it to strings.
uint64_t Size;
+ uint64_t Index;
- if (!DisAsm.getInstruction(Inst, Size, memoryObject, 0,
- /*REMOVE*/ nulls())) {
- SM.PrintMessage(SMLoc::getFromPointer(Bytes[0].second),
- "invalid instruction encoding", "error");
- return true;
- }
-
- Printer.printInst(&Inst);
- outs() << "\n";
-
- // If the disassembled instruction was smaller than the number of bytes we
- // read, reject the excess bytes.
- if (Bytes.size() != Size) {
- SM.PrintMessage(SMLoc::getFromPointer(Bytes[Size].second),
- "excess data detected in input", "error");
- return true;
+ for (Index = 0; Index < Bytes.size(); Index += Size) {
+ MCInst Inst;
+
+ if (DisAsm.getInstruction(Inst, Size, memoryObject, Index,
+ /*REMOVE*/ nulls())) {
+ Printer.printInst(&Inst);
+ outs() << "\n";
+ }
+ else {
+ SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
+ "invalid instruction encoding", "warning");
+ if (Size == 0)
+ Size = 1; // skip illegible bytes
+ }
}
return false;
@@ -117,15 +115,9 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
continue;
}
- // If this is the end of a line or start of a comment, process the
- // instruction we have so far.
+ // If this is the end of a line or start of a comment, remove the rest of
+ // the line.
if (Str[0] == '\n' || Str[0] == '#') {
- // If we have bytes to process, do so.
- if (!ByteArray.empty()) {
- ErrorOccurred |= PrintInst(*DisAsm, *InstPrinter, ByteArray, SM);
- ByteArray.clear();
- }
-
// Strip to the end of line if we already processed any bytes on this
// line. This strips the comment and/or the \n.
if (Str[0] == '\n')
@@ -159,7 +151,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
}
if (!ByteArray.empty())
- ErrorOccurred |= PrintInst(*DisAsm, *InstPrinter, ByteArray, SM);
+ ErrorOccurred |= PrintInsts(*DisAsm, *InstPrinter, ByteArray, SM);
return ErrorOccurred;
}