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