1 //===-- llvm/Target/TargetAsmInfo.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/Support/DataTypes.h"
24 template <typename T> class SmallVectorImpl;
26 /// TargetAsmInfo - 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 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
37 /// section on this target. Null if this target doesn't support zerofill.
38 const char *ZeroFillDirective; // Default is null.
40 /// NonexecutableStackDirective - Directive for declaring to the
41 /// linker and beyond that the emitted code does not require stack
42 /// memory to be executable.
43 const char *NonexecutableStackDirective; // Default is null.
45 /// NeedsSet - True if target asm treats expressions in data directives
46 /// as linktime-relocatable. For assembly-time computation, we need to
50 /// is computed at assembly time, while
52 /// is relocated if the relative locations of x and y change at linktime.
53 /// We want both these things in different places.
54 bool NeedsSet; // Defaults to false.
56 /// MaxInstLength - This is the maximum possible length of an instruction,
57 /// which is needed to compute the size of an inline asm.
58 unsigned MaxInstLength; // Defaults to 4.
60 /// PCSymbol - The symbol used to represent the current PC. Used in PC
61 /// relative expressions.
62 const char *PCSymbol; // Defaults to "$".
64 /// SeparatorChar - This character, if specified, is used to separate
65 /// instructions from each other when on the same line. This is used to
66 /// measure inline asm instructions.
67 char SeparatorChar; // Defaults to ';'
69 /// CommentColumn - This indicates the comment num (zero-based) at
70 /// which asm comments should be printed.
71 unsigned CommentColumn; // Defaults to 60
73 /// CommentString - This indicates the comment character used by the
75 const char *CommentString; // Defaults to "#"
77 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
78 /// onto all global symbols. This is often used for "_" or ".".
79 const char *GlobalPrefix; // Defaults to ""
81 /// PrivateGlobalPrefix - This prefix is used for globals like constant
82 /// pool entries that are completely private to the .s file and should not
83 /// have names in the .o file. This is often "." or "L".
84 const char *PrivateGlobalPrefix; // Defaults to "."
86 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
87 /// be passed through the assembler but be removed by the linker. This
88 /// is "l" on Darwin, currently used for some ObjC metadata.
89 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
91 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
92 /// emitted before jump tables with the specified prefix.
93 const char *JumpTableSpecialLabelPrefix; // Default to null.
95 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
96 /// will enclose any GlobalVariable (that isn't a function)
98 const char *GlobalVarAddrPrefix; // Defaults to ""
99 const char *GlobalVarAddrSuffix; // Defaults to ""
101 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
102 /// will enclose any GlobalVariable that points to a function.
104 const char *FunctionAddrPrefix; // Defaults to ""
105 const char *FunctionAddrSuffix; // Defaults to ""
107 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
108 /// enclose any personality function in the common frame section.
110 const char *PersonalityPrefix; // Defaults to ""
111 const char *PersonalitySuffix; // Defaults to ""
113 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
116 bool NeedsIndirectEncoding; // Defaults to false
118 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
119 /// emit before and after an inline assembly statement.
120 const char *InlineAsmStart; // Defaults to "#APP\n"
121 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
123 /// AssemblerDialect - Which dialect of an assembler variant to use.
124 unsigned AssemblerDialect; // Defaults to 0
126 /// AllowQuotesInName - This is true if the assembler allows for complex
127 /// symbol names to be surrounded in quotes. This defaults to false.
128 bool AllowQuotesInName;
130 //===--- Data Emission Directives -------------------------------------===//
132 /// ZeroDirective - this should be set to the directive used to get some
133 /// number of zero bytes emitted to the current section. Common cases are
134 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
135 /// Data*bitsDirective's will be used to emit zero bytes.
136 const char *ZeroDirective; // Defaults to "\t.zero\t"
137 const char *ZeroDirectiveSuffix; // Defaults to ""
139 /// AsciiDirective - This directive allows emission of an ascii string with
140 /// the standard C escape characters embedded into it.
141 const char *AsciiDirective; // Defaults to "\t.ascii\t"
143 /// AscizDirective - If not null, this allows for special handling of
144 /// zero terminated strings on this target. This is commonly supported as
145 /// ".asciz". If a target doesn't support this, it can be set to null.
146 const char *AscizDirective; // Defaults to "\t.asciz\t"
148 /// DataDirectives - These directives are used to output some unit of
149 /// integer data to the current section. If a data directive is set to
150 /// null, smaller data directives will be used to emit the large sizes.
151 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
152 const char *Data16bitsDirective; // Defaults to "\t.short\t"
153 const char *Data32bitsDirective; // Defaults to "\t.long\t"
154 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
156 /// getDataASDirective - Return the directive that should be used to emit
157 /// data of the specified size to the specified numeric address space.
158 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
159 assert(AS != 0 && "Don't know the directives for default addr space");
163 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
164 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
165 /// normal ELF syntax (,"a,w") in .section directives.
166 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
168 //===--- Alignment Information ----------------------------------------===//
170 /// AlignDirective - The directive used to emit round up to an alignment
173 const char *AlignDirective; // Defaults to "\t.align\t"
175 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
176 /// emits ".align N" directives, where N is the number of bytes to align to.
177 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
179 bool AlignmentIsInBytes; // Defaults to true
181 /// TextAlignFillValue - If non-zero, this is used to fill the executable
182 /// space created as the result of a alignment directive.
183 unsigned TextAlignFillValue;
185 //===--- Section Switching Directives ---------------------------------===//
187 /// JumpTableDirective - if non-null, the directive to emit before jump
188 /// table entries. FIXME: REMOVE THIS.
189 const char *JumpTableDirective;
190 const char *PICJumpTableDirective;
193 //===--- Global Variable Emission Directives --------------------------===//
195 /// GlobalDirective - This is the directive used to declare a global entity.
197 const char *GlobalDirective; // Defaults to NULL.
199 /// ExternDirective - This is the directive used to declare external
202 const char *ExternDirective; // Defaults to NULL.
204 /// SetDirective - This is the name of a directive that can be used to tell
205 /// the assembler to set the value of a variable to some expression.
206 const char *SetDirective; // Defaults to null.
208 /// LCOMMDirective - This is the name of a directive (if supported) that can
209 /// be used to efficiently declare a local (internal) block of zero
210 /// initialized data in the .bss/.data section. The syntax expected is:
211 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
213 const char *LCOMMDirective; // Defaults to null.
215 const char *COMMDirective; // Defaults to "\t.comm\t".
217 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
218 /// argument that specifies the alignment of the declaration.
219 bool COMMDirectiveTakesAlignment; // Defaults to true.
221 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
222 /// directives, this is true for most ELF targets.
223 bool HasDotTypeDotSizeDirective; // Defaults to true.
225 /// HasSingleParameterDotFile - True if the target has a single parameter
226 /// .file directive, this is true for ELF targets.
227 bool HasSingleParameterDotFile; // Defaults to true.
229 /// UsedDirective - This directive, if non-null, is used to declare a global
230 /// as being used somehow that the assembler can't see. This prevents dead
231 /// code elimination on some targets.
232 const char *UsedDirective; // Defaults to null.
234 /// WeakRefDirective - This directive, if non-null, is used to declare a
235 /// global as being a weak undefined symbol.
236 const char *WeakRefDirective; // Defaults to null.
238 /// WeakDefDirective - This directive, if non-null, is used to declare a
239 /// global as being a weak defined symbol.
240 const char *WeakDefDirective; // Defaults to null.
242 /// HiddenDirective - This directive, if non-null, is used to declare a
243 /// global or function as having hidden visibility.
244 const char *HiddenDirective; // Defaults to "\t.hidden\t".
246 /// ProtectedDirective - This directive, if non-null, is used to declare a
247 /// global or function as having protected visibility.
248 const char *ProtectedDirective; // Defaults to "\t.protected\t".
250 //===--- Dwarf Emission Directives -----------------------------------===//
252 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
253 /// offsets for debug information. Defaults to false.
254 bool AbsoluteDebugSectionOffsets;
256 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
257 /// offsets for EH information. Defaults to false.
258 bool AbsoluteEHSectionOffsets;
260 /// HasLEB128 - True if target asm supports leb128 directives.
262 bool HasLEB128; // Defaults to false.
264 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
265 /// directives for emitting debugging information.
267 bool HasDotLocAndDotFile; // Defaults to false.
269 /// SupportsDebugInformation - True if target supports emission of debugging
271 bool SupportsDebugInformation;
273 /// SupportsExceptionHandling - True if target supports
274 /// exception handling.
277 ExceptionHandling::ExceptionsType ExceptionsType;
279 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
281 bool DwarfRequiresFrameSection; // Defaults to true.
283 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
284 /// encode inline subroutine information.
285 bool DwarfUsesInlineInfoSection; // Defaults to false.
287 /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
288 /// doesn't show up in the symbol table of the object file.
289 bool Is_EHSymbolPrivate; // Defaults to true.
291 /// GlobalEHDirective - This is the directive used to make exception frame
292 /// tables globally visible.
294 const char *GlobalEHDirective; // Defaults to NULL.
296 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
297 /// handle a weak_definition of constant 0 for an omitted EH frame.
298 bool SupportsWeakOmittedEHFrame; // Defaults to true.
300 /// DwarfSectionOffsetDirective - Special section offset directive.
301 const char* DwarfSectionOffsetDirective; // Defaults to NULL
303 //===--- CBE Asm Translation Table -----------------------------------===//
305 const char *const *AsmTransCBE; // Defaults to empty
308 explicit TargetAsmInfo();
309 virtual ~TargetAsmInfo();
311 /// getSLEB128Size - Compute the number of bytes required for a signed
313 static unsigned getSLEB128Size(int Value);
315 /// getULEB128Size - Compute the number of bytes required for an unsigned
317 static unsigned getULEB128Size(unsigned Value);
319 // Data directive accessors.
321 const char *getData8bitsDirective(unsigned AS = 0) const {
322 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
324 const char *getData16bitsDirective(unsigned AS = 0) const {
325 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
327 const char *getData32bitsDirective(unsigned AS = 0) const {
328 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
330 const char *getData64bitsDirective(unsigned AS = 0) const {
331 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
335 bool usesSunStyleELFSectionSwitchSyntax() const {
336 return SunStyleELFSectionSwitchSyntax;
342 const char *getZeroFillDirective() const {
343 return ZeroFillDirective;
345 const char *getNonexecutableStackDirective() const {
346 return NonexecutableStackDirective;
348 bool needsSet() const {
351 unsigned getMaxInstLength() const {
352 return MaxInstLength;
354 const char *getPCSymbol() const {
357 char getSeparatorChar() const {
358 return SeparatorChar;
360 unsigned getCommentColumn() const {
361 return CommentColumn;
363 const char *getCommentString() const {
364 return CommentString;
366 const char *getGlobalPrefix() const {
369 const char *getPrivateGlobalPrefix() const {
370 return PrivateGlobalPrefix;
372 const char *getLinkerPrivateGlobalPrefix() const {
373 return LinkerPrivateGlobalPrefix;
375 const char *getJumpTableSpecialLabelPrefix() const {
376 return JumpTableSpecialLabelPrefix;
378 const char *getGlobalVarAddrPrefix() const {
379 return GlobalVarAddrPrefix;
381 const char *getGlobalVarAddrSuffix() const {
382 return GlobalVarAddrSuffix;
384 const char *getFunctionAddrPrefix() const {
385 return FunctionAddrPrefix;
387 const char *getFunctionAddrSuffix() const {
388 return FunctionAddrSuffix;
390 const char *getPersonalityPrefix() const {
391 return PersonalityPrefix;
393 const char *getPersonalitySuffix() const {
394 return PersonalitySuffix;
396 bool getNeedsIndirectEncoding() const {
397 return NeedsIndirectEncoding;
399 const char *getInlineAsmStart() const {
400 return InlineAsmStart;
402 const char *getInlineAsmEnd() const {
405 unsigned getAssemblerDialect() const {
406 return AssemblerDialect;
408 bool doesAllowQuotesInName() const {
409 return AllowQuotesInName;
411 const char *getZeroDirective() const {
412 return ZeroDirective;
414 const char *getZeroDirectiveSuffix() const {
415 return ZeroDirectiveSuffix;
417 const char *getAsciiDirective() const {
418 return AsciiDirective;
420 const char *getAscizDirective() const {
421 return AscizDirective;
423 const char *getJumpTableDirective(bool isPIC) const {
424 return isPIC ? PICJumpTableDirective : JumpTableDirective;
426 const char *getAlignDirective() const {
427 return AlignDirective;
429 bool getAlignmentIsInBytes() const {
430 return AlignmentIsInBytes;
432 unsigned getTextAlignFillValue() const {
433 return TextAlignFillValue;
435 const char *getGlobalDirective() const {
436 return GlobalDirective;
438 const char *getExternDirective() const {
439 return ExternDirective;
441 const char *getSetDirective() const {
444 const char *getLCOMMDirective() const {
445 return LCOMMDirective;
447 const char *getCOMMDirective() const {
448 return COMMDirective;
450 bool getCOMMDirectiveTakesAlignment() const {
451 return COMMDirectiveTakesAlignment;
453 bool hasDotTypeDotSizeDirective() const {
454 return HasDotTypeDotSizeDirective;
456 bool hasSingleParameterDotFile() const {
457 return HasSingleParameterDotFile;
459 const char *getUsedDirective() const {
460 return UsedDirective;
462 const char *getWeakRefDirective() const {
463 return WeakRefDirective;
465 const char *getWeakDefDirective() const {
466 return WeakDefDirective;
468 const char *getHiddenDirective() const {
469 return HiddenDirective;
471 const char *getProtectedDirective() const {
472 return ProtectedDirective;
474 bool isAbsoluteDebugSectionOffsets() const {
475 return AbsoluteDebugSectionOffsets;
477 bool isAbsoluteEHSectionOffsets() const {
478 return AbsoluteEHSectionOffsets;
480 bool hasLEB128() const {
483 bool hasDotLocAndDotFile() const {
484 return HasDotLocAndDotFile;
486 bool doesSupportDebugInformation() const {
487 return SupportsDebugInformation;
489 bool doesSupportExceptionHandling() const {
490 return ExceptionsType != ExceptionHandling::None;
492 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
493 return ExceptionsType;
495 bool doesDwarfRequireFrameSection() const {
496 return DwarfRequiresFrameSection;
498 bool doesDwarfUsesInlineInfoSection() const {
499 return DwarfUsesInlineInfoSection;
501 bool is_EHSymbolPrivate() const {
502 return Is_EHSymbolPrivate;
504 const char *getGlobalEHDirective() const {
505 return GlobalEHDirective;
507 bool getSupportsWeakOmittedEHFrame() const {
508 return SupportsWeakOmittedEHFrame;
510 const char *getDwarfSectionOffsetDirective() const {
511 return DwarfSectionOffsetDirective;
513 const char *const *getAsmCBE() const {