diff options
author | Chad Rosier <mcrosier@apple.com> | 2012-10-03 22:06:44 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2012-10-03 22:06:44 +0000 |
commit | 34448ae39398eeb5339a3dc6c669b4ca6791eadc (patch) | |
tree | 33e3565df4721abeb19144de019342c080abcc8b /lib/Target/X86/X86AsmPrinter.cpp | |
parent | 42faefc11da326f10a4a52d72953318921d9e43d (diff) | |
download | llvm-34448ae39398eeb5339a3dc6c669b4ca6791eadc.tar.gz llvm-34448ae39398eeb5339a3dc6c669b4ca6791eadc.tar.bz2 llvm-34448ae39398eeb5339a3dc6c669b4ca6791eadc.tar.xz |
[ms-inline asm] Add support in the X86AsmPrinter for printing memory references
in the Intel syntax.
The MC layer supports emitting in the Intel syntax, but this would require the
inline assembly MachineInstr to be lowered to an MCInst before emission. This
is potential future work, but for now emitting directly from the MachineInstr
suffices.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165173 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/X86AsmPrinter.cpp')
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 2fc83a2df7..283a9a0f6f 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -365,6 +365,53 @@ void X86AsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, printLeaMemReference(MI, Op, O, Modifier); } +void X86AsmPrinter::printIntelMemReference(const MachineInstr *MI, unsigned Op, + raw_ostream &O, const char *Modifier, + unsigned AsmVariant){ + const MachineOperand &BaseReg = MI->getOperand(Op); + unsigned ScaleVal = MI->getOperand(Op+1).getImm(); + const MachineOperand &IndexReg = MI->getOperand(Op+2); + const MachineOperand &DispSpec = MI->getOperand(Op+3); + const MachineOperand &SegReg = MI->getOperand(Op+4); + + // If this has a segment register, print it. + if (SegReg.getReg()) { + printOperand(MI, Op+4, O, Modifier, AsmVariant); + O << ':'; + } + + O << '['; + + bool NeedPlus = false; + if (BaseReg.getReg()) { + printOperand(MI, Op, O, Modifier, AsmVariant); + NeedPlus = true; + } + + if (IndexReg.getReg()) { + if (NeedPlus) O << " + "; + if (ScaleVal != 1) + O << ScaleVal << '*'; + printOperand(MI, Op+2, O, Modifier, AsmVariant); + NeedPlus = true; + } + + assert (DispSpec.isImm() && "Displacement is not an immediate!"); + int64_t DispVal = DispSpec.getImm(); + if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) { + if (NeedPlus) { + if (DispVal > 0) + O << " + "; + else { + O << " - "; + DispVal = -DispVal; + } + } + O << DispVal; + } + O << ']'; +} + void X86AsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op, raw_ostream &O) { O << *MF->getPICBaseSymbol() << '\n'; @@ -481,6 +528,11 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &O) { + if (AsmVariant) { + printIntelMemReference(MI, OpNo, O); + return false; + } + if (ExtraCode && ExtraCode[0]) { if (ExtraCode[1] != 0) return true; // Unknown modifier. |