Remove the MachineMove class.
[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     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
93     /// relative expressions.
94     const char *PCSymbol;                    // Defaults to "$".
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     /// getDataASDirective - Return the directive that should be used to emit
200     /// data of the specified size to the specified numeric address space.
201     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
202       assert(AS != 0 && "Don't know the directives for default addr space");
203       return 0;
204     }
205
206     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
207     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
208     /// normal ELF syntax (,"a,w") in .section directives.
209     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
210
211     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
212     /// '.section' directive before the '.bss' one. It's used for PPC/Linux
213     /// which doesn't support the '.bss' directive only.
214     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
215
216     /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
217     /// style mangling for functions with X86_StdCall/X86_FastCall calling
218     /// convention.
219     bool HasMicrosoftFastStdCallMangling;    // Defaults to false.
220
221     bool NeedsDwarfSectionOffsetDirective;
222
223     //===--- Alignment Information ----------------------------------------===//
224
225     /// AlignDirective - The directive used to emit round up to an alignment
226     /// boundary.
227     ///
228     const char *AlignDirective;              // Defaults to "\t.align\t"
229
230     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
231     /// emits ".align N" directives, where N is the number of bytes to align to.
232     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
233     /// boundary.
234     bool AlignmentIsInBytes;                 // Defaults to true
235
236     /// TextAlignFillValue - If non-zero, this is used to fill the executable
237     /// space created as the result of a alignment directive.
238     unsigned TextAlignFillValue;             // Defaults to 0
239
240     //===--- Global Variable Emission Directives --------------------------===//
241
242     /// GlobalDirective - This is the directive used to declare a global entity.
243     ///
244     const char *GlobalDirective;             // Defaults to NULL.
245
246     /// ExternDirective - This is the directive used to declare external
247     /// globals.
248     ///
249     const char *ExternDirective;             // Defaults to NULL.
250
251     /// HasSetDirective - True if the assembler supports the .set directive.
252     bool HasSetDirective;                    // Defaults to true.
253
254     /// HasAggressiveSymbolFolding - False if the assembler requires that we use
255     /// Lc = a - b
256     /// .long Lc
257     /// instead of
258     /// .long a - b
259     bool HasAggressiveSymbolFolding;           // Defaults to true.
260
261     /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
262     /// alignment is to be specified in bytes instead of log2(n).
263     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
264
265     /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
266     /// target supports an alignment argument and how it is interpreted.
267     LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
268
269     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
270     /// directives, this is true for most ELF targets.
271     bool HasDotTypeDotSizeDirective;         // Defaults to true.
272
273     /// HasSingleParameterDotFile - True if the target has a single parameter
274     /// .file directive, this is true for ELF targets.
275     bool HasSingleParameterDotFile;          // Defaults to true.
276
277     /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
278     /// directive.
279     bool HasNoDeadStrip;                     // Defaults to false.
280
281     /// HasSymbolResolver - True if this target supports the MachO
282     /// .symbol_resolver directive.
283     bool HasSymbolResolver;                     // Defaults to false.
284
285     /// WeakRefDirective - This directive, if non-null, is used to declare a
286     /// global as being a weak undefined symbol.
287     const char *WeakRefDirective;            // Defaults to NULL.
288
289     /// WeakDefDirective - This directive, if non-null, is used to declare a
290     /// global as being a weak defined symbol.
291     const char *WeakDefDirective;            // Defaults to NULL.
292
293     /// LinkOnceDirective - This directive, if non-null is used to declare a
294     /// global as being a weak defined symbol.  This is used on cygwin/mingw.
295     const char *LinkOnceDirective;           // Defaults to NULL.
296
297     /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
298     /// declare a symbol as having hidden visibility.
299     MCSymbolAttr HiddenVisibilityAttr;       // Defaults to MCSA_Hidden.
300
301     /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
302     /// is used to declare an undefined symbol as having hidden visibility.
303     MCSymbolAttr HiddenDeclarationVisibilityAttr;   // Defaults to MCSA_Hidden.
304
305
306     /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
307     /// to declare a symbol as having protected visibility.
308     MCSymbolAttr ProtectedVisibilityAttr;    // Defaults to MCSA_Protected
309
310     //===--- Dwarf Emission Directives -----------------------------------===//
311
312     /// HasLEB128 - True if target asm supports leb128 directives.
313     bool HasLEB128;                          // Defaults to false.
314
315     /// SupportsDebugInformation - True if target supports emission of debugging
316     /// information.
317     bool SupportsDebugInformation;           // Defaults to false.
318
319     /// SupportsExceptionHandling - True if target supports exception handling.
320     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
321
322     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
323     /// encode inline subroutine information.
324     bool DwarfUsesInlineInfoSection;         // Defaults to false.
325
326     /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
327     /// uses relocations for references to other .debug_* sections.
328     bool DwarfUsesRelocationsAcrossSections;
329
330     /// DwarfRegNumForCFI - True if dwarf register numbers are printed
331     /// instead of symbolic register names in .cfi_* directives.
332     bool DwarfRegNumForCFI;  // Defaults to false;
333
334     //===--- Prologue State ----------------------------------------------===//
335
336     std::vector<MCCFIInstruction> InitialFrameState;
337
338   public:
339     explicit MCAsmInfo();
340     virtual ~MCAsmInfo();
341
342     // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
343     static unsigned getSLEB128Size(int Value);
344     static unsigned getULEB128Size(unsigned Value);
345
346     /// getPointerSize - Get the pointer size in bytes.
347     unsigned getPointerSize() const {
348       return PointerSize;
349     }
350
351     /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
352     /// size in bytes.
353     unsigned getCalleeSaveStackSlotSize() const {
354       return CalleeSaveStackSlotSize;
355     }
356
357     /// isLittleEndian - True if the target is little endian.
358     bool isLittleEndian() const {
359       return IsLittleEndian;
360     }
361
362     /// isStackGrowthDirectionUp - True if target stack grow up.
363     bool isStackGrowthDirectionUp() const {
364       return StackGrowsUp;
365     }
366
367     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
368
369     // Data directive accessors.
370     //
371     const char *getData8bitsDirective(unsigned AS = 0) const {
372       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
373     }
374     const char *getData16bitsDirective(unsigned AS = 0) const {
375       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
376     }
377     const char *getData32bitsDirective(unsigned AS = 0) const {
378       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
379     }
380     const char *getData64bitsDirective(unsigned AS = 0) const {
381       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
382     }
383     const char *getGPRel64Directive() const { return GPRel64Directive; }
384     const char *getGPRel32Directive() const { return GPRel32Directive; }
385
386     /// getNonexecutableStackSection - Targets can implement this method to
387     /// specify a section to switch to if the translation unit doesn't have any
388     /// trampolines that require an executable stack.
389     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
390       return 0;
391     }
392
393     virtual const MCExpr *
394     getExprForPersonalitySymbol(const MCSymbol *Sym,
395                                 unsigned Encoding,
396                                 MCStreamer &Streamer) const;
397
398     const MCExpr *
399     getExprForFDESymbol(const MCSymbol *Sym,
400                         unsigned Encoding,
401                         MCStreamer &Streamer) const;
402
403     bool usesSunStyleELFSectionSwitchSyntax() const {
404       return SunStyleELFSectionSwitchSyntax;
405     }
406
407     bool usesELFSectionDirectiveForBSS() const {
408       return UsesELFSectionDirectiveForBSS;
409     }
410
411     bool hasMicrosoftFastStdCallMangling() const {
412       return HasMicrosoftFastStdCallMangling;
413     }
414
415     bool needsDwarfSectionOffsetDirective() const {
416       return NeedsDwarfSectionOffsetDirective;
417     }
418
419     // Accessors.
420     //
421     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
422     bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
423     bool hasStaticCtorDtorReferenceInStaticMode() const {
424       return HasStaticCtorDtorReferenceInStaticMode;
425     }
426     bool getLinkerRequiresNonEmptyDwarfLines() const {
427       return LinkerRequiresNonEmptyDwarfLines;
428     }
429     unsigned getMaxInstLength() const {
430       return MaxInstLength;
431     }
432     const char *getPCSymbol() const {
433       return PCSymbol;
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 doesAllowUTF8() const {
489       return AllowUTF8;
490     }
491     bool doesSupportDataRegionDirectives() const {
492       return UseDataRegionDirectives;
493     }
494     const char *getZeroDirective() const {
495       return ZeroDirective;
496     }
497     const char *getAsciiDirective() const {
498       return AsciiDirective;
499     }
500     const char *getAscizDirective() const {
501       return AscizDirective;
502     }
503     const char *getAlignDirective() const {
504       return AlignDirective;
505     }
506     bool getAlignmentIsInBytes() const {
507       return AlignmentIsInBytes;
508     }
509     unsigned getTextAlignFillValue() const {
510       return TextAlignFillValue;
511     }
512     const char *getGlobalDirective() const {
513       return GlobalDirective;
514     }
515     const char *getExternDirective() const {
516       return ExternDirective;
517     }
518     bool hasSetDirective() const { return HasSetDirective; }
519     bool hasAggressiveSymbolFolding() const {
520       return HasAggressiveSymbolFolding;
521     }
522     bool getCOMMDirectiveAlignmentIsInBytes() const {
523       return COMMDirectiveAlignmentIsInBytes;
524     }
525     LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
526       return LCOMMDirectiveAlignmentType;
527     }
528     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
529     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
530     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
531     bool hasSymbolResolver() const { return HasSymbolResolver; }
532     const char *getWeakRefDirective() const { return WeakRefDirective; }
533     const char *getWeakDefDirective() const { return WeakDefDirective; }
534     const char *getLinkOnceDirective() const { return LinkOnceDirective; }
535
536     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
537     MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
538       return HiddenDeclarationVisibilityAttr;
539     }
540     MCSymbolAttr getProtectedVisibilityAttr() const {
541       return ProtectedVisibilityAttr;
542     }
543     bool hasLEB128() const {
544       return HasLEB128;
545     }
546     bool doesSupportDebugInformation() const {
547       return SupportsDebugInformation;
548     }
549     bool doesSupportExceptionHandling() const {
550       return ExceptionsType != ExceptionHandling::None;
551     }
552     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
553       return ExceptionsType;
554     }
555     bool isExceptionHandlingDwarf() const {
556       return
557         (ExceptionsType == ExceptionHandling::DwarfCFI ||
558          ExceptionsType == ExceptionHandling::ARM ||
559          ExceptionsType == ExceptionHandling::Win64);
560     }
561     bool doesDwarfUseInlineInfoSection() const {
562       return DwarfUsesInlineInfoSection;
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