Remove the DwarfTable enum.
[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   /// MCAsmInfo - This class is intended to be used as a base class for asm
30   /// properties and features specific to the target.
31   namespace ExceptionHandling {
32     enum ExceptionsType { None, DwarfCFI, SjLj, ARM };
33   }
34
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     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
273     bool DwarfRequiresFrameSection;          // Defaults to true.
274
275     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
276     /// encode inline subroutine information.
277     bool DwarfUsesInlineInfoSection;         // Defaults to false.
278
279     /// DwarfSectionOffsetDirective - Special section offset directive.
280     const char* DwarfSectionOffsetDirective; // Defaults to NULL
281
282     /// DwarfRequiresRelocationForStmtList - True if DW_AT_stmt_list needs
283     /// a relocation to the correct offset.
284     bool DwarfRequiresRelocationForStmtList;  // Defaults to true;
285
286     // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
287     // use EmitLabelOffsetDifference.
288     bool DwarfUsesLabelOffsetForRanges;
289
290     //===--- CBE Asm Translation Table -----------------------------------===//
291
292     const char *const *AsmTransCBE;          // Defaults to empty
293
294   public:
295     explicit MCAsmInfo();
296     virtual ~MCAsmInfo();
297
298     // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
299     static unsigned getSLEB128Size(int Value);
300     static unsigned getULEB128Size(unsigned Value);
301
302     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
303
304     // Data directive accessors.
305     //
306     const char *getData8bitsDirective(unsigned AS = 0) const {
307       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
308     }
309     const char *getData16bitsDirective(unsigned AS = 0) const {
310       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
311     }
312     const char *getData32bitsDirective(unsigned AS = 0) const {
313       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
314     }
315     const char *getData64bitsDirective(unsigned AS = 0) const {
316       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
317     }
318     const char *getGPRel32Directive() const { return GPRel32Directive; }
319
320     /// getNonexecutableStackSection - Targets can implement this method to
321     /// specify a section to switch to if the translation unit doesn't have any
322     /// trampolines that require an executable stack.
323     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
324       return 0;
325     }
326
327     virtual const MCExpr *
328     getExprForPersonalitySymbol(const MCSymbol *Sym,
329                                 unsigned Encoding,
330                                 MCStreamer &Streamer) const;
331
332     const MCExpr *
333     getExprForFDESymbol(const MCSymbol *Sym,
334                         unsigned Encoding,
335                         MCStreamer &Streamer) const;
336
337     bool usesSunStyleELFSectionSwitchSyntax() const {
338       return SunStyleELFSectionSwitchSyntax;
339     }
340
341     bool usesELFSectionDirectiveForBSS() const {
342       return UsesELFSectionDirectiveForBSS;
343     }
344
345     bool hasMicrosoftFastStdCallMangling() const {
346       return HasMicrosoftFastStdCallMangling;
347     }
348
349     // Accessors.
350     //
351     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
352     bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
353     bool hasStaticCtorDtorReferenceInStaticMode() const {
354       return HasStaticCtorDtorReferenceInStaticMode;
355     }
356     bool getLinkerRequiresNonEmptyDwarfLines() const {
357       return LinkerRequiresNonEmptyDwarfLines;
358     }
359     unsigned getMaxInstLength() const {
360       return MaxInstLength;
361     }
362     const char *getPCSymbol() const {
363       return PCSymbol;
364     }
365     const char *getSeparatorString() const {
366       return SeparatorString;
367     }
368     unsigned getCommentColumn() const {
369       return CommentColumn;
370     }
371     const char *getCommentString() const {
372       return CommentString;
373     }
374     const char *getLabelSuffix() const {
375       return LabelSuffix;
376     }
377     const char *getGlobalPrefix() const {
378       return GlobalPrefix;
379     }
380     const char *getPrivateGlobalPrefix() const {
381       return PrivateGlobalPrefix;
382     }
383     const char *getLinkerPrivateGlobalPrefix() const {
384       return LinkerPrivateGlobalPrefix;
385     }
386     const char *getInlineAsmStart() const {
387       return InlineAsmStart;
388     }
389     const char *getInlineAsmEnd() const {
390       return InlineAsmEnd;
391     }
392     unsigned getAssemblerDialect() const {
393       return AssemblerDialect;
394     }
395     bool doesAllowQuotesInName() const {
396       return AllowQuotesInName;
397     }
398     bool doesAllowNameToStartWithDigit() const {
399       return AllowNameToStartWithDigit;
400     }
401     bool doesAllowPeriodsInName() const {
402       return AllowPeriodsInName;
403     }
404     const char *getZeroDirective() const {
405       return ZeroDirective;
406     }
407     const char *getAsciiDirective() const {
408       return AsciiDirective;
409     }
410     const char *getAscizDirective() const {
411       return AscizDirective;
412     }
413     const char *getAlignDirective() const {
414       return AlignDirective;
415     }
416     bool getAlignmentIsInBytes() const {
417       return AlignmentIsInBytes;
418     }
419     unsigned getTextAlignFillValue() const {
420       return TextAlignFillValue;
421     }
422     const char *getGlobalDirective() const {
423       return GlobalDirective;
424     }
425     const char *getExternDirective() const {
426       return ExternDirective;
427     }
428     bool hasSetDirective() const { return HasSetDirective; }
429     bool hasAggressiveSymbolFolding() const {
430       return HasAggressiveSymbolFolding;
431     }
432     bool hasLCOMMDirective() const { return HasLCOMMDirective; }
433     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
434     bool getCOMMDirectiveAlignmentIsInBytes() const {
435       return COMMDirectiveAlignmentIsInBytes;
436     }
437     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
438     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
439     bool hasSymbolResolver() const { return HasSymbolResolver; }
440     const char *getWeakRefDirective() const { return WeakRefDirective; }
441     const char *getWeakDefDirective() const { return WeakDefDirective; }
442     const char *getLinkOnceDirective() const { return LinkOnceDirective; }
443
444     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
445     MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
446       return HiddenDeclarationVisibilityAttr;
447     }
448     MCSymbolAttr getProtectedVisibilityAttr() const {
449       return ProtectedVisibilityAttr;
450     }
451     bool hasLEB128() const {
452       return HasLEB128;
453     }
454     bool doesSupportDebugInformation() const {
455       return SupportsDebugInformation;
456     }
457     bool doesSupportExceptionHandling() const {
458       return ExceptionsType != ExceptionHandling::None;
459     }
460     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
461       return ExceptionsType;
462     }
463     bool isExceptionHandlingDwarf() const {
464       return
465         (ExceptionsType == ExceptionHandling::DwarfCFI ||
466          ExceptionsType == ExceptionHandling::ARM);
467     }
468
469     bool doesDwarfRequireFrameSection() const {
470       return DwarfRequiresFrameSection;
471     }
472     bool doesDwarfUsesInlineInfoSection() const {
473       return DwarfUsesInlineInfoSection;
474     }
475     const char *getDwarfSectionOffsetDirective() const {
476       return DwarfSectionOffsetDirective;
477     }
478     bool doesDwarfRequireRelocationForStmtList() const {
479       return DwarfRequiresRelocationForStmtList;
480     }
481     bool doesDwarfUsesLabelOffsetForRanges() const {
482       return DwarfUsesLabelOffsetForRanges;
483     }
484     const char *const *getAsmCBE() const {
485       return AsmTransCBE;
486     }
487   };
488 }
489
490 #endif