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 /// AssemblerDialect - Which dialect of an assembler variant to use.
121 unsigned AssemblerDialect; // Defaults to 0
123 /// AllowQuotesInName - This is true if the assembler allows for complex
124 /// symbol names to be surrounded in quotes. This defaults to false.
125 bool AllowQuotesInName;
127 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
128 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
129 bool AllowNameToStartWithDigit;
131 /// AllowPeriodsInName - This is true if the assembler allows periods in
132 /// symbol names. This defaults to true.
133 bool AllowPeriodsInName;
135 //===--- Data Emission Directives -------------------------------------===//
137 /// ZeroDirective - this should be set to the directive used to get some
138 /// number of zero bytes emitted to the current section. Common cases are
139 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
140 /// Data*bitsDirective's will be used to emit zero bytes.
141 const char *ZeroDirective; // Defaults to "\t.zero\t"
143 /// AsciiDirective - This directive allows emission of an ascii string with
144 /// the standard C escape characters embedded into it.
145 const char *AsciiDirective; // Defaults to "\t.ascii\t"
147 /// AscizDirective - If not null, this allows for special handling of
148 /// zero terminated strings on this target. This is commonly supported as
149 /// ".asciz". If a target doesn't support this, it can be set to null.
150 const char *AscizDirective; // Defaults to "\t.asciz\t"
152 /// DataDirectives - These directives are used to output some unit of
153 /// integer data to the current section. If a data directive is set to
154 /// null, smaller data directives will be used to emit the large sizes.
155 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
156 const char *Data16bitsDirective; // Defaults to "\t.short\t"
157 const char *Data32bitsDirective; // Defaults to "\t.long\t"
158 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
160 /// GPRel32Directive - if non-null, a directive that is used to emit a word
161 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
162 /// on Mips or .gprel32 on Alpha.
163 const char *GPRel32Directive; // Defaults to NULL.
165 /// getDataASDirective - Return the directive that should be used to emit
166 /// data of the specified size to the specified numeric address space.
167 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
168 assert(AS != 0 && "Don't know the directives for default addr space");
172 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
173 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
174 /// normal ELF syntax (,"a,w") in .section directives.
175 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
177 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
178 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
179 /// which doesn't support the '.bss' directive only.
180 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
182 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
183 /// style mangling for functions with X86_StdCall/X86_FastCall calling
185 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
187 //===--- Alignment Information ----------------------------------------===//
189 /// AlignDirective - The directive used to emit round up to an alignment
192 const char *AlignDirective; // Defaults to "\t.align\t"
194 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
195 /// emits ".align N" directives, where N is the number of bytes to align to.
196 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
198 bool AlignmentIsInBytes; // Defaults to true
200 /// TextAlignFillValue - If non-zero, this is used to fill the executable
201 /// space created as the result of a alignment directive.
202 unsigned TextAlignFillValue; // Defaults to 0
204 //===--- Global Variable Emission Directives --------------------------===//
206 /// GlobalDirective - This is the directive used to declare a global entity.
208 const char *GlobalDirective; // Defaults to NULL.
210 /// ExternDirective - This is the directive used to declare external
213 const char *ExternDirective; // Defaults to NULL.
215 /// HasSetDirective - True if the assembler supports the .set directive.
216 bool HasSetDirective; // Defaults to true.
218 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
223 bool HasAggressiveSymbolFolding; // Defaults to true.
225 /// HasLCOMMDirective - This is true if the target supports the .lcomm
227 bool HasLCOMMDirective; // Defaults to false.
229 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
230 /// alignment is to be specified in bytes instead of log2(n).
231 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
233 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
234 /// directives, this is true for most ELF targets.
235 bool HasDotTypeDotSizeDirective; // Defaults to true.
237 /// HasSingleParameterDotFile - True if the target has a single parameter
238 /// .file directive, this is true for ELF targets.
239 bool HasSingleParameterDotFile; // Defaults to true.
241 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
243 bool HasNoDeadStrip; // Defaults to false.
245 /// HasSymbolResolver - True if this target supports the MachO
246 /// .symbol_resolver directive.
247 bool HasSymbolResolver; // Defaults to false.
249 /// WeakRefDirective - This directive, if non-null, is used to declare a
250 /// global as being a weak undefined symbol.
251 const char *WeakRefDirective; // Defaults to NULL.
253 /// WeakDefDirective - This directive, if non-null, is used to declare a
254 /// global as being a weak defined symbol.
255 const char *WeakDefDirective; // Defaults to NULL.
257 /// LinkOnceDirective - This directive, if non-null is used to declare a
258 /// global as being a weak defined symbol. This is used on cygwin/mingw.
259 const char *LinkOnceDirective; // Defaults to NULL.
261 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
262 /// declare a symbol as having hidden visibility.
263 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
265 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
266 /// is used to declare an undefined symbol as having hidden visibility.
267 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
270 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
271 /// to declare a symbol as having protected visibility.
272 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
274 //===--- Dwarf Emission Directives -----------------------------------===//
276 /// HasLEB128 - True if target asm supports leb128 directives.
277 bool HasLEB128; // Defaults to false.
279 /// SupportsDebugInformation - True if target supports emission of debugging
281 bool SupportsDebugInformation; // Defaults to false.
283 /// SupportsExceptionHandling - True if target supports exception handling.
284 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
286 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
287 /// encode inline subroutine information.
288 bool DwarfUsesInlineInfoSection; // Defaults to false.
290 /// DwarfSectionOffsetDirective - Special section offset directive.
291 const char* DwarfSectionOffsetDirective; // Defaults to NULL
293 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
294 // relocation when we want a section offset in dwarf.
295 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
297 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
298 // use EmitLabelOffsetDifference.
299 bool DwarfUsesLabelOffsetForRanges;
301 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
302 /// instead of symbolic register names in .cfi_* directives.
303 bool DwarfRegNumForCFI; // Defaults to false;
305 //===--- CBE Asm Translation Table -----------------------------------===//
307 const char *const *AsmTransCBE; // Defaults to empty
309 //===--- Prologue State ----------------------------------------------===//
311 std::vector<MachineMove> InitialFrameState;
314 explicit MCAsmInfo();
315 virtual ~MCAsmInfo();
317 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
318 static unsigned getSLEB128Size(int Value);
319 static unsigned getULEB128Size(unsigned Value);
321 /// getPointerSize - Get the pointer size in bytes.
322 unsigned getPointerSize() const {
326 /// islittleendian - True if the target is little endian.
327 bool isLittleEndian() const {
328 return IsLittleEndian;
331 /// isStackGrowthDirectionUp - True if target stack grow up.
332 bool isStackGrowthDirectionUp() const {
336 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
338 // Data directive accessors.
340 const char *getData8bitsDirective(unsigned AS = 0) const {
341 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
343 const char *getData16bitsDirective(unsigned AS = 0) const {
344 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
346 const char *getData32bitsDirective(unsigned AS = 0) const {
347 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
349 const char *getData64bitsDirective(unsigned AS = 0) const {
350 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
352 const char *getGPRel32Directive() const { return GPRel32Directive; }
354 /// getNonexecutableStackSection - Targets can implement this method to
355 /// specify a section to switch to if the translation unit doesn't have any
356 /// trampolines that require an executable stack.
357 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
361 virtual const MCExpr *
362 getExprForPersonalitySymbol(const MCSymbol *Sym,
364 MCStreamer &Streamer) const;
367 getExprForFDESymbol(const MCSymbol *Sym,
369 MCStreamer &Streamer) const;
371 bool usesSunStyleELFSectionSwitchSyntax() const {
372 return SunStyleELFSectionSwitchSyntax;
375 bool usesELFSectionDirectiveForBSS() const {
376 return UsesELFSectionDirectiveForBSS;
379 bool hasMicrosoftFastStdCallMangling() const {
380 return HasMicrosoftFastStdCallMangling;
385 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
386 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
387 bool hasStaticCtorDtorReferenceInStaticMode() const {
388 return HasStaticCtorDtorReferenceInStaticMode;
390 bool getLinkerRequiresNonEmptyDwarfLines() const {
391 return LinkerRequiresNonEmptyDwarfLines;
393 unsigned getMaxInstLength() const {
394 return MaxInstLength;
396 const char *getPCSymbol() const {
399 const char *getSeparatorString() const {
400 return SeparatorString;
402 unsigned getCommentColumn() const {
403 return CommentColumn;
405 const char *getCommentString() const {
406 return CommentString;
408 const char *getLabelSuffix() const {
411 const char *getGlobalPrefix() const {
414 const char *getPrivateGlobalPrefix() const {
415 return PrivateGlobalPrefix;
417 const char *getLinkerPrivateGlobalPrefix() const {
418 return LinkerPrivateGlobalPrefix;
420 const char *getInlineAsmStart() const {
421 return InlineAsmStart;
423 const char *getInlineAsmEnd() const {
426 unsigned getAssemblerDialect() const {
427 return AssemblerDialect;
429 bool doesAllowQuotesInName() const {
430 return AllowQuotesInName;
432 bool doesAllowNameToStartWithDigit() const {
433 return AllowNameToStartWithDigit;
435 bool doesAllowPeriodsInName() const {
436 return AllowPeriodsInName;
438 const char *getZeroDirective() const {
439 return ZeroDirective;
441 const char *getAsciiDirective() const {
442 return AsciiDirective;
444 const char *getAscizDirective() const {
445 return AscizDirective;
447 const char *getAlignDirective() const {
448 return AlignDirective;
450 bool getAlignmentIsInBytes() const {
451 return AlignmentIsInBytes;
453 unsigned getTextAlignFillValue() const {
454 return TextAlignFillValue;
456 const char *getGlobalDirective() const {
457 return GlobalDirective;
459 const char *getExternDirective() const {
460 return ExternDirective;
462 bool hasSetDirective() const { return HasSetDirective; }
463 bool hasAggressiveSymbolFolding() const {
464 return HasAggressiveSymbolFolding;
466 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
467 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
468 bool getCOMMDirectiveAlignmentIsInBytes() const {
469 return COMMDirectiveAlignmentIsInBytes;
471 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
472 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
473 bool hasSymbolResolver() const { return HasSymbolResolver; }
474 const char *getWeakRefDirective() const { return WeakRefDirective; }
475 const char *getWeakDefDirective() const { return WeakDefDirective; }
476 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
478 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
479 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
480 return HiddenDeclarationVisibilityAttr;
482 MCSymbolAttr getProtectedVisibilityAttr() const {
483 return ProtectedVisibilityAttr;
485 bool hasLEB128() const {
488 bool doesSupportDebugInformation() const {
489 return SupportsDebugInformation;
491 bool doesSupportExceptionHandling() const {
492 return ExceptionsType != ExceptionHandling::None;
494 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
495 return ExceptionsType;
497 bool isExceptionHandlingDwarf() const {
499 (ExceptionsType == ExceptionHandling::DwarfCFI ||
500 ExceptionsType == ExceptionHandling::ARM ||
501 ExceptionsType == ExceptionHandling::Win64);
503 bool doesDwarfUsesInlineInfoSection() const {
504 return DwarfUsesInlineInfoSection;
506 const char *getDwarfSectionOffsetDirective() const {
507 return DwarfSectionOffsetDirective;
509 bool doesDwarfRequireRelocationForSectionOffset() const {
510 return DwarfRequiresRelocationForSectionOffset;
512 bool doesDwarfUsesLabelOffsetForRanges() const {
513 return DwarfUsesLabelOffsetForRanges;
515 bool useDwarfRegNumForCFI() const {
516 return DwarfRegNumForCFI;
518 const char *const *getAsmCBE() const {
522 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
523 const MachineLocation &S) {
524 InitialFrameState.push_back(MachineMove(label, D, S));
526 const std::vector<MachineMove> &getInitialFrameState() const {
527 return InitialFrameState;