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