diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 13304c0abf9..9acec26f622 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -15,6 +15,7 @@ #define DEBUG_TYPE "asm-printer" #include "X86ATTAsmPrinter.h" +#include "X86ATTInstPrinter.h" #include "X86MCInstLower.h" #include "X86.h" #include "X86COFF.h" @@ -46,6 +47,10 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed"); // Primitive Helper Functions. //===----------------------------------------------------------------------===// +void X86ATTAsmPrinter::printMCInst(const MCInst *MI) { + X86ATTInstPrinter(O, MAI, TRI).printInstruction(MI); +} + void X86ATTAsmPrinter::PrintPICBaseSymbol() const { // FIXME: Gross const cast hack. X86ATTAsmPrinter *AP = const_cast(this); diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h index 1dd19e38542..12c3d1168e9 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.h @@ -29,7 +29,6 @@ namespace llvm { class MachineJumpTableInfo; class MCContext; class MCInst; -class MCOperand; class MCStreamer; class MCSymbol; @@ -63,62 +62,11 @@ class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { void printInstructionThroughMCStreamer(const MachineInstr *MI); - - // New MCInst printing stuff. - void printInstruction(const MCInst *MI); - - virtual void printMCInst(const MCInst *MI) { printInstruction(MI); } + // FIXME: REMOVE. + virtual void printMCInst(const MCInst *MI); void printSymbolOperand(const MachineOperand &MO); - void printOperand(const MCInst *MI, unsigned OpNo, - const char *Modifier = 0); - void printMemReference(const MCInst *MI, unsigned Op); - void printLeaMemReference(const MCInst *MI, unsigned Op); - void printSSECC(const MCInst *MI, unsigned Op); - void printPICLabel(const MCInst *MI, unsigned Op); - void print_pcrel_imm(const MCInst *MI, unsigned OpNo); - - void printopaquemem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - - void printi8mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printi16mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printi32mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printi64mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printi128mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printf32mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printf64mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printf80mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printf128mem(const MCInst *MI, unsigned OpNo) { - printMemReference(MI, OpNo); - } - void printlea32mem(const MCInst *MI, unsigned OpNo) { - printLeaMemReference(MI, OpNo); - } - void printlea64mem(const MCInst *MI, unsigned OpNo) { - printLeaMemReference(MI, OpNo); - } - void printlea64_32mem(const MCInst *MI, unsigned OpNo) { - printLeaMemReference(MI, OpNo); - } diff --git a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp index 2c0b5689ae7..c37b656e47b 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp @@ -13,12 +13,13 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "asm-printer" +#include "X86ATTInstPrinter.h" #include "llvm/MC/MCInst.h" -#include "X86ATTAsmPrinter.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCExpr.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Target/TargetRegisterInfo.h" // FIXME: REMOVE. using namespace llvm; // Include the auto-generated portion of the assembly writer. @@ -27,7 +28,7 @@ using namespace llvm; #include "X86GenAsmWriter.inc" #undef MachineInstr -void X86ATTAsmPrinter::printSSECC(const MCInst *MI, unsigned Op) { +void X86ATTInstPrinter::printSSECC(const MCInst *MI, unsigned Op) { switch (MI->getOperand(Op).getImm()) { default: llvm_unreachable("Invalid ssecc argument!"); case 0: O << "eq"; break; @@ -42,16 +43,16 @@ void X86ATTAsmPrinter::printSSECC(const MCInst *MI, unsigned Op) { } -void X86ATTAsmPrinter::printPICLabel(const MCInst *MI, unsigned Op) { +void X86ATTInstPrinter::printPICLabel(const MCInst *MI, unsigned Op) { llvm_unreachable("This is only used for MOVPC32r," - "should lower before asm printing!"); + "should lower before instruction printing!"); } /// print_pcrel_imm - This is used to print an immediate value that ends up /// being encoded as a pc-relative value. These print slightly differently, for /// example, a $ is not emitted. -void X86ATTAsmPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) { +void X86ATTInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) { const MCOperand &Op = MI->getOperand(OpNo); if (Op.isImm()) @@ -63,7 +64,7 @@ void X86ATTAsmPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) { } -void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo, +void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, const char *Modifier) { assert(Modifier == 0 && "Modifiers should not be used"); @@ -85,7 +86,7 @@ void X86ATTAsmPrinter::printOperand(const MCInst *MI, unsigned OpNo, O << "<>"; } -void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) { +void X86ATTInstPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) { const MCOperand &BaseReg = MI->getOperand(Op); const MCOperand &IndexReg = MI->getOperand(Op+2); const MCOperand &DispSpec = MI->getOperand(Op+3); @@ -100,8 +101,6 @@ void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) { } if (IndexReg.getReg() || BaseReg.getReg()) { - assert(IndexReg.getReg() != X86::ESP && IndexReg.getReg() != X86::RSP); - O << '('; if (BaseReg.getReg()) printOperand(MI, Op); @@ -117,7 +116,7 @@ void X86ATTAsmPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) { } } -void X86ATTAsmPrinter::printMemReference(const MCInst *MI, unsigned Op) { +void X86ATTInstPrinter::printMemReference(const MCInst *MI, unsigned Op) { const MCOperand &Segment = MI->getOperand(Op+4); if (Segment.getReg()) { printOperand(MI, Op+4); diff --git a/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h new file mode 100644 index 00000000000..76f151d8897 --- /dev/null +++ b/lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h @@ -0,0 +1,86 @@ +//===-- X86ATTInstPrinter.h - Convert X86 MCInst to assembly syntax -------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This class prints an X86 MCInst to AT&T style .s file syntax. +// +//===----------------------------------------------------------------------===// + +#ifndef X86_ATT_INST_PRINTER_H +#define X86_ATT_INST_PRINTER_H + +namespace llvm { + class MCAsmInfo; + class MCInst; + class MCOperand; + class raw_ostream; + class TargetRegisterInfo; // FIXME: ELIM + +class X86ATTInstPrinter { + raw_ostream &O; + const MCAsmInfo *MAI; + const TargetRegisterInfo *TRI; // FIXME: Elim. +public: + X86ATTInstPrinter(raw_ostream &o, const MCAsmInfo *mai, + const TargetRegisterInfo *tri) : O(o), MAI(mai), TRI(tri) {} + + void printInstruction(const MCInst *MI); + + void printOperand(const MCInst *MI, unsigned OpNo, + const char *Modifier = 0); + void printMemReference(const MCInst *MI, unsigned Op); + void printLeaMemReference(const MCInst *MI, unsigned Op); + void printSSECC(const MCInst *MI, unsigned Op); + void printPICLabel(const MCInst *MI, unsigned Op); + void print_pcrel_imm(const MCInst *MI, unsigned OpNo); + + void printopaquemem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + + void printi8mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printi16mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printi32mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printi64mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printi128mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printf32mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printf64mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printf80mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printf128mem(const MCInst *MI, unsigned OpNo) { + printMemReference(MI, OpNo); + } + void printlea32mem(const MCInst *MI, unsigned OpNo) { + printLeaMemReference(MI, OpNo); + } + void printlea64mem(const MCInst *MI, unsigned OpNo) { + printLeaMemReference(MI, OpNo); + } + void printlea64_32mem(const MCInst *MI, unsigned OpNo) { + printLeaMemReference(MI, OpNo); + } +}; + +} + +#endif diff --git a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp index e7e3dfe6e0c..fcdfdc7e6a9 100644 --- a/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp +++ b/lib/Target/X86/AsmPrinter/X86MCInstLower.cpp @@ -411,7 +411,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) { // lot of extra uniquing. TmpInst.addOperand(MCOperand::CreateExpr(MCSymbolRefExpr::Create(PICBase, OutContext))); - printInstruction(&TmpInst); + printMCInst(&TmpInst); O << '\n'; // Emit the label. @@ -420,7 +420,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) { // popl $reg TmpInst.setOpcode(X86::POP32r); TmpInst.getOperand(0) = MCOperand::CreateReg(MI->getOperand(0).getReg()); - printInstruction(&TmpInst); + printMCInst(&TmpInst); return; } @@ -458,7 +458,7 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) { TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg())); TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg())); TmpInst.addOperand(MCOperand::CreateExpr(DotExpr)); - printInstruction(&TmpInst); + printMCInst(&TmpInst); return; } } @@ -467,5 +467,6 @@ printInstructionThroughMCStreamer(const MachineInstr *MI) { MCInstLowering.Lower(MI, TmpInst); - printInstruction(&TmpInst); + printMCInst(&TmpInst); } + diff --git a/lib/Target/X86/X86.td b/lib/Target/X86/X86.td index 203dd378a99..aca8bf5ee6e 100644 --- a/lib/Target/X86/X86.td +++ b/lib/Target/X86/X86.td @@ -198,7 +198,7 @@ def ATTAsmParser : AsmParser { // The X86 target supports two different syntaxes for emitting machine code. // This is controlled by the -x86-asm-syntax={att|intel} def ATTAsmWriter : AsmWriter { - string AsmWriterClassName = "ATTAsmPrinter"; + string AsmWriterClassName = "ATTInstPrinter"; int Variant = 0; } def IntelAsmWriter : AsmWriter {