[llvm-commits] [llvm] r91894 - in /llvm/trunk: test/MC/Disassembler/ test/MC/Disassembler/dg.exp test/MC/Disassembler/simple-tests.txt tools/llvm-mc/HexDisassembler.cpp
Chris Lattner
sabre at nondot.org
Mon Dec 21 22:37:58 PST 2009
Author: lattner
Date: Tue Dec 22 00:37:58 2009
New Revision: 91894
URL: http://llvm.org/viewvc/llvm-project?rev=91894&view=rev
Log:
rewrite the file parser for the disassembler, implementing support for
comments. Also, check in a simple testcase for the disassembler,
including a test for r91864
Added:
llvm/trunk/test/MC/Disassembler/
llvm/trunk/test/MC/Disassembler/dg.exp
llvm/trunk/test/MC/Disassembler/simple-tests.txt
Modified:
llvm/trunk/tools/llvm-mc/HexDisassembler.cpp
Added: llvm/trunk/test/MC/Disassembler/dg.exp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/dg.exp?rev=91894&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/dg.exp (added)
+++ llvm/trunk/test/MC/Disassembler/dg.exp Tue Dec 22 00:37:58 2009
@@ -0,0 +1,4 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{txt}]]
+
Added: llvm/trunk/test/MC/Disassembler/simple-tests.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/simple-tests.txt?rev=91894&view=auto
==============================================================================
--- llvm/trunk/test/MC/Disassembler/simple-tests.txt (added)
+++ llvm/trunk/test/MC/Disassembler/simple-tests.txt Tue Dec 22 00:37:58 2009
@@ -0,0 +1,15 @@
+# RUN: llvm-mc --disassemble %s | FileCheck %s
+
+# CHECK: int $33
+0xCD 0x21
+
+# CHECK: int $33
+0xCD 0x21
+
+
+# CHECK: addb %al, (%rax)
+0 0 0 0 0 0
+
+# CHECK: callq -1234
+0xe8 0x2e 0xfb 0xff 0xff
+
Modified: llvm/trunk/tools/llvm-mc/HexDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/HexDisassembler.cpp?rev=91894&r1=91893&r2=91894&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/HexDisassembler.cpp (original)
+++ llvm/trunk/tools/llvm-mc/HexDisassembler.cpp Tue Dec 22 00:37:58 2009
@@ -114,31 +114,43 @@
StringRef Str = Buffer.getBuffer();
while (!Str.empty()) {
- if (Str.find_first_of('\n') < Str.find_first_not_of(" \t\n\r")) {
- if (!ByteArray.empty())
+ // Strip horizontal whitespace.
+ if (size_t Pos = Str.find_first_not_of(" \t\r")) {
+ Str = Str.substr(Pos);
+ continue;
+ }
+
+ // If this is the end of a line or start of a comment, process the
+ // instruction we have so far.
+ if (Str[0] == '\n' || Str[0] == '#') {
+ // If we have bytes to process, do so.
+ if (!ByteArray.empty()) {
printInst(*DisAsm, *InstPrinter, ByteArray);
+ ByteArray.clear();
+ }
- 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')
+ Str = Str.substr(1);
+ else {
+ Str = Str.substr(Str.find_first_of('\n'));
+ if (!Str.empty())
+ Str = Str.substr(1);
+ }
+ continue;
}
- // Skip leading space.
- Str = Str.substr(Str.find_first_not_of(" \t\n\r"));
-
// Get the current token.
- size_t Next = Str.find_first_of(" \t\n\r");
-
- if(Next == (size_t)StringRef::npos)
- break;
-
- StringRef Value = Str.slice(0, Next);
+ size_t Next = Str.find_first_of(" \t\n\r#");
+ StringRef Value = Str.substr(0, Next);
// Convert to a byte and add to the byte vector.
unsigned ByteVal;
if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
errs() << "warning: invalid input token '" << Value << "' of length "
<< Next << "\n";
- }
- else {
+ } else {
ByteArray.push_back((unsigned char)ByteVal);
}
Str = Str.substr(Next);
More information about the llvm-commits
mailing list