MC: Overhaul handling of .lcomm
[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/MachineLocation.h"
20 #include "llvm/MC/MCDirectives.h"
21 #include <cassert>
22 #include <vector>
23
24 namespace llvm {
25   class MCExpr;
26   class MCSection;
27   class MCStreamer;
28   class MCSymbol;
29   class MCContext;
30
31   namespace ExceptionHandling {
32     enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
33   }
34
35   /// MCAsmInfo - This class is intended to be used as a base class for asm
36   /// properties and features specific to the target.
37   class MCAsmInfo {
38   protected:
39     //===------------------------------------------------------------------===//
40     // Properties to be set by the target writer, used to configure asm printer.
41     //
42
43     /// PointerSize - Pointer size in bytes.
44     ///               Default is 4.
45     unsigned PointerSize;
46
47     /// IsLittleEndian - True if target is little endian.
48     ///                  Default is true.
49     bool IsLittleEndian;
50
51     /// StackGrowsUp - True if target stack grow up.
52     ///                Default is false.
53     bool StackGrowsUp;
54
55     /// HasSubsectionsViaSymbols - True if this target has the MachO
56     /// .subsections_via_symbols directive.
57     bool HasSubsectionsViaSymbols;           // Default is false.
58
59     /// HasMachoZeroFillDirective - True if this is a MachO target that supports
60     /// the macho-specific .zerofill directive for emitting BSS Symbols.
61     bool HasMachoZeroFillDirective;               // Default is false.
62
63     /// HasMachoTBSSDirective - True if this is a MachO target that supports
64     /// the macho-specific .tbss directive for emitting thread local BSS Symbols
65     bool HasMachoTBSSDirective;                 // Default is false.
66
67     /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
68     /// emit a ".reference .constructors_used" or ".reference .destructors_used"
69     /// directive after the a static ctor/dtor list.  This directive is only
70     /// emitted in Static relocation model.
71     bool HasStaticCtorDtorReferenceInStaticMode;  // Default is false.
72
73     /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
74     /// requires that the debug_line section be of a minimum size. In practice
75     /// such a linker requires a non empty line sequence if a file is present.
76     bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
77
78     /// MaxInstLength - This is the maximum possible length of an instruction,
79     /// which is needed to compute the size of an inline asm.
80     unsigned MaxInstLength;                  // Defaults to 4.
81
82     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
83     /// relative expressions.
84     const char *PCSymbol;                    // Defaults to "$".
85
86     /// SeparatorString - This string, if specified, is used to separate
87     /// instructions from each other when on the same line.
88     const char *SeparatorString;             // Defaults to ';'
89
90     /// CommentColumn - This indicates the comment num (zero-based) at
91     /// which asm comments should be printed.
92     unsigned CommentColumn;                  // Defaults to 40
93
94     /// CommentString - This indicates the comment character used by the
95     /// assembler.
96     const char *CommentString;               // Defaults to "#"
97
98     /// LabelSuffix - This is appended to emitted labels.
99     const char *LabelSuffix;                 // Defaults to ":"
100
101     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
102     /// onto all global symbols.  This is often used for "_" or ".".
103     const char *GlobalPrefix;                // Defaults to ""
104
105     /// PrivateGlobalPrefix - This prefix is used for globals like constant
106     /// pool entries that are completely private to the .s file and should not
107     /// have names in the .o file.  This is often "." or "L".
108     const char *PrivateGlobalPrefix;         // Defaults to "."
109
110     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
111     /// be passed through the assembler but be removed by the linker.  This
112     /// is "l" on Darwin, currently used for some ObjC metadata.
113     const char *LinkerPrivateGlobalPrefix;   // Defaults to ""
114
115     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
116     /// emit before and after an inline assembly statement.
117     const char *InlineAsmStart;              // Defaults to "#APP\n"
118     const char *InlineAsmEnd;                // Defaults to "#NO_APP\n"
119
120     /// Code16Directive, Code32Directive, Code64Directive - These are assembly
121     /// directives that tells the assembler to interpret the following
122     /// instructions differently.
123     const char *Code16Directive;             // Defaults to ".code16"
124     const char *Code32Directive;             // Defaults to ".code32"
125     const char *Code64Directive;             // Defaults to ".code64"
126
127     /// AssemblerDialect - Which dialect of an assembler variant to use.
128     unsigned AssemblerDialect;               // Defaults to 0
129
130     /// AllowQuotesInName - This is true if the assembler allows for complex
131     /// symbol names to be surrounded in quotes.  This defaults to false.
132     bool AllowQuotesInName;
133
134     /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
135     /// names to start with a digit (e.g., "0x0021").  This defaults to false.
136     bool AllowNameToStartWithDigit;
137
138     /// AllowPeriodsInName - This is true if the assembler allows periods in
139     /// symbol names.  This defaults to true.
140     bool AllowPeriodsInName;
141
142     /// AllowUTF8 - This is true if the assembler accepts UTF-8 input.
143     // FIXME: Make this a more general encoding setting?
144     bool AllowUTF8;
145
146     /// UseDataRegionDirectives - This is true if data region markers should
147     /// be printed as ".data_region/.end_data_region" directives. If false,
148     /// use "$d/$a" labels instead.
149     bool UseDataRegionDirectives;
150
151     //===--- Data Emission Directives -------------------------------------===//
152
153     /// ZeroDirective - this should be set to the directive used to get some
154     /// number of zero bytes emitted to the current section.  Common cases are
155     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
156     /// Data*bitsDirective's will be used to emit zero bytes.
157     const char *ZeroDirective;               // Defaults to "\t.zero\t"
158
159     /// AsciiDirective - This directive allows emission of an ascii string with
160     /// the standard C escape characters embedded into it.
161     const char *AsciiDirective;              // Defaults to "\t.ascii\t"
162
163     /// AscizDirective - If not null, this allows for special handling of
164     /// zero terminated strings on this target.  This is commonly supported as
165     /// ".asciz".  If a target doesn't support this, it can be set to null.
166     const char *AscizDirective;              // Defaults to "\t.asciz\t"
167
168     /// DataDirectives - These directives are used to output some unit of
169     /// integer data to the current section.  If a data directive is set to
170     /// null, smaller data directives will be used to emit the large sizes.
171     const char *Data8bitsDirective;          // Defaults to "\t.byte\t"
172     const char *Data16bitsDirective;         // Defaults to "\t.short\t"
173     const char *Data32bitsDirective;         // Defaults to "\t.long\t"
174     const char *Data64bitsDirective;         // Defaults to "\t.quad\t"
175
176     /// GPRel64Directive - if non-null, a directive that is used to emit a word
177     /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
178     /// on Mips.
179     const char *GPRel64Directive;            // Defaults to NULL.
180
181     /// GPRel32Directive - if non-null, a directive that is used to emit a word
182     /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
183     /// on Mips or .gprel32 on Alpha.
184     const char *GPRel32Directive;            // Defaults to NULL.
185
186     /// getDataASDirective - Return the directive that should be used to emit
187     /// data of the specified size to the specified numeric address space.
188     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
189       assert(AS != 0 && "Don't know the directives for default addr space");
190       return 0;
191     }
192
193     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
194     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
195     /// normal ELF syntax (,"a,w") in .section directives.
196     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
197
198     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
199     /// '.section' directive before the '.bss' one. It's used for PPC/Linux
200     /// which doesn't support the '.bss' directive only.
201     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
202
203     /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
204     /// style mangling for functions with X86_StdCall/X86_FastCall calling
205     /// convention.
206     bool HasMicrosoftFastStdCallMangling;    // Defaults to false.
207
208     //===--- Alignment Information ----------------------------------------===//
209
210     /// AlignDirective - The directive used to emit round up to an alignment
211     /// boundary.
212     ///
213     const char *AlignDirective;              // Defaults to "\t.align\t"
214
215     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
216     /// emits ".align N" directives, where N is the number of bytes to align to.
217     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
218     /// boundary.
219     bool AlignmentIsInBytes;                 // Defaults to true
220
221     /// TextAlignFillValue - If non-zero, this is used to fill the executable
222     /// space created as the result of a alignment directive.
223     unsigned TextAlignFillValue;             // Defaults to 0
224
225     //===--- Global Variable Emission Directives --------------------------===//
226
227     /// GlobalDirective - This is the directive used to declare a global entity.
228     ///
229     const char *GlobalDirective;             // Defaults to NULL.
230
231     /// ExternDirective - This is the directive used to declare external
232     /// globals.
233     ///
234     const char *ExternDirective;             // Defaults to NULL.
235
236     /// HasSetDirective - True if the assembler supports the .set directive.
237     bool HasSetDirective;                    // Defaults to true.
238
239     /// HasAggressiveSymbolFolding - False if the assembler requires that we use
240     /// Lc = a - b
241     /// .long Lc
242     /// instead of
243     /// .long a - b
244     bool HasAggressiveSymbolFolding;           // Defaults to true.
245
246     /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
247     /// alignment is to be specified in bytes instead of log2(n).
248     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
249
250     /// LCOMMDirectiveSupportsAlignment - True if .lcomm supports an optional
251     /// alignment argument on this target.
252     bool LCOMMDirectiveSupportsAlignment;    // Defaults to false.
253
254     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
255     /// directives, this is true for most ELF targets.
256     bool HasDotTypeDotSizeDirective;         // Defaults to true.
257
258     /// HasSingleParameterDotFile - True if the target has a single parameter
259     /// .file directive, this is true for ELF targets.
260     bool HasSingleParameterDotFile;          // Defaults to true.
261
262     /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
263     /// directive.
264     bool HasNoDeadStrip;                     // Defaults to false.
265
266     /// HasSymbolResolver - True if this target supports the MachO
267     /// .symbol_resolver directive.
268     bool HasSymbolResolver;                     // Defaults to false.
269
270     /// WeakRefDirective - This directive, if non-null, is used to declare a
271     /// global as being a weak undefined symbol.
272     const char *WeakRefDirective;            // Defaults to NULL.
273
274     /// WeakDefDirective - This directive, if non-null, is used to declare a
275     /// global as being a weak defined symbol.
276     const char *WeakDefDirective;            // Defaults to NULL.
277
278     /// LinkOnceDirective - This directive, if non-null is used to declare a
279     /// global as being a weak defined symbol.  This is used on cygwin/mingw.
280     const char *LinkOnceDirective;           // Defaults to NULL.
281
282     /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
283     /// declare a symbol as having hidden visibility.
284     MCSymbolAttr HiddenVisibilityAttr;       // Defaults to MCSA_Hidden.
285
286     /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
287     /// is used to declare an undefined symbol as having hidden visibility.
288     MCSymbolAttr HiddenDeclarationVisibilityAttr;   // Defaults to MCSA_Hidden.
289
290
291     /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
292     /// to declare a symbol as having protected visibility.
293     MCSymbolAttr ProtectedVisibilityAttr;    // Defaults to MCSA_Protected
294
295     //===--- Dwarf Emission Directives -----------------------------------===//
296
297     /// HasLEB128 - True if target asm supports leb128 directives.
298     bool HasLEB128;                          // Defaults to false.
299
300     /// SupportsDebugInformation - True if target supports emission of debugging
301     /// information.
302     bool SupportsDebugInformation;           // Defaults to false.
303
304     /// SupportsExceptionHandling - True if target supports exception handling.
305     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
306
307     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
308     /// encode inline subroutine information.
309     bool DwarfUsesInlineInfoSection;         // Defaults to false.
310
311     /// DwarfSectionOffsetDirective - Special section offset directive.
312     const char* DwarfSectionOffsetDirective; // Defaults to NULL
313
314     /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
315     /// uses relocations for references to other .debug_* sections.
316     bool DwarfUsesRelocationsAcrossSections;
317
318     /// DwarfRegNumForCFI - True if dwarf register numbers are printed
319     /// instead of symbolic register names in .cfi_* directives.
320     bool DwarfRegNumForCFI;  // Defaults to false;
321
322     //===--- Prologue State ----------------------------------------------===//
323
324     std::vector<MachineMove> InitialFrameState;
325
326   public:
327     explicit MCAsmInfo();
328     virtual ~MCAsmInfo();
329
330     // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
331     static unsigned getSLEB128Size(int Value);
332     static unsigned getULEB128Size(unsigned Value);
333
334     /// getPointerSize - Get the pointer size in bytes.
335     unsigned getPointerSize() const {
336       return PointerSize;
337     }
338
339     /// islittleendian - True if the target is little endian.
340     bool isLittleEndian() const {
341       return IsLittleEndian;
342     }
343
344     /// isStackGrowthDirectionUp - True if target stack grow up.
345     bool isStackGrowthDirectionUp() const {
346       return StackGrowsUp;
347     }
348
349     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
350
351     // Data directive accessors.
352     //
353     const char *getData8bitsDirective(unsigned AS = 0) const {
354       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
355     }
356     const char *getData16bitsDirective(unsigned AS = 0) const {
357       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
358     }
359     const char *getData32bitsDirective(unsigned AS = 0) const {
360       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
361     }
362     const char *getData64bitsDirective(unsigned AS = 0) const {
363       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
364     }
365     const char *getGPRel64Directive() const { return GPRel64Directive; }
366     const char *getGPRel32Directive() const { return GPRel32Directive; }
367
368     /// getNonexecutableStackSection - Targets can implement this method to
369     /// specify a section to switch to if the translation unit doesn't have any
370     /// trampolines that require an executable stack.
371     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
372       return 0;
373     }
374
375     virtual const MCExpr *
376     getExprForPersonalitySymbol(const MCSymbol *Sym,
377                                 unsigned Encoding,
378                                 MCStreamer &Streamer) const;
379
380     const MCExpr *
381     getExprForFDESymbol(const MCSymbol *Sym,
382                         unsigned Encoding,
383                         MCStreamer &Streamer) const;
384
385     bool usesSunStyleELFSectionSwitchSyntax() const {
386       return SunStyleELFSectionSwitchSyntax;
387     }
388
389     bool usesELFSectionDirectiveForBSS() const {
390       return UsesELFSectionDirectiveForBSS;
391     }
392
393     bool hasMicrosoftFastStdCallMangling() const {
394       return HasMicrosoftFastStdCallMangling;
395     }
396
397     // Accessors.
398     //
399     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
400     bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
401     bool hasStaticCtorDtorReferenceInStaticMode() const {
402       return HasStaticCtorDtorReferenceInStaticMode;
403     }
404     bool getLinkerRequiresNonEmptyDwarfLines() const {
405       return LinkerRequiresNonEmptyDwarfLines;
406     }
407     unsigned getMaxInstLength() const {
408       return MaxInstLength;
409     }
410     const char *getPCSymbol() const {
411       return PCSymbol;
412     }
413     const char *getSeparatorString() const {
414       return SeparatorString;
415     }
416     unsigned getCommentColumn() const {
417       return CommentColumn;
418     }
419     const char *getCommentString() const {
420       return CommentString;
421     }
422     const char *getLabelSuffix() const {
423       return LabelSuffix;
424     }
425     const char *getGlobalPrefix() const {
426       return GlobalPrefix;
427     }
428     const char *getPrivateGlobalPrefix() const {
429       return PrivateGlobalPrefix;
430     }
431     const char *getLinkerPrivateGlobalPrefix() const {
432       return LinkerPrivateGlobalPrefix;
433     }
434     const char *getInlineAsmStart() const {
435       return InlineAsmStart;
436     }
437     const char *getInlineAsmEnd() const {
438       return InlineAsmEnd;
439     }
440     const char *getCode16Directive() const {
441       return Code16Directive;
442     }
443     const char *getCode32Directive() const {
444       return Code32Directive;
445     }
446     const char *getCode64Directive() const {
447       return Code64Directive;
448     }
449     unsigned getAssemblerDialect() const {
450       return AssemblerDialect;
451     }
452     bool doesAllowQuotesInName() const {
453       return AllowQuotesInName;
454     }
455     bool doesAllowNameToStartWithDigit() const {
456       return AllowNameToStartWithDigit;
457     }
458     bool doesAllowPeriodsInName() const {
459       return AllowPeriodsInName;
460     }
461     bool doesAllowUTF8() const {
462       return AllowUTF8;
463     }
464     bool doesSupportDataRegionDirectives() const {
465       return UseDataRegionDirectives;
466     }
467     const char *getZeroDirective() const {
468       return ZeroDirective;
469     }
470     const char *getAsciiDirective() const {
471       return AsciiDirective;
472     }
473     const char *getAscizDirective() const {
474       return AscizDirective;
475     }
476     const char *getAlignDirective() const {
477       return AlignDirective;
478     }
479     bool getAlignmentIsInBytes() const {
480       return AlignmentIsInBytes;
481     }
482     unsigned getTextAlignFillValue() const {
483       return TextAlignFillValue;
484     }
485     const char *getGlobalDirective() const {
486       return GlobalDirective;
487     }
488     const char *getExternDirective() const {
489       return ExternDirective;
490     }
491     bool hasSetDirective() const { return HasSetDirective; }
492     bool hasAggressiveSymbolFolding() const {
493       return HasAggressiveSymbolFolding;
494     }
495     bool getCOMMDirectiveAlignmentIsInBytes() const {
496       return COMMDirectiveAlignmentIsInBytes;
497     }
498     bool getLCOMMDirectiveSupportsAlignment() const {
499       return LCOMMDirectiveSupportsAlignment;
500     }
501     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
502     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
503     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
504     bool hasSymbolResolver() const { return HasSymbolResolver; }
505     const char *getWeakRefDirective() const { return WeakRefDirective; }
506     const char *getWeakDefDirective() const { return WeakDefDirective; }
507     const char *getLinkOnceDirective() const { return LinkOnceDirective; }
508
509     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
510     MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
511       return HiddenDeclarationVisibilityAttr;
512     }
513     MCSymbolAttr getProtectedVisibilityAttr() const {
514       return ProtectedVisibilityAttr;
515     }
516     bool hasLEB128() const {
517       return HasLEB128;
518     }
519     bool doesSupportDebugInformation() const {
520       return SupportsDebugInformation;
521     }
522     bool doesSupportExceptionHandling() const {
523       return ExceptionsType != ExceptionHandling::None;
524     }
525     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
526       return ExceptionsType;
527     }
528     bool isExceptionHandlingDwarf() const {
529       return
530         (ExceptionsType == ExceptionHandling::DwarfCFI ||
531          ExceptionsType == ExceptionHandling::ARM ||
532          ExceptionsType == ExceptionHandling::Win64);
533     }
534     bool doesDwarfUseInlineInfoSection() const {
535       return DwarfUsesInlineInfoSection;
536     }
537     const char *getDwarfSectionOffsetDirective() const {
538       return DwarfSectionOffsetDirective;
539     }
540     bool doesDwarfUseRelocationsAcrossSections() const {
541       return DwarfUsesRelocationsAcrossSections;
542     }
543     bool useDwarfRegNumForCFI() const {
544       return DwarfRegNumForCFI;
545     }
546
547     void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
548                               const MachineLocation &S) {
549       InitialFrameState.push_back(MachineMove(label, D, S));
550     }
551     const std::vector<MachineMove> &getInitialFrameState() const {
552       return InitialFrameState;
553     }
554   };
555 }
556
557 #endif