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