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