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_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
19 #include "llvm/MC/MachineLocation.h"
20 #include "llvm/MC/MCDirectives.h"
31 namespace ExceptionHandling {
32 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
36 enum LCOMMType { None, NoAlignment, ByteAlignment };
40 enum OutputOrder { None, PriorityOrder, ReversePriorityOrder };
43 /// MCAsmInfo - This class is intended to be used as a base class for asm
44 /// properties and features specific to the target.
47 //===------------------------------------------------------------------===//
48 // Properties to be set by the target writer, used to configure asm printer.
51 /// PointerSize - Pointer size in bytes.
55 /// IsLittleEndian - True if target is little endian.
59 /// StackGrowsUp - True if target stack grow up.
63 /// HasSubsectionsViaSymbols - True if this target has the MachO
64 /// .subsections_via_symbols directive.
65 bool HasSubsectionsViaSymbols; // Default is false.
67 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
68 /// the macho-specific .zerofill directive for emitting BSS Symbols.
69 bool HasMachoZeroFillDirective; // Default is false.
71 /// HasMachoTBSSDirective - True if this is a MachO target that supports
72 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
73 bool HasMachoTBSSDirective; // Default is false.
75 /// StructorOutputOrder - Whether the static ctor/dtor list should be output
76 /// in no particular order, in order of increasing priority or the reverse:
77 /// in order of decreasing priority (the default).
78 Structors::OutputOrder StructorOutputOrder; // Default is reverse order.
80 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
81 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
82 /// directive after the a static ctor/dtor list. This directive is only
83 /// emitted in Static relocation model.
84 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
86 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
87 /// requires that the debug_line section be of a minimum size. In practice
88 /// such a linker requires a non empty line sequence if a file is present.
89 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
91 /// MaxInstLength - This is the maximum possible length of an instruction,
92 /// which is needed to compute the size of an inline asm.
93 unsigned MaxInstLength; // Defaults to 4.
95 /// PCSymbol - The symbol used to represent the current PC. Used in PC
96 /// relative expressions.
97 const char *PCSymbol; // Defaults to "$".
99 /// SeparatorString - This string, if specified, is used to separate
100 /// instructions from each other when on the same line.
101 const char *SeparatorString; // Defaults to ';'
103 /// CommentColumn - This indicates the comment num (zero-based) at
104 /// which asm comments should be printed.
105 unsigned CommentColumn; // Defaults to 40
107 /// CommentString - This indicates the comment character used by the
109 const char *CommentString; // Defaults to "#"
111 /// LabelSuffix - This is appended to emitted labels.
112 const char *LabelSuffix; // 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 //===--- Data Emission Directives -------------------------------------===//
157 /// ZeroDirective - this should be set to the directive used to get some
158 /// number of zero bytes emitted to the current section. Common cases are
159 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
160 /// Data*bitsDirective's will be used to emit zero bytes.
161 const char *ZeroDirective; // Defaults to "\t.zero\t"
163 /// AsciiDirective - This directive allows emission of an ascii string with
164 /// the standard C escape characters embedded into it.
165 const char *AsciiDirective; // Defaults to "\t.ascii\t"
167 /// AscizDirective - If not null, this allows for special handling of
168 /// zero terminated strings on this target. This is commonly supported as
169 /// ".asciz". If a target doesn't support this, it can be set to null.
170 const char *AscizDirective; // Defaults to "\t.asciz\t"
172 /// DataDirectives - These directives are used to output some unit of
173 /// integer data to the current section. If a data directive is set to
174 /// null, smaller data directives will be used to emit the large sizes.
175 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
176 const char *Data16bitsDirective; // Defaults to "\t.short\t"
177 const char *Data32bitsDirective; // Defaults to "\t.long\t"
178 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
180 /// GPRel32Directive - if non-null, a directive that is used to emit a word
181 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
182 /// on Mips or .gprel32 on Alpha.
183 const char *GPRel32Directive; // Defaults to NULL.
185 /// getDataASDirective - Return the directive that should be used to emit
186 /// data of the specified size to the specified numeric address space.
187 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
188 assert(AS != 0 && "Don't know the directives for default addr space");
192 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
193 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
194 /// normal ELF syntax (,"a,w") in .section directives.
195 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
197 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
198 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
199 /// which doesn't support the '.bss' directive only.
200 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
202 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
203 /// style mangling for functions with X86_StdCall/X86_FastCall calling
205 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
207 //===--- Alignment Information ----------------------------------------===//
209 /// AlignDirective - The directive used to emit round up to an alignment
212 const char *AlignDirective; // Defaults to "\t.align\t"
214 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
215 /// emits ".align N" directives, where N is the number of bytes to align to.
216 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
218 bool AlignmentIsInBytes; // Defaults to true
220 /// TextAlignFillValue - If non-zero, this is used to fill the executable
221 /// space created as the result of a alignment directive.
222 unsigned TextAlignFillValue; // Defaults to 0
224 //===--- Global Variable Emission Directives --------------------------===//
226 /// GlobalDirective - This is the directive used to declare a global entity.
228 const char *GlobalDirective; // Defaults to NULL.
230 /// ExternDirective - This is the directive used to declare external
233 const char *ExternDirective; // Defaults to NULL.
235 /// HasSetDirective - True if the assembler supports the .set directive.
236 bool HasSetDirective; // Defaults to true.
238 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
243 bool HasAggressiveSymbolFolding; // Defaults to true.
245 /// LCOMMDirectiveType - Describes if the target supports the .lcomm
246 /// directive and whether it has an alignment parameter.
247 LCOMM::LCOMMType LCOMMDirectiveType; // Defaults to LCOMM::None.
249 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
250 /// alignment is to be specified in bytes instead of log2(n).
251 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
253 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
254 /// directives, this is true for most ELF targets.
255 bool HasDotTypeDotSizeDirective; // Defaults to true.
257 /// HasSingleParameterDotFile - True if the target has a single parameter
258 /// .file directive, this is true for ELF targets.
259 bool HasSingleParameterDotFile; // Defaults to true.
261 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
263 bool HasNoDeadStrip; // Defaults to false.
265 /// HasSymbolResolver - True if this target supports the MachO
266 /// .symbol_resolver directive.
267 bool HasSymbolResolver; // Defaults to false.
269 /// WeakRefDirective - This directive, if non-null, is used to declare a
270 /// global as being a weak undefined symbol.
271 const char *WeakRefDirective; // Defaults to NULL.
273 /// WeakDefDirective - This directive, if non-null, is used to declare a
274 /// global as being a weak defined symbol.
275 const char *WeakDefDirective; // Defaults to NULL.
277 /// LinkOnceDirective - This directive, if non-null is used to declare a
278 /// global as being a weak defined symbol. This is used on cygwin/mingw.
279 const char *LinkOnceDirective; // Defaults to NULL.
281 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
282 /// declare a symbol as having hidden visibility.
283 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
285 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
286 /// is used to declare an undefined symbol as having hidden visibility.
287 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
290 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
291 /// to declare a symbol as having protected visibility.
292 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
294 //===--- Dwarf Emission Directives -----------------------------------===//
296 /// HasLEB128 - True if target asm supports leb128 directives.
297 bool HasLEB128; // Defaults to false.
299 /// SupportsDebugInformation - True if target supports emission of debugging
301 bool SupportsDebugInformation; // Defaults to false.
303 /// SupportsExceptionHandling - True if target supports exception handling.
304 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
306 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
307 /// encode inline subroutine information.
308 bool DwarfUsesInlineInfoSection; // Defaults to false.
310 /// DwarfSectionOffsetDirective - Special section offset directive.
311 const char* DwarfSectionOffsetDirective; // Defaults to NULL
313 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
314 // relocation when we want a section offset in dwarf.
315 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
317 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
318 // use EmitLabelOffsetDifference.
319 bool DwarfUsesLabelOffsetForRanges;
321 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
322 /// instead of symbolic register names in .cfi_* directives.
323 bool DwarfRegNumForCFI; // Defaults to false;
325 //===--- CBE Asm Translation Table -----------------------------------===//
327 const char *const *AsmTransCBE; // Defaults to empty
329 //===--- Prologue State ----------------------------------------------===//
331 std::vector<MachineMove> InitialFrameState;
334 explicit MCAsmInfo();
335 virtual ~MCAsmInfo();
337 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
338 static unsigned getSLEB128Size(int Value);
339 static unsigned getULEB128Size(unsigned Value);
341 /// getPointerSize - Get the pointer size in bytes.
342 unsigned getPointerSize() const {
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(unsigned AS = 0) const {
361 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
363 const char *getData16bitsDirective(unsigned AS = 0) const {
364 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
366 const char *getData32bitsDirective(unsigned AS = 0) const {
367 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
369 const char *getData64bitsDirective(unsigned AS = 0) const {
370 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
372 const char *getGPRel32Directive() const { return GPRel32Directive; }
374 /// getNonexecutableStackSection - Targets can implement this method to
375 /// specify a section to switch to if the translation unit doesn't have any
376 /// trampolines that require an executable stack.
377 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
381 virtual const MCExpr *
382 getExprForPersonalitySymbol(const MCSymbol *Sym,
384 MCStreamer &Streamer) const;
387 getExprForFDESymbol(const MCSymbol *Sym,
389 MCStreamer &Streamer) const;
391 bool usesSunStyleELFSectionSwitchSyntax() const {
392 return SunStyleELFSectionSwitchSyntax;
395 bool usesELFSectionDirectiveForBSS() const {
396 return UsesELFSectionDirectiveForBSS;
399 bool hasMicrosoftFastStdCallMangling() const {
400 return HasMicrosoftFastStdCallMangling;
405 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
406 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
407 Structors::OutputOrder getStructorOutputOrder() const {
408 return StructorOutputOrder;
410 bool hasStaticCtorDtorReferenceInStaticMode() const {
411 return HasStaticCtorDtorReferenceInStaticMode;
413 bool getLinkerRequiresNonEmptyDwarfLines() const {
414 return LinkerRequiresNonEmptyDwarfLines;
416 unsigned getMaxInstLength() const {
417 return MaxInstLength;
419 const char *getPCSymbol() const {
422 const char *getSeparatorString() const {
423 return SeparatorString;
425 unsigned getCommentColumn() const {
426 return CommentColumn;
428 const char *getCommentString() const {
429 return CommentString;
431 const char *getLabelSuffix() const {
434 const char *getGlobalPrefix() const {
437 const char *getPrivateGlobalPrefix() const {
438 return PrivateGlobalPrefix;
440 const char *getLinkerPrivateGlobalPrefix() const {
441 return LinkerPrivateGlobalPrefix;
443 const char *getInlineAsmStart() const {
444 return InlineAsmStart;
446 const char *getInlineAsmEnd() const {
449 const char *getCode16Directive() const {
450 return Code16Directive;
452 const char *getCode32Directive() const {
453 return Code32Directive;
455 const char *getCode64Directive() const {
456 return Code64Directive;
458 unsigned getAssemblerDialect() const {
459 return AssemblerDialect;
461 bool doesAllowQuotesInName() const {
462 return AllowQuotesInName;
464 bool doesAllowNameToStartWithDigit() const {
465 return AllowNameToStartWithDigit;
467 bool doesAllowPeriodsInName() const {
468 return AllowPeriodsInName;
470 const char *getZeroDirective() const {
471 return ZeroDirective;
473 const char *getAsciiDirective() const {
474 return AsciiDirective;
476 const char *getAscizDirective() const {
477 return AscizDirective;
479 const char *getAlignDirective() const {
480 return AlignDirective;
482 bool getAlignmentIsInBytes() const {
483 return AlignmentIsInBytes;
485 unsigned getTextAlignFillValue() const {
486 return TextAlignFillValue;
488 const char *getGlobalDirective() const {
489 return GlobalDirective;
491 const char *getExternDirective() const {
492 return ExternDirective;
494 bool hasSetDirective() const { return HasSetDirective; }
495 bool hasAggressiveSymbolFolding() const {
496 return HasAggressiveSymbolFolding;
498 LCOMM::LCOMMType getLCOMMDirectiveType() const {
499 return LCOMMDirectiveType;
501 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
502 bool getCOMMDirectiveAlignmentIsInBytes() const {
503 return COMMDirectiveAlignmentIsInBytes;
505 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
506 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
507 bool hasSymbolResolver() const { return HasSymbolResolver; }
508 const char *getWeakRefDirective() const { return WeakRefDirective; }
509 const char *getWeakDefDirective() const { return WeakDefDirective; }
510 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
512 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
513 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
514 return HiddenDeclarationVisibilityAttr;
516 MCSymbolAttr getProtectedVisibilityAttr() const {
517 return ProtectedVisibilityAttr;
519 bool hasLEB128() const {
522 bool doesSupportDebugInformation() const {
523 return SupportsDebugInformation;
525 bool doesSupportExceptionHandling() const {
526 return ExceptionsType != ExceptionHandling::None;
528 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
529 return ExceptionsType;
531 bool isExceptionHandlingDwarf() const {
533 (ExceptionsType == ExceptionHandling::DwarfCFI ||
534 ExceptionsType == ExceptionHandling::ARM ||
535 ExceptionsType == ExceptionHandling::Win64);
537 bool doesDwarfUsesInlineInfoSection() const {
538 return DwarfUsesInlineInfoSection;
540 const char *getDwarfSectionOffsetDirective() const {
541 return DwarfSectionOffsetDirective;
543 bool doesDwarfRequireRelocationForSectionOffset() const {
544 return DwarfRequiresRelocationForSectionOffset;
546 bool doesDwarfUsesLabelOffsetForRanges() const {
547 return DwarfUsesLabelOffsetForRanges;
549 bool useDwarfRegNumForCFI() const {
550 return DwarfRegNumForCFI;
552 const char *const *getAsmCBE() const {
556 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
557 const MachineLocation &S) {
558 InitialFrameState.push_back(MachineMove(label, D, S));
560 const std::vector<MachineMove> &getInitialFrameState() const {
561 return InitialFrameState;