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