c01dd8441f5169d2eac53769fa6a659d9f27e4bb
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.h
1 //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file the shared super class printer that converts from our internal
11 // representation of machine-dependent LLVM code to Intel and AT&T format
12 // assembly language.  This printer is the output mechanism used by `llc'.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef X86ASMPRINTER_H
17 #define X86ASMPRINTER_H
18
19 #include "X86.h"
20 #include "X86TargetMachine.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include "llvm/CodeGen/DwarfWriter.h"
23 #include "llvm/CodeGen/MachineConstantPool.h"
24 #include "llvm/CodeGen/MachineDebugInfo.h"
25 #include "llvm/ADT/Statistic.h"
26 #include <set>
27
28
29 namespace llvm {
30
31 extern Statistic<> EmittedInsts;
32
33 /// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
34 ///
35 struct X86DwarfWriter : public DwarfWriter {
36  // Ctor.
37 X86DwarfWriter(std::ostream &o, AsmPrinter *ap)
38   : DwarfWriter(o, ap)
39     {
40       needsSet = true;
41       DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev";
42       DwarfInfoSection = ".section __DWARFA,__debug_info";
43       DwarfLineSection = ".section __DWARFA,__debug_line";
44       DwarfFrameSection = ".section __DWARFA,__debug_frame";
45       DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames";
46       DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes";
47       DwarfStrSection = ".section __DWARFA,__debug_str";
48       DwarfLocSection = ".section __DWARFA,__debug_loc";
49       DwarfARangesSection = ".section __DWARFA,__debug_aranges";
50       DwarfRangesSection = ".section __DWARFA,__debug_ranges";
51       DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo";
52       TextSection = ".text";
53        DataSection = ".data";
54     }
55 };
56
57 struct X86SharedAsmPrinter : public AsmPrinter {
58   X86DwarfWriter DW;
59
60   X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
61     : AsmPrinter(O, TM), DW(O, this) {
62     Subtarget = &TM.getSubtarget<X86Subtarget>();
63   }
64
65   bool doInitialization(Module &M);
66   bool doFinalization(Module &M);
67
68   void getAnalysisUsage(AnalysisUsage &AU) const {
69     AU.setPreservesAll();
70     AU.addRequired<MachineDebugInfo>();
71     MachineFunctionPass::getAnalysisUsage(AU);
72   }
73
74   const char *DefaultTextSection;   // "_text" for MASM, ".text" for others.
75   const char *DefaultDataSection;   // "_data" for MASM, ".data" for others.
76   const X86Subtarget *Subtarget;
77
78   // Necessary for Darwin to print out the apprioriate types of linker stubs
79   std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
80
81   inline static bool isScale(const MachineOperand &MO) {
82     return MO.isImmediate() &&
83           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
84           MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
85   }
86
87   inline static bool isMem(const MachineInstr *MI, unsigned Op) {
88     if (MI->getOperand(Op).isFrameIndex()) return true;
89     return Op+4 <= MI->getNumOperands() &&
90       MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
91       MI->getOperand(Op+2).isRegister() &&
92       (MI->getOperand(Op+3).isImmediate() ||
93        MI->getOperand(Op+3).isGlobalAddress() ||
94        MI->getOperand(Op+3).isConstantPoolIndex());
95   }
96
97   virtual void EmitConstantPool(MachineConstantPool *MCP);
98   void EmitConstantPool(MachineConstantPool *MCP,
99                 std::vector<std::pair<MachineConstantPoolEntry, unsigned> > &CP,
100                         const char *Section);
101 };
102
103 } // end namespace llvm
104
105 #endif