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