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"
26 /// MCAsmInfo - This class is intended to be used as a base class for asm
27 /// properties and features specific to the target.
28 namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
32 //===------------------------------------------------------------------===//
33 // Properties to be set by the target writer, used to configure asm printer.
36 /// HasSubsectionsViaSymbols - True if this target has the MachO
37 /// .subsections_via_symbols directive.
38 bool HasSubsectionsViaSymbols; // Default is false.
40 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
41 /// the macho-specific .zerofill directive for emitting BSS Symbols.
42 bool HasMachoZeroFillDirective; // Default is false.
44 /// HasMachoTBSSDirective - True if this is a MachO target that supports
45 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
46 bool HasMachoTBSSDirective; // Default is false.
48 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
49 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
50 /// directive after the a static ctor/dtor list. This directive is only
51 /// emitted in Static relocation model.
52 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
54 /// MaxInstLength - This is the maximum possible length of an instruction,
55 /// which is needed to compute the size of an inline asm.
56 unsigned MaxInstLength; // Defaults to 4.
58 /// PCSymbol - The symbol used to represent the current PC. Used in PC
59 /// relative expressions.
60 const char *PCSymbol; // Defaults to "$".
62 /// SeparatorChar - This character, if specified, is used to separate
63 /// instructions from each other when on the same line. This is used to
64 /// measure inline asm instructions.
65 char SeparatorChar; // Defaults to ';'
67 /// CommentColumn - This indicates the comment num (zero-based) at
68 /// which asm comments should be printed.
69 unsigned CommentColumn; // Defaults to 40
71 /// CommentString - This indicates the comment character used by the
73 const char *CommentString; // Defaults to "#"
75 /// LabelSuffix - This is appended to emitted labels.
76 const char *LabelSuffix; // Defaults to ":"
78 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
79 /// onto all global symbols. This is often used for "_" or ".".
80 const char *GlobalPrefix; // Defaults to ""
82 /// PrivateGlobalPrefix - This prefix is used for globals like constant
83 /// pool entries that are completely private to the .s file and should not
84 /// have names in the .o file. This is often "." or "L".
85 const char *PrivateGlobalPrefix; // Defaults to "."
87 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
88 /// be passed through the assembler but be removed by the linker. This
89 /// is "l" on Darwin, currently used for some ObjC metadata.
90 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
92 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
93 /// emit before and after an inline assembly statement.
94 const char *InlineAsmStart; // Defaults to "#APP\n"
95 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
97 /// AssemblerDialect - Which dialect of an assembler variant to use.
98 unsigned AssemblerDialect; // Defaults to 0
100 /// AllowQuotesInName - This is true if the assembler allows for complex
101 /// symbol names to be surrounded in quotes. This defaults to false.
102 bool AllowQuotesInName;
104 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
105 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
106 bool AllowNameToStartWithDigit;
108 /// AllowPeriodsInName - This is true if the assembler allows periods in
109 /// symbol names. This defaults to true.
110 bool AllowPeriodsInName;
112 //===--- Data Emission Directives -------------------------------------===//
114 /// ZeroDirective - this should be set to the directive used to get some
115 /// number of zero bytes emitted to the current section. Common cases are
116 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
117 /// Data*bitsDirective's will be used to emit zero bytes.
118 const char *ZeroDirective; // Defaults to "\t.zero\t"
120 /// AsciiDirective - This directive allows emission of an ascii string with
121 /// the standard C escape characters embedded into it.
122 const char *AsciiDirective; // Defaults to "\t.ascii\t"
124 /// AscizDirective - If not null, this allows for special handling of
125 /// zero terminated strings on this target. This is commonly supported as
126 /// ".asciz". If a target doesn't support this, it can be set to null.
127 const char *AscizDirective; // Defaults to "\t.asciz\t"
129 /// DataDirectives - These directives are used to output some unit of
130 /// integer data to the current section. If a data directive is set to
131 /// null, smaller data directives will be used to emit the large sizes.
132 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
133 const char *Data16bitsDirective; // Defaults to "\t.short\t"
134 const char *Data32bitsDirective; // Defaults to "\t.long\t"
135 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
137 /// GPRel32Directive - if non-null, a directive that is used to emit a word
138 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
139 /// on Mips or .gprel32 on Alpha.
140 const char *GPRel32Directive; // Defaults to NULL.
142 /// getDataASDirective - Return the directive that should be used to emit
143 /// data of the specified size to the specified numeric address space.
144 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
145 assert(AS != 0 && "Don't know the directives for default addr space");
149 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
150 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
151 /// normal ELF syntax (,"a,w") in .section directives.
152 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
154 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
155 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
156 /// which doesn't support the '.bss' directive only.
157 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
159 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
160 /// style mangling for functions with X86_StdCall/X86_FastCall calling
162 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
164 //===--- Alignment Information ----------------------------------------===//
166 /// AlignDirective - The directive used to emit round up to an alignment
169 const char *AlignDirective; // Defaults to "\t.align\t"
171 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
172 /// emits ".align N" directives, where N is the number of bytes to align to.
173 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
175 bool AlignmentIsInBytes; // Defaults to true
177 /// TextAlignFillValue - If non-zero, this is used to fill the executable
178 /// space created as the result of a alignment directive.
179 unsigned TextAlignFillValue; // Defaults to 0
181 //===--- Global Variable Emission Directives --------------------------===//
183 /// GlobalDirective - This is the directive used to declare a global entity.
185 const char *GlobalDirective; // Defaults to NULL.
187 /// ExternDirective - This is the directive used to declare external
190 const char *ExternDirective; // Defaults to NULL.
192 /// HasSetDirective - True if the assembler supports the .set directive.
193 bool HasSetDirective; // Defaults to true.
195 /// HasLCOMMDirective - This is true if the target supports the .lcomm
197 bool HasLCOMMDirective; // Defaults to false.
199 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
200 /// alignment is to be specified in bytes instead of log2(n).
201 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
203 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
204 /// directives, this is true for most ELF targets.
205 bool HasDotTypeDotSizeDirective; // Defaults to true.
207 /// HasSingleParameterDotFile - True if the target has a single parameter
208 /// .file directive, this is true for ELF targets.
209 bool HasSingleParameterDotFile; // Defaults to true.
211 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
213 bool HasNoDeadStrip; // Defaults to false.
215 /// WeakRefDirective - This directive, if non-null, is used to declare a
216 /// global as being a weak undefined symbol.
217 const char *WeakRefDirective; // Defaults to NULL.
219 /// WeakDefDirective - This directive, if non-null, is used to declare a
220 /// global as being a weak defined symbol.
221 const char *WeakDefDirective; // Defaults to NULL.
223 /// LinkOnceDirective - This directive, if non-null is used to declare a
224 /// global as being a weak defined symbol. This is used on cygwin/mingw.
225 const char *LinkOnceDirective; // Defaults to NULL.
227 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
228 /// declare a symbol as having hidden visibility.
229 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
231 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
232 /// to declare a symbol as having protected visibility.
233 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
235 //===--- Dwarf Emission Directives -----------------------------------===//
237 /// HasLEB128 - True if target asm supports leb128 directives.
238 bool HasLEB128; // Defaults to false.
240 /// SupportsDebugInformation - True if target supports emission of debugging
242 bool SupportsDebugInformation; // Defaults to false.
244 /// SupportsExceptionHandling - True if target supports exception handling.
245 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
247 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
248 bool DwarfRequiresFrameSection; // Defaults to true.
250 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
251 /// encode inline subroutine information.
252 bool DwarfUsesInlineInfoSection; // Defaults to false.
254 /// DwarfSectionOffsetDirective - Special section offset directive.
255 const char* DwarfSectionOffsetDirective; // Defaults to NULL
257 /// DwarfUsesAbsoluteLabelForStmtList - True if DW_AT_stmt_list needs
258 /// absolute label instead of offset.
259 bool DwarfUsesAbsoluteLabelForStmtList; // Defaults to true;
261 // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
262 // use EmitLabelOffsetDifference.
263 bool DwarfUsesLabelOffsetForRanges;
265 //===--- CBE Asm Translation Table -----------------------------------===//
267 const char *const *AsmTransCBE; // Defaults to empty
270 explicit MCAsmInfo();
271 virtual ~MCAsmInfo();
273 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
274 static unsigned getSLEB128Size(int Value);
275 static unsigned getULEB128Size(unsigned Value);
277 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
279 // Data directive accessors.
281 const char *getData8bitsDirective(unsigned AS = 0) const {
282 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
284 const char *getData16bitsDirective(unsigned AS = 0) const {
285 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
287 const char *getData32bitsDirective(unsigned AS = 0) const {
288 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
290 const char *getData64bitsDirective(unsigned AS = 0) const {
291 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
293 const char *getGPRel32Directive() const { return GPRel32Directive; }
295 /// getNonexecutableStackSection - Targets can implement this method to
296 /// specify a section to switch to if the translation unit doesn't have any
297 /// trampolines that require an executable stack.
298 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
302 bool usesSunStyleELFSectionSwitchSyntax() const {
303 return SunStyleELFSectionSwitchSyntax;
306 bool usesELFSectionDirectiveForBSS() const {
307 return UsesELFSectionDirectiveForBSS;
310 bool hasMicrosoftFastStdCallMangling() const {
311 return HasMicrosoftFastStdCallMangling;
316 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
317 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
318 bool hasStaticCtorDtorReferenceInStaticMode() const {
319 return HasStaticCtorDtorReferenceInStaticMode;
321 unsigned getMaxInstLength() const {
322 return MaxInstLength;
324 const char *getPCSymbol() const {
327 char getSeparatorChar() const {
328 return SeparatorChar;
330 unsigned getCommentColumn() const {
331 return CommentColumn;
333 const char *getCommentString() const {
334 return CommentString;
336 const char *getLabelSuffix() const {
339 const char *getGlobalPrefix() const {
342 const char *getPrivateGlobalPrefix() const {
343 return PrivateGlobalPrefix;
345 const char *getLinkerPrivateGlobalPrefix() const {
346 return LinkerPrivateGlobalPrefix;
348 const char *getInlineAsmStart() const {
349 return InlineAsmStart;
351 const char *getInlineAsmEnd() const {
354 unsigned getAssemblerDialect() const {
355 return AssemblerDialect;
357 bool doesAllowQuotesInName() const {
358 return AllowQuotesInName;
360 bool doesAllowNameToStartWithDigit() const {
361 return AllowNameToStartWithDigit;
363 bool doesAllowPeriodsInName() const {
364 return AllowPeriodsInName;
366 const char *getZeroDirective() const {
367 return ZeroDirective;
369 const char *getAsciiDirective() const {
370 return AsciiDirective;
372 const char *getAscizDirective() const {
373 return AscizDirective;
375 const char *getAlignDirective() const {
376 return AlignDirective;
378 bool getAlignmentIsInBytes() const {
379 return AlignmentIsInBytes;
381 unsigned getTextAlignFillValue() const {
382 return TextAlignFillValue;
384 const char *getGlobalDirective() const {
385 return GlobalDirective;
387 const char *getExternDirective() const {
388 return ExternDirective;
390 bool hasSetDirective() const { return HasSetDirective; }
391 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
392 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
393 bool getCOMMDirectiveAlignmentIsInBytes() const {
394 return COMMDirectiveAlignmentIsInBytes;
396 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
397 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
398 const char *getWeakRefDirective() const { return WeakRefDirective; }
399 const char *getWeakDefDirective() const { return WeakDefDirective; }
400 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
402 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
403 MCSymbolAttr getProtectedVisibilityAttr() const {
404 return ProtectedVisibilityAttr;
406 bool hasLEB128() const {
409 bool doesSupportDebugInformation() const {
410 return SupportsDebugInformation;
412 bool doesSupportExceptionHandling() const {
413 return ExceptionsType != ExceptionHandling::None;
415 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
416 return ExceptionsType;
418 bool doesDwarfRequireFrameSection() const {
419 return DwarfRequiresFrameSection;
421 bool doesDwarfUsesInlineInfoSection() const {
422 return DwarfUsesInlineInfoSection;
424 const char *getDwarfSectionOffsetDirective() const {
425 return DwarfSectionOffsetDirective;
427 bool doesDwarfUsesAbsoluteLabelForStmtList() const {
428 return DwarfUsesAbsoluteLabelForStmtList;
430 bool doesDwarfUsesLabelOffsetForRanges() const {
431 return DwarfUsesLabelOffsetForRanges;
433 const char *const *getAsmCBE() const {