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 "X86Subtarget.h"
19 #include "MCTargetDesc/X86TargetDesc.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/FormattedStream.h"
28 // Include the auto-generated portion of the assembly writer.
29 #define GET_INSTRUCTION_NAME
30 #include "X86GenAsmWriter1.inc"
32 void X86IntelInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
33 OS << getRegisterName(RegNo);
36 void X86IntelInstPrinter::printInst(const MCInst *MI, raw_ostream &OS) {
37 printInstruction(MI, OS);
39 // If verbose assembly is enabled, we can print some informative comments.
41 EmitAnyX86InstComments(MI, *CommentStream, getRegisterName);
43 StringRef X86IntelInstPrinter::getOpcodeName(unsigned Opcode) const {
44 return getInstructionName(Opcode);
47 void X86IntelInstPrinter::printSSECC(const MCInst *MI, unsigned Op,
49 switch (MI->getOperand(Op).getImm()) {
50 default: assert(0 && "Invalid ssecc argument!");
51 case 0: O << "eq"; break;
52 case 1: O << "lt"; break;
53 case 2: O << "le"; break;
54 case 3: O << "unord"; break;
55 case 4: O << "neq"; break;
56 case 5: O << "nlt"; break;
57 case 6: O << "nle"; break;
58 case 7: O << "ord"; break;
62 /// print_pcrel_imm - This is used to print an immediate value that ends up
63 /// being encoded as a pc-relative value.
64 void X86IntelInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo,
66 const MCOperand &Op = MI->getOperand(OpNo);
70 assert(Op.isExpr() && "unknown pcrel immediate operand");
75 static void PrintRegName(raw_ostream &O, StringRef RegName) {
76 for (unsigned i = 0, e = RegName.size(); i != e; ++i)
77 O << (char)toupper(RegName[i]);
80 void X86IntelInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
82 const MCOperand &Op = MI->getOperand(OpNo);
84 PrintRegName(O, getRegisterName(Op.getReg()));
85 } else if (Op.isImm()) {
88 assert(Op.isExpr() && "unknown operand kind in printOperand");
93 void X86IntelInstPrinter::printMemReference(const MCInst *MI, unsigned Op,
95 const MCOperand &BaseReg = MI->getOperand(Op);
96 unsigned ScaleVal = MI->getOperand(Op+1).getImm();
97 const MCOperand &IndexReg = MI->getOperand(Op+2);
98 const MCOperand &DispSpec = MI->getOperand(Op+3);
99 const MCOperand &SegReg = MI->getOperand(Op+4);
101 // If this has a segment register, print it.
102 if (SegReg.getReg()) {
103 printOperand(MI, Op+4, O);
109 bool NeedPlus = false;
110 if (BaseReg.getReg()) {
111 printOperand(MI, Op, O);
115 if (IndexReg.getReg()) {
116 if (NeedPlus) O << " + ";
118 O << ScaleVal << '*';
119 printOperand(MI, Op+2, O);
124 if (!DispSpec.isImm()) {
125 if (NeedPlus) O << " + ";
126 assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
127 O << *DispSpec.getExpr();
129 int64_t DispVal = DispSpec.getImm();
130 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {