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 EmitAnyX86InstComments(MI
, *CommentStream
, getRegisterName
);
42 StringRef
X86IntelInstPrinter::getOpcodeName(unsigned Opcode
) const {
43 return getInstructionName(Opcode
);
46 void X86IntelInstPrinter::printSSECC(const MCInst
*MI
, unsigned Op
,
48 switch (MI
->getOperand(Op
).getImm()) {
49 default: assert(0 && "Invalid ssecc argument!");
50 case 0: O
<< "eq"; break;
51 case 1: O
<< "lt"; break;
52 case 2: O
<< "le"; break;
53 case 3: O
<< "unord"; break;
54 case 4: O
<< "neq"; break;
55 case 5: O
<< "nlt"; break;
56 case 6: O
<< "nle"; break;
57 case 7: O
<< "ord"; break;
61 /// print_pcrel_imm - This is used to print an immediate value that ends up
62 /// being encoded as a pc-relative value.
63 void X86IntelInstPrinter::print_pcrel_imm(const MCInst
*MI
, unsigned OpNo
,
65 const MCOperand
&Op
= MI
->getOperand(OpNo
);
69 assert(Op
.isExpr() && "unknown pcrel immediate operand");
74 static void PrintRegName(raw_ostream
&O
, StringRef RegName
) {
75 for (unsigned i
= 0, e
= RegName
.size(); i
!= e
; ++i
)
76 O
<< (char)toupper(RegName
[i
]);
79 void X86IntelInstPrinter::printOperand(const MCInst
*MI
, unsigned OpNo
,
81 const MCOperand
&Op
= MI
->getOperand(OpNo
);
83 PrintRegName(O
, getRegisterName(Op
.getReg()));
84 } else if (Op
.isImm()) {
87 assert(Op
.isExpr() && "unknown operand kind in printOperand");
92 void X86IntelInstPrinter::printMemReference(const MCInst
*MI
, unsigned Op
,
94 const MCOperand
&BaseReg
= MI
->getOperand(Op
);
95 unsigned ScaleVal
= MI
->getOperand(Op
+1).getImm();
96 const MCOperand
&IndexReg
= MI
->getOperand(Op
+2);
97 const MCOperand
&DispSpec
= MI
->getOperand(Op
+3);
98 const MCOperand
&SegReg
= MI
->getOperand(Op
+4);
100 // If this has a segment register, print it.
101 if (SegReg
.getReg()) {
102 printOperand(MI
, Op
+4, O
);
108 bool NeedPlus
= false;
109 if (BaseReg
.getReg()) {
110 printOperand(MI
, Op
, O
);
114 if (IndexReg
.getReg()) {
115 if (NeedPlus
) O
<< " + ";
117 O
<< ScaleVal
<< '*';
118 printOperand(MI
, Op
+2, O
);
123 if (!DispSpec
.isImm()) {
124 if (NeedPlus
) O
<< " + ";
125 assert(DispSpec
.isExpr() && "non-immediate displacement for LEA?");
126 O
<< *DispSpec
.getExpr();
128 int64_t DispVal
= DispSpec
.getImm();
129 if (DispVal
|| (!IndexReg
.getReg() && !BaseReg
.getReg())) {