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 /// MCAsmInfo - This class is intended to be used as a base class for asm
30 /// properties and features specific to the target.
31 namespace ExceptionHandling {
32 enum ExceptionsType { None, DwarfTable, DwarfCFI, SjLj, ARM };
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 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
273 bool DwarfRequiresFrameSection; // Defaults to true.
275 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
276 /// encode inline subroutine information.
277 bool DwarfUsesInlineInfoSection; // Defaults to false.
279 /// DwarfSectionOffsetDirective - Special section offset directive.
280 const char* DwarfSectionOffsetDirective; // Defaults to NULL
282 /// DwarfUsesAbsoluteLabelForStmtList - True if DW_AT_stmt_list needs
283 /// absolute label instead of offset.
284 bool DwarfUsesAbsoluteLabelForStmtList; // Defaults to true;
286 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
287 // use EmitLabelOffsetDifference.
288 bool DwarfUsesLabelOffsetForRanges;
290 //===--- CBE Asm Translation Table -----------------------------------===//
292 const char *const *AsmTransCBE; // Defaults to empty
295 explicit MCAsmInfo();
296 virtual ~MCAsmInfo();
298 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
299 static unsigned getSLEB128Size(int Value);
300 static unsigned getULEB128Size(unsigned Value);
302 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
304 // Data directive accessors.
306 const char *getData8bitsDirective(unsigned AS = 0) const {
307 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
309 const char *getData16bitsDirective(unsigned AS = 0) const {
310 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
312 const char *getData32bitsDirective(unsigned AS = 0) const {
313 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
315 const char *getData64bitsDirective(unsigned AS = 0) const {
316 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
318 const char *getGPRel32Directive() const { return GPRel32Directive; }
320 /// getNonexecutableStackSection - Targets can implement this method to
321 /// specify a section to switch to if the translation unit doesn't have any
322 /// trampolines that require an executable stack.
323 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
327 virtual const MCExpr *
328 getExprForPersonalitySymbol(const MCSymbol *Sym,
330 MCStreamer &Streamer) const;
333 getExprForFDESymbol(const MCSymbol *Sym,
335 MCStreamer &Streamer) const;
337 bool usesSunStyleELFSectionSwitchSyntax() const {
338 return SunStyleELFSectionSwitchSyntax;
341 bool usesELFSectionDirectiveForBSS() const {
342 return UsesELFSectionDirectiveForBSS;
345 bool hasMicrosoftFastStdCallMangling() const {
346 return HasMicrosoftFastStdCallMangling;
351 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
352 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
353 bool hasStaticCtorDtorReferenceInStaticMode() const {
354 return HasStaticCtorDtorReferenceInStaticMode;
356 bool getLinkerRequiresNonEmptyDwarfLines() const {
357 return LinkerRequiresNonEmptyDwarfLines;
359 unsigned getMaxInstLength() const {
360 return MaxInstLength;
362 const char *getPCSymbol() const {
365 const char *getSeparatorString() const {
366 return SeparatorString;
368 unsigned getCommentColumn() const {
369 return CommentColumn;
371 const char *getCommentString() const {
372 return CommentString;
374 const char *getLabelSuffix() const {
377 const char *getGlobalPrefix() const {
380 const char *getPrivateGlobalPrefix() const {
381 return PrivateGlobalPrefix;
383 const char *getLinkerPrivateGlobalPrefix() const {
384 return LinkerPrivateGlobalPrefix;
386 const char *getInlineAsmStart() const {
387 return InlineAsmStart;
389 const char *getInlineAsmEnd() const {
392 unsigned getAssemblerDialect() const {
393 return AssemblerDialect;
395 bool doesAllowQuotesInName() const {
396 return AllowQuotesInName;
398 bool doesAllowNameToStartWithDigit() const {
399 return AllowNameToStartWithDigit;
401 bool doesAllowPeriodsInName() const {
402 return AllowPeriodsInName;
404 const char *getZeroDirective() const {
405 return ZeroDirective;
407 const char *getAsciiDirective() const {
408 return AsciiDirective;
410 const char *getAscizDirective() const {
411 return AscizDirective;
413 const char *getAlignDirective() const {
414 return AlignDirective;
416 bool getAlignmentIsInBytes() const {
417 return AlignmentIsInBytes;
419 unsigned getTextAlignFillValue() const {
420 return TextAlignFillValue;
422 const char *getGlobalDirective() const {
423 return GlobalDirective;
425 const char *getExternDirective() const {
426 return ExternDirective;
428 bool hasSetDirective() const { return HasSetDirective; }
429 bool hasAggressiveSymbolFolding() const {
430 return HasAggressiveSymbolFolding;
432 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
433 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
434 bool getCOMMDirectiveAlignmentIsInBytes() const {
435 return COMMDirectiveAlignmentIsInBytes;
437 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
438 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
439 bool hasSymbolResolver() const { return HasSymbolResolver; }
440 const char *getWeakRefDirective() const { return WeakRefDirective; }
441 const char *getWeakDefDirective() const { return WeakDefDirective; }
442 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
444 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
445 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
446 return HiddenDeclarationVisibilityAttr;
448 MCSymbolAttr getProtectedVisibilityAttr() const {
449 return ProtectedVisibilityAttr;
451 bool hasLEB128() const {
454 bool doesSupportDebugInformation() const {
455 return SupportsDebugInformation;
457 bool doesSupportExceptionHandling() const {
458 return ExceptionsType != ExceptionHandling::None;
460 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
461 return ExceptionsType;
463 bool isExceptionHandlingDwarf() const {
465 (ExceptionsType == ExceptionHandling::DwarfTable ||
466 ExceptionsType == ExceptionHandling::DwarfCFI ||
467 ExceptionsType == ExceptionHandling::ARM);
470 bool doesDwarfRequireFrameSection() const {
471 return DwarfRequiresFrameSection;
473 bool doesDwarfUsesInlineInfoSection() const {
474 return DwarfUsesInlineInfoSection;
476 const char *getDwarfSectionOffsetDirective() const {
477 return DwarfSectionOffsetDirective;
479 bool doesDwarfUsesAbsoluteLabelForStmtList() const {
480 return DwarfUsesAbsoluteLabelForStmtList;
482 bool doesDwarfUsesLabelOffsetForRanges() const {
483 return DwarfUsesLabelOffsetForRanges;
485 const char *const *getAsmCBE() const {