summaryrefslogtreecommitdiff
path: root/tools/llvm-mc/Disassembler.cpp
diff options
context:
space:
mode:
authorRichard Barton <richard.barton@arm.com>2012-04-16 11:32:10 +0000
committerRichard Barton <richard.barton@arm.com>2012-04-16 11:32:10 +0000
commitd0c478d95f440b4db76279fe47d6cf734a28fa9a (patch)
tree576fb2a0a160f27b42950b8074dea0f829799e9c /tools/llvm-mc/Disassembler.cpp
parent4d2e9d9a1c213db144785f386ce661914d17afb6 (diff)
downloadllvm-d0c478d95f440b4db76279fe47d6cf734a28fa9a.tar.gz
llvm-d0c478d95f440b4db76279fe47d6cf734a28fa9a.tar.bz2
llvm-d0c478d95f440b4db76279fe47d6cf734a28fa9a.tar.xz
Add -disassemble support for -show-inst and -show-encode capability llvm-mc. Also refactor so all MC paraphernalia are created once for all uses as much as possible.
The test change is to account for the fact that the default disassembler behaviour has changed with regards to specifying the assembly syntax to use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/Disassembler.cpp')
-rw-r--r--tools/llvm-mc/Disassembler.cpp67
1 files changed, 14 insertions, 53 deletions
diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp
index a8cd7c1c89..5f2fdb8071 100644
--- a/tools/llvm-mc/Disassembler.cpp
+++ b/tools/llvm-mc/Disassembler.cpp
@@ -17,21 +17,18 @@
#include "../../lib/MC/MCDisassembler/EDInst.h"
#include "../../lib/MC/MCDisassembler/EDOperand.h"
#include "../../lib/MC/MCDisassembler/EDToken.h"
-#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCDisassembler.h"
#include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCInstPrinter.h"
-#include "llvm/MC/MCInstrInfo.h"
-#include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/MC/MCStreamer.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/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;
@@ -56,8 +53,9 @@ public:
}
static bool PrintInsts(const MCDisassembler &DisAsm,
- MCInstPrinter &Printer, const ByteArrayTy &Bytes,
- SourceMgr &SM, raw_ostream &Out) {
+ const ByteArrayTy &Bytes,
+ SourceMgr &SM, raw_ostream &Out,
+ MCStreamer &Streamer) {
// Wrap the vector in a MemoryObject.
VectorMemoryObject memoryObject(Bytes);
@@ -87,8 +85,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
// Fall through
case MCDisassembler::Success:
- Printer.printInst(&Inst, Out, "");
- Out << "\n";
+ Streamer.EmitInstruction(Inst);
break;
}
}
@@ -145,56 +142,22 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
int Disassembler::disassemble(const Target &T,
const std::string &Triple,
- const std::string &Cpu,
- const std::string &FeaturesStr,
+ MCSubtargetInfo &STI,
+ MCStreamer &Streamer,
MemoryBuffer &Buffer,
+ SourceMgr &SM,
raw_ostream &Out) {
- // Set up disassembler.
- OwningPtr<const MCAsmInfo> AsmInfo(T.createMCAsmInfo(Triple));
-
- if (!AsmInfo) {
- errs() << "error: no assembly info for target " << Triple << "\n";
- return -1;
- }
-
- 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));
+ OwningPtr<const MCDisassembler> DisAsm(T.createMCDisassembler(STI));
if (!DisAsm) {
errs() << "error: no disassembler for target " << Triple << "\n";
return -1;
}
- OwningPtr<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple));
- if (!MRI) {
- errs() << "error: no register info for target " << Triple << "\n";
- return -1;
- }
-
- OwningPtr<const MCInstrInfo> MII(T.createMCInstrInfo());
- if (!MII) {
- errs() << "error: no instruction info for target " << Triple << "\n";
- return -1;
- }
-
- int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
- OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(AsmPrinterVariant, *AsmInfo,
- *MII, *MRI, *STI));
- if (!IP) {
- errs() << "error: no instruction printer for target " << Triple << '\n';
- return -1;
- }
+ // Set up initial section manually here
+ Streamer.InitSections();
bool ErrorOccurred = false;
- SourceMgr SM;
- SM.AddNewSourceBuffer(&Buffer, SMLoc());
-
// Convert the input to a vector for disassembly.
ByteArrayTy ByteArray;
StringRef Str = Buffer.getBuffer();
@@ -202,7 +165,7 @@ int Disassembler::disassemble(const Target &T,
ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM);
if (!ByteArray.empty())
- ErrorOccurred |= PrintInsts(*DisAsm, *IP, ByteArray, SM, Out);
+ ErrorOccurred |= PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer);
return ErrorOccurred;
}
@@ -236,12 +199,10 @@ static int verboseEvaluator(uint64_t *V, unsigned R, void *Arg) {
int Disassembler::disassembleEnhanced(const std::string &TS,
MemoryBuffer &Buffer,
+ SourceMgr &SM,
raw_ostream &Out) {
ByteArrayTy ByteArray;
StringRef Str = Buffer.getBuffer();
- SourceMgr SM;
-
- SM.AddNewSourceBuffer(&Buffer, SMLoc());
if (ByteArrayFromString(ByteArray, Str, SM)) {
return -1;