]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
Update LLVM to r89205.
[FreeBSD/FreeBSD.git] / lib / Target / X86 / AsmPrinter / X86ATTInstPrinter.cpp
1 //===-- X86ATTInstPrinter.cpp - AT&T assembly instruction printing --------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file includes code for rendering MCInst instances as AT&T-style
11 // assembly.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "asm-printer"
16 #include "X86ATTInstPrinter.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/FormattedStream.h"
22 #include "X86GenInstrNames.inc"
23 using namespace llvm;
24
25 // Include the auto-generated portion of the assembly writer.
26 #define MachineInstr MCInst
27 #define NO_ASM_WRITER_BOILERPLATE
28 #include "X86GenAsmWriter.inc"
29 #undef MachineInstr
30
31 void X86ATTInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
32
33 void X86ATTInstPrinter::printSSECC(const MCInst *MI, unsigned Op) {
34   switch (MI->getOperand(Op).getImm()) {
35   default: llvm_unreachable("Invalid ssecc argument!");
36   case 0: O << "eq"; break;
37   case 1: O << "lt"; break;
38   case 2: O << "le"; break;
39   case 3: O << "unord"; break;
40   case 4: O << "neq"; break;
41   case 5: O << "nlt"; break;
42   case 6: O << "nle"; break;
43   case 7: O << "ord"; break;
44   }
45 }
46
47 /// print_pcrel_imm - This is used to print an immediate value that ends up
48 /// being encoded as a pc-relative value.  These print slightly differently, for
49 /// example, a $ is not emitted.
50 void X86ATTInstPrinter::print_pcrel_imm(const MCInst *MI, unsigned OpNo) {
51   const MCOperand &Op = MI->getOperand(OpNo);
52   if (Op.isImm())
53     O << Op.getImm();
54   else {
55     assert(Op.isExpr() && "unknown pcrel immediate operand");
56     Op.getExpr()->print(O, &MAI);
57   }
58 }
59
60 void X86ATTInstPrinter::printOperand(const MCInst *MI, unsigned OpNo) {
61   
62   const MCOperand &Op = MI->getOperand(OpNo);
63   if (Op.isReg()) {
64     O << '%' << getRegisterName(Op.getReg());
65   } else if (Op.isImm()) {
66     O << '$' << Op.getImm();
67   } else {
68     assert(Op.isExpr() && "unknown operand kind in printOperand");
69     O << '$';
70     Op.getExpr()->print(O, &MAI);
71   }
72 }
73
74 void X86ATTInstPrinter::printLeaMemReference(const MCInst *MI, unsigned Op) {
75   const MCOperand &BaseReg  = MI->getOperand(Op);
76   const MCOperand &IndexReg = MI->getOperand(Op+2);
77   const MCOperand &DispSpec = MI->getOperand(Op+3);
78   
79   if (DispSpec.isImm()) {
80     int64_t DispVal = DispSpec.getImm();
81     if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
82       O << DispVal;
83   } else {
84     assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
85     DispSpec.getExpr()->print(O, &MAI);
86   }
87   
88   if (IndexReg.getReg() || BaseReg.getReg()) {
89     O << '(';
90     if (BaseReg.getReg())
91       printOperand(MI, Op);
92     
93     if (IndexReg.getReg()) {
94       O << ',';
95       printOperand(MI, Op+2);
96       unsigned ScaleVal = MI->getOperand(Op+1).getImm();
97       if (ScaleVal != 1)
98         O << ',' << ScaleVal;
99     }
100     O << ')';
101   }
102 }
103
104 void X86ATTInstPrinter::printMemReference(const MCInst *MI, unsigned Op) {
105   // If this has a segment register, print it.
106   if (MI->getOperand(Op+4).getReg()) {
107     printOperand(MI, Op+4);
108     O << ':';
109   }
110   printLeaMemReference(MI, Op);
111 }