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/MCDirectives.h"
29 namespace ExceptionHandling {
30 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
33 /// MCAsmInfo - This class is intended to be used as a base class for asm
34 /// properties and features specific to the target.
37 //===------------------------------------------------------------------===//
38 // Properties to be set by the target writer, used to configure asm printer.
41 /// PointerSize - Pointer size in bytes.
45 /// IsLittleEndian - True if target is little endian.
49 /// StackGrowsUp - True if target stack grow up.
53 /// HasSubsectionsViaSymbols - True if this target has the MachO
54 /// .subsections_via_symbols directive.
55 bool HasSubsectionsViaSymbols; // Default is false.
57 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
58 /// the macho-specific .zerofill directive for emitting BSS Symbols.
59 bool HasMachoZeroFillDirective; // Default is false.
61 /// HasMachoTBSSDirective - True if this is a MachO target that supports
62 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
63 bool HasMachoTBSSDirective; // Default is false.
65 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
66 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
67 /// directive after the a static ctor/dtor list. This directive is only
68 /// emitted in Static relocation model.
69 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
71 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
72 /// requires that the debug_line section be of a minimum size. In practice
73 /// such a linker requires a non empty line sequence if a file is present.
74 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
76 /// MaxInstLength - This is the maximum possible length of an instruction,
77 /// which is needed to compute the size of an inline asm.
78 unsigned MaxInstLength; // Defaults to 4.
80 /// PCSymbol - The symbol used to represent the current PC. Used in PC
81 /// relative expressions.
82 const char *PCSymbol; // Defaults to "$".
84 /// SeparatorString - This string, if specified, is used to separate
85 /// instructions from each other when on the same line.
86 const char *SeparatorString; // Defaults to ';'
88 /// CommentColumn - This indicates the comment num (zero-based) at
89 /// which asm comments should be printed.
90 unsigned CommentColumn; // Defaults to 40
92 /// CommentString - This indicates the comment character used by the
94 const char *CommentString; // Defaults to "#"
96 /// LabelSuffix - This is appended to emitted labels.
97 const char *LabelSuffix; // Defaults to ":"
99 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
100 /// onto all global symbols. This is often used for "_" or ".".
101 const char *GlobalPrefix; // Defaults to ""
103 /// PrivateGlobalPrefix - This prefix is used for globals like constant
104 /// pool entries that are completely private to the .s file and should not
105 /// have names in the .o file. This is often "." or "L".
106 const char *PrivateGlobalPrefix; // Defaults to "."
108 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
109 /// be passed through the assembler but be removed by the linker. This
110 /// is "l" on Darwin, currently used for some ObjC metadata.
111 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
113 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
114 /// emit before and after an inline assembly statement.
115 const char *InlineAsmStart; // Defaults to "#APP\n"
116 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
118 /// AssemblerDialect - Which dialect of an assembler variant to use.
119 unsigned AssemblerDialect; // Defaults to 0
121 /// AllowQuotesInName - This is true if the assembler allows for complex
122 /// symbol names to be surrounded in quotes. This defaults to false.
123 bool AllowQuotesInName;
125 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
126 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
127 bool AllowNameToStartWithDigit;
129 /// AllowPeriodsInName - This is true if the assembler allows periods in
130 /// symbol names. This defaults to true.
131 bool AllowPeriodsInName;
133 //===--- Data Emission Directives -------------------------------------===//
135 /// ZeroDirective - this should be set to the directive used to get some
136 /// number of zero bytes emitted to the current section. Common cases are
137 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
138 /// Data*bitsDirective's will be used to emit zero bytes.
139 const char *ZeroDirective; // Defaults to "\t.zero\t"
141 /// AsciiDirective - This directive allows emission of an ascii string with
142 /// the standard C escape characters embedded into it.
143 const char *AsciiDirective; // Defaults to "\t.ascii\t"
145 /// AscizDirective - If not null, this allows for special handling of
146 /// zero terminated strings on this target. This is commonly supported as
147 /// ".asciz". If a target doesn't support this, it can be set to null.
148 const char *AscizDirective; // Defaults to "\t.asciz\t"
150 /// DataDirectives - These directives are used to output some unit of
151 /// integer data to the current section. If a data directive is set to
152 /// null, smaller data directives will be used to emit the large sizes.
153 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
154 const char *Data16bitsDirective; // Defaults to "\t.short\t"
155 const char *Data32bitsDirective; // Defaults to "\t.long\t"
156 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
158 /// GPRel32Directive - if non-null, a directive that is used to emit a word
159 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
160 /// on Mips or .gprel32 on Alpha.
161 const char *GPRel32Directive; // Defaults to NULL.
163 /// getDataASDirective - Return the directive that should be used to emit
164 /// data of the specified size to the specified numeric address space.
165 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
166 assert(AS != 0 && "Don't know the directives for default addr space");
170 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
171 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
172 /// normal ELF syntax (,"a,w") in .section directives.
173 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
175 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
176 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
177 /// which doesn't support the '.bss' directive only.
178 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
180 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
181 /// style mangling for functions with X86_StdCall/X86_FastCall calling
183 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
185 //===--- Alignment Information ----------------------------------------===//
187 /// AlignDirective - The directive used to emit round up to an alignment
190 const char *AlignDirective; // Defaults to "\t.align\t"
192 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
193 /// emits ".align N" directives, where N is the number of bytes to align to.
194 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
196 bool AlignmentIsInBytes; // Defaults to true
198 /// TextAlignFillValue - If non-zero, this is used to fill the executable
199 /// space created as the result of a alignment directive.
200 unsigned TextAlignFillValue; // Defaults to 0
202 //===--- Global Variable Emission Directives --------------------------===//
204 /// GlobalDirective - This is the directive used to declare a global entity.
206 const char *GlobalDirective; // Defaults to NULL.
208 /// ExternDirective - This is the directive used to declare external
211 const char *ExternDirective; // Defaults to NULL.
213 /// HasSetDirective - True if the assembler supports the .set directive.
214 bool HasSetDirective; // Defaults to true.
216 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
221 bool HasAggressiveSymbolFolding; // Defaults to true.
223 /// HasLCOMMDirective - This is true if the target supports the .lcomm
225 bool HasLCOMMDirective; // Defaults to false.
227 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
228 /// alignment is to be specified in bytes instead of log2(n).
229 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
231 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
232 /// directives, this is true for most ELF targets.
233 bool HasDotTypeDotSizeDirective; // Defaults to true.
235 /// HasSingleParameterDotFile - True if the target has a single parameter
236 /// .file directive, this is true for ELF targets.
237 bool HasSingleParameterDotFile; // Defaults to true.
239 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
241 bool HasNoDeadStrip; // Defaults to false.
243 /// HasSymbolResolver - True if this target supports the MachO
244 /// .symbol_resolver directive.
245 bool HasSymbolResolver; // Defaults to false.
247 /// WeakRefDirective - This directive, if non-null, is used to declare a
248 /// global as being a weak undefined symbol.
249 const char *WeakRefDirective; // Defaults to NULL.
251 /// WeakDefDirective - This directive, if non-null, is used to declare a
252 /// global as being a weak defined symbol.
253 const char *WeakDefDirective; // Defaults to NULL.
255 /// LinkOnceDirective - This directive, if non-null is used to declare a
256 /// global as being a weak defined symbol. This is used on cygwin/mingw.
257 const char *LinkOnceDirective; // Defaults to NULL.
259 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
260 /// declare a symbol as having hidden visibility.
261 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
263 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
264 /// is used to declare an undefined symbol as having hidden visibility.
265 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
268 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
269 /// to declare a symbol as having protected visibility.
270 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
272 //===--- Dwarf Emission Directives -----------------------------------===//
274 /// HasLEB128 - True if target asm supports leb128 directives.
275 bool HasLEB128; // Defaults to false.
277 /// SupportsDebugInformation - True if target supports emission of debugging
279 bool SupportsDebugInformation; // Defaults to false.
281 /// SupportsExceptionHandling - True if target supports exception handling.
282 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
284 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
285 /// encode inline subroutine information.
286 bool DwarfUsesInlineInfoSection; // Defaults to false.
288 /// DwarfSectionOffsetDirective - Special section offset directive.
289 const char* DwarfSectionOffsetDirective; // Defaults to NULL
291 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
292 // relocation when we want a section offset in dwarf.
293 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
295 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
296 // use EmitLabelOffsetDifference.
297 bool DwarfUsesLabelOffsetForRanges;
299 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
300 /// instead of symbolic register names in .cfi_* directives.
301 bool DwarfRegNumForCFI; // Defaults to false;
303 //===--- CBE Asm Translation Table -----------------------------------===//
305 const char *const *AsmTransCBE; // Defaults to empty
308 explicit MCAsmInfo();
309 virtual ~MCAsmInfo();
311 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
312 static unsigned getSLEB128Size(int Value);
313 static unsigned getULEB128Size(unsigned Value);
315 /// getPointerSize - Get the pointer size in bytes.
316 unsigned getPointerSize() const {
320 /// islittleendian - True if the target is little endian.
321 bool isLittleEndian() const {
322 return IsLittleEndian;
325 /// isStackGrowthDirectionUp - True if target stack grow up.
326 bool isStackGrowthDirectionUp() const {
330 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
332 // Data directive accessors.
334 const char *getData8bitsDirective(unsigned AS = 0) const {
335 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
337 const char *getData16bitsDirective(unsigned AS = 0) const {
338 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
340 const char *getData32bitsDirective(unsigned AS = 0) const {
341 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
343 const char *getData64bitsDirective(unsigned AS = 0) const {
344 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
346 const char *getGPRel32Directive() const { return GPRel32Directive; }
348 /// getNonexecutableStackSection - Targets can implement this method to
349 /// specify a section to switch to if the translation unit doesn't have any
350 /// trampolines that require an executable stack.
351 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
355 virtual const MCExpr *
356 getExprForPersonalitySymbol(const MCSymbol *Sym,
358 MCStreamer &Streamer) const;
361 getExprForFDESymbol(const MCSymbol *Sym,
363 MCStreamer &Streamer) const;
365 bool usesSunStyleELFSectionSwitchSyntax() const {
366 return SunStyleELFSectionSwitchSyntax;
369 bool usesELFSectionDirectiveForBSS() const {
370 return UsesELFSectionDirectiveForBSS;
373 bool hasMicrosoftFastStdCallMangling() const {
374 return HasMicrosoftFastStdCallMangling;
379 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
380 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
381 bool hasStaticCtorDtorReferenceInStaticMode() const {
382 return HasStaticCtorDtorReferenceInStaticMode;
384 bool getLinkerRequiresNonEmptyDwarfLines() const {
385 return LinkerRequiresNonEmptyDwarfLines;
387 unsigned getMaxInstLength() const {
388 return MaxInstLength;
390 const char *getPCSymbol() const {
393 const char *getSeparatorString() const {
394 return SeparatorString;
396 unsigned getCommentColumn() const {
397 return CommentColumn;
399 const char *getCommentString() const {
400 return CommentString;
402 const char *getLabelSuffix() const {
405 const char *getGlobalPrefix() const {
408 const char *getPrivateGlobalPrefix() const {
409 return PrivateGlobalPrefix;
411 const char *getLinkerPrivateGlobalPrefix() const {
412 return LinkerPrivateGlobalPrefix;
414 const char *getInlineAsmStart() const {
415 return InlineAsmStart;
417 const char *getInlineAsmEnd() const {
420 unsigned getAssemblerDialect() const {
421 return AssemblerDialect;
423 bool doesAllowQuotesInName() const {
424 return AllowQuotesInName;
426 bool doesAllowNameToStartWithDigit() const {
427 return AllowNameToStartWithDigit;
429 bool doesAllowPeriodsInName() const {
430 return AllowPeriodsInName;
432 const char *getZeroDirective() const {
433 return ZeroDirective;
435 const char *getAsciiDirective() const {
436 return AsciiDirective;
438 const char *getAscizDirective() const {
439 return AscizDirective;
441 const char *getAlignDirective() const {
442 return AlignDirective;
444 bool getAlignmentIsInBytes() const {
445 return AlignmentIsInBytes;
447 unsigned getTextAlignFillValue() const {
448 return TextAlignFillValue;
450 const char *getGlobalDirective() const {
451 return GlobalDirective;
453 const char *getExternDirective() const {
454 return ExternDirective;
456 bool hasSetDirective() const { return HasSetDirective; }
457 bool hasAggressiveSymbolFolding() const {
458 return HasAggressiveSymbolFolding;
460 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
461 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
462 bool getCOMMDirectiveAlignmentIsInBytes() const {
463 return COMMDirectiveAlignmentIsInBytes;
465 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
466 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
467 bool hasSymbolResolver() const { return HasSymbolResolver; }
468 const char *getWeakRefDirective() const { return WeakRefDirective; }
469 const char *getWeakDefDirective() const { return WeakDefDirective; }
470 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
472 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
473 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
474 return HiddenDeclarationVisibilityAttr;
476 MCSymbolAttr getProtectedVisibilityAttr() const {
477 return ProtectedVisibilityAttr;
479 bool hasLEB128() const {
482 bool doesSupportDebugInformation() const {
483 return SupportsDebugInformation;
485 bool doesSupportExceptionHandling() const {
486 return ExceptionsType != ExceptionHandling::None;
488 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
489 return ExceptionsType;
491 bool isExceptionHandlingDwarf() const {
493 (ExceptionsType == ExceptionHandling::DwarfCFI ||
494 ExceptionsType == ExceptionHandling::ARM ||
495 ExceptionsType == ExceptionHandling::Win64);
497 bool doesDwarfUsesInlineInfoSection() const {
498 return DwarfUsesInlineInfoSection;
500 const char *getDwarfSectionOffsetDirective() const {
501 return DwarfSectionOffsetDirective;
503 bool doesDwarfRequireRelocationForSectionOffset() const {
504 return DwarfRequiresRelocationForSectionOffset;
506 bool doesDwarfUsesLabelOffsetForRanges() const {
507 return DwarfUsesLabelOffsetForRanges;
509 bool useDwarfRegNumForCFI() const {
510 return DwarfRegNumForCFI;
512 const char *const *getAsmCBE() const {