1 //===-- X86IntelAsmPrinter.h - Convert X86 LLVM code to Intel assembly ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Intel assembly code printer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef X86INTELASMPRINTER_H
15 #define X86INTELASMPRINTER_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/FormattedStream.h"
27 struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
28 explicit X86IntelAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
29 const MCAsmInfo *T, bool V)
30 : AsmPrinter(O, TM, T, V) {}
32 virtual const char *getPassName() const {
33 return "X86 Intel-Style Assembly Printer";
36 /// printInstruction - This method is automatically generated by tablegen
37 /// from the instruction set description. This method returns true if the
38 /// machine instruction was sufficiently described to print it, otherwise it
40 void printInstruction(const MachineInstr *MI);
41 static const char *getRegisterName(unsigned RegNo);
44 // This method is used by the tablegen'erated instruction printer.
45 void printOperand(const MachineInstr *MI, unsigned OpNo,
46 const char *Modifier = 0);
48 void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
50 void printopaquemem(const MachineInstr *MI, unsigned OpNo) {
52 printMemReference(MI, OpNo);
55 void printi8mem(const MachineInstr *MI, unsigned OpNo) {
57 printMemReference(MI, OpNo);
59 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
61 printMemReference(MI, OpNo);
63 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
65 printMemReference(MI, OpNo);
67 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
69 printMemReference(MI, OpNo);
71 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
73 printMemReference(MI, OpNo);
75 void printi256mem(const MachineInstr *MI, unsigned OpNo) {
77 printMemReference(MI, OpNo);
79 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
81 printMemReference(MI, OpNo);
83 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
85 printMemReference(MI, OpNo);
87 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
89 printMemReference(MI, OpNo);
91 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
93 printMemReference(MI, OpNo);
95 void printf256mem(const MachineInstr *MI, unsigned OpNo) {
97 printMemReference(MI, OpNo);
99 void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
101 printLeaMemReference(MI, OpNo);
103 void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
105 printLeaMemReference(MI, OpNo);
107 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
109 printLeaMemReference(MI, OpNo, "subreg64");
112 bool printAsmMRegister(const MachineOperand &MO, const char Mode);
113 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
114 unsigned AsmVariant, const char *ExtraCode);
115 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
116 unsigned AsmVariant, const char *ExtraCode);
117 void printMachineInstruction(const MachineInstr *MI);
118 void printOp(const MachineOperand &MO, const char *Modifier = 0);
119 void printSSECC(const MachineInstr *MI, unsigned Op);
120 void printMemReference(const MachineInstr *MI, unsigned Op,
121 const char *Modifier=NULL);
122 void printLeaMemReference(const MachineInstr *MI, unsigned Op,
123 const char *Modifier=NULL);
124 void printPICJumpTableSetLabel(unsigned uid,
125 const MachineBasicBlock *MBB) const;
126 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
127 const MachineBasicBlock *MBB) const {
128 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
130 void printPICLabel(const MachineInstr *MI, unsigned Op);
131 bool runOnMachineFunction(MachineFunction &F);
132 bool doInitialization(Module &M);
133 bool doFinalization(Module &M);
135 void PrintGlobalVariable(const GlobalVariable *GV);
137 // We have to propagate some information about MachineFunction to
138 // AsmPrinter. It's ok, when we're printing the function, since we have
139 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
140 // Unfortunately, this is not possible when we're printing reference to
141 // Function (e.g. calling it and so on). Even more, there is no way to get the
142 // corresponding MachineFunctions: it can even be not created at all. That's
143 // why we should use additional structure, when we're collecting all necessary
146 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
147 // function, since we have to use arguments' size for decoration.
148 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
149 FMFInfoMap FunctionInfoMap;
151 void decorateName(std::string& Name, const GlobalValue* GV);
153 virtual void EmitString(const ConstantArray *CVA) const;
155 // Necessary for dllexport support
156 StringSet<> DLLExportedFns, DLLExportedGVs;
159 } // end namespace llvm