1 //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_MC_MCASMINFO_H
17 #define LLVM_MC_MCASMINFO_H
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MachineLocation.h"
32 namespace ExceptionHandling {
33 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
37 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
40 /// MCAsmInfo - This class is intended to be used as a base class for asm
41 /// properties and features specific to the target.
44 //===------------------------------------------------------------------===//
45 // Properties to be set by the target writer, used to configure asm printer.
48 /// PointerSize - Pointer size in bytes.
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;
57 /// IsLittleEndian - True if target is little endian.
61 /// StackGrowsUp - True if target stack grow up.
65 /// HasSubsectionsViaSymbols - True if this target has the MachO
66 /// .subsections_via_symbols directive.
67 bool HasSubsectionsViaSymbols; // Default is false.
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.
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.
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.
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.
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.
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.
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 ';'
100 /// CommentColumn - This indicates the comment num (zero-based) at
101 /// which asm comments should be printed.
102 unsigned CommentColumn; // Defaults to 40
104 /// CommentString - This indicates the comment character used by the
106 const char *CommentString; // Defaults to "#"
108 /// LabelSuffix - This is appended to emitted labels.
109 const char *LabelSuffix; // Defaults to ":"
111 /// LabelSuffix - This is appended to emitted labels.
112 const char *DebugLabelSuffix; // Defaults to ":"
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 ""
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 "."
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 ""
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"
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"
140 /// AssemblerDialect - Which dialect of an assembler variant to use.
141 unsigned AssemblerDialect; // Defaults to 0
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;
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;
151 /// AllowPeriodsInName - This is true if the assembler allows periods in
152 /// symbol names. This defaults to true.
153 bool AllowPeriodsInName;
155 /// AllowUTF8 - This is true if the assembler accepts UTF-8 input.
156 // FIXME: Make this a more general encoding setting?
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;
164 //===--- Data Emission Directives -------------------------------------===//
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"
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"
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"
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"
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
192 const char *GPRel64Directive; // Defaults to NULL.
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.
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.
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.
209 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
210 /// style mangling for functions with X86_StdCall/X86_FastCall calling
212 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
214 bool NeedsDwarfSectionOffsetDirective;
216 //===--- Alignment Information ----------------------------------------===//
218 /// AlignDirective - The directive used to emit round up to an alignment
221 const char *AlignDirective; // Defaults to "\t.align\t"
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
227 bool AlignmentIsInBytes; // Defaults to true
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
233 //===--- Global Variable Emission Directives --------------------------===//
235 /// GlobalDirective - This is the directive used to declare a global entity.
237 const char *GlobalDirective; // Defaults to NULL.
239 /// ExternDirective - This is the directive used to declare external
242 const char *ExternDirective; // Defaults to NULL.
244 /// HasSetDirective - True if the assembler supports the .set directive.
245 bool HasSetDirective; // Defaults to true.
247 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
252 bool HasAggressiveSymbolFolding; // Defaults to true.
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;
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.
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.
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.
270 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
272 bool HasNoDeadStrip; // Defaults to false.
274 /// HasSymbolResolver - True if this target supports the MachO
275 /// .symbol_resolver directive.
276 bool HasSymbolResolver; // Defaults to false.
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.
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.
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.
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.
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.
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
303 //===--- Dwarf Emission Directives -----------------------------------===//
305 /// HasLEB128 - True if target asm supports leb128 directives.
306 bool HasLEB128; // Defaults to false.
308 /// SupportsDebugInformation - True if target supports emission of debugging
310 bool SupportsDebugInformation; // Defaults to false.
312 /// SupportsExceptionHandling - True if target supports exception handling.
313 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
315 /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
316 /// uses relocations for references to other .debug_* sections.
317 bool DwarfUsesRelocationsAcrossSections;
319 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
320 /// instead of symbolic register names in .cfi_* directives.
321 bool DwarfRegNumForCFI; // Defaults to false;
323 //===--- Prologue State ----------------------------------------------===//
325 std::vector<MCCFIInstruction> InitialFrameState;
328 explicit MCAsmInfo();
329 virtual ~MCAsmInfo();
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);
335 /// getPointerSize - Get the pointer size in bytes.
336 unsigned getPointerSize() const {
340 /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
342 unsigned getCalleeSaveStackSlotSize() const {
343 return CalleeSaveStackSlotSize;
346 /// isLittleEndian - True if the target is little endian.
347 bool isLittleEndian() const {
348 return IsLittleEndian;
351 /// isStackGrowthDirectionUp - True if target stack grow up.
352 bool isStackGrowthDirectionUp() const {
356 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
358 // Data directive accessors.
360 const char *getData8bitsDirective() const {
361 return Data8bitsDirective;
363 const char *getData16bitsDirective() const {
364 return Data16bitsDirective;
366 const char *getData32bitsDirective() const {
367 return Data32bitsDirective;
369 const char *getData64bitsDirective() const {
370 return Data64bitsDirective;
372 const char *getGPRel64Directive() const { return GPRel64Directive; }
373 const char *getGPRel32Directive() const { return GPRel32Directive; }
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{
382 virtual const MCExpr *
383 getExprForPersonalitySymbol(const MCSymbol *Sym,
385 MCStreamer &Streamer) const;
388 getExprForFDESymbol(const MCSymbol *Sym,
390 MCStreamer &Streamer) const;
392 bool usesSunStyleELFSectionSwitchSyntax() const {
393 return SunStyleELFSectionSwitchSyntax;
396 bool usesELFSectionDirectiveForBSS() const {
397 return UsesELFSectionDirectiveForBSS;
400 bool hasMicrosoftFastStdCallMangling() const {
401 return HasMicrosoftFastStdCallMangling;
404 bool needsDwarfSectionOffsetDirective() const {
405 return NeedsDwarfSectionOffsetDirective;
410 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
411 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
412 bool hasStaticCtorDtorReferenceInStaticMode() const {
413 return HasStaticCtorDtorReferenceInStaticMode;
415 bool getLinkerRequiresNonEmptyDwarfLines() const {
416 return LinkerRequiresNonEmptyDwarfLines;
418 unsigned getMaxInstLength() const {
419 return MaxInstLength;
421 unsigned getMinInstAlignment() const {
422 return MinInstAlignment;
424 const char *getSeparatorString() const {
425 return SeparatorString;
427 unsigned getCommentColumn() const {
428 return CommentColumn;
430 const char *getCommentString() const {
431 return CommentString;
433 const char *getLabelSuffix() const {
437 const char *getDebugLabelSuffix() const {
438 return DebugLabelSuffix;
441 const char *getGlobalPrefix() const {
444 const char *getPrivateGlobalPrefix() const {
445 return PrivateGlobalPrefix;
447 const char *getLinkerPrivateGlobalPrefix() const {
448 return LinkerPrivateGlobalPrefix;
450 const char *getInlineAsmStart() const {
451 return InlineAsmStart;
453 const char *getInlineAsmEnd() const {
456 const char *getCode16Directive() const {
457 return Code16Directive;
459 const char *getCode32Directive() const {
460 return Code32Directive;
462 const char *getCode64Directive() const {
463 return Code64Directive;
465 unsigned getAssemblerDialect() const {
466 return AssemblerDialect;
468 bool doesAllowQuotesInName() const {
469 return AllowQuotesInName;
471 bool doesAllowNameToStartWithDigit() const {
472 return AllowNameToStartWithDigit;
474 bool doesAllowPeriodsInName() const {
475 return AllowPeriodsInName;
477 bool doesAllowUTF8() const {
480 bool doesSupportDataRegionDirectives() const {
481 return UseDataRegionDirectives;
483 const char *getZeroDirective() const {
484 return ZeroDirective;
486 const char *getAsciiDirective() const {
487 return AsciiDirective;
489 const char *getAscizDirective() const {
490 return AscizDirective;
492 const char *getAlignDirective() const {
493 return AlignDirective;
495 bool getAlignmentIsInBytes() const {
496 return AlignmentIsInBytes;
498 unsigned getTextAlignFillValue() const {
499 return TextAlignFillValue;
501 const char *getGlobalDirective() const {
502 return GlobalDirective;
504 const char *getExternDirective() const {
505 return ExternDirective;
507 bool hasSetDirective() const { return HasSetDirective; }
508 bool hasAggressiveSymbolFolding() const {
509 return HasAggressiveSymbolFolding;
511 bool getCOMMDirectiveAlignmentIsInBytes() const {
512 return COMMDirectiveAlignmentIsInBytes;
514 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
515 return LCOMMDirectiveAlignmentType;
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; }
525 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
526 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
527 return HiddenDeclarationVisibilityAttr;
529 MCSymbolAttr getProtectedVisibilityAttr() const {
530 return ProtectedVisibilityAttr;
532 bool hasLEB128() const {
535 bool doesSupportDebugInformation() const {
536 return SupportsDebugInformation;
538 bool doesSupportExceptionHandling() const {
539 return ExceptionsType != ExceptionHandling::None;
541 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
542 return ExceptionsType;
544 bool isExceptionHandlingDwarf() const {
546 (ExceptionsType == ExceptionHandling::DwarfCFI ||
547 ExceptionsType == ExceptionHandling::ARM ||
548 ExceptionsType == ExceptionHandling::Win64);
550 bool doesDwarfUseRelocationsAcrossSections() const {
551 return DwarfUsesRelocationsAcrossSections;
553 bool useDwarfRegNumForCFI() const {
554 return DwarfRegNumForCFI;
557 void addInitialFrameState(const MCCFIInstruction &Inst) {
558 InitialFrameState.push_back(Inst);
561 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
562 return InitialFrameState;