Merge branch 'master' into systemz
[llvm/systemz.git] / lib / Target / X86 / AsmPrinter / X86ATTAsmPrinter.h
blobb8a25a6bedf02b06524e63b3ae1fc858ee45b191
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef X86ATTASMPRINTER_H
15 #define X86ATTASMPRINTER_H
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"
27 namespace llvm {
29 class MachineJumpTableInfo;
30 class MCContext;
31 class MCInst;
32 class MCStreamer;
34 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
35 const X86Subtarget *Subtarget;
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;
48 virtual const char *getPassName() const {
49 return "X86 AT&T-Style Assembly Printer";
52 void getAnalysisUsage(AnalysisUsage &AU) const {
53 AU.setPreservesAll();
54 if (Subtarget->isTargetDarwin() ||
55 Subtarget->isTargetELF() ||
56 Subtarget->isTargetCygMing()) {
57 AU.addRequired<MachineModuleInfo>();
59 AU.addRequired<DwarfWriter>();
60 AsmPrinter::getAnalysisUsage(AU);
63 bool doInitialization(Module &M);
64 bool doFinalization(Module &M);
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);
73 // New MCInst printing stuff.
74 bool printInstruction(const MCInst *MI);
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);
85 void printi8mem(const MCInst *MI, unsigned OpNo) {
86 printMemReference(MI, OpNo);
88 void printi16mem(const MCInst *MI, unsigned OpNo) {
89 printMemReference(MI, OpNo);
91 void printi32mem(const MCInst *MI, unsigned OpNo) {
92 printMemReference(MI, OpNo);
94 void printi64mem(const MCInst *MI, unsigned OpNo) {
95 printMemReference(MI, OpNo);
97 void printi128mem(const MCInst *MI, unsigned OpNo) {
98 printMemReference(MI, OpNo);
100 void printf32mem(const MCInst *MI, unsigned OpNo) {
101 printMemReference(MI, OpNo);
103 void printf64mem(const MCInst *MI, unsigned OpNo) {
104 printMemReference(MI, OpNo);
106 void printf80mem(const MCInst *MI, unsigned OpNo) {
107 printMemReference(MI, OpNo);
109 void printf128mem(const MCInst *MI, unsigned OpNo) {
110 printMemReference(MI, OpNo);
112 void printlea32mem(const MCInst *MI, unsigned OpNo) {
113 printLeaMemReference(MI, OpNo);
115 void printlea64mem(const MCInst *MI, unsigned OpNo) {
116 printLeaMemReference(MI, OpNo);
118 void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
119 printLeaMemReference(MI, OpNo);
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);
131 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
132 printMemReference(MI, OpNo);
134 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
135 printMemReference(MI, OpNo);
137 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
138 printMemReference(MI, OpNo);
140 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
141 printMemReference(MI, OpNo);
143 void printi256mem(const MachineInstr *MI, unsigned OpNo) {
144 printMemReference(MI, OpNo);
146 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
147 printMemReference(MI, OpNo);
149 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
150 printMemReference(MI, OpNo);
152 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
153 printMemReference(MI, OpNo);
155 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
156 printMemReference(MI, OpNo);
158 void printf256mem(const MachineInstr *MI, unsigned OpNo) {
159 printMemReference(MI, OpNo);
161 void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
162 printLeaMemReference(MI, OpNo);
164 void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
165 printLeaMemReference(MI, OpNo);
167 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
168 printLeaMemReference(MI, OpNo, "subreg64");
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);
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);
189 void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
190 const MachineBasicBlock *MBB,
191 unsigned uid) const;
193 void printPICLabel(const MachineInstr *MI, unsigned Op);
194 void printModuleLevelGV(const GlobalVariable* GVar);
196 void PrintPICBaseSymbol() const;
198 bool runOnMachineFunction(MachineFunction &F);
200 void emitFunctionHeader(const MachineFunction &MF);
202 // Necessary for Darwin to print out the apprioriate types of linker stubs
203 StringMap<std::string> FnStubs, GVStubs, HiddenGVStubs;
205 // Necessary for dllexport support
206 StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;
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.
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;
222 void DecorateCygMingName(std::string &Name, const GlobalValue *GV);
225 } // end namespace llvm
227 #endif