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/raw_ostream.h"
27 struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
28 explicit X86IntelAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
29 const TargetAsmInfo *T, CodeGenOpt::Level OL,
31 : AsmPrinter(O, TM, T, OL, V) {}
33 virtual const char *getPassName() const {
34 return "X86 Intel-Style Assembly Printer";
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
41 bool printInstruction(const MachineInstr *MI);
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);
48 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
50 O << TM.getRegisterInfo()->get(MO.getReg()).Name; // Capitalized names
52 printOp(MO, Modifier);
56 void printi8mem(const MachineInstr *MI, unsigned OpNo) {
58 printMemReference(MI, OpNo);
60 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
62 printMemReference(MI, OpNo);
64 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
66 printMemReference(MI, OpNo);
68 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
70 printMemReference(MI, OpNo);
72 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
74 printMemReference(MI, OpNo);
76 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
78 printMemReference(MI, OpNo);
80 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
82 printMemReference(MI, OpNo);
84 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
86 printMemReference(MI, OpNo);
88 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
90 printMemReference(MI, OpNo);
92 void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
94 printLeaMemReference(MI, OpNo);
96 void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
98 printLeaMemReference(MI, OpNo);
100 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
102 printLeaMemReference(MI, OpNo, "subreg64");
105 bool printAsmMRegister(const MachineOperand &MO, const char Mode);
106 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
107 unsigned AsmVariant, const char *ExtraCode);
108 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
109 unsigned AsmVariant, const char *ExtraCode);
110 void printMachineInstruction(const MachineInstr *MI);
111 void printOp(const MachineOperand &MO, const char *Modifier = 0);
112 void printSSECC(const MachineInstr *MI, unsigned Op);
113 void printMemReference(const MachineInstr *MI, unsigned Op,
114 const char *Modifier=NULL);
115 void printLeaMemReference(const MachineInstr *MI, unsigned Op,
116 const char *Modifier=NULL);
117 void printPICJumpTableSetLabel(unsigned uid,
118 const MachineBasicBlock *MBB) const;
119 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
120 const MachineBasicBlock *MBB) const {
121 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
123 void printPICLabel(const MachineInstr *MI, unsigned Op);
124 bool runOnMachineFunction(MachineFunction &F);
125 bool doInitialization(Module &M);
126 bool doFinalization(Module &M);
128 // We have to propagate some information about MachineFunction to
129 // AsmPrinter. It's ok, when we're printing the function, since we have
130 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
131 // Unfortunately, this is not possible when we're printing reference to
132 // Function (e.g. calling it and so on). Even more, there is no way to get the
133 // corresponding MachineFunctions: it can even be not created at all. That's
134 // why we should use additional structure, when we're collecting all necessary
137 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
138 // function, since we have to use arguments' size for decoration.
139 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
140 FMFInfoMap FunctionInfoMap;
142 void decorateName(std::string& Name, const GlobalValue* GV);
144 virtual void EmitString(const ConstantArray *CVA) const;
146 // Necessary for dllexport support
147 StringSet<> DLLExportedFns, DLLExportedGVs;
150 } // end namespace llvm