Add an out-of-line virtual method for X86DwarfWriter to give it a home.
[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/MachineDebugInfo.h"
24 #include "llvm/ADT/Statistic.h"
25 #include <set>
26
27
28 namespace llvm {
29
30 extern Statistic<> EmittedInsts;
31
32 /// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
33 ///
34 struct X86DwarfWriter : public DwarfWriter {
35   X86DwarfWriter(std::ostream &o, AsmPrinter *ap) : DwarfWriter(o, ap) {
36     needsSet = true;
37     DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev";
38     DwarfInfoSection = ".section __DWARFA,__debug_info";
39     DwarfLineSection = ".section __DWARFA,__debug_line";
40     DwarfFrameSection = ".section __DWARFA,__debug_frame";
41     DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames";
42     DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes";
43     DwarfStrSection = ".section __DWARFA,__debug_str";
44     DwarfLocSection = ".section __DWARFA,__debug_loc";
45     DwarfARangesSection = ".section __DWARFA,__debug_aranges";
46     DwarfRangesSection = ".section __DWARFA,__debug_ranges";
47     DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo";
48     TextSection = ".text";
49     DataSection = ".data";
50   }
51   virtual void virtfn();  // out of line virtual fn.
52 };
53
54 struct X86SharedAsmPrinter : public AsmPrinter {
55   X86DwarfWriter DW;
56
57   X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
58     : AsmPrinter(O, TM), DW(O, this) {
59     Subtarget = &TM.getSubtarget<X86Subtarget>();
60   }
61
62   bool doInitialization(Module &M);
63   bool doFinalization(Module &M);
64
65   void getAnalysisUsage(AnalysisUsage &AU) const {
66     AU.setPreservesAll();
67     AU.addRequired<MachineDebugInfo>();
68     MachineFunctionPass::getAnalysisUsage(AU);
69   }
70
71   const char *DefaultTextSection;   // "_text" for MASM, ".text" for others.
72   const char *DefaultDataSection;   // "_data" for MASM, ".data" for others.
73   const X86Subtarget *Subtarget;
74
75   // Necessary for Darwin to print out the apprioriate types of linker stubs
76   std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
77
78   inline static bool isScale(const MachineOperand &MO) {
79     return MO.isImmediate() &&
80           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
81           MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
82   }
83
84   inline static bool isMem(const MachineInstr *MI, unsigned Op) {
85     if (MI->getOperand(Op).isFrameIndex()) return true;
86     return Op+4 <= MI->getNumOperands() &&
87       MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
88       MI->getOperand(Op+2).isRegister() &&
89       (MI->getOperand(Op+3).isImmediate() ||
90        MI->getOperand(Op+3).isGlobalAddress() ||
91        MI->getOperand(Op+3).isConstantPoolIndex());
92   }
93 };
94
95 } // end namespace llvm
96
97 #endif