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 /// HasSubsectionsViaSymbols - True if this target has the MachO
42 /// .subsections_via_symbols directive.
43 bool HasSubsectionsViaSymbols; // Default is false.
45 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
46 /// the macho-specific .zerofill directive for emitting BSS Symbols.
47 bool HasMachoZeroFillDirective; // Default is false.
49 /// HasMachoTBSSDirective - True if this is a MachO target that supports
50 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
51 bool HasMachoTBSSDirective; // Default is false.
53 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
54 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
55 /// directive after the a static ctor/dtor list. This directive is only
56 /// emitted in Static relocation model.
57 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
59 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
60 /// requires that the debug_line section be of a minimum size. In practice
61 /// such a linker requires a non empty line sequence if a file is present.
62 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
64 /// MaxInstLength - This is the maximum possible length of an instruction,
65 /// which is needed to compute the size of an inline asm.
66 unsigned MaxInstLength; // Defaults to 4.
68 /// PCSymbol - The symbol used to represent the current PC. Used in PC
69 /// relative expressions.
70 const char *PCSymbol; // Defaults to "$".
72 /// SeparatorString - This string, if specified, is used to separate
73 /// instructions from each other when on the same line.
74 const char *SeparatorString; // Defaults to ';'
76 /// CommentColumn - This indicates the comment num (zero-based) at
77 /// which asm comments should be printed.
78 unsigned CommentColumn; // Defaults to 40
80 /// CommentString - This indicates the comment character used by the
82 const char *CommentString; // Defaults to "#"
84 /// LabelSuffix - This is appended to emitted labels.
85 const char *LabelSuffix; // Defaults to ":"
87 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
88 /// onto all global symbols. This is often used for "_" or ".".
89 const char *GlobalPrefix; // Defaults to ""
91 /// PrivateGlobalPrefix - This prefix is used for globals like constant
92 /// pool entries that are completely private to the .s file and should not
93 /// have names in the .o file. This is often "." or "L".
94 const char *PrivateGlobalPrefix; // Defaults to "."
96 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
97 /// be passed through the assembler but be removed by the linker. This
98 /// is "l" on Darwin, currently used for some ObjC metadata.
99 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
101 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
102 /// emit before and after an inline assembly statement.
103 const char *InlineAsmStart; // Defaults to "#APP\n"
104 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
106 /// AssemblerDialect - Which dialect of an assembler variant to use.
107 unsigned AssemblerDialect; // Defaults to 0
109 /// AllowQuotesInName - This is true if the assembler allows for complex
110 /// symbol names to be surrounded in quotes. This defaults to false.
111 bool AllowQuotesInName;
113 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
114 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
115 bool AllowNameToStartWithDigit;
117 /// AllowPeriodsInName - This is true if the assembler allows periods in
118 /// symbol names. This defaults to true.
119 bool AllowPeriodsInName;
121 //===--- Data Emission Directives -------------------------------------===//
123 /// ZeroDirective - this should be set to the directive used to get some
124 /// number of zero bytes emitted to the current section. Common cases are
125 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
126 /// Data*bitsDirective's will be used to emit zero bytes.
127 const char *ZeroDirective; // Defaults to "\t.zero\t"
129 /// AsciiDirective - This directive allows emission of an ascii string with
130 /// the standard C escape characters embedded into it.
131 const char *AsciiDirective; // Defaults to "\t.ascii\t"
133 /// AscizDirective - If not null, this allows for special handling of
134 /// zero terminated strings on this target. This is commonly supported as
135 /// ".asciz". If a target doesn't support this, it can be set to null.
136 const char *AscizDirective; // Defaults to "\t.asciz\t"
138 /// DataDirectives - These directives are used to output some unit of
139 /// integer data to the current section. If a data directive is set to
140 /// null, smaller data directives will be used to emit the large sizes.
141 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
142 const char *Data16bitsDirective; // Defaults to "\t.short\t"
143 const char *Data32bitsDirective; // Defaults to "\t.long\t"
144 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
146 /// GPRel32Directive - if non-null, a directive that is used to emit a word
147 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
148 /// on Mips or .gprel32 on Alpha.
149 const char *GPRel32Directive; // Defaults to NULL.
151 /// getDataASDirective - Return the directive that should be used to emit
152 /// data of the specified size to the specified numeric address space.
153 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
154 assert(AS != 0 && "Don't know the directives for default addr space");
158 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
159 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
160 /// normal ELF syntax (,"a,w") in .section directives.
161 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
163 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
164 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
165 /// which doesn't support the '.bss' directive only.
166 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
168 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
169 /// style mangling for functions with X86_StdCall/X86_FastCall calling
171 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
173 //===--- Alignment Information ----------------------------------------===//
175 /// AlignDirective - The directive used to emit round up to an alignment
178 const char *AlignDirective; // Defaults to "\t.align\t"
180 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
181 /// emits ".align N" directives, where N is the number of bytes to align to.
182 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
184 bool AlignmentIsInBytes; // Defaults to true
186 /// TextAlignFillValue - If non-zero, this is used to fill the executable
187 /// space created as the result of a alignment directive.
188 unsigned TextAlignFillValue; // Defaults to 0
190 //===--- Global Variable Emission Directives --------------------------===//
192 /// GlobalDirective - This is the directive used to declare a global entity.
194 const char *GlobalDirective; // Defaults to NULL.
196 /// ExternDirective - This is the directive used to declare external
199 const char *ExternDirective; // Defaults to NULL.
201 /// HasSetDirective - True if the assembler supports the .set directive.
202 bool HasSetDirective; // Defaults to true.
204 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
209 bool HasAggressiveSymbolFolding; // Defaults to true.
211 /// HasLCOMMDirective - This is true if the target supports the .lcomm
213 bool HasLCOMMDirective; // Defaults to false.
215 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
216 /// alignment is to be specified in bytes instead of log2(n).
217 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
219 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
220 /// directives, this is true for most ELF targets.
221 bool HasDotTypeDotSizeDirective; // Defaults to true.
223 /// HasSingleParameterDotFile - True if the target has a single parameter
224 /// .file directive, this is true for ELF targets.
225 bool HasSingleParameterDotFile; // Defaults to true.
227 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
229 bool HasNoDeadStrip; // Defaults to false.
231 /// HasSymbolResolver - True if this target supports the MachO
232 /// .symbol_resolver directive.
233 bool HasSymbolResolver; // Defaults to false.
235 /// WeakRefDirective - This directive, if non-null, is used to declare a
236 /// global as being a weak undefined symbol.
237 const char *WeakRefDirective; // Defaults to NULL.
239 /// WeakDefDirective - This directive, if non-null, is used to declare a
240 /// global as being a weak defined symbol.
241 const char *WeakDefDirective; // Defaults to NULL.
243 /// LinkOnceDirective - This directive, if non-null is used to declare a
244 /// global as being a weak defined symbol. This is used on cygwin/mingw.
245 const char *LinkOnceDirective; // Defaults to NULL.
247 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
248 /// declare a symbol as having hidden visibility.
249 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
251 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
252 /// is used to declare an undefined symbol as having hidden visibility.
253 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
256 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
257 /// to declare a symbol as having protected visibility.
258 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
260 //===--- Dwarf Emission Directives -----------------------------------===//
262 /// HasLEB128 - True if target asm supports leb128 directives.
263 bool HasLEB128; // Defaults to false.
265 /// SupportsDebugInformation - True if target supports emission of debugging
267 bool SupportsDebugInformation; // Defaults to false.
269 /// SupportsExceptionHandling - True if target supports exception handling.
270 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
272 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
273 /// encode inline subroutine information.
274 bool DwarfUsesInlineInfoSection; // Defaults to false.
276 /// DwarfSectionOffsetDirective - Special section offset directive.
277 const char* DwarfSectionOffsetDirective; // Defaults to NULL
279 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
280 // relocation when we want a section offset in dwarf.
281 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
283 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
284 // use EmitLabelOffsetDifference.
285 bool DwarfUsesLabelOffsetForRanges;
287 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
288 /// instead of symbolic register names in .cfi_* directives.
289 bool DwarfRegNumForCFI; // Defaults to false;
291 //===--- CBE Asm Translation Table -----------------------------------===//
293 const char *const *AsmTransCBE; // Defaults to empty
296 explicit MCAsmInfo();
297 virtual ~MCAsmInfo();
299 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
300 static unsigned getSLEB128Size(int Value);
301 static unsigned getULEB128Size(unsigned Value);
303 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
305 // Data directive accessors.
307 const char *getData8bitsDirective(unsigned AS = 0) const {
308 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
310 const char *getData16bitsDirective(unsigned AS = 0) const {
311 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
313 const char *getData32bitsDirective(unsigned AS = 0) const {
314 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
316 const char *getData64bitsDirective(unsigned AS = 0) const {
317 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
319 const char *getGPRel32Directive() const { return GPRel32Directive; }
321 /// getNonexecutableStackSection - Targets can implement this method to
322 /// specify a section to switch to if the translation unit doesn't have any
323 /// trampolines that require an executable stack.
324 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
328 virtual const MCExpr *
329 getExprForPersonalitySymbol(const MCSymbol *Sym,
331 MCStreamer &Streamer) const;
334 getExprForFDESymbol(const MCSymbol *Sym,
336 MCStreamer &Streamer) const;
338 bool usesSunStyleELFSectionSwitchSyntax() const {
339 return SunStyleELFSectionSwitchSyntax;
342 bool usesELFSectionDirectiveForBSS() const {
343 return UsesELFSectionDirectiveForBSS;
346 bool hasMicrosoftFastStdCallMangling() const {
347 return HasMicrosoftFastStdCallMangling;
352 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
353 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
354 bool hasStaticCtorDtorReferenceInStaticMode() const {
355 return HasStaticCtorDtorReferenceInStaticMode;
357 bool getLinkerRequiresNonEmptyDwarfLines() const {
358 return LinkerRequiresNonEmptyDwarfLines;
360 unsigned getMaxInstLength() const {
361 return MaxInstLength;
363 const char *getPCSymbol() const {
366 const char *getSeparatorString() const {
367 return SeparatorString;
369 unsigned getCommentColumn() const {
370 return CommentColumn;
372 const char *getCommentString() const {
373 return CommentString;
375 const char *getLabelSuffix() const {
378 const char *getGlobalPrefix() const {
381 const char *getPrivateGlobalPrefix() const {
382 return PrivateGlobalPrefix;
384 const char *getLinkerPrivateGlobalPrefix() const {
385 return LinkerPrivateGlobalPrefix;
387 const char *getInlineAsmStart() const {
388 return InlineAsmStart;
390 const char *getInlineAsmEnd() const {
393 unsigned getAssemblerDialect() const {
394 return AssemblerDialect;
396 bool doesAllowQuotesInName() const {
397 return AllowQuotesInName;
399 bool doesAllowNameToStartWithDigit() const {
400 return AllowNameToStartWithDigit;
402 bool doesAllowPeriodsInName() const {
403 return AllowPeriodsInName;
405 const char *getZeroDirective() const {
406 return ZeroDirective;
408 const char *getAsciiDirective() const {
409 return AsciiDirective;
411 const char *getAscizDirective() const {
412 return AscizDirective;
414 const char *getAlignDirective() const {
415 return AlignDirective;
417 bool getAlignmentIsInBytes() const {
418 return AlignmentIsInBytes;
420 unsigned getTextAlignFillValue() const {
421 return TextAlignFillValue;
423 const char *getGlobalDirective() const {
424 return GlobalDirective;
426 const char *getExternDirective() const {
427 return ExternDirective;
429 bool hasSetDirective() const { return HasSetDirective; }
430 bool hasAggressiveSymbolFolding() const {
431 return HasAggressiveSymbolFolding;
433 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
434 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
435 bool getCOMMDirectiveAlignmentIsInBytes() const {
436 return COMMDirectiveAlignmentIsInBytes;
438 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
439 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
440 bool hasSymbolResolver() const { return HasSymbolResolver; }
441 const char *getWeakRefDirective() const { return WeakRefDirective; }
442 const char *getWeakDefDirective() const { return WeakDefDirective; }
443 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
445 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
446 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
447 return HiddenDeclarationVisibilityAttr;
449 MCSymbolAttr getProtectedVisibilityAttr() const {
450 return ProtectedVisibilityAttr;
452 bool hasLEB128() const {
455 bool doesSupportDebugInformation() const {
456 return SupportsDebugInformation;
458 bool doesSupportExceptionHandling() const {
459 return ExceptionsType != ExceptionHandling::None;
461 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
462 return ExceptionsType;
464 bool isExceptionHandlingDwarf() const {
466 (ExceptionsType == ExceptionHandling::DwarfCFI ||
467 ExceptionsType == ExceptionHandling::ARM ||
468 ExceptionsType == ExceptionHandling::Win64);
470 bool doesDwarfUsesInlineInfoSection() const {
471 return DwarfUsesInlineInfoSection;
473 const char *getDwarfSectionOffsetDirective() const {
474 return DwarfSectionOffsetDirective;
476 bool doesDwarfRequireRelocationForSectionOffset() const {
477 return DwarfRequiresRelocationForSectionOffset;
479 bool doesDwarfUsesLabelOffsetForRanges() const {
480 return DwarfUsesLabelOffsetForRanges;
482 bool useDwarfRegNumForCFI() const {
483 return DwarfRegNumForCFI;
485 const char *const *getAsmCBE() const {