[llvm-commits] [llvm] r91895 - /llvm/trunk/tools/llvm-mc/HexDisassembler.cpp

Chris Lattner sabre at nondot.org
Mon Dec 21 22:45:48 PST 2009


Author: lattner
Date: Tue Dec 22 00:45:48 2009
New Revision: 91895

URL: http://llvm.org/viewvc/llvm-project?rev=91895&view=rev
Log:
If you thought that it didn't make sense for the disassembler
to not produce caret diagnostics, you were right!

Modified:
    llvm/trunk/tools/llvm-mc/HexDisassembler.cpp

Modified: llvm/trunk/tools/llvm-mc/HexDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/HexDisassembler.cpp?rev=91895&r1=91894&r2=91895&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/HexDisassembler.cpp (original)
+++ llvm/trunk/tools/llvm-mc/HexDisassembler.cpp Tue Dec 22 00:45:48 2009
@@ -23,8 +23,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/MemoryObject.h"
 #include "llvm/Support/raw_ostream.h"
-
-#include <vector>
+#include "llvm/Support/SourceMgr.h"
 
 using namespace llvm;
 
@@ -47,9 +46,7 @@
   int readByte(uint64_t addr, uint8_t *byte) const {
     if (addr > getExtent())
       return -1;
-    else
-      *byte = Bytes[addr];
-    
+    *byte = Bytes[addr];
     return 0;
   }
 };
@@ -58,26 +55,19 @@
                llvm::MCInstPrinter &instPrinter,
                const std::vector<unsigned char> &bytes) {
   // Wrap the vector in a MemoryObject.
-  
   VectorMemoryObject memoryObject(bytes);
   
   // Disassemble it.
-  
   MCInst inst;
   uint64_t size;
   
   std::string verboseOStr;
   llvm::raw_string_ostream verboseOS(verboseOStr); 
   
-  if (disassembler.getInstruction(inst, 
-                                  size, 
-                                  memoryObject, 
-                                  0, 
-                                  verboseOS)) {
+  if (disassembler.getInstruction(inst, size, memoryObject, 0, verboseOS)) {
     instPrinter.printInst(&inst);
     outs() << "\n";
-  }
-  else {
+  } else {
     errs() << "error: invalid instruction" << "\n";
     errs() << "Diagnostic log:" << "\n";
     errs() << verboseOStr.c_str() << "\n";
@@ -108,11 +98,13 @@
     return -1;
   }
   
+  SourceMgr SourceManager;
+  SourceManager.AddNewSourceBuffer(&Buffer, SMLoc());
+  
   // Convert the input to a vector for disassembly.
   std::vector<unsigned char> ByteArray;
   
   StringRef Str = Buffer.getBuffer();
-  
   while (!Str.empty()) {
     // Strip horizontal whitespace.
     if (size_t Pos = Str.find_first_not_of(" \t\r")) {
@@ -148,11 +140,15 @@
     // 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 {
-      ByteArray.push_back((unsigned char)ByteVal);
+      // If we have an error, print it and skip to the end of line.
+      SourceManager.PrintMessage(SMLoc::getFromPointer(Value.data()),
+                                 "invalid input token", "error");
+      Str = Str.substr(Str.find('\n'));
+      ByteArray.clear();
+      continue;
     }
+    
+    ByteArray.push_back((unsigned char)ByteVal);
     Str = Str.substr(Next);
   }
   





More information about the llvm-commits mailing list