the apple "ld_classic" linker doesn't support .literal16 in 32-bit
[oota-llvm.git] / include / llvm / Target / TargetLoweringObjectFile.h
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17
18 // FIXME: Switch to MC.
19 #include "llvm/Target/TargetAsmInfo.h"
20
21 namespace llvm {
22   
23 class TargetLoweringObjectFile {
24 private:
25   mutable StringMap<Section> Sections;
26 protected:
27   
28   TargetLoweringObjectFile();
29   
30   /// TextSection - Section directive for standard text.
31   ///
32   const Section *TextSection;           // Defaults to ".text".
33   
34   /// DataSection - Section directive for standard data.
35   ///
36   const Section *DataSection;           // Defaults to ".data".
37   
38   
39   
40   // FIXME: SINK THESE.
41   const Section *BSSSection_;
42
43   /// ReadOnlySection - This is the directive that is emitted to switch to a
44   /// read-only section for constant data (e.g. data declared const,
45   /// jump tables).
46   const Section *ReadOnlySection;       // Defaults to NULL
47   
48   /// TLSDataSection - Section directive for Thread Local data.
49   ///
50   const Section *TLSDataSection;        // Defaults to ".tdata".
51   
52   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
53   /// Null if this target doesn't support a BSS section.
54   ///
55   const Section *TLSBSSSection;         // Defaults to ".tbss".
56   
57   const Section *CStringSection_;
58   
59 public:
60   // FIXME: NONPUB.
61   const Section *getOrCreateSection(const char *Name,
62                                     bool isDirective,
63                                     SectionKind::Kind K) const;
64 public:
65   
66   virtual ~TargetLoweringObjectFile();
67   
68   const Section *getTextSection() const { return TextSection; }
69   const Section *getDataSection() const { return DataSection; }
70   
71   
72   /// getSectionForMergeableConstant - Given a mergeable constant with the
73   /// specified size and relocation information, return a section that it
74   /// should be placed in.
75   virtual const Section *
76   getSectionForMergeableConstant(SectionKind Kind) const;
77   
78   /// getKindForNamedSection - If this target wants to be able to override
79   /// section flags based on the name of the section specified for a global
80   /// variable, it can implement this.  This is used on ELF systems so that
81   /// ".tbss" gets the TLS bit set etc.
82   virtual SectionKind::Kind getKindForNamedSection(const char *Section,
83                                                    SectionKind::Kind K) const{
84     return K;
85   }
86   
87   /// SectionForGlobal - This method computes the appropriate section to emit
88   /// the specified global variable or function definition.  This should not
89   /// be passed external (or available externally) globals.
90   const Section *SectionForGlobal(const GlobalValue *GV,
91                                   const TargetMachine &TM) const;
92   
93   /// getSpecialCasedSectionGlobals - Allow the target to completely override
94   /// section assignment of a global.
95   /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
96   /// getFlagsForNamedSection.
97   virtual const Section *
98   getSpecialCasedSectionGlobals(const GlobalValue *GV,
99                                 SectionKind Kind) const {
100     return 0;
101   }
102   
103   /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
104   /// into a string that can be printed to the assembly file after the
105   /// ".section foo" part of a section directive.
106   virtual void getSectionFlagsAsString(SectionKind Kind,
107                                        SmallVectorImpl<char> &Str) const {
108   }
109   
110 protected:
111   virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
112                                                 SectionKind Kind,
113                                                 const TargetMachine &TM) const;
114 };
115   
116   
117   
118
119 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
120   bool AtIsCommentChar;  // True if @ is the comment character on this target.
121 public:
122   /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
123   /// is "@".
124   TargetLoweringObjectFileELF(bool AtIsCommentChar = false,
125                               // FIXME: REMOVE AFTER UNIQUING IS FIXED.
126                               bool HasCrazyBSS = false);
127   
128   /// getSectionForMergeableConstant - Given a mergeable constant with the
129   /// specified size and relocation information, return a section that it
130   /// should be placed in.
131   virtual const Section *
132   getSectionForMergeableConstant(SectionKind Kind) const;
133   
134   virtual SectionKind::Kind getKindForNamedSection(const char *Section,
135                                                    SectionKind::Kind K) const;
136   void getSectionFlagsAsString(SectionKind Kind,
137                                SmallVectorImpl<char> &Str) const;
138   
139   virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
140                                                 SectionKind Kind,
141                                                 const TargetMachine &TM) const;
142 protected:
143   const Section *DataRelSection;
144   const Section *DataRelLocalSection;
145   const Section *DataRelROSection;
146   const Section *DataRelROLocalSection;
147   
148   const Section *MergeableConst4Section;
149   const Section *MergeableConst8Section;
150   const Section *MergeableConst16Section;
151 };
152
153 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
154   const Section *TextCoalSection;
155   const Section *ConstTextCoalSection;
156   const Section *ConstDataCoalSection;
157   const Section *ConstDataSection;
158   const Section *DataCoalSection;
159   const Section *FourByteConstantSection;
160   const Section *EightByteConstantSection;
161   const Section *SixteenByteConstantSection;
162 public:
163   TargetLoweringObjectFileMachO(const TargetMachine &TM);
164   virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
165                                                 SectionKind Kind,
166                                                 const TargetMachine &TM) const;
167   
168   virtual const Section *
169   getSectionForMergeableConstant(SectionKind Kind) const;
170 };
171
172
173
174 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
175 public:
176   TargetLoweringObjectFileCOFF();
177   virtual void getSectionFlagsAsString(SectionKind Kind,
178                                        SmallVectorImpl<char> &Str) const;
179   
180   virtual const Section *
181   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
182                          const TargetMachine &TM) const;
183 };
184
185 } // end namespace llvm
186
187 #endif