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