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