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 /// PCSymbol - The symbol used to represent the current PC. Used in PC
93 /// relative expressions.
94 const char *PCSymbol; // Defaults to "$".
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 /// 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");
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.
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.
216 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
217 /// style mangling for functions with X86_StdCall/X86_FastCall calling
219 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
221 bool NeedsDwarfSectionOffsetDirective;
223 //===--- Alignment Information ----------------------------------------===//
225 /// AlignDirective - The directive used to emit round up to an alignment
228 const char *AlignDirective; // Defaults to "\t.align\t"
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
234 bool AlignmentIsInBytes; // Defaults to true
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
240 //===--- Global Variable Emission Directives --------------------------===//
242 /// GlobalDirective - This is the directive used to declare a global entity.
244 const char *GlobalDirective; // Defaults to NULL.
246 /// ExternDirective - This is the directive used to declare external
249 const char *ExternDirective; // Defaults to NULL.
251 /// HasSetDirective - True if the assembler supports the .set directive.
252 bool HasSetDirective; // Defaults to true.
254 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
259 bool HasAggressiveSymbolFolding; // Defaults to true.
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;
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.
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.
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.
277 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
279 bool HasNoDeadStrip; // Defaults to false.
281 /// HasSymbolResolver - True if this target supports the MachO
282 /// .symbol_resolver directive.
283 bool HasSymbolResolver; // Defaults to false.
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.
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.
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.
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.
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.
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
310 //===--- Dwarf Emission Directives -----------------------------------===//
312 /// HasLEB128 - True if target asm supports leb128 directives.
313 bool HasLEB128; // Defaults to false.
315 /// SupportsDebugInformation - True if target supports emission of debugging
317 bool SupportsDebugInformation; // Defaults to false.
319 /// SupportsExceptionHandling - True if target supports exception handling.
320 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
322 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
323 /// encode inline subroutine information.
324 bool DwarfUsesInlineInfoSection; // Defaults to false.
326 /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
327 /// uses relocations for references to other .debug_* sections.
328 bool DwarfUsesRelocationsAcrossSections;
330 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
331 /// instead of symbolic register names in .cfi_* directives.
332 bool DwarfRegNumForCFI; // Defaults to false;
334 //===--- Prologue State ----------------------------------------------===//
336 std::vector<MCCFIInstruction> InitialFrameState;
339 explicit MCAsmInfo();
340 virtual ~MCAsmInfo();
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);
346 /// getPointerSize - Get the pointer size in bytes.
347 unsigned getPointerSize() const {
351 /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
353 unsigned getCalleeSaveStackSlotSize() const {
354 return CalleeSaveStackSlotSize;
357 /// isLittleEndian - True if the target is little endian.
358 bool isLittleEndian() const {
359 return IsLittleEndian;
362 /// isStackGrowthDirectionUp - True if target stack grow up.
363 bool isStackGrowthDirectionUp() const {
367 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
369 // Data directive accessors.
371 const char *getData8bitsDirective(unsigned AS = 0) const {
372 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
374 const char *getData16bitsDirective(unsigned AS = 0) const {
375 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
377 const char *getData32bitsDirective(unsigned AS = 0) const {
378 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
380 const char *getData64bitsDirective(unsigned AS = 0) const {
381 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
383 const char *getGPRel64Directive() const { return GPRel64Directive; }
384 const char *getGPRel32Directive() const { return GPRel32Directive; }
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{
393 virtual const MCExpr *
394 getExprForPersonalitySymbol(const MCSymbol *Sym,
396 MCStreamer &Streamer) const;
399 getExprForFDESymbol(const MCSymbol *Sym,
401 MCStreamer &Streamer) const;
403 bool usesSunStyleELFSectionSwitchSyntax() const {
404 return SunStyleELFSectionSwitchSyntax;
407 bool usesELFSectionDirectiveForBSS() const {
408 return UsesELFSectionDirectiveForBSS;
411 bool hasMicrosoftFastStdCallMangling() const {
412 return HasMicrosoftFastStdCallMangling;
415 bool needsDwarfSectionOffsetDirective() const {
416 return NeedsDwarfSectionOffsetDirective;
421 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
422 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
423 bool hasStaticCtorDtorReferenceInStaticMode() const {
424 return HasStaticCtorDtorReferenceInStaticMode;
426 bool getLinkerRequiresNonEmptyDwarfLines() const {
427 return LinkerRequiresNonEmptyDwarfLines;
429 unsigned getMaxInstLength() const {
430 return MaxInstLength;
432 const char *getPCSymbol() const {
435 const char *getSeparatorString() const {
436 return SeparatorString;
438 unsigned getCommentColumn() const {
439 return CommentColumn;
441 const char *getCommentString() const {
442 return CommentString;
444 const char *getLabelSuffix() const {
448 const char *getDebugLabelSuffix() const {
449 return DebugLabelSuffix;
452 const char *getGlobalPrefix() const {
455 const char *getPrivateGlobalPrefix() const {
456 return PrivateGlobalPrefix;
458 const char *getLinkerPrivateGlobalPrefix() const {
459 return LinkerPrivateGlobalPrefix;
461 const char *getInlineAsmStart() const {
462 return InlineAsmStart;
464 const char *getInlineAsmEnd() const {
467 const char *getCode16Directive() const {
468 return Code16Directive;
470 const char *getCode32Directive() const {
471 return Code32Directive;
473 const char *getCode64Directive() const {
474 return Code64Directive;
476 unsigned getAssemblerDialect() const {
477 return AssemblerDialect;
479 bool doesAllowQuotesInName() const {
480 return AllowQuotesInName;
482 bool doesAllowNameToStartWithDigit() const {
483 return AllowNameToStartWithDigit;
485 bool doesAllowPeriodsInName() const {
486 return AllowPeriodsInName;
488 bool doesAllowUTF8() const {
491 bool doesSupportDataRegionDirectives() const {
492 return UseDataRegionDirectives;
494 const char *getZeroDirective() const {
495 return ZeroDirective;
497 const char *getAsciiDirective() const {
498 return AsciiDirective;
500 const char *getAscizDirective() const {
501 return AscizDirective;
503 const char *getAlignDirective() const {
504 return AlignDirective;
506 bool getAlignmentIsInBytes() const {
507 return AlignmentIsInBytes;
509 unsigned getTextAlignFillValue() const {
510 return TextAlignFillValue;
512 const char *getGlobalDirective() const {
513 return GlobalDirective;
515 const char *getExternDirective() const {
516 return ExternDirective;
518 bool hasSetDirective() const { return HasSetDirective; }
519 bool hasAggressiveSymbolFolding() const {
520 return HasAggressiveSymbolFolding;
522 bool getCOMMDirectiveAlignmentIsInBytes() const {
523 return COMMDirectiveAlignmentIsInBytes;
525 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
526 return LCOMMDirectiveAlignmentType;
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; }
536 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
537 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
538 return HiddenDeclarationVisibilityAttr;
540 MCSymbolAttr getProtectedVisibilityAttr() const {
541 return ProtectedVisibilityAttr;
543 bool hasLEB128() const {
546 bool doesSupportDebugInformation() const {
547 return SupportsDebugInformation;
549 bool doesSupportExceptionHandling() const {
550 return ExceptionsType != ExceptionHandling::None;
552 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
553 return ExceptionsType;
555 bool isExceptionHandlingDwarf() const {
557 (ExceptionsType == ExceptionHandling::DwarfCFI ||
558 ExceptionsType == ExceptionHandling::ARM ||
559 ExceptionsType == ExceptionHandling::Win64);
561 bool doesDwarfUseInlineInfoSection() const {
562 return DwarfUsesInlineInfoSection;
564 bool doesDwarfUseRelocationsAcrossSections() const {
565 return DwarfUsesRelocationsAcrossSections;
567 bool useDwarfRegNumForCFI() const {
568 return DwarfRegNumForCFI;
571 void addInitialFrameState(const MCCFIInstruction &Inst) {
572 InitialFrameState.push_back(Inst);
575 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
576 return InitialFrameState;