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