Make the llvm mangler depend only on DataLayout.
[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_MC_MCASMINFO_H
17 #define LLVM_MC_MCASMINFO_H
18
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MachineLocation.h"
22 #include <cassert>
23 #include <vector>
24
25 namespace llvm {
26   class MCExpr;
27   class MCSection;
28   class MCStreamer;
29   class MCSymbol;
30   class MCContext;
31
32   namespace ExceptionHandling {
33     enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
34   }
35
36   namespace LCOMM {
37     enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
38   }
39
40   /// MCAsmInfo - This class is intended to be used as a base class for asm
41   /// properties and features specific to the target.
42   class MCAsmInfo {
43   protected:
44     //===------------------------------------------------------------------===//
45     // Properties to be set by the target writer, used to configure asm printer.
46     //
47
48     /// PointerSize - Pointer size in bytes.
49     ///               Default is 4.
50     unsigned PointerSize;
51
52     /// CalleeSaveStackSlotSize - Size of the stack slot reserved for
53     ///                           callee-saved registers, in bytes.
54     ///                           Default is same as pointer size.
55     unsigned CalleeSaveStackSlotSize;
56
57     /// IsLittleEndian - True if target is little endian.
58     ///                  Default is true.
59     bool IsLittleEndian;
60
61     /// StackGrowsUp - True if target stack grow up.
62     ///                Default is false.
63     bool StackGrowsUp;
64
65     /// HasSubsectionsViaSymbols - True if this target has the MachO
66     /// .subsections_via_symbols directive.
67     bool HasSubsectionsViaSymbols;           // Default is false.
68
69     /// HasMachoZeroFillDirective - True if this is a MachO target that supports
70     /// the macho-specific .zerofill directive for emitting BSS Symbols.
71     bool HasMachoZeroFillDirective;               // Default is false.
72
73     /// HasMachoTBSSDirective - True if this is a MachO target that supports
74     /// the macho-specific .tbss directive for emitting thread local BSS Symbols
75     bool HasMachoTBSSDirective;                 // Default is false.
76
77     /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
78     /// emit a ".reference .constructors_used" or ".reference .destructors_used"
79     /// directive after the a static ctor/dtor list.  This directive is only
80     /// emitted in Static relocation model.
81     bool HasStaticCtorDtorReferenceInStaticMode;  // Default is false.
82
83     /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
84     /// requires that the debug_line section be of a minimum size. In practice
85     /// such a linker requires a non-empty line sequence if a file is present.
86     bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
87
88     /// MaxInstLength - This is the maximum possible length of an instruction,
89     /// which is needed to compute the size of an inline asm.
90     unsigned MaxInstLength;                  // Defaults to 4.
91
92     /// MinInstAlignment - Every possible instruction length is a multiple of
93     /// this value.  Factored out in .debug_frame and .debug_line.
94     unsigned MinInstAlignment;                  // Defaults to 1.
95
96     /// DollarIsPC - The '$' token, when not referencing an identifier or
97     /// constant, refers to the current PC.
98     bool DollarIsPC;                         // Defaults to false.
99
100     /// SeparatorString - This string, if specified, is used to separate
101     /// instructions from each other when on the same line.
102     const char *SeparatorString;             // Defaults to ';'
103
104     /// CommentColumn - This indicates the comment num (zero-based) at
105     /// which asm comments should be printed.
106     unsigned CommentColumn;                  // Defaults to 40
107
108     /// CommentString - This indicates the comment character used by the
109     /// assembler.
110     const char *CommentString;               // Defaults to "#"
111
112     /// LabelSuffix - This is appended to emitted labels.
113     const char *LabelSuffix;                 // Defaults to ":"
114
115     /// LabelSuffix - This is appended to emitted labels.
116     const char *DebugLabelSuffix;                 // Defaults to ":"
117
118     /// This prefix is used for globals like constant pool entries that are
119     /// completely private to the .s file and should not have names in the .o
120     /// file.
121     const char *PrivateGlobalPrefix;         // Defaults to "L"
122
123     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
124     /// emit before and after an inline assembly statement.
125     const char *InlineAsmStart;              // Defaults to "#APP\n"
126     const char *InlineAsmEnd;                // Defaults to "#NO_APP\n"
127
128     /// Code16Directive, Code32Directive, Code64Directive - These are assembly
129     /// directives that tells the assembler to interpret the following
130     /// instructions differently.
131     const char *Code16Directive;             // Defaults to ".code16"
132     const char *Code32Directive;             // Defaults to ".code32"
133     const char *Code64Directive;             // Defaults to ".code64"
134
135     /// AssemblerDialect - Which dialect of an assembler variant to use.
136     unsigned AssemblerDialect;               // Defaults to 0
137
138     /// \brief This is true if the assembler allows @ characters in symbol
139     /// names. Defaults to false.
140     bool AllowAtInName;
141
142     /// UseDataRegionDirectives - This is true if data region markers should
143     /// be printed as ".data_region/.end_data_region" directives. If false,
144     /// use "$d/$a" labels instead.
145     bool UseDataRegionDirectives;
146
147     //===--- Data Emission Directives -------------------------------------===//
148
149     /// ZeroDirective - this should be set to the directive used to get some
150     /// number of zero bytes emitted to the current section.  Common cases are
151     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
152     /// Data*bitsDirective's will be used to emit zero bytes.
153     const char *ZeroDirective;               // Defaults to "\t.zero\t"
154
155     /// AsciiDirective - This directive allows emission of an ascii string with
156     /// the standard C escape characters embedded into it.
157     const char *AsciiDirective;              // Defaults to "\t.ascii\t"
158
159     /// AscizDirective - If not null, this allows for special handling of
160     /// zero terminated strings on this target.  This is commonly supported as
161     /// ".asciz".  If a target doesn't support this, it can be set to null.
162     const char *AscizDirective;              // Defaults to "\t.asciz\t"
163
164     /// DataDirectives - These directives are used to output some unit of
165     /// integer data to the current section.  If a data directive is set to
166     /// null, smaller data directives will be used to emit the large sizes.
167     const char *Data8bitsDirective;          // Defaults to "\t.byte\t"
168     const char *Data16bitsDirective;         // Defaults to "\t.short\t"
169     const char *Data32bitsDirective;         // Defaults to "\t.long\t"
170     const char *Data64bitsDirective;         // Defaults to "\t.quad\t"
171
172     /// GPRel64Directive - if non-null, a directive that is used to emit a word
173     /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
174     /// on Mips.
175     const char *GPRel64Directive;            // Defaults to NULL.
176
177     /// GPRel32Directive - if non-null, a directive that is used to emit a word
178     /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
179     /// on Mips or .gprel32 on Alpha.
180     const char *GPRel32Directive;            // Defaults to NULL.
181
182     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
183     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
184     /// normal ELF syntax (,"a,w") in .section directives.
185     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
186
187     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
188     /// '.section' directive before the '.bss' one. It's used for PPC/Linux
189     /// which doesn't support the '.bss' directive only.
190     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
191
192     bool NeedsDwarfSectionOffsetDirective;
193
194     //===--- Alignment Information ----------------------------------------===//
195
196     /// AlignDirective - The directive used to emit round up to an alignment
197     /// boundary.
198     ///
199     const char *AlignDirective;              // Defaults to "\t.align\t"
200
201     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
202     /// emits ".align N" directives, where N is the number of bytes to align to.
203     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
204     /// boundary.
205     bool AlignmentIsInBytes;                 // Defaults to true
206
207     /// TextAlignFillValue - If non-zero, this is used to fill the executable
208     /// space created as the result of a alignment directive.
209     unsigned TextAlignFillValue;             // Defaults to 0
210
211     //===--- Global Variable Emission Directives --------------------------===//
212
213     /// GlobalDirective - This is the directive used to declare a global entity.
214     ///
215     const char *GlobalDirective;             // Defaults to NULL.
216
217     /// HasSetDirective - True if the assembler supports the .set directive.
218     bool HasSetDirective;                    // Defaults to true.
219
220     /// HasAggressiveSymbolFolding - False if the assembler requires that we use
221     /// Lc = a - b
222     /// .long Lc
223     /// instead of
224     /// .long a - b
225     bool HasAggressiveSymbolFolding;           // Defaults to true.
226
227     /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
228     /// alignment is to be specified in bytes instead of log2(n).
229     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
230
231     /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
232     /// target supports an alignment argument and how it is interpreted.
233     LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
234
235     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
236     /// directives, this is true for most ELF targets.
237     bool HasDotTypeDotSizeDirective;         // Defaults to true.
238
239     /// HasSingleParameterDotFile - True if the target has a single parameter
240     /// .file directive, this is true for ELF targets.
241     bool HasSingleParameterDotFile;          // Defaults to true.
242
243     /// hasIdentDirective - True if the target has a .ident directive, this is
244     /// true for ELF targets.
245     bool HasIdentDirective;                  // Defaults to false.
246
247     /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
248     /// directive.
249     bool HasNoDeadStrip;                     // Defaults to false.
250
251     /// WeakRefDirective - This directive, if non-null, is used to declare a
252     /// global as being a weak undefined symbol.
253     const char *WeakRefDirective;            // Defaults to NULL.
254
255     /// True if we have a directive to declare a global as being a weak
256     /// defined symbol.
257     bool HasWeakDefDirective;                // Defaults to false.
258
259     /// True if we have a directive to declare a global as being a weak
260     /// defined symbol that can be hidden (unexported).
261     bool HasWeakDefCanBeHiddenDirective;     // Defaults to false.
262
263     /// True if we have a .linkonce directive.  This is used on cygwin/mingw.
264     bool HasLinkOnceDirective;               // Defaults to false.
265
266     /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
267     /// declare a symbol as having hidden visibility.
268     MCSymbolAttr HiddenVisibilityAttr;       // Defaults to MCSA_Hidden.
269
270     /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
271     /// is used to declare an undefined symbol as having hidden visibility.
272     MCSymbolAttr HiddenDeclarationVisibilityAttr;   // Defaults to MCSA_Hidden.
273
274
275     /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
276     /// to declare a symbol as having protected visibility.
277     MCSymbolAttr ProtectedVisibilityAttr;    // Defaults to MCSA_Protected
278
279     //===--- Dwarf Emission Directives -----------------------------------===//
280
281     /// HasLEB128 - True if target asm supports leb128 directives.
282     bool HasLEB128;                          // Defaults to false.
283
284     /// SupportsDebugInformation - True if target supports emission of debugging
285     /// information.
286     bool SupportsDebugInformation;           // Defaults to false.
287
288     /// SupportsExceptionHandling - True if target supports exception handling.
289     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
290
291     /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
292     /// uses relocations for references to other .debug_* sections.
293     bool DwarfUsesRelocationsAcrossSections;
294
295     /// DwarfRegNumForCFI - True if dwarf register numbers are printed
296     /// instead of symbolic register names in .cfi_* directives.
297     bool DwarfRegNumForCFI;  // Defaults to false;
298
299     /// UseParensForSymbolVariant - True if target uses parens to indicate the
300     /// symbol variant instead of @. For example, foo(plt) instead of foo@plt.
301     bool UseParensForSymbolVariant; // Defaults to false;
302
303     //===--- Prologue State ----------------------------------------------===//
304
305     std::vector<MCCFIInstruction> InitialFrameState;
306
307   public:
308     explicit MCAsmInfo();
309     virtual ~MCAsmInfo();
310
311     // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
312     static unsigned getSLEB128Size(int64_t Value);
313     static unsigned getULEB128Size(uint64_t Value);
314
315     /// getPointerSize - Get the pointer size in bytes.
316     unsigned getPointerSize() const {
317       return PointerSize;
318     }
319
320     /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
321     /// size in bytes.
322     unsigned getCalleeSaveStackSlotSize() const {
323       return CalleeSaveStackSlotSize;
324     }
325
326     /// isLittleEndian - True if the target is little endian.
327     bool isLittleEndian() const {
328       return IsLittleEndian;
329     }
330
331     /// isStackGrowthDirectionUp - True if target stack grow up.
332     bool isStackGrowthDirectionUp() const {
333       return StackGrowsUp;
334     }
335
336     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
337
338     // Data directive accessors.
339     //
340     const char *getData8bitsDirective() const {
341       return Data8bitsDirective;
342     }
343     const char *getData16bitsDirective() const {
344       return Data16bitsDirective;
345     }
346     const char *getData32bitsDirective() const {
347       return Data32bitsDirective;
348     }
349     const char *getData64bitsDirective() const {
350       return Data64bitsDirective;
351     }
352     const char *getGPRel64Directive() const { return GPRel64Directive; }
353     const char *getGPRel32Directive() const { return GPRel32Directive; }
354
355     /// getNonexecutableStackSection - Targets can implement this method to
356     /// specify a section to switch to if the translation unit doesn't have any
357     /// trampolines that require an executable stack.
358     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
359       return 0;
360     }
361
362     virtual const MCExpr *
363     getExprForPersonalitySymbol(const MCSymbol *Sym,
364                                 unsigned Encoding,
365                                 MCStreamer &Streamer) const;
366
367     const MCExpr *
368     getExprForFDESymbol(const MCSymbol *Sym,
369                         unsigned Encoding,
370                         MCStreamer &Streamer) const;
371
372     bool usesSunStyleELFSectionSwitchSyntax() const {
373       return SunStyleELFSectionSwitchSyntax;
374     }
375
376     bool usesELFSectionDirectiveForBSS() const {
377       return UsesELFSectionDirectiveForBSS;
378     }
379
380     bool needsDwarfSectionOffsetDirective() const {
381       return NeedsDwarfSectionOffsetDirective;
382     }
383
384     // Accessors.
385     //
386     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
387     bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
388     bool hasStaticCtorDtorReferenceInStaticMode() const {
389       return HasStaticCtorDtorReferenceInStaticMode;
390     }
391     bool getLinkerRequiresNonEmptyDwarfLines() const {
392       return LinkerRequiresNonEmptyDwarfLines;
393     }
394     unsigned getMaxInstLength() const {
395       return MaxInstLength;
396     }
397     unsigned getMinInstAlignment() const {
398       return MinInstAlignment;
399     }
400     bool getDollarIsPC() const {
401       return DollarIsPC;
402     }
403     const char *getSeparatorString() const {
404       return SeparatorString;
405     }
406     unsigned getCommentColumn() const {
407       return CommentColumn;
408     }
409     const char *getCommentString() const {
410       return CommentString;
411     }
412     const char *getLabelSuffix() const {
413       return LabelSuffix;
414     }
415
416     const char *getDebugLabelSuffix() const {
417       return DebugLabelSuffix;
418     }
419     const char *getPrivateGlobalPrefix() const {
420       return PrivateGlobalPrefix;
421     }
422     const char *getInlineAsmStart() const {
423       return InlineAsmStart;
424     }
425     const char *getInlineAsmEnd() const {
426       return InlineAsmEnd;
427     }
428     const char *getCode16Directive() const {
429       return Code16Directive;
430     }
431     const char *getCode32Directive() const {
432       return Code32Directive;
433     }
434     const char *getCode64Directive() const {
435       return Code64Directive;
436     }
437     unsigned getAssemblerDialect() const {
438       return AssemblerDialect;
439     }
440     bool doesAllowAtInName() const {
441       return AllowAtInName;
442     }
443     bool doesSupportDataRegionDirectives() const {
444       return UseDataRegionDirectives;
445     }
446     const char *getZeroDirective() const {
447       return ZeroDirective;
448     }
449     const char *getAsciiDirective() const {
450       return AsciiDirective;
451     }
452     const char *getAscizDirective() const {
453       return AscizDirective;
454     }
455     const char *getAlignDirective() const {
456       return AlignDirective;
457     }
458     bool getAlignmentIsInBytes() const {
459       return AlignmentIsInBytes;
460     }
461     unsigned getTextAlignFillValue() const {
462       return TextAlignFillValue;
463     }
464     const char *getGlobalDirective() const {
465       return GlobalDirective;
466     }
467     bool hasSetDirective() const { return HasSetDirective; }
468     bool hasAggressiveSymbolFolding() const {
469       return HasAggressiveSymbolFolding;
470     }
471     bool getCOMMDirectiveAlignmentIsInBytes() const {
472       return COMMDirectiveAlignmentIsInBytes;
473     }
474     LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
475       return LCOMMDirectiveAlignmentType;
476     }
477     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
478     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
479     bool hasIdentDirective() const { return HasIdentDirective; }
480     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
481     const char *getWeakRefDirective() const { return WeakRefDirective; }
482     bool hasWeakDefDirective() const { return HasWeakDefDirective; }
483     bool hasWeakDefCanBeHiddenDirective() const {
484       return HasWeakDefCanBeHiddenDirective;
485     }
486     bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
487
488     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
489     MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
490       return HiddenDeclarationVisibilityAttr;
491     }
492     MCSymbolAttr getProtectedVisibilityAttr() const {
493       return ProtectedVisibilityAttr;
494     }
495     bool hasLEB128() const {
496       return HasLEB128;
497     }
498     bool doesSupportDebugInformation() const {
499       return SupportsDebugInformation;
500     }
501     bool doesSupportExceptionHandling() const {
502       return ExceptionsType != ExceptionHandling::None;
503     }
504     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
505       return ExceptionsType;
506     }
507     bool isExceptionHandlingDwarf() const {
508       return
509         (ExceptionsType == ExceptionHandling::DwarfCFI ||
510          ExceptionsType == ExceptionHandling::ARM ||
511          ExceptionsType == ExceptionHandling::Win64);
512     }
513     bool doesDwarfUseRelocationsAcrossSections() const {
514       return DwarfUsesRelocationsAcrossSections;
515     }
516     bool useDwarfRegNumForCFI() const {
517       return DwarfRegNumForCFI;
518     }
519     bool useParensForSymbolVariant() const {
520       return UseParensForSymbolVariant;
521     }
522
523     void addInitialFrameState(const MCCFIInstruction &Inst) {
524       InitialFrameState.push_back(Inst);
525     }
526
527     const std::vector<MCCFIInstruction> &getInitialFrameState() const {
528       return InitialFrameState;
529     }
530   };
531 }
532
533 #endif