Get darwin intel debugging up and running.
[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 __DWARF,__debug_abbrev,regular,debug";
38       DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
39       DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
40       DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
41       DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
42       DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
43       DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
44       DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
45       DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
46       DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
47       DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
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     if (Subtarget->isTargetDarwin()) {
68       AU.addRequired<MachineDebugInfo>();
69     }
70     MachineFunctionPass::getAnalysisUsage(AU);
71   }
72
73   const char *DefaultTextSection;   // "_text" for MASM, ".text" for others.
74   const char *DefaultDataSection;   // "_data" for MASM, ".data" for others.
75   const X86Subtarget *Subtarget;
76
77   // Necessary for Darwin to print out the apprioriate types of linker stubs
78   std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
79
80   inline static bool isScale(const MachineOperand &MO) {
81     return MO.isImmediate() &&
82           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
83           MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
84   }
85
86   inline static bool isMem(const MachineInstr *MI, unsigned Op) {
87     if (MI->getOperand(Op).isFrameIndex()) return true;
88     return Op+4 <= MI->getNumOperands() &&
89       MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
90       MI->getOperand(Op+2).isRegister() &&
91       (MI->getOperand(Op+3).isImmediate() ||
92        MI->getOperand(Op+3).isGlobalAddress() ||
93        MI->getOperand(Op+3).isConstantPoolIndex());
94   }
95 };
96
97 } // end namespace llvm
98
99 #endif