delete the fixme too! :)
[oota-llvm.git] / lib / Target / X86 / AsmPrinter / X86ATTAsmPrinter.h
1 //===-- X86ATTAsmPrinter.h - Convert X86 LLVM code to AT&T assembly -------===//
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 // AT&T assembly code printer class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86ATTASMPRINTER_H
15 #define X86ATTASMPRINTER_H
16
17 #include "../X86.h"
18 #include "../X86MachineFunctionInfo.h"
19 #include "../X86TargetMachine.h"
20 #include "llvm/ADT/StringSet.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include "llvm/CodeGen/DwarfWriter.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/CodeGen/ValueTypes.h"
25 #include "llvm/Support/Compiler.h"
26
27 namespace llvm {
28
29 class MachineJumpTableInfo;
30 class MCContext;
31 class MCInst;
32 class MCOperand;
33 class MCStreamer;
34 class MCSymbol;
35
36 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
37   const X86Subtarget *Subtarget;
38  public:
39   explicit X86ATTAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
40                             const MCAsmInfo *T, bool V)
41     : AsmPrinter(O, TM, T, V) {
42     Subtarget = &TM.getSubtarget<X86Subtarget>();
43   }
44
45   virtual const char *getPassName() const {
46     return "X86 AT&T-Style Assembly Printer";
47   }
48   
49   const X86Subtarget &getSubtarget() const { return *Subtarget; }
50
51   void getAnalysisUsage(AnalysisUsage &AU) const {
52     AU.setPreservesAll();
53     if (Subtarget->isTargetDarwin() ||
54         Subtarget->isTargetELF() ||
55         Subtarget->isTargetCygMing()) {
56       AU.addRequired<MachineModuleInfo>();
57     }
58     AU.addRequired<DwarfWriter>();
59     AsmPrinter::getAnalysisUsage(AU);
60   }
61
62   bool doFinalization(Module &M);
63
64   void printInstructionThroughMCStreamer(const MachineInstr *MI);
65
66   
67   // New MCInst printing stuff.
68   void printInstruction(const MCInst *MI);
69
70
71   virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }
72
73   void printSymbolOperand(const MachineOperand &MO);
74   void printOperand(const MCInst *MI, unsigned OpNo,
75                     const char *Modifier = 0);
76   void printMemReference(const MCInst *MI, unsigned Op);
77   void printLeaMemReference(const MCInst *MI, unsigned Op);
78   void printSSECC(const MCInst *MI, unsigned Op);
79   void printPICLabel(const MCInst *MI, unsigned Op);
80   void print_pcrel_imm(const MCInst *MI, unsigned OpNo);
81   
82   void printopaquemem(const MCInst *MI, unsigned OpNo) {
83     printMemReference(MI, OpNo);
84   }
85   
86   void printi8mem(const MCInst *MI, unsigned OpNo) {
87     printMemReference(MI, OpNo);
88   }
89   void printi16mem(const MCInst *MI, unsigned OpNo) {
90     printMemReference(MI, OpNo);
91   }
92   void printi32mem(const MCInst *MI, unsigned OpNo) {
93     printMemReference(MI, OpNo);
94   }
95   void printi64mem(const MCInst *MI, unsigned OpNo) {
96     printMemReference(MI, OpNo);
97   }
98   void printi128mem(const MCInst *MI, unsigned OpNo) {
99     printMemReference(MI, OpNo);
100   }
101   void printf32mem(const MCInst *MI, unsigned OpNo) {
102     printMemReference(MI, OpNo);
103   }
104   void printf64mem(const MCInst *MI, unsigned OpNo) {
105     printMemReference(MI, OpNo);
106   }
107   void printf80mem(const MCInst *MI, unsigned OpNo) {
108     printMemReference(MI, OpNo);
109   }
110   void printf128mem(const MCInst *MI, unsigned OpNo) {
111     printMemReference(MI, OpNo);
112   }
113   void printlea32mem(const MCInst *MI, unsigned OpNo) {
114     printLeaMemReference(MI, OpNo);
115   }
116   void printlea64mem(const MCInst *MI, unsigned OpNo) {
117     printLeaMemReference(MI, OpNo);
118   }
119   void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
120     printLeaMemReference(MI, OpNo);
121   }
122   
123   
124
125   // These methods are used by the tablegen'erated instruction printer.
126   void printOperand(const MachineInstr *MI, unsigned OpNo,
127                     const char *Modifier = 0);
128   void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
129
130   void printopaquemem(const MachineInstr *MI, unsigned OpNo) {
131     printMemReference(MI, OpNo);
132   }
133
134   void printi8mem(const MachineInstr *MI, unsigned OpNo) {
135     printMemReference(MI, OpNo);
136   }
137   void printi16mem(const MachineInstr *MI, unsigned OpNo) {
138     printMemReference(MI, OpNo);
139   }
140   void printi32mem(const MachineInstr *MI, unsigned OpNo) {
141     printMemReference(MI, OpNo);
142   }
143   void printi64mem(const MachineInstr *MI, unsigned OpNo) {
144     printMemReference(MI, OpNo);
145   }
146   void printi128mem(const MachineInstr *MI, unsigned OpNo) {
147     printMemReference(MI, OpNo);
148   }
149   void printi256mem(const MachineInstr *MI, unsigned OpNo) {
150     printMemReference(MI, OpNo);
151   }
152   void printf32mem(const MachineInstr *MI, unsigned OpNo) {
153     printMemReference(MI, OpNo);
154   }
155   void printf64mem(const MachineInstr *MI, unsigned OpNo) {
156     printMemReference(MI, OpNo);
157   }
158   void printf80mem(const MachineInstr *MI, unsigned OpNo) {
159     printMemReference(MI, OpNo);
160   }
161   void printf128mem(const MachineInstr *MI, unsigned OpNo) {
162     printMemReference(MI, OpNo);
163   }
164   void printf256mem(const MachineInstr *MI, unsigned OpNo) {
165     printMemReference(MI, OpNo);
166   }
167   void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
168     printLeaMemReference(MI, OpNo);
169   }
170   void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
171     printLeaMemReference(MI, OpNo);
172   }
173   void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
174     printLeaMemReference(MI, OpNo, "subreg64");
175   }
176
177   bool printAsmMRegister(const MachineOperand &MO, char Mode);
178   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
179                        unsigned AsmVariant, const char *ExtraCode);
180   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
181                              unsigned AsmVariant, const char *ExtraCode);
182
183   void printMachineInstruction(const MachineInstr *MI);
184   void printSSECC(const MachineInstr *MI, unsigned Op);
185   void printMemReference(const MachineInstr *MI, unsigned Op,
186                          const char *Modifier=NULL);
187   void printLeaMemReference(const MachineInstr *MI, unsigned Op,
188                             const char *Modifier=NULL);
189   void printPICJumpTableSetLabel(unsigned uid,
190                                  const MachineBasicBlock *MBB) const;
191   void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
192                                  const MachineBasicBlock *MBB) const {
193     AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
194   }
195   void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
196                               const MachineBasicBlock *MBB,
197                               unsigned uid) const;
198
199   void printPICLabel(const MachineInstr *MI, unsigned Op);
200   void PrintGlobalVariable(const GlobalVariable* GVar);
201
202   void PrintPICBaseSymbol() const;
203   
204   bool runOnMachineFunction(MachineFunction &F);
205
206   void emitFunctionHeader(const MachineFunction &MF);
207
208   // Necessary for Darwin to print out the appropriate types of linker stubs.
209   DenseMap<MCSymbol*, MCSymbol*> FnStubs;  // Darwin $stub stubs.
210   DenseMap<MCSymbol*, MCSymbol*> GVStubs;  // Darwin $non_lazy_ptr stub.
211   DenseMap<MCSymbol*, MCSymbol*> HiddenGVStubs;  // Darwin $non_lazy_ptr stub.
212
213   // Necessary for dllexport support
214   StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;
215
216   // We have to propagate some information about MachineFunction to
217   // AsmPrinter. It's ok, when we're printing the function, since we have
218   // access to MachineFunction and can get the appropriate MachineFunctionInfo.
219   // Unfortunately, this is not possible when we're printing reference to
220   // Function (e.g. calling it and so on). Even more, there is no way to get the
221   // corresponding MachineFunctions: it can even be not created at all. That's
222   // why we should use additional structure, when we're collecting all necessary
223   // information.
224   //
225   // This structure is using e.g. for name decoration for stdcall & fastcall'ed
226   // function, since we have to use arguments' size for decoration.
227   typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
228   FMFInfoMap FunctionInfoMap;
229
230   void DecorateCygMingName(std::string &Name, const GlobalValue *GV);
231   void DecorateCygMingName(SmallVectorImpl<char> &Name, const GlobalValue *GV);
232 };
233
234 } // end namespace llvm
235
236 #endif