Emit .comm alignment in bytes but .align in powers of 2 for ARM ELF.
[oota-llvm.git] / include / llvm / MC / MCAsmInfo.h
1 //===-- llvm/MC/MCAsmInfo.h - Asm 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 contains a class to be used as the basis for target specific
11 // asm writers.  This class primarily takes care of global printing constants,
12 // which are used in very similar ways across all targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
18
19 #include "llvm/MC/MCDirectives.h"
20 #include <cassert>
21
22 namespace llvm {
23   class MCSection;
24   class MCContext;
25   
26   /// MCAsmInfo - This class is intended to be used as a base class for asm
27   /// properties and features specific to the target.
28   namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
29
30   class MCAsmInfo {
31   protected:
32     //===------------------------------------------------------------------===//
33     // Properties to be set by the target writer, used to configure asm printer.
34     //
35
36     /// HasSubsectionsViaSymbols - True if this target has the MachO
37     /// .subsections_via_symbols directive.
38     bool HasSubsectionsViaSymbols;           // Default is false.
39     
40     /// HasMachoZeroFillDirective - True if this is a MachO target that supports
41     /// the macho-specific .zerofill directive for emitting BSS Symbols.
42     bool HasMachoZeroFillDirective;               // Default is false.
43     
44     /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
45     /// emit a ".reference .constructors_used" or ".reference .destructors_used"
46     /// directive after the a static ctor/dtor list.  This directive is only
47     /// emitted in Static relocation model.
48     bool HasStaticCtorDtorReferenceInStaticMode;  // Default is false.
49     
50     /// MaxInstLength - This is the maximum possible length of an instruction,
51     /// which is needed to compute the size of an inline asm.
52     unsigned MaxInstLength;                  // Defaults to 4.
53     
54     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
55     /// relative expressions.
56     const char *PCSymbol;                    // Defaults to "$".
57
58     /// SeparatorChar - This character, if specified, is used to separate
59     /// instructions from each other when on the same line.  This is used to
60     /// measure inline asm instructions.
61     char SeparatorChar;                      // Defaults to ';'
62
63     /// CommentColumn - This indicates the comment num (zero-based) at
64     /// which asm comments should be printed.
65     unsigned CommentColumn;                  // Defaults to 60
66
67     /// CommentString - This indicates the comment character used by the
68     /// assembler.
69     const char *CommentString;               // Defaults to "#"
70
71     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
72     /// onto all global symbols.  This is often used for "_" or ".".
73     const char *GlobalPrefix;                // Defaults to ""
74
75     /// PrivateGlobalPrefix - This prefix is used for globals like constant
76     /// pool entries that are completely private to the .s file and should not
77     /// have names in the .o file.  This is often "." or "L".
78     const char *PrivateGlobalPrefix;         // Defaults to "."
79     
80     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
81     /// be passed through the assembler but be removed by the linker.  This
82     /// is "l" on Darwin, currently used for some ObjC metadata.
83     const char *LinkerPrivateGlobalPrefix;   // Defaults to ""
84     
85     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
86     /// emit before and after an inline assembly statement.
87     const char *InlineAsmStart;              // Defaults to "#APP\n"
88     const char *InlineAsmEnd;                // Defaults to "#NO_APP\n"
89
90     /// AssemblerDialect - Which dialect of an assembler variant to use.
91     unsigned AssemblerDialect;               // Defaults to 0
92
93     /// AllowQuotesInName - This is true if the assembler allows for complex
94     /// symbol names to be surrounded in quotes.  This defaults to false.
95     bool AllowQuotesInName;
96
97     /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
98     /// names to start with a digit (e.g., "0x0021").  This defaults to false.
99     bool AllowNameToStartWithDigit;
100     
101     //===--- Data Emission Directives -------------------------------------===//
102
103     /// ZeroDirective - this should be set to the directive used to get some
104     /// number of zero bytes emitted to the current section.  Common cases are
105     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
106     /// Data*bitsDirective's will be used to emit zero bytes.
107     const char *ZeroDirective;               // Defaults to "\t.zero\t"
108
109     /// AsciiDirective - This directive allows emission of an ascii string with
110     /// the standard C escape characters embedded into it.
111     const char *AsciiDirective;              // Defaults to "\t.ascii\t"
112     
113     /// AscizDirective - If not null, this allows for special handling of
114     /// zero terminated strings on this target.  This is commonly supported as
115     /// ".asciz".  If a target doesn't support this, it can be set to null.
116     const char *AscizDirective;              // Defaults to "\t.asciz\t"
117
118     /// DataDirectives - These directives are used to output some unit of
119     /// integer data to the current section.  If a data directive is set to
120     /// null, smaller data directives will be used to emit the large sizes.
121     const char *Data8bitsDirective;          // Defaults to "\t.byte\t"
122     const char *Data16bitsDirective;         // Defaults to "\t.short\t"
123     const char *Data32bitsDirective;         // Defaults to "\t.long\t"
124     const char *Data64bitsDirective;         // Defaults to "\t.quad\t"
125
126     /// GPRel32Directive - if non-null, a directive that is used to emit a word
127     /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
128     /// on Mips or .gprel32 on Alpha.
129     const char *GPRel32Directive;            // Defaults to NULL.
130     
131     /// getDataASDirective - Return the directive that should be used to emit
132     /// data of the specified size to the specified numeric address space.
133     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
134       assert(AS != 0 && "Don't know the directives for default addr space");
135       return 0;
136     }
137
138     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
139     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
140     /// normal ELF syntax (,"a,w") in .section directives.
141     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
142
143     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
144     /// '.section' directive before the '.bss' one. It's used for PPC/Linux 
145     /// which doesn't support the '.bss' directive only.
146     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
147     
148     //===--- Alignment Information ----------------------------------------===//
149
150     /// AlignDirective - The directive used to emit round up to an alignment
151     /// boundary.
152     ///
153     const char *AlignDirective;              // Defaults to "\t.align\t"
154
155     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
156     /// emits ".align N" directives, where N is the number of bytes to align to.
157     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
158     /// boundary.
159     bool AlignmentIsInBytes;                 // Defaults to true
160
161     /// TextAlignFillValue - If non-zero, this is used to fill the executable
162     /// space created as the result of a alignment directive.
163     unsigned TextAlignFillValue;             // Defaults to 0
164
165     //===--- Global Variable Emission Directives --------------------------===//
166     
167     /// GlobalDirective - This is the directive used to declare a global entity.
168     ///
169     const char *GlobalDirective;             // Defaults to NULL.
170
171     /// ExternDirective - This is the directive used to declare external 
172     /// globals.
173     ///
174     const char *ExternDirective;             // Defaults to NULL.
175     
176     /// SetDirective - This is the name of a directive that can be used to tell
177     /// the assembler to set the value of a variable to some expression.
178     const char *SetDirective;                // Defaults to null.
179     
180     /// HasLCOMMDirective - This is true if the target supports the .lcomm
181     /// directive.
182     bool HasLCOMMDirective;              // Defaults to false.
183     
184     /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
185     /// alignment is to be specified in bytes instead of log2(n).
186     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
187     
188     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
189     /// directives, this is true for most ELF targets.
190     bool HasDotTypeDotSizeDirective;         // Defaults to true.
191
192     /// HasSingleParameterDotFile - True if the target has a single parameter
193     /// .file directive, this is true for ELF targets.
194     bool HasSingleParameterDotFile;          // Defaults to true.
195
196     /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
197     /// directive.
198     bool HasNoDeadStrip;                     // Defaults to false.
199
200     /// WeakRefDirective - This directive, if non-null, is used to declare a
201     /// global as being a weak undefined symbol.
202     const char *WeakRefDirective;            // Defaults to NULL.
203     
204     /// WeakDefDirective - This directive, if non-null, is used to declare a
205     /// global as being a weak defined symbol.
206     const char *WeakDefDirective;            // Defaults to NULL.
207
208     /// LinkOnceDirective - This directive, if non-null is used to declare a
209     /// global as being a weak defined symbol.  This is used on cygwin/mingw.
210     const char *LinkOnceDirective;           // Defaults to NULL.
211     
212     /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
213     /// declare a symbol as having hidden visibility.
214     MCSymbolAttr HiddenVisibilityAttr;       // Defaults to MCSA_Hidden.
215
216     /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
217     /// to declare a symbol as having protected visibility.
218     MCSymbolAttr ProtectedVisibilityAttr;    // Defaults to MCSA_Protected
219
220     //===--- Dwarf Emission Directives -----------------------------------===//
221
222     /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
223     /// offsets for debug information.
224     bool AbsoluteDebugSectionOffsets;        // Defaults to false.
225
226     /// AbsoluteEHSectionOffsets - True if we should emit abolute section
227     /// offsets for EH information. Defaults to false.
228     bool AbsoluteEHSectionOffsets;
229
230     /// HasLEB128 - True if target asm supports leb128 directives.
231     bool HasLEB128;                          // Defaults to false.
232
233     /// hasDotLocAndDotFile - True if target asm supports .loc and .file
234     /// directives for emitting debugging information.
235     bool HasDotLocAndDotFile;                // Defaults to false.
236
237     /// SupportsDebugInformation - True if target supports emission of debugging
238     /// information.
239     bool SupportsDebugInformation;           // Defaults to false.
240
241     /// SupportsExceptionHandling - True if target supports exception handling.
242     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
243
244     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
245     bool DwarfRequiresFrameSection;          // Defaults to true.
246
247     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
248     /// encode inline subroutine information.
249     bool DwarfUsesInlineInfoSection;         // Defaults to false.
250
251     /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
252     /// doesn't show up in the symbol table of the object file.
253     bool Is_EHSymbolPrivate;                 // Defaults to true.
254
255     /// GlobalEHDirective - This is the directive used to make exception frame
256     /// tables globally visible.
257     const char *GlobalEHDirective;           // Defaults to NULL.
258
259     /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
260     /// handle a weak_definition of constant 0 for an omitted EH frame.
261     bool SupportsWeakOmittedEHFrame;         // Defaults to true.
262
263     /// DwarfSectionOffsetDirective - Special section offset directive.
264     const char* DwarfSectionOffsetDirective; // Defaults to NULL
265     
266     //===--- CBE Asm Translation Table -----------------------------------===//
267
268     const char *const *AsmTransCBE;          // Defaults to empty
269
270   public:
271     explicit MCAsmInfo();
272     virtual ~MCAsmInfo();
273
274     // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
275     static unsigned getSLEB128Size(int Value);
276     static unsigned getULEB128Size(unsigned Value);
277
278     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
279     
280     // Data directive accessors.
281     //
282     const char *getData8bitsDirective(unsigned AS = 0) const {
283       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
284     }
285     const char *getData16bitsDirective(unsigned AS = 0) const {
286       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
287     }
288     const char *getData32bitsDirective(unsigned AS = 0) const {
289       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
290     }
291     const char *getData64bitsDirective(unsigned AS = 0) const {
292       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
293     }
294     const char *getGPRel32Directive() const { return GPRel32Directive; }
295
296     /// getNonexecutableStackSection - Targets can implement this method to
297     /// specify a section to switch to if the translation unit doesn't have any
298     /// trampolines that require an executable stack.
299     virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
300       return 0;
301     }
302     
303     bool usesSunStyleELFSectionSwitchSyntax() const {
304       return SunStyleELFSectionSwitchSyntax;
305     }
306     
307     bool usesELFSectionDirectiveForBSS() const {
308       return UsesELFSectionDirectiveForBSS;
309     }
310
311     // Accessors.
312     //
313     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
314     bool hasStaticCtorDtorReferenceInStaticMode() const {
315       return HasStaticCtorDtorReferenceInStaticMode;
316     }
317     unsigned getMaxInstLength() const {
318       return MaxInstLength;
319     }
320     const char *getPCSymbol() const {
321       return PCSymbol;
322     }
323     char getSeparatorChar() const {
324       return SeparatorChar;
325     }
326     unsigned getCommentColumn() const {
327       return CommentColumn;
328     }
329     const char *getCommentString() const {
330       return CommentString;
331     }
332     const char *getGlobalPrefix() const {
333       return GlobalPrefix;
334     }
335     const char *getPrivateGlobalPrefix() const {
336       return PrivateGlobalPrefix;
337     }
338     const char *getLinkerPrivateGlobalPrefix() const {
339       return LinkerPrivateGlobalPrefix;
340     }
341     const char *getInlineAsmStart() const {
342       return InlineAsmStart;
343     }
344     const char *getInlineAsmEnd() const {
345       return InlineAsmEnd;
346     }
347     unsigned getAssemblerDialect() const {
348       return AssemblerDialect;
349     }
350     bool doesAllowQuotesInName() const {
351       return AllowQuotesInName;
352     }
353     bool doesAllowNameToStartWithDigit() const {
354       return AllowNameToStartWithDigit;
355     }
356     const char *getZeroDirective() const {
357       return ZeroDirective;
358     }
359     const char *getAsciiDirective() const {
360       return AsciiDirective;
361     }
362     const char *getAscizDirective() const {
363       return AscizDirective;
364     }
365     const char *getAlignDirective() const {
366       return AlignDirective;
367     }
368     bool getAlignmentIsInBytes() const {
369       return AlignmentIsInBytes;
370     }
371     unsigned getTextAlignFillValue() const {
372       return TextAlignFillValue;
373     }
374     const char *getGlobalDirective() const {
375       return GlobalDirective;
376     }
377     const char *getExternDirective() const {
378       return ExternDirective;
379     }
380     const char *getSetDirective() const {
381       return SetDirective;
382     }
383     bool hasLCOMMDirective() const { return HasLCOMMDirective; }
384     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
385     bool getCOMMDirectiveAlignmentIsInBytes() const {
386       return COMMDirectiveAlignmentIsInBytes;
387     }
388     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
389     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
390     const char *getWeakRefDirective() const { return WeakRefDirective; }
391     const char *getWeakDefDirective() const { return WeakDefDirective; }
392     const char *getLinkOnceDirective() const { return LinkOnceDirective; }
393     
394     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
395     MCSymbolAttr getProtectedVisibilityAttr() const {
396       return ProtectedVisibilityAttr;
397     }
398     bool isAbsoluteDebugSectionOffsets() const {
399       return AbsoluteDebugSectionOffsets;
400     }
401     bool isAbsoluteEHSectionOffsets() const {
402       return AbsoluteEHSectionOffsets;
403     }
404     bool hasLEB128() const {
405       return HasLEB128;
406     }
407     bool hasDotLocAndDotFile() const {
408       return HasDotLocAndDotFile;
409     }
410     bool doesSupportDebugInformation() const {
411       return SupportsDebugInformation;
412     }
413     bool doesSupportExceptionHandling() const {
414       return ExceptionsType != ExceptionHandling::None;
415     }
416     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
417       return ExceptionsType;
418     }
419     bool doesDwarfRequireFrameSection() const {
420       return DwarfRequiresFrameSection;
421     }
422     bool doesDwarfUsesInlineInfoSection() const {
423       return DwarfUsesInlineInfoSection;
424     }
425     bool is_EHSymbolPrivate() const {
426       return Is_EHSymbolPrivate;
427     }
428     const char *getGlobalEHDirective() const {
429       return GlobalEHDirective;
430     }
431     bool getSupportsWeakOmittedEHFrame() const {
432       return SupportsWeakOmittedEHFrame;
433     }
434     const char *getDwarfSectionOffsetDirective() const {
435       return DwarfSectionOffsetDirective;
436     }
437     const char *const *getAsmCBE() const {
438       return AsmTransCBE;
439     }
440   };
441 }
442
443 #endif