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 };
35 /// MCAsmInfo - This class is intended to be used as a base class for asm
36 /// properties and features specific to the target.
39 //===------------------------------------------------------------------===//
40 // Properties to be set by the target writer, used to configure asm printer.
43 /// PointerSize - Pointer size in bytes.
47 /// IsLittleEndian - True if target is little endian.
51 /// StackGrowsUp - True if target stack grow up.
55 /// HasSubsectionsViaSymbols - True if this target has the MachO
56 /// .subsections_via_symbols directive.
57 bool HasSubsectionsViaSymbols; // Default is false.
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.
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.
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.
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.
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.
82 /// PCSymbol - The symbol used to represent the current PC. Used in PC
83 /// relative expressions.
84 const char *PCSymbol; // Defaults to "$".
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 ';'
90 /// CommentColumn - This indicates the comment num (zero-based) at
91 /// which asm comments should be printed.
92 unsigned CommentColumn; // Defaults to 40
94 /// CommentString - This indicates the comment character used by the
96 const char *CommentString; // Defaults to "#"
98 /// LabelSuffix - This is appended to emitted labels.
99 const char *LabelSuffix; // Defaults to ":"
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 ""
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 "."
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 ""
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"
120 /// Code16Directive, Code32Directive, Code64Directive - These are assembly
121 /// directives that tells the assembler to interpret the following
122 /// instructions differently.
123 const char *Code16Directive; // Defaults to ".code16"
124 const char *Code32Directive; // Defaults to ".code32"
125 const char *Code64Directive; // Defaults to ".code64"
127 /// AssemblerDialect - Which dialect of an assembler variant to use.
128 unsigned AssemblerDialect; // Defaults to 0
130 /// AllowQuotesInName - This is true if the assembler allows for complex
131 /// symbol names to be surrounded in quotes. This defaults to false.
132 bool AllowQuotesInName;
134 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
135 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
136 bool AllowNameToStartWithDigit;
138 /// AllowPeriodsInName - This is true if the assembler allows periods in
139 /// symbol names. This defaults to true.
140 bool AllowPeriodsInName;
142 //===--- Data Emission Directives -------------------------------------===//
144 /// ZeroDirective - this should be set to the directive used to get some
145 /// number of zero bytes emitted to the current section. Common cases are
146 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
147 /// Data*bitsDirective's will be used to emit zero bytes.
148 const char *ZeroDirective; // Defaults to "\t.zero\t"
150 /// AsciiDirective - This directive allows emission of an ascii string with
151 /// the standard C escape characters embedded into it.
152 const char *AsciiDirective; // Defaults to "\t.ascii\t"
154 /// AscizDirective - If not null, this allows for special handling of
155 /// zero terminated strings on this target. This is commonly supported as
156 /// ".asciz". If a target doesn't support this, it can be set to null.
157 const char *AscizDirective; // Defaults to "\t.asciz\t"
159 /// DataDirectives - These directives are used to output some unit of
160 /// integer data to the current section. If a data directive is set to
161 /// null, smaller data directives will be used to emit the large sizes.
162 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
163 const char *Data16bitsDirective; // Defaults to "\t.short\t"
164 const char *Data32bitsDirective; // Defaults to "\t.long\t"
165 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
167 /// GPRel32Directive - if non-null, a directive that is used to emit a word
168 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
169 /// on Mips or .gprel32 on Alpha.
170 const char *GPRel32Directive; // Defaults to NULL.
172 /// getDataASDirective - Return the directive that should be used to emit
173 /// data of the specified size to the specified numeric address space.
174 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
175 assert(AS != 0 && "Don't know the directives for default addr space");
179 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
180 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
181 /// normal ELF syntax (,"a,w") in .section directives.
182 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
184 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
185 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
186 /// which doesn't support the '.bss' directive only.
187 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
189 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
190 /// style mangling for functions with X86_StdCall/X86_FastCall calling
192 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
194 //===--- Alignment Information ----------------------------------------===//
196 /// AlignDirective - The directive used to emit round up to an alignment
199 const char *AlignDirective; // Defaults to "\t.align\t"
201 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
202 /// emits ".align N" directives, where N is the number of bytes to align to.
203 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
205 bool AlignmentIsInBytes; // Defaults to true
207 /// TextAlignFillValue - If non-zero, this is used to fill the executable
208 /// space created as the result of a alignment directive.
209 unsigned TextAlignFillValue; // Defaults to 0
211 //===--- Global Variable Emission Directives --------------------------===//
213 /// GlobalDirective - This is the directive used to declare a global entity.
215 const char *GlobalDirective; // Defaults to NULL.
217 /// ExternDirective - This is the directive used to declare external
220 const char *ExternDirective; // Defaults to NULL.
222 /// HasSetDirective - True if the assembler supports the .set directive.
223 bool HasSetDirective; // Defaults to true.
225 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
230 bool HasAggressiveSymbolFolding; // Defaults to true.
232 /// HasLCOMMDirective - This is true if the target supports the .lcomm
234 bool HasLCOMMDirective; // Defaults to false.
236 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
237 /// alignment is to be specified in bytes instead of log2(n).
238 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
240 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
241 /// directives, this is true for most ELF targets.
242 bool HasDotTypeDotSizeDirective; // Defaults to true.
244 /// HasSingleParameterDotFile - True if the target has a single parameter
245 /// .file directive, this is true for ELF targets.
246 bool HasSingleParameterDotFile; // Defaults to true.
248 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
250 bool HasNoDeadStrip; // Defaults to false.
252 /// HasSymbolResolver - True if this target supports the MachO
253 /// .symbol_resolver directive.
254 bool HasSymbolResolver; // Defaults to false.
256 /// WeakRefDirective - This directive, if non-null, is used to declare a
257 /// global as being a weak undefined symbol.
258 const char *WeakRefDirective; // Defaults to NULL.
260 /// WeakDefDirective - This directive, if non-null, is used to declare a
261 /// global as being a weak defined symbol.
262 const char *WeakDefDirective; // Defaults to NULL.
264 /// LinkOnceDirective - This directive, if non-null is used to declare a
265 /// global as being a weak defined symbol. This is used on cygwin/mingw.
266 const char *LinkOnceDirective; // Defaults to NULL.
268 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
269 /// declare a symbol as having hidden visibility.
270 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
272 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
273 /// is used to declare an undefined symbol as having hidden visibility.
274 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
277 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
278 /// to declare a symbol as having protected visibility.
279 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
281 //===--- Dwarf Emission Directives -----------------------------------===//
283 /// HasLEB128 - True if target asm supports leb128 directives.
284 bool HasLEB128; // Defaults to false.
286 /// SupportsDebugInformation - True if target supports emission of debugging
288 bool SupportsDebugInformation; // Defaults to false.
290 /// SupportsExceptionHandling - True if target supports exception handling.
291 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
293 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
294 /// encode inline subroutine information.
295 bool DwarfUsesInlineInfoSection; // Defaults to false.
297 /// DwarfSectionOffsetDirective - Special section offset directive.
298 const char* DwarfSectionOffsetDirective; // Defaults to NULL
300 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
301 // relocation when we want a section offset in dwarf.
302 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
304 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
305 // use EmitLabelOffsetDifference.
306 bool DwarfUsesLabelOffsetForRanges;
308 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
309 /// instead of symbolic register names in .cfi_* directives.
310 bool DwarfRegNumForCFI; // Defaults to false;
312 //===--- CBE Asm Translation Table -----------------------------------===//
314 const char *const *AsmTransCBE; // Defaults to empty
316 //===--- Prologue State ----------------------------------------------===//
318 std::vector<MachineMove> InitialFrameState;
321 explicit MCAsmInfo();
322 virtual ~MCAsmInfo();
324 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
325 static unsigned getSLEB128Size(int Value);
326 static unsigned getULEB128Size(unsigned Value);
328 /// getPointerSize - Get the pointer size in bytes.
329 unsigned getPointerSize() const {
333 /// islittleendian - True if the target is little endian.
334 bool isLittleEndian() const {
335 return IsLittleEndian;
338 /// isStackGrowthDirectionUp - True if target stack grow up.
339 bool isStackGrowthDirectionUp() const {
343 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
345 // Data directive accessors.
347 const char *getData8bitsDirective(unsigned AS = 0) const {
348 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
350 const char *getData16bitsDirective(unsigned AS = 0) const {
351 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
353 const char *getData32bitsDirective(unsigned AS = 0) const {
354 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
356 const char *getData64bitsDirective(unsigned AS = 0) const {
357 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
359 const char *getGPRel32Directive() const { return GPRel32Directive; }
361 /// getNonexecutableStackSection - Targets can implement this method to
362 /// specify a section to switch to if the translation unit doesn't have any
363 /// trampolines that require an executable stack.
364 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
368 virtual const MCExpr *
369 getExprForPersonalitySymbol(const MCSymbol *Sym,
371 MCStreamer &Streamer) const;
374 getExprForFDESymbol(const MCSymbol *Sym,
376 MCStreamer &Streamer) const;
378 bool usesSunStyleELFSectionSwitchSyntax() const {
379 return SunStyleELFSectionSwitchSyntax;
382 bool usesELFSectionDirectiveForBSS() const {
383 return UsesELFSectionDirectiveForBSS;
386 bool hasMicrosoftFastStdCallMangling() const {
387 return HasMicrosoftFastStdCallMangling;
392 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
393 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
394 bool hasStaticCtorDtorReferenceInStaticMode() const {
395 return HasStaticCtorDtorReferenceInStaticMode;
397 bool getLinkerRequiresNonEmptyDwarfLines() const {
398 return LinkerRequiresNonEmptyDwarfLines;
400 unsigned getMaxInstLength() const {
401 return MaxInstLength;
403 const char *getPCSymbol() const {
406 const char *getSeparatorString() const {
407 return SeparatorString;
409 unsigned getCommentColumn() const {
410 return CommentColumn;
412 const char *getCommentString() const {
413 return CommentString;
415 const char *getLabelSuffix() const {
418 const char *getGlobalPrefix() const {
421 const char *getPrivateGlobalPrefix() const {
422 return PrivateGlobalPrefix;
424 const char *getLinkerPrivateGlobalPrefix() const {
425 return LinkerPrivateGlobalPrefix;
427 const char *getInlineAsmStart() const {
428 return InlineAsmStart;
430 const char *getInlineAsmEnd() const {
433 const char *getCode16Directive() const {
434 return Code16Directive;
436 const char *getCode32Directive() const {
437 return Code32Directive;
439 const char *getCode64Directive() const {
440 return Code64Directive;
442 unsigned getAssemblerDialect() const {
443 return AssemblerDialect;
445 bool doesAllowQuotesInName() const {
446 return AllowQuotesInName;
448 bool doesAllowNameToStartWithDigit() const {
449 return AllowNameToStartWithDigit;
451 bool doesAllowPeriodsInName() const {
452 return AllowPeriodsInName;
454 const char *getZeroDirective() const {
455 return ZeroDirective;
457 const char *getAsciiDirective() const {
458 return AsciiDirective;
460 const char *getAscizDirective() const {
461 return AscizDirective;
463 const char *getAlignDirective() const {
464 return AlignDirective;
466 bool getAlignmentIsInBytes() const {
467 return AlignmentIsInBytes;
469 unsigned getTextAlignFillValue() const {
470 return TextAlignFillValue;
472 const char *getGlobalDirective() const {
473 return GlobalDirective;
475 const char *getExternDirective() const {
476 return ExternDirective;
478 bool hasSetDirective() const { return HasSetDirective; }
479 bool hasAggressiveSymbolFolding() const {
480 return HasAggressiveSymbolFolding;
482 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
483 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
484 bool getCOMMDirectiveAlignmentIsInBytes() const {
485 return COMMDirectiveAlignmentIsInBytes;
487 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
488 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
489 bool hasSymbolResolver() const { return HasSymbolResolver; }
490 const char *getWeakRefDirective() const { return WeakRefDirective; }
491 const char *getWeakDefDirective() const { return WeakDefDirective; }
492 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
494 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
495 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
496 return HiddenDeclarationVisibilityAttr;
498 MCSymbolAttr getProtectedVisibilityAttr() const {
499 return ProtectedVisibilityAttr;
501 bool hasLEB128() const {
504 bool doesSupportDebugInformation() const {
505 return SupportsDebugInformation;
507 bool doesSupportExceptionHandling() const {
508 return ExceptionsType != ExceptionHandling::None;
510 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
511 return ExceptionsType;
513 bool isExceptionHandlingDwarf() const {
515 (ExceptionsType == ExceptionHandling::DwarfCFI ||
516 ExceptionsType == ExceptionHandling::ARM ||
517 ExceptionsType == ExceptionHandling::Win64);
519 bool doesDwarfUsesInlineInfoSection() const {
520 return DwarfUsesInlineInfoSection;
522 const char *getDwarfSectionOffsetDirective() const {
523 return DwarfSectionOffsetDirective;
525 bool doesDwarfRequireRelocationForSectionOffset() const {
526 return DwarfRequiresRelocationForSectionOffset;
528 bool doesDwarfUsesLabelOffsetForRanges() const {
529 return DwarfUsesLabelOffsetForRanges;
531 bool useDwarfRegNumForCFI() const {
532 return DwarfRegNumForCFI;
534 const char *const *getAsmCBE() const {
538 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
539 const MachineLocation &S) {
540 InitialFrameState.push_back(MachineMove(label, D, S));
542 const std::vector<MachineMove> &getInitialFrameState() const {
543 return InitialFrameState;