mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-25 13:08:00 +00:00
The the MC disassembler C API to print in verbose mode. Perhaps there should be a parameter to request verbose mode?
llvm-svn: 139821
This commit is contained in:
parent
84d4e5d0e2
commit
5514958222
@ -81,6 +81,9 @@ LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
|
||||
TheTarget, MAI, MRI,
|
||||
Ctx, DisAsm, IP);
|
||||
assert(DC && "Allocation failure!");
|
||||
|
||||
IP->setCommentStream(DC->CommentStream);
|
||||
|
||||
return DC;
|
||||
}
|
||||
|
||||
@ -154,6 +157,25 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
|
||||
IP->printInst(&Inst, OS);
|
||||
OS.flush();
|
||||
|
||||
DC->CommentStream.flush();
|
||||
assert(DC->CommentsToEmit.back() == '\n');
|
||||
|
||||
DC->CommentsToEmit.push_back('\n');
|
||||
StringRef Comments = DC->CommentsToEmit.str();
|
||||
|
||||
do {
|
||||
// Emit a line of comments.
|
||||
size_t Position = Comments.find('\n');
|
||||
OS << ' ' << DC->getAsmInfo()->getCommentString()
|
||||
<< ' ' << Comments.substr(0, Position) << '\n';
|
||||
|
||||
Comments = Comments.substr(Position+1);
|
||||
} while (!Comments.empty());
|
||||
|
||||
DC->CommentsToEmit.clear();
|
||||
// Tell the comment stream that the vector changed underneath it.
|
||||
DC->CommentStream.resync();
|
||||
|
||||
assert(OutStringSize != 0 && "Output buffer cannot be zero size");
|
||||
size_t OutputSize = std::min(OutStringSize-1, InsnStr.size());
|
||||
std::memcpy(OutString, InsnStr.data(), OutputSize);
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "llvm-c/Disassembler.h"
|
||||
#include <string>
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace llvm {
|
||||
class MCContext;
|
||||
@ -67,6 +69,10 @@ private:
|
||||
llvm::OwningPtr<llvm::MCInstPrinter> IP;
|
||||
|
||||
public:
|
||||
// Comment stream and backing vector.
|
||||
SmallString<128> CommentsToEmit;
|
||||
raw_svector_ostream CommentStream;
|
||||
|
||||
LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
|
||||
LLVMOpInfoCallback getOpInfo,
|
||||
LLVMSymbolLookupCallback symbolLookUp,
|
||||
@ -75,7 +81,8 @@ public:
|
||||
llvm::MCContext *ctx, const MCDisassembler *disAsm,
|
||||
MCInstPrinter *iP) : TripleName(tripleName),
|
||||
DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
|
||||
SymbolLookUp(symbolLookUp), TheTarget(theTarget) {
|
||||
SymbolLookUp(symbolLookUp), TheTarget(theTarget),
|
||||
CommentStream(CommentsToEmit) {
|
||||
MAI.reset(mAI);
|
||||
MRI.reset(mRI);
|
||||
Ctx.reset(ctx);
|
||||
@ -83,6 +90,7 @@ public:
|
||||
IP.reset(iP);
|
||||
}
|
||||
const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
|
||||
const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
|
||||
MCInstPrinter *getIP() { return IP.get(); }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user