Enable streaming of bitcode
[oota-llvm.git] / tools / llvm-mc / Disassembler.cpp
index 33a9e8e2e5c215db1c10c5b7914eddeb95b13d87..32fc2ba57d3713c315fcac56b0feba19b8ce1554 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/MC/MCDisassembler.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCInstPrinter.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/ADT/Twine.h"
@@ -41,9 +42,9 @@ public:
   VectorMemoryObject(const ByteArrayTy &bytes) : Bytes(bytes) {}
 
   uint64_t getBase() const { return 0; }
-  uint64_t getExtent() const { return Bytes.size(); }
+  uint64_t getExtent() { return Bytes.size(); }
 
-  int readByte(uint64_t Addr, uint8_t *Byte) const {
+  int readByte(uint64_t Addr, uint8_t *Byte) {
     if (Addr >= getExtent())
       return -1;
     *Byte = Bytes[Addr].first;
@@ -67,22 +68,24 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
 
     MCDisassembler::DecodeStatus S;
     S = DisAsm.getInstruction(Inst, Size, memoryObject, Index,
-                              /*REMOVE*/ nulls());
+                              /*REMOVE*/ nulls(), nulls());
     switch (S) {
     case MCDisassembler::Fail:
       SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
-                      "invalid instruction encoding", "warning");
+                      SourceMgr::DK_Warning,
+                      "invalid instruction encoding");
       if (Size == 0)
         Size = 1; // skip illegible bytes
       break;
 
     case MCDisassembler::SoftFail:
       SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
-                      "potentially undefined instruction encoding", "warning");
+                      SourceMgr::DK_Warning,
+                      "potentially undefined instruction encoding");
       // Fall through
 
     case MCDisassembler::Success:
-      Printer.printInst(&Inst, Out);
+      Printer.printInst(&Inst, Out, "");
       Out << "\n";
       break;
     }
@@ -124,8 +127,8 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
     unsigned ByteVal;
     if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
       // If we have an error, print it and skip to the end of line.
-      SM.PrintMessage(SMLoc::getFromPointer(Value.data()),
-                      "invalid input token", "error");
+      SM.PrintMessage(SMLoc::getFromPointer(Value.data()), SourceMgr::DK_Error,
+                      "invalid input token");
       Str = Str.substr(Str.find('\n'));
       ByteArray.clear();
       continue;
@@ -140,6 +143,8 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
 
 int Disassembler::disassemble(const Target &T,
                               const std::string &Triple,
+                              const std::string &Cpu,
+                              const std::string &FeaturesStr,
                               MemoryBuffer &Buffer,
                               raw_ostream &Out) {
   // Set up disassembler.
@@ -150,7 +155,13 @@ int Disassembler::disassemble(const Target &T,
     return -1;
   }
 
-  OwningPtr<const MCDisassembler> DisAsm(T.createMCDisassembler());
+  OwningPtr<const MCSubtargetInfo> STI(T.createMCSubtargetInfo(Triple, Cpu, FeaturesStr));
+  if (!STI) {
+    errs() << "error: no subtarget info for target " << Triple << "\n";
+    return -1;
+  }
+  
+  OwningPtr<const MCDisassembler> DisAsm(T.createMCDisassembler(*STI));
   if (!DisAsm) {
     errs() << "error: no disassembler for target " << Triple << "\n";
     return -1;
@@ -158,7 +169,7 @@ int Disassembler::disassemble(const Target &T,
 
   int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
   OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(AsmPrinterVariant,
-                                                    *AsmInfo));
+                                                    *AsmInfo, *STI));
   if (!IP) {
     errs() << "error: no instruction printer for target " << Triple << '\n';
     return -1;
@@ -238,7 +249,6 @@ int Disassembler::disassembleEnhanced(const std::string &TS,
     break;
   }
 
-  EDDisassembler::initialize();
   OwningPtr<EDDisassembler>
     disassembler(EDDisassembler::getDisassembler(TS.c_str(), AS));
 
@@ -285,7 +295,6 @@ int Disassembler::disassembleEnhanced(const std::string &TS,
         Out << operandIndex << "-";
 
       switch (token->type()) {
-      default: Out << "?"; break;
       case EDToken::kTokenWhitespace: Out << "w"; break;
       case EDToken::kTokenPunctuation: Out << "p"; break;
       case EDToken::kTokenOpcode: Out << "o"; break;