MC: Move assembler variable values from MCContext to MCSymbol.
[oota-llvm.git] / include / llvm / MC / SectionKind.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_MC_SECTIONKIND_H
16 #define LLVM_MC_SECTIONKIND_H
17
18 namespace llvm {
19
20 /// SectionKind - This is a simple POD value that classifies the properties of
21 /// a section.  A section is classified into the deepest possible
22 /// classification, and then the target maps them onto their sections based on
23 /// what capabilities they have.
24 ///
25 /// The comments below describe these as if they were an inheritance hierarchy
26 /// in order to explain the predicates below.
27 ///
28 class SectionKind {
29   enum Kind {
30     /// Metadata - Debug info sections or other metadata.
31     Metadata,
32     
33     /// Text - Text section, used for functions and other executable code.
34     Text,
35     
36     /// ReadOnly - Data that is never written to at program runtime by the
37     /// program or the dynamic linker.  Things in the top-level readonly
38     /// SectionKind are not mergeable.
39     ReadOnly,
40
41         /// MergableCString - Any null-terminated string which allows merging.
42         /// These values are known to end in a nul value of the specified size,
43         /// not otherwise contain a nul value, and be mergable.  This allows the
44         /// linker to unique the strings if it so desires.
45
46            /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
47            Mergeable1ByteCString,
48     
49            /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
50            Mergeable2ByteCString,
51
52            /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
53            Mergeable4ByteCString,
54
55         /// MergeableConst - These are sections for merging fixed-length
56         /// constants together.  For example, this can be used to unique
57         /// constant pool entries etc.
58         MergeableConst,
59     
60             /// MergeableConst4 - This is a section used by 4-byte constants,
61             /// for example, floats.
62             MergeableConst4,
63     
64             /// MergeableConst8 - This is a section used by 8-byte constants,
65             /// for example, doubles.
66             MergeableConst8,
67
68             /// MergeableConst16 - This is a section used by 16-byte constants,
69             /// for example, vectors.
70             MergeableConst16,
71     
72     /// Writeable - This is the base of all segments that need to be written
73     /// to during program runtime.
74     
75        /// ThreadLocal - This is the base of all TLS segments.  All TLS
76        /// objects must be writeable, otherwise there is no reason for them to
77        /// be thread local!
78     
79            /// ThreadBSS - Zero-initialized TLS data objects.
80            ThreadBSS,
81     
82            /// ThreadData - Initialized TLS data objects.
83            ThreadData,
84     
85        /// GlobalWriteableData - Writeable data that is global (not thread
86        /// local).
87     
88            /// BSS - Zero initialized writeable data.
89            BSS,
90
91            /// DataRel - This is the most general form of data that is written
92            /// to by the program, it can have random relocations to arbitrary
93            /// globals.
94            DataRel,
95
96                /// DataRelLocal - This is writeable data that has a non-zero
97                /// initializer and has relocations in it, but all of the
98                /// relocations are known to be within the final linked image
99                /// the global is linked into.
100                DataRelLocal,
101
102                    /// DataNoRel - This is writeable data that has a non-zero
103                    /// initializer, but whose initializer is known to have no
104                    /// relocations.
105                    DataNoRel,
106
107            /// ReadOnlyWithRel - These are global variables that are never
108            /// written to by the program, but that have relocations, so they
109            /// must be stuck in a writeable section so that the dynamic linker
110            /// can write to them.  If it chooses to, the dynamic linker can
111            /// mark the pages these globals end up on as read-only after it is
112            /// done with its relocation phase.
113            ReadOnlyWithRel,
114     
115                /// ReadOnlyWithRelLocal - This is data that is readonly by the
116                /// program, but must be writeable so that the dynamic linker
117                /// can perform relocations in it.  This is used when we know
118                /// that all the relocations are to globals in this final
119                /// linked image.
120                ReadOnlyWithRelLocal
121     
122   } K : 8;
123 public:
124   
125   bool isMetadata() const { return K == Metadata; }
126   bool isText() const { return K == Text; }
127   
128   bool isReadOnly() const {
129     return K == ReadOnly || isMergeableCString() ||
130            isMergeableConst();
131   }
132
133   bool isMergeableCString() const {
134     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
135            K == Mergeable4ByteCString;
136   }
137   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
138   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
139   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
140   
141   bool isMergeableConst() const {
142     return K == MergeableConst || K == MergeableConst4 ||
143            K == MergeableConst8 || K == MergeableConst16;
144   }
145   bool isMergeableConst4() const { return K == MergeableConst4; }
146   bool isMergeableConst8() const { return K == MergeableConst8; }
147   bool isMergeableConst16() const { return K == MergeableConst16; }
148   
149   bool isWriteable() const {
150     return isThreadLocal() || isGlobalWriteableData();
151   }
152   
153   bool isThreadLocal() const {
154     return K == ThreadData || K == ThreadBSS;
155   }
156   
157   bool isThreadBSS() const { return K == ThreadBSS; } 
158   bool isThreadData() const { return K == ThreadData; } 
159
160   bool isGlobalWriteableData() const {
161     return isBSS() || isDataRel() || isReadOnlyWithRel();
162   }
163   
164   bool isBSS() const { return K == BSS; }
165   
166   bool isDataRel() const {
167     return K == DataRel || K == DataRelLocal || K == DataNoRel;
168   }
169   
170   bool isDataRelLocal() const {
171     return K == DataRelLocal || K == DataNoRel;
172   }
173
174   bool isDataNoRel() const { return K == DataNoRel; }
175   
176   bool isReadOnlyWithRel() const {
177     return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal;
178   }
179
180   bool isReadOnlyWithRelLocal() const {
181     return K == ReadOnlyWithRelLocal;
182   }
183 private: 
184   static SectionKind get(Kind K) {
185     SectionKind Res;
186     Res.K = K;
187     return Res;
188   }
189 public:
190   
191   static SectionKind getMetadata() { return get(Metadata); }
192   static SectionKind getText() { return get(Text); }
193   static SectionKind getReadOnly() { return get(ReadOnly); }
194   static SectionKind getMergeable1ByteCString() {
195     return get(Mergeable1ByteCString);
196   }
197   static SectionKind getMergeable2ByteCString() {
198     return get(Mergeable2ByteCString);
199   }
200   static SectionKind getMergeable4ByteCString() {
201     return get(Mergeable4ByteCString);
202   }
203   static SectionKind getMergeableConst() { return get(MergeableConst); }
204   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
205   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
206   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
207   static SectionKind getThreadBSS() { return get(ThreadBSS); }
208   static SectionKind getThreadData() { return get(ThreadData); }
209   static SectionKind getBSS() { return get(BSS); }
210   static SectionKind getDataRel() { return get(DataRel); }
211   static SectionKind getDataRelLocal() { return get(DataRelLocal); }
212   static SectionKind getDataNoRel() { return get(DataNoRel); }
213   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
214   static SectionKind getReadOnlyWithRelLocal(){
215     return get(ReadOnlyWithRelLocal);
216   }
217 };
218   
219 } // end namespace llvm
220
221 #endif