eliminate the "call" operand modifier from the asm descriptions, modeling
[oota-llvm.git] / lib / Target / X86 / AsmPrinter / X86IntelAsmPrinter.h
1 //===-- X86IntelAsmPrinter.h - Convert X86 LLVM code to Intel 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 // Intel assembly code printer class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86INTELASMPRINTER_H
15 #define X86INTELASMPRINTER_H
16
17 #include "../X86.h"
18 #include "../X86MachineFunctionInfo.h"
19 #include "../X86TargetMachine.h"
20 #include "llvm/CodeGen/AsmPrinter.h"
21 #include "llvm/ADT/StringSet.h"
22 #include "llvm/Support/Compiler.h"
23 #include "llvm/Support/raw_ostream.h"
24
25 namespace llvm {
26
27 struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
28   explicit X86IntelAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
29                               const TargetAsmInfo *T, CodeGenOpt::Level OL,
30                               bool V)
31     : AsmPrinter(O, TM, T, OL, V) {}
32
33   virtual const char *getPassName() const {
34     return "X86 Intel-Style Assembly Printer";
35   }
36
37   /// printInstruction - This method is automatically generated by tablegen
38   /// from the instruction set description.  This method returns true if the
39   /// machine instruction was sufficiently described to print it, otherwise it
40   /// returns false.
41   bool printInstruction(const MachineInstr *MI);
42
43   // This method is used by the tablegen'erated instruction printer.
44   void printOperand(const MachineInstr *MI, unsigned OpNo,
45                     const char *Modifier = 0) {
46     const MachineOperand &MO = MI->getOperand(OpNo);
47     if (MO.isReg()) {
48       assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
49              "Not physreg??");
50       O << TM.getRegisterInfo()->get(MO.getReg()).Name;  // Capitalized names
51     } else {
52       printOp(MO, Modifier);
53     }
54   }
55   
56   void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
57
58
59   void printi8mem(const MachineInstr *MI, unsigned OpNo) {
60     O << "BYTE PTR ";
61     printMemReference(MI, OpNo);
62   }
63   void printi16mem(const MachineInstr *MI, unsigned OpNo) {
64     O << "WORD PTR ";
65     printMemReference(MI, OpNo);
66   }
67   void printi32mem(const MachineInstr *MI, unsigned OpNo) {
68     O << "DWORD PTR ";
69     printMemReference(MI, OpNo);
70   }
71   void printi64mem(const MachineInstr *MI, unsigned OpNo) {
72     O << "QWORD PTR ";
73     printMemReference(MI, OpNo);
74   }
75   void printi128mem(const MachineInstr *MI, unsigned OpNo) {
76     O << "XMMWORD PTR ";
77     printMemReference(MI, OpNo);
78   }
79   void printf32mem(const MachineInstr *MI, unsigned OpNo) {
80     O << "DWORD PTR ";
81     printMemReference(MI, OpNo);
82   }
83   void printf64mem(const MachineInstr *MI, unsigned OpNo) {
84     O << "QWORD PTR ";
85     printMemReference(MI, OpNo);
86   }
87   void printf80mem(const MachineInstr *MI, unsigned OpNo) {
88     O << "XWORD PTR ";
89     printMemReference(MI, OpNo);
90   }
91   void printf128mem(const MachineInstr *MI, unsigned OpNo) {
92     O << "XMMWORD PTR ";
93     printMemReference(MI, OpNo);
94   }
95   void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
96     O << "DWORD PTR ";
97     printLeaMemReference(MI, OpNo);
98   }
99   void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
100     O << "QWORD PTR ";
101     printLeaMemReference(MI, OpNo);
102   }
103   void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
104     O << "QWORD PTR ";
105     printLeaMemReference(MI, OpNo, "subreg64");
106   }
107
108   bool printAsmMRegister(const MachineOperand &MO, const char Mode);
109   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
110                        unsigned AsmVariant, const char *ExtraCode);
111   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
112                              unsigned AsmVariant, const char *ExtraCode);
113   void printMachineInstruction(const MachineInstr *MI);
114   void printOp(const MachineOperand &MO, const char *Modifier = 0);
115   void printSSECC(const MachineInstr *MI, unsigned Op);
116   void printMemReference(const MachineInstr *MI, unsigned Op,
117                          const char *Modifier=NULL);
118   void printLeaMemReference(const MachineInstr *MI, unsigned Op,
119                             const char *Modifier=NULL);
120   void printPICJumpTableSetLabel(unsigned uid,
121                                  const MachineBasicBlock *MBB) const;
122   void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
123                                  const MachineBasicBlock *MBB) const {
124     AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
125   }
126   void printPICLabel(const MachineInstr *MI, unsigned Op);
127   bool runOnMachineFunction(MachineFunction &F);
128   bool doInitialization(Module &M);
129   bool doFinalization(Module &M);
130
131   // We have to propagate some information about MachineFunction to
132   // AsmPrinter. It's ok, when we're printing the function, since we have
133   // access to MachineFunction and can get the appropriate MachineFunctionInfo.
134   // Unfortunately, this is not possible when we're printing reference to
135   // Function (e.g. calling it and so on). Even more, there is no way to get the
136   // corresponding MachineFunctions: it can even be not created at all. That's
137   // why we should use additional structure, when we're collecting all necessary
138   // information.
139   //
140   // This structure is using e.g. for name decoration for stdcall & fastcall'ed
141   // function, since we have to use arguments' size for decoration.
142   typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
143   FMFInfoMap FunctionInfoMap;
144
145   void decorateName(std::string& Name, const GlobalValue* GV);
146
147   virtual void EmitString(const ConstantArray *CVA) const;
148
149   // Necessary for dllexport support
150   StringSet<> DLLExportedFns, DLLExportedGVs;
151 };
152
153 } // end namespace llvm
154
155 #endif