summaryrefslogtreecommitdiff
path: root/lib/MC/MCDisassembler/Disassembler.cpp
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2012-12-18 23:47:28 +0000
committerKevin Enderby <enderby@apple.com>2012-12-18 23:47:28 +0000
commit5469f605fe86edcfb6d3f0e36f3e3ce0254334cc (patch)
tree8be658a578dabe4badcb23c639e0e0cc669901dd /lib/MC/MCDisassembler/Disassembler.cpp
parent445a02b5ad80de64d4e9d1d9efc8ab19ee2dd118 (diff)
downloadllvm-5469f605fe86edcfb6d3f0e36f3e3ce0254334cc.tar.gz
llvm-5469f605fe86edcfb6d3f0e36f3e3ce0254334cc.tar.bz2
llvm-5469f605fe86edcfb6d3f0e36f3e3ce0254334cc.tar.xz
Add to the disassembler C API an option to print the disassembled
instructions in the assembly code variant if one exists. The intended use for this is so tools like lldb and darwin's otool(1) can be switched to print Intel-flavored disassembly. I discussed extensively this API with Jim Grosbach and we feel while it may not be fully general, in reality there is only one syntax for each assembly with the exception of X86 which has exactly two for historical reasons. rdar://10989182 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170477 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCDisassembler/Disassembler.cpp')
-rw-r--r--lib/MC/MCDisassembler/Disassembler.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/MC/MCDisassembler/Disassembler.cpp b/lib/MC/MCDisassembler/Disassembler.cpp
index ac583ac127..d3fa906a06 100644
--- a/lib/MC/MCDisassembler/Disassembler.cpp
+++ b/lib/MC/MCDisassembler/Disassembler.cpp
@@ -195,5 +195,21 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options){
IP->setPrintImmHex(1);
Options &= ~LLVMDisassembler_Option_PrintImmHex;
}
+ if (Options & LLVMDisassembler_Option_AsmPrinterVariant){
+ LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR;
+ // Try to set up the new instruction printer.
+ const MCAsmInfo *MAI = DC->getAsmInfo();
+ const MCInstrInfo *MII = DC->getInstrInfo();
+ const MCRegisterInfo *MRI = DC->getRegisterInfo();
+ const MCSubtargetInfo *STI = DC->getSubtargetInfo();
+ int AsmPrinterVariant = MAI->getAssemblerDialect();
+ AsmPrinterVariant = AsmPrinterVariant == 0 ? 1 : 0;
+ MCInstPrinter *IP = DC->getTarget()->createMCInstPrinter(
+ AsmPrinterVariant, *MAI, *MII, *MRI, *STI);
+ if (IP) {
+ DC->setIP(IP);
+ Options &= ~LLVMDisassembler_Option_AsmPrinterVariant;
+ }
+ }
return (Options == 0);
}