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