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