diff options
author | Logan Chien <loganchien@google.com> | 2011-10-20 00:08:13 +0800 |
---|---|---|
committer | Logan Chien <loganchien@google.com> | 2011-10-20 00:09:35 +0800 |
commit | 0ebc07a576037e4e36f68bf5cece32740ca120c0 (patch) | |
tree | c2e40648043d01498ee25af839a071193561e425 /tools/llvm-mc/Disassembler.cpp | |
parent | 62383e889e0b06fd12a6b88311717cd33a1925c4 (diff) | |
parent | cdd8e46bec4e975d00a5abea808d8eb4138515c5 (diff) | |
download | external_llvm-0ebc07a576037e4e36f68bf5cece32740ca120c0.tar.gz external_llvm-0ebc07a576037e4e36f68bf5cece32740ca120c0.tar.bz2 external_llvm-0ebc07a576037e4e36f68bf5cece32740ca120c0.zip |
Merge with LLVM upstream 2011/10/20 (r142530)
Conflicts:
lib/Support/Unix/Host.inc
Change-Id: Idc00db3b63912dca6348bddd9f8a1af2a8d5d147
Diffstat (limited to 'tools/llvm-mc/Disassembler.cpp')
-rw-r--r-- | tools/llvm-mc/Disassembler.cpp | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index c389f6a953..e0064888de 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -21,14 +21,15 @@ #include "llvm/MC/MCDisassembler.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" -#include "llvm/Target/TargetRegistry.h" +#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryObject.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/SourceMgr.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; typedef std::vector<std::pair<unsigned char, const char*> > ByteArrayTy; @@ -65,15 +66,28 @@ static bool PrintInsts(const MCDisassembler &DisAsm, for (Index = 0; Index < Bytes.size(); Index += Size) { MCInst Inst; - if (DisAsm.getInstruction(Inst, Size, memoryObject, Index, - /*REMOVE*/ nulls())) { - Printer.printInst(&Inst, Out); - Out << "\n"; - } else { + MCDisassembler::DecodeStatus S; + S = DisAsm.getInstruction(Inst, Size, memoryObject, Index, + /*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), + SourceMgr::DK_Warning, + "potentially undefined instruction encoding"); + // Fall through + + case MCDisassembler::Success: + Printer.printInst(&Inst, Out, ""); + Out << "\n"; + break; } } @@ -113,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; @@ -129,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. @@ -139,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; @@ -147,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; |