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