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