1 //===-- X86IntelInstPrinter.cpp - AT&T assembly instruction printing ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file includes code for rendering MCInst instances as AT&T-style
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "asm-printer"
16 #include "X86IntelInstPrinter.h"
17 #include "X86InstComments.h"
18 #include "MCTargetDesc/X86MCTargetDesc.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/FormattedStream.h"
27 // Include the auto-generated portion of the assembly writer.
28 #define GET_INSTRUCTION_NAME
29 #include "X86GenAsmWriter1.inc"
31 void X86IntelInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
32 OS << getRegisterName(RegNo);
35 void X86IntelInstPrinter::printInst(const MCInst *MI, raw_ostream &OS) {
36 printInstruction(MI, OS);
38 // If verbose assembly is enabled, we can print some informative comments.
40 printAnnotations(MI, *CommentStream);
41 EmitAnyX86InstComments(MI, *CommentStream, getRegisterName);
44 StringRef X86IntelInstPrinter::getOpcodeName(unsigned Opcode) const {
45 return getInstructionName(Opcode);
48 void X86IntelInstPrinter::printSSECC(const MCInst *MI, unsigned Op,
50 switch (MI->getOperand(Op).getImm()) {
51 default: assert(0 && "Invalid ssecc argument!");
52 case 0: O << "eq"; break;
53 case 1: O << "lt"; break;
54 case 2: O << "le"; break;
55 case 3: O << "unord"; break;
56 case 4: O << "neq"; break;
57 case 5: O << "nlt"; break;
58 case 6: O << "nle"; break;
59 case 7: O << "ord"; break;
63 /// print_pcrel_imm - This is used to print an immediate value that ends up
64 /// being encoded as a pc-relative value.
65 void X86IntelInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo,
67 const MCOperand &Op = MI->getOperand(OpNo);
71 assert(Op.isExpr() && "unknown pcrel immediate operand");
76 static void PrintRegName(raw_ostream &O, StringRef RegName) {
77 for (unsigned i = 0, e = RegName.size(); i != e; ++i)
78 O << (char)toupper(RegName[i]);
81 void X86IntelInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
83 const MCOperand &Op = MI->getOperand(OpNo);
85 PrintRegName(O, getRegisterName(Op.getReg()));
86 } else if (Op.isImm()) {
89 assert(Op.isExpr() && "unknown operand kind in printOperand");
94 void X86IntelInstPrinter::printMemReference(const MCInst *MI, unsigned Op,
96 const MCOperand &BaseReg = MI->getOperand(Op);
97 unsigned ScaleVal = MI->getOperand(Op+1).getImm();
98 const MCOperand &IndexReg = MI->getOperand(Op+2);
99 const MCOperand &DispSpec = MI->getOperand(Op+3);
100 const MCOperand &SegReg = MI->getOperand(Op+4);
102 // If this has a segment register, print it.
103 if (SegReg.getReg()) {
104 printOperand(MI, Op+4, O);
110 bool NeedPlus = false;
111 if (BaseReg.getReg()) {
112 printOperand(MI, Op, O);
116 if (IndexReg.getReg()) {
117 if (NeedPlus) O << " + ";
119 O << ScaleVal << '*';
120 printOperand(MI, Op+2, O);
125 if (!DispSpec.isImm()) {
126 if (NeedPlus) O << " + ";
127 assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
128 O << *DispSpec.getExpr();
130 int64_t DispVal = DispSpec.getImm();
131 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {