[C++11] More 'nullptr' conversion or in some cases just using a boolean check instead...
[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     /// CommentString - This indicates the comment character used by the
105     /// assembler.
106     const char *CommentString;               // Defaults to "#"
107
108     /// LabelSuffix - This is appended to emitted labels.
109     const char *LabelSuffix;                 // Defaults to ":"
110
111     /// LabelSuffix - This is appended to emitted labels.
112     const char *DebugLabelSuffix;                 // Defaults to ":"
113
114     /// This prefix is used for globals like constant pool entries that are
115     /// completely private to the .s file and should not have names in the .o
116     /// file.
117     const char *PrivateGlobalPrefix;         // Defaults to "L"
118
119     /// This prefix is used for symbols that should be passed through the
120     /// assembler but be removed by the linker.  This is 'l' on Darwin,
121     /// currently used for some ObjC metadata.
122     /// The default of "" meast that for this system a plain private symbol
123     /// should be used.
124     const char *LinkerPrivateGlobalPrefix;    // Defaults to "".
125
126     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
127     /// emit before and after an inline assembly statement.
128     const char *InlineAsmStart;              // Defaults to "#APP\n"
129     const char *InlineAsmEnd;                // Defaults to "#NO_APP\n"
130
131     /// Code16Directive, Code32Directive, Code64Directive - These are assembly
132     /// directives that tells the assembler to interpret the following
133     /// instructions differently.
134     const char *Code16Directive;             // Defaults to ".code16"
135     const char *Code32Directive;             // Defaults to ".code32"
136     const char *Code64Directive;             // Defaults to ".code64"
137
138     /// AssemblerDialect - Which dialect of an assembler variant to use.
139     unsigned AssemblerDialect;               // Defaults to 0
140
141     /// \brief This is true if the assembler allows @ characters in symbol
142     /// names. Defaults to false.
143     bool AllowAtInName;
144
145     /// UseDataRegionDirectives - This is true if data region markers should
146     /// be printed as ".data_region/.end_data_region" directives. If false,
147     /// use "$d/$a" labels instead.
148     bool UseDataRegionDirectives;
149
150     //===--- Data Emission Directives -------------------------------------===//
151
152     /// ZeroDirective - this should be set to the directive used to get some
153     /// number of zero bytes emitted to the current section.  Common cases are
154     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
155     /// Data*bitsDirective's will be used to emit zero bytes.
156     const char *ZeroDirective;               // Defaults to "\t.zero\t"
157
158     /// AsciiDirective - This directive allows emission of an ascii string with
159     /// the standard C escape characters embedded into it.
160     const char *AsciiDirective;              // Defaults to "\t.ascii\t"
161
162     /// AscizDirective - If not null, this allows for special handling of
163     /// zero terminated strings on this target.  This is commonly supported as
164     /// ".asciz".  If a target doesn't support this, it can be set to null.
165     const char *AscizDirective;              // Defaults to "\t.asciz\t"
166
167     /// DataDirectives - These directives are used to output some unit of
168     /// integer data to the current section.  If a data directive is set to
169     /// null, smaller data directives will be used to emit the large sizes.
170     const char *Data8bitsDirective;          // Defaults to "\t.byte\t"
171     const char *Data16bitsDirective;         // Defaults to "\t.short\t"
172     const char *Data32bitsDirective;         // Defaults to "\t.long\t"
173     const char *Data64bitsDirective;         // Defaults to "\t.quad\t"
174
175     /// GPRel64Directive - if non-null, a directive that is used to emit a word
176     /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
177     /// on Mips.
178     const char *GPRel64Directive;            // Defaults to NULL.
179
180     /// GPRel32Directive - if non-null, a directive that is used to emit a word
181     /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
182     /// on Mips or .gprel32 on Alpha.
183     const char *GPRel32Directive;            // Defaults to NULL.
184
185     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
186     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
187     /// normal ELF syntax (,"a,w") in .section directives.
188     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
189
190     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
191     /// '.section' directive before the '.bss' one. It's used for PPC/Linux
192     /// which doesn't support the '.bss' directive only.
193     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
194
195     bool NeedsDwarfSectionOffsetDirective;
196
197     //===--- Alignment Information ----------------------------------------===//
198
199     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
200     /// emits ".align N" directives, where N is the number of bytes to align to.
201     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
202     /// boundary.
203     bool AlignmentIsInBytes;                 // Defaults to true
204
205     /// TextAlignFillValue - If non-zero, this is used to fill the executable
206     /// space created as the result of a alignment directive.
207     unsigned TextAlignFillValue;             // Defaults to 0
208
209     //===--- Global Variable Emission Directives --------------------------===//
210
211     /// GlobalDirective - This is the directive used to declare a global entity.
212     ///
213     const char *GlobalDirective;             // Defaults to NULL.
214
215     /// HasSetDirective - True if the assembler supports the .set directive.
216     bool HasSetDirective;                    // Defaults to true.
217
218     /// HasAggressiveSymbolFolding - False if the assembler requires that we use
219     /// Lc = a - b
220     /// .long Lc
221     /// instead of
222     /// .long a - b
223     bool HasAggressiveSymbolFolding;           // Defaults to true.
224
225     /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
226     /// alignment is to be specified in bytes instead of log2(n).
227     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
228
229     /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
230     /// target supports an alignment argument and how it is interpreted.
231     LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
232
233     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
234     /// directives, this is true for most ELF targets.
235     bool HasDotTypeDotSizeDirective;         // Defaults to true.
236
237     /// HasSingleParameterDotFile - True if the target has a single parameter
238     /// .file directive, this is true for ELF targets.
239     bool HasSingleParameterDotFile;          // Defaults to true.
240
241     /// hasIdentDirective - True if the target has a .ident directive, this is
242     /// true for ELF targets.
243     bool HasIdentDirective;                  // Defaults to false.
244
245     /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
246     /// directive.
247     bool HasNoDeadStrip;                     // Defaults to false.
248
249     /// WeakRefDirective - This directive, if non-null, is used to declare a
250     /// global as being a weak undefined symbol.
251     const char *WeakRefDirective;            // Defaults to NULL.
252
253     /// True if we have a directive to declare a global as being a weak
254     /// defined symbol.
255     bool HasWeakDefDirective;                // Defaults to false.
256
257     /// True if we have a directive to declare a global as being a weak
258     /// defined symbol that can be hidden (unexported).
259     bool HasWeakDefCanBeHiddenDirective;     // Defaults to false.
260
261     /// True if we have a .linkonce directive.  This is used on cygwin/mingw.
262     bool HasLinkOnceDirective;               // Defaults to false.
263
264     /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
265     /// declare a symbol as having hidden visibility.
266     MCSymbolAttr HiddenVisibilityAttr;       // Defaults to MCSA_Hidden.
267
268     /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
269     /// is used to declare an undefined symbol as having hidden visibility.
270     MCSymbolAttr HiddenDeclarationVisibilityAttr;   // Defaults to MCSA_Hidden.
271
272
273     /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
274     /// to declare a symbol as having protected visibility.
275     MCSymbolAttr ProtectedVisibilityAttr;    // Defaults to MCSA_Protected
276
277     //===--- Dwarf Emission Directives -----------------------------------===//
278
279     /// HasLEB128 - True if target asm supports leb128 directives.
280     bool HasLEB128;                          // Defaults to false.
281
282     /// SupportsDebugInformation - True if target supports emission of debugging
283     /// information.
284     bool SupportsDebugInformation;           // Defaults to false.
285
286     /// SupportsExceptionHandling - True if target supports exception handling.
287     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
288
289     /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
290     /// uses relocations for references to other .debug_* sections.
291     bool DwarfUsesRelocationsAcrossSections;
292
293     /// DwarfFDESymbolsUseAbsDiff - true if DWARF FDE symbol reference
294     /// relocations should be replaced by an absolute difference.
295     bool DwarfFDESymbolsUseAbsDiff;
296
297     /// DwarfRegNumForCFI - True if dwarf register numbers are printed
298     /// instead of symbolic register names in .cfi_* directives.
299     bool DwarfRegNumForCFI;  // Defaults to false;
300
301     /// UseParensForSymbolVariant - True if target uses parens to indicate the
302     /// symbol variant instead of @. For example, foo(plt) instead of foo@plt.
303     bool UseParensForSymbolVariant; // Defaults to false;
304
305     //===--- Prologue State ----------------------------------------------===//
306
307     std::vector<MCCFIInstruction> InitialFrameState;
308
309     //===--- Integrated Assembler State ----------------------------------===//
310     /// Should we use the integrated assembler?
311     /// The integrated assembler should be enabled by default (by the
312     /// constructors) when failing to parse a valid piece of assembly (inline
313     /// or otherwise) is considered a bug. It may then be overridden after
314     /// construction (see LLVMTargetMachine::initAsmInfo()).
315     bool UseIntegratedAssembler;
316
317     /// Compress DWARF debug sections. Defaults to false.
318     bool CompressDebugSections;
319
320   public:
321     explicit MCAsmInfo();
322     virtual ~MCAsmInfo();
323
324     /// getPointerSize - Get the pointer size in bytes.
325     unsigned getPointerSize() const {
326       return PointerSize;
327     }
328
329     /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
330     /// size in bytes.
331     unsigned getCalleeSaveStackSlotSize() const {
332       return CalleeSaveStackSlotSize;
333     }
334
335     /// isLittleEndian - True if the target is little endian.
336     bool isLittleEndian() const {
337       return IsLittleEndian;
338     }
339
340     /// isStackGrowthDirectionUp - True if target stack grow up.
341     bool isStackGrowthDirectionUp() const {
342       return StackGrowsUp;
343     }
344
345     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
346
347     // Data directive accessors.
348     //
349     const char *getData8bitsDirective() const {
350       return Data8bitsDirective;
351     }
352     const char *getData16bitsDirective() const {
353       return Data16bitsDirective;
354     }
355     const char *getData32bitsDirective() const {
356       return Data32bitsDirective;
357     }
358     const char *getData64bitsDirective() const {
359       return Data64bitsDirective;
360     }
361     const char *getGPRel64Directive() const { return GPRel64Directive; }
362     const char *getGPRel32Directive() const { return GPRel32Directive; }
363
364     /// getNonexecutableStackSection - Targets can implement this method to
365     /// specify a section to switch to if the translation unit doesn't have any
366     /// trampolines that require an executable stack.
367     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
368       return nullptr;
369     }
370
371     virtual const MCExpr *
372     getExprForPersonalitySymbol(const MCSymbol *Sym,
373                                 unsigned Encoding,
374                                 MCStreamer &Streamer) const;
375
376     virtual const MCExpr *
377     getExprForFDESymbol(const MCSymbol *Sym,
378                         unsigned Encoding,
379                         MCStreamer &Streamer) const;
380
381     bool usesSunStyleELFSectionSwitchSyntax() const {
382       return SunStyleELFSectionSwitchSyntax;
383     }
384
385     bool usesELFSectionDirectiveForBSS() const {
386       return UsesELFSectionDirectiveForBSS;
387     }
388
389     bool needsDwarfSectionOffsetDirective() const {
390       return NeedsDwarfSectionOffsetDirective;
391     }
392
393     // Accessors.
394     //
395     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
396     bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
397     bool hasStaticCtorDtorReferenceInStaticMode() const {
398       return HasStaticCtorDtorReferenceInStaticMode;
399     }
400     bool getLinkerRequiresNonEmptyDwarfLines() const {
401       return LinkerRequiresNonEmptyDwarfLines;
402     }
403     unsigned getMaxInstLength() const {
404       return MaxInstLength;
405     }
406     unsigned getMinInstAlignment() const {
407       return MinInstAlignment;
408     }
409     bool getDollarIsPC() const {
410       return DollarIsPC;
411     }
412     const char *getSeparatorString() const {
413       return SeparatorString;
414     }
415
416     /// This indicates the column (zero-based) at which asm comments should be
417     /// printed.
418     unsigned getCommentColumn() const {
419       return 40;
420     }
421
422     const char *getCommentString() const {
423       return CommentString;
424     }
425     const char *getLabelSuffix() const {
426       return LabelSuffix;
427     }
428
429     const char *getDebugLabelSuffix() const {
430       return DebugLabelSuffix;
431     }
432     const char *getPrivateGlobalPrefix() const {
433       return PrivateGlobalPrefix;
434     }
435     bool hasLinkerPrivateGlobalPrefix() const {
436       return LinkerPrivateGlobalPrefix[0] != '\0';
437     }
438     const char *getLinkerPrivateGlobalPrefix() const {
439       if (hasLinkerPrivateGlobalPrefix())
440         return LinkerPrivateGlobalPrefix;
441       return getPrivateGlobalPrefix();
442     }
443     const char *getInlineAsmStart() const {
444       return InlineAsmStart;
445     }
446     const char *getInlineAsmEnd() const {
447       return InlineAsmEnd;
448     }
449     const char *getCode16Directive() const {
450       return Code16Directive;
451     }
452     const char *getCode32Directive() const {
453       return Code32Directive;
454     }
455     const char *getCode64Directive() const {
456       return Code64Directive;
457     }
458     unsigned getAssemblerDialect() const {
459       return AssemblerDialect;
460     }
461     bool doesAllowAtInName() const {
462       return AllowAtInName;
463     }
464     bool doesSupportDataRegionDirectives() const {
465       return UseDataRegionDirectives;
466     }
467     const char *getZeroDirective() const {
468       return ZeroDirective;
469     }
470     const char *getAsciiDirective() const {
471       return AsciiDirective;
472     }
473     const char *getAscizDirective() const {
474       return AscizDirective;
475     }
476     bool getAlignmentIsInBytes() const {
477       return AlignmentIsInBytes;
478     }
479     unsigned getTextAlignFillValue() const {
480       return TextAlignFillValue;
481     }
482     const char *getGlobalDirective() const {
483       return GlobalDirective;
484     }
485     bool hasSetDirective() const { return HasSetDirective; }
486     bool hasAggressiveSymbolFolding() const {
487       return HasAggressiveSymbolFolding;
488     }
489     bool getCOMMDirectiveAlignmentIsInBytes() const {
490       return COMMDirectiveAlignmentIsInBytes;
491     }
492     LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
493       return LCOMMDirectiveAlignmentType;
494     }
495     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
496     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
497     bool hasIdentDirective() const { return HasIdentDirective; }
498     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
499     const char *getWeakRefDirective() const { return WeakRefDirective; }
500     bool hasWeakDefDirective() const { return HasWeakDefDirective; }
501     bool hasWeakDefCanBeHiddenDirective() const {
502       return HasWeakDefCanBeHiddenDirective;
503     }
504     bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
505
506     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
507     MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
508       return HiddenDeclarationVisibilityAttr;
509     }
510     MCSymbolAttr getProtectedVisibilityAttr() const {
511       return ProtectedVisibilityAttr;
512     }
513     bool hasLEB128() const {
514       return HasLEB128;
515     }
516     bool doesSupportDebugInformation() const {
517       return SupportsDebugInformation;
518     }
519     bool doesSupportExceptionHandling() const {
520       return ExceptionsType != ExceptionHandling::None;
521     }
522     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
523       return ExceptionsType;
524     }
525     bool isExceptionHandlingDwarf() const {
526       return
527         (ExceptionsType == ExceptionHandling::DwarfCFI ||
528          ExceptionsType == ExceptionHandling::ARM ||
529          ExceptionsType == ExceptionHandling::Win64);
530     }
531     bool doesDwarfUseRelocationsAcrossSections() const {
532       return DwarfUsesRelocationsAcrossSections;
533     }
534     bool doDwarfFDESymbolsUseAbsDiff() const {
535       return DwarfFDESymbolsUseAbsDiff;
536     }
537     bool useDwarfRegNumForCFI() const {
538       return DwarfRegNumForCFI;
539     }
540     bool useParensForSymbolVariant() const {
541       return UseParensForSymbolVariant;
542     }
543
544     void addInitialFrameState(const MCCFIInstruction &Inst) {
545       InitialFrameState.push_back(Inst);
546     }
547
548     const std::vector<MCCFIInstruction> &getInitialFrameState() const {
549       return InitialFrameState;
550     }
551
552     /// Return true if assembly (inline or otherwise) should be parsed.
553     bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
554
555     /// Set whether assembly (inline or otherwise) should be parsed.
556     virtual void setUseIntegratedAssembler(bool Value) {
557       UseIntegratedAssembler = Value;
558     }
559
560     bool compressDebugSections() const { return CompressDebugSections; }
561
562     void setCompressDebugSections(bool CompressDebugSections) {
563       this->CompressDebugSections = CompressDebugSections;
564     }
565   };
566 }
567
568 #endif