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 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
45 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
46 /// directive after the a static ctor/dtor list. This directive is only
47 /// emitted in Static relocation model.
48 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
50 /// MaxInstLength - This is the maximum possible length of an instruction,
51 /// which is needed to compute the size of an inline asm.
52 unsigned MaxInstLength; // Defaults to 4.
54 /// PCSymbol - The symbol used to represent the current PC. Used in PC
55 /// relative expressions.
56 const char *PCSymbol; // Defaults to "$".
58 /// SeparatorChar - This character, if specified, is used to separate
59 /// instructions from each other when on the same line. This is used to
60 /// measure inline asm instructions.
61 char SeparatorChar; // Defaults to ';'
63 /// CommentColumn - This indicates the comment num (zero-based) at
64 /// which asm comments should be printed.
65 unsigned CommentColumn; // Defaults to 40
67 /// CommentString - This indicates the comment character used by the
69 const char *CommentString; // Defaults to "#"
71 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
72 /// onto all global symbols. This is often used for "_" or ".".
73 const char *GlobalPrefix; // Defaults to ""
75 /// PrivateGlobalPrefix - This prefix is used for globals like constant
76 /// pool entries that are completely private to the .s file and should not
77 /// have names in the .o file. This is often "." or "L".
78 const char *PrivateGlobalPrefix; // Defaults to "."
80 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
81 /// be passed through the assembler but be removed by the linker. This
82 /// is "l" on Darwin, currently used for some ObjC metadata.
83 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
85 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
86 /// emit before and after an inline assembly statement.
87 const char *InlineAsmStart; // Defaults to "#APP\n"
88 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
90 /// AssemblerDialect - Which dialect of an assembler variant to use.
91 unsigned AssemblerDialect; // Defaults to 0
93 /// AllowQuotesInName - This is true if the assembler allows for complex
94 /// symbol names to be surrounded in quotes. This defaults to false.
95 bool AllowQuotesInName;
97 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
98 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
99 bool AllowNameToStartWithDigit;
101 /// AllowPeriodsInName - This is true if the assembler allows periods in
102 /// symbol names. This defaults to true.
103 bool AllowPeriodsInName;
105 //===--- Data Emission Directives -------------------------------------===//
107 /// ZeroDirective - this should be set to the directive used to get some
108 /// number of zero bytes emitted to the current section. Common cases are
109 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
110 /// Data*bitsDirective's will be used to emit zero bytes.
111 const char *ZeroDirective; // Defaults to "\t.zero\t"
113 /// AsciiDirective - This directive allows emission of an ascii string with
114 /// the standard C escape characters embedded into it.
115 const char *AsciiDirective; // Defaults to "\t.ascii\t"
117 /// AscizDirective - If not null, this allows for special handling of
118 /// zero terminated strings on this target. This is commonly supported as
119 /// ".asciz". If a target doesn't support this, it can be set to null.
120 const char *AscizDirective; // Defaults to "\t.asciz\t"
122 /// DataDirectives - These directives are used to output some unit of
123 /// integer data to the current section. If a data directive is set to
124 /// null, smaller data directives will be used to emit the large sizes.
125 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
126 const char *Data16bitsDirective; // Defaults to "\t.short\t"
127 const char *Data32bitsDirective; // Defaults to "\t.long\t"
128 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
130 /// GPRel32Directive - if non-null, a directive that is used to emit a word
131 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
132 /// on Mips or .gprel32 on Alpha.
133 const char *GPRel32Directive; // Defaults to NULL.
135 /// getDataASDirective - Return the directive that should be used to emit
136 /// data of the specified size to the specified numeric address space.
137 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
138 assert(AS != 0 && "Don't know the directives for default addr space");
142 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
143 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
144 /// normal ELF syntax (,"a,w") in .section directives.
145 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
147 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
148 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
149 /// which doesn't support the '.bss' directive only.
150 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
152 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
153 /// style mangling for functions with X86_StdCall/X86_FastCall calling
155 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
157 //===--- Alignment Information ----------------------------------------===//
159 /// AlignDirective - The directive used to emit round up to an alignment
162 const char *AlignDirective; // Defaults to "\t.align\t"
164 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
165 /// emits ".align N" directives, where N is the number of bytes to align to.
166 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
168 bool AlignmentIsInBytes; // Defaults to true
170 /// TextAlignFillValue - If non-zero, this is used to fill the executable
171 /// space created as the result of a alignment directive.
172 unsigned TextAlignFillValue; // Defaults to 0
174 //===--- Global Variable Emission Directives --------------------------===//
176 /// GlobalDirective - This is the directive used to declare a global entity.
178 const char *GlobalDirective; // Defaults to NULL.
180 /// ExternDirective - This is the directive used to declare external
183 const char *ExternDirective; // Defaults to NULL.
185 /// HasSetDirective - True if the assembler supports the .set directive.
186 bool HasSetDirective; // Defaults to true.
188 /// HasLCOMMDirective - This is true if the target supports the .lcomm
190 bool HasLCOMMDirective; // Defaults to false.
192 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
193 /// alignment is to be specified in bytes instead of log2(n).
194 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
196 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
197 /// directives, this is true for most ELF targets.
198 bool HasDotTypeDotSizeDirective; // Defaults to true.
200 /// HasSingleParameterDotFile - True if the target has a single parameter
201 /// .file directive, this is true for ELF targets.
202 bool HasSingleParameterDotFile; // Defaults to true.
204 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
206 bool HasNoDeadStrip; // Defaults to false.
208 /// WeakRefDirective - This directive, if non-null, is used to declare a
209 /// global as being a weak undefined symbol.
210 const char *WeakRefDirective; // Defaults to NULL.
212 /// WeakDefDirective - This directive, if non-null, is used to declare a
213 /// global as being a weak defined symbol.
214 const char *WeakDefDirective; // Defaults to NULL.
216 /// LinkOnceDirective - This directive, if non-null is used to declare a
217 /// global as being a weak defined symbol. This is used on cygwin/mingw.
218 const char *LinkOnceDirective; // Defaults to NULL.
220 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
221 /// declare a symbol as having hidden visibility.
222 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
224 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
225 /// to declare a symbol as having protected visibility.
226 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
228 //===--- Dwarf Emission Directives -----------------------------------===//
230 /// HasLEB128 - True if target asm supports leb128 directives.
231 bool HasLEB128; // Defaults to false.
233 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
234 /// directives for emitting debugging information.
235 bool HasDotLocAndDotFile; // Defaults to false.
237 /// SupportsDebugInformation - True if target supports emission of debugging
239 bool SupportsDebugInformation; // Defaults to false.
241 /// SupportsExceptionHandling - True if target supports exception handling.
242 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
244 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
245 bool DwarfRequiresFrameSection; // Defaults to true.
247 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
248 /// encode inline subroutine information.
249 bool DwarfUsesInlineInfoSection; // Defaults to false.
251 /// DwarfSectionOffsetDirective - Special section offset directive.
252 const char* DwarfSectionOffsetDirective; // Defaults to NULL
254 //===--- CBE Asm Translation Table -----------------------------------===//
256 const char *const *AsmTransCBE; // Defaults to empty
259 explicit MCAsmInfo();
260 virtual ~MCAsmInfo();
262 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
263 static unsigned getSLEB128Size(int Value);
264 static unsigned getULEB128Size(unsigned Value);
266 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
268 // Data directive accessors.
270 const char *getData8bitsDirective(unsigned AS = 0) const {
271 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
273 const char *getData16bitsDirective(unsigned AS = 0) const {
274 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
276 const char *getData32bitsDirective(unsigned AS = 0) const {
277 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
279 const char *getData64bitsDirective(unsigned AS = 0) const {
280 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
282 const char *getGPRel32Directive() const { return GPRel32Directive; }
284 /// getNonexecutableStackSection - Targets can implement this method to
285 /// specify a section to switch to if the translation unit doesn't have any
286 /// trampolines that require an executable stack.
287 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
291 bool usesSunStyleELFSectionSwitchSyntax() const {
292 return SunStyleELFSectionSwitchSyntax;
295 bool usesELFSectionDirectiveForBSS() const {
296 return UsesELFSectionDirectiveForBSS;
299 bool hasMicrosoftFastStdCallMangling() const {
300 return HasMicrosoftFastStdCallMangling;
305 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
306 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
307 bool hasStaticCtorDtorReferenceInStaticMode() const {
308 return HasStaticCtorDtorReferenceInStaticMode;
310 unsigned getMaxInstLength() const {
311 return MaxInstLength;
313 const char *getPCSymbol() const {
316 char getSeparatorChar() const {
317 return SeparatorChar;
319 unsigned getCommentColumn() const {
320 return CommentColumn;
322 const char *getCommentString() const {
323 return CommentString;
325 const char *getGlobalPrefix() const {
328 const char *getPrivateGlobalPrefix() const {
329 return PrivateGlobalPrefix;
331 const char *getLinkerPrivateGlobalPrefix() const {
332 return LinkerPrivateGlobalPrefix;
334 const char *getInlineAsmStart() const {
335 return InlineAsmStart;
337 const char *getInlineAsmEnd() const {
340 unsigned getAssemblerDialect() const {
341 return AssemblerDialect;
343 bool doesAllowQuotesInName() const {
344 return AllowQuotesInName;
346 bool doesAllowNameToStartWithDigit() const {
347 return AllowNameToStartWithDigit;
349 bool doesAllowPeriodsInName() const {
350 return AllowPeriodsInName;
352 const char *getZeroDirective() const {
353 return ZeroDirective;
355 const char *getAsciiDirective() const {
356 return AsciiDirective;
358 const char *getAscizDirective() const {
359 return AscizDirective;
361 const char *getAlignDirective() const {
362 return AlignDirective;
364 bool getAlignmentIsInBytes() const {
365 return AlignmentIsInBytes;
367 unsigned getTextAlignFillValue() const {
368 return TextAlignFillValue;
370 const char *getGlobalDirective() const {
371 return GlobalDirective;
373 const char *getExternDirective() const {
374 return ExternDirective;
376 bool hasSetDirective() const { return HasSetDirective; }
377 bool hasLCOMMDirective() const { return HasLCOMMDirective; }
378 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
379 bool getCOMMDirectiveAlignmentIsInBytes() const {
380 return COMMDirectiveAlignmentIsInBytes;
382 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
383 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
384 const char *getWeakRefDirective() const { return WeakRefDirective; }
385 const char *getWeakDefDirective() const { return WeakDefDirective; }
386 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
388 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
389 MCSymbolAttr getProtectedVisibilityAttr() const {
390 return ProtectedVisibilityAttr;
392 bool hasLEB128() const {
395 bool hasDotLocAndDotFile() const {
396 return HasDotLocAndDotFile;
398 bool doesSupportDebugInformation() const {
399 return SupportsDebugInformation;
401 bool doesSupportExceptionHandling() const {
402 return ExceptionsType != ExceptionHandling::None;
404 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
405 return ExceptionsType;
407 bool doesDwarfRequireFrameSection() const {
408 return DwarfRequiresFrameSection;
410 bool doesDwarfUsesInlineInfoSection() const {
411 return DwarfUsesInlineInfoSection;
413 const char *getDwarfSectionOffsetDirective() const {
414 return DwarfSectionOffsetDirective;
416 const char *const *getAsmCBE() const {