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