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;
27 /// TargetAsmInfo - This class is intended to be used as a base class for asm
28 /// properties and features specific to the target.
31 /// TM - The current TargetMachine.
32 const TargetMachine &TM;
34 //===------------------------------------------------------------------===//
35 // Properties to be set by the target writer, used to configure asm printer.
38 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
39 /// section on this target. Null if this target doesn't support zerofill.
40 const char *ZeroFillDirective; // Default is null.
42 /// NonexecutableStackDirective - Directive for declaring to the
43 /// linker and beyond that the emitted code does not require stack
44 /// memory to be executable.
45 const char *NonexecutableStackDirective; // Default is null.
47 /// NeedsSet - True if target asm treats expressions in data directives
48 /// as linktime-relocatable. For assembly-time computation, we need to
52 /// is computed at assembly time, while
54 /// is relocated if the relative locations of x and y change at linktime.
55 /// We want both these things in different places.
56 bool NeedsSet; // Defaults to false.
58 /// MaxInstLength - This is the maximum possible length of an instruction,
59 /// which is needed to compute the size of an inline asm.
60 unsigned MaxInstLength; // Defaults to 4.
62 /// PCSymbol - The symbol used to represent the current PC. Used in PC
63 /// relative expressions.
64 const char *PCSymbol; // Defaults to "$".
66 /// SeparatorChar - This character, if specified, is used to separate
67 /// instructions from each other when on the same line. This is used to
68 /// measure inline asm instructions.
69 char SeparatorChar; // Defaults to ';'
71 /// CommentColumn - This indicates the comment num (zero-based) at
72 /// which asm comments should be printed.
73 unsigned CommentColumn; // Defaults to 60
75 /// CommentString - This indicates the comment character used by the
77 const char *CommentString; // Defaults to "#"
79 /// FirstOperandColumn - The output column where the first operand
81 unsigned FirstOperandColumn; // Defaults to 0 (ignored)
83 /// MaxOperandLength - The maximum length of any printed asm
85 unsigned MaxOperandLength; // Defaults to 0 (ignored)
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 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
102 /// emitted before jump tables with the specified prefix.
103 const char *JumpTableSpecialLabelPrefix; // Default to null.
105 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
106 /// will enclose any GlobalVariable (that isn't a function)
108 const char *GlobalVarAddrPrefix; // Defaults to ""
109 const char *GlobalVarAddrSuffix; // Defaults to ""
111 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
112 /// will enclose any GlobalVariable that points to a function.
114 const char *FunctionAddrPrefix; // Defaults to ""
115 const char *FunctionAddrSuffix; // Defaults to ""
117 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
118 /// enclose any personality function in the common frame section.
120 const char *PersonalityPrefix; // Defaults to ""
121 const char *PersonalitySuffix; // Defaults to ""
123 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
126 bool NeedsIndirectEncoding; // Defaults to false
128 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
129 /// emit before and after an inline assembly statement.
130 const char *InlineAsmStart; // Defaults to "#APP\n"
131 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
133 /// AssemblerDialect - Which dialect of an assembler variant to use.
134 unsigned AssemblerDialect; // Defaults to 0
136 /// AllowQuotesInName - This is true if the assembler allows for complex
137 /// symbol names to be surrounded in quotes. This defaults to false.
138 bool AllowQuotesInName;
140 //===--- Data Emission Directives -------------------------------------===//
142 /// ZeroDirective - this should be set to the directive used to get some
143 /// number of zero bytes emitted to the current section. Common cases are
144 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
145 /// Data*bitsDirective's will be used to emit zero bytes.
146 const char *ZeroDirective; // Defaults to "\t.zero\t"
147 const char *ZeroDirectiveSuffix; // Defaults to ""
149 /// AsciiDirective - This directive allows emission of an ascii string with
150 /// the standard C escape characters embedded into it.
151 const char *AsciiDirective; // Defaults to "\t.ascii\t"
153 /// AscizDirective - If not null, this allows for special handling of
154 /// zero terminated strings on this target. This is commonly supported as
155 /// ".asciz". If a target doesn't support this, it can be set to null.
156 const char *AscizDirective; // Defaults to "\t.asciz\t"
158 /// DataDirectives - These directives are used to output some unit of
159 /// integer data to the current section. If a data directive is set to
160 /// null, smaller data directives will be used to emit the large sizes.
161 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
162 const char *Data16bitsDirective; // Defaults to "\t.short\t"
163 const char *Data32bitsDirective; // Defaults to "\t.long\t"
164 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
166 /// getDataASDirective - Return the directive that should be used to emit
167 /// data of the specified size to the specified numeric address space.
168 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
169 assert(AS != 0 && "Don't know the directives for default addr space");
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;
190 //===--- Section Switching Directives ---------------------------------===//
192 /// SwitchToSectionDirective - This is the directive used when we want to
193 /// emit a global to an arbitrary section. The section name is emited after
195 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
197 /// TextSectionStartSuffix - This is printed after each start of section
198 /// directive for text sections.
199 const char *TextSectionStartSuffix; // Defaults to "".
201 /// DataSectionStartSuffix - This is printed after each start of section
202 /// directive for data sections.
203 const char *DataSectionStartSuffix; // Defaults to "".
205 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
206 /// section with the section name and this suffix printed.
207 const char *SectionEndDirectiveSuffix;// Defaults to null.
209 /// JumpTableDirective - if non-null, the directive to emit before a jump
211 const char *JumpTableDirective;
213 //===--- Global Variable Emission Directives --------------------------===//
215 /// GlobalDirective - This is the directive used to declare a global entity.
217 const char *GlobalDirective; // Defaults to NULL.
219 /// ExternDirective - This is the directive used to declare external
222 const char *ExternDirective; // Defaults to NULL.
224 /// SetDirective - This is the name of a directive that can be used to tell
225 /// the assembler to set the value of a variable to some expression.
226 const char *SetDirective; // Defaults to null.
228 /// LCOMMDirective - This is the name of a directive (if supported) that can
229 /// be used to efficiently declare a local (internal) block of zero
230 /// initialized data in the .bss/.data section. The syntax expected is:
231 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
233 const char *LCOMMDirective; // Defaults to null.
235 const char *COMMDirective; // Defaults to "\t.comm\t".
237 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
238 /// argument that specifies the alignment of the declaration.
239 bool COMMDirectiveTakesAlignment; // Defaults to true.
241 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
242 /// directives, this is true for most ELF targets.
243 bool HasDotTypeDotSizeDirective; // Defaults to true.
245 /// HasSingleParameterDotFile - True if the target has a single parameter
246 /// .file directive, this is true for ELF targets.
247 bool HasSingleParameterDotFile; // Defaults to true.
249 /// UsedDirective - This directive, if non-null, is used to declare a global
250 /// as being used somehow that the assembler can't see. This prevents dead
251 /// code elimination on some targets.
252 const char *UsedDirective; // Defaults to null.
254 /// WeakRefDirective - This directive, if non-null, is used to declare a
255 /// global as being a weak undefined symbol.
256 const char *WeakRefDirective; // Defaults to null.
258 /// WeakDefDirective - This directive, if non-null, is used to declare a
259 /// global as being a weak defined symbol.
260 const char *WeakDefDirective; // Defaults to null.
262 /// HiddenDirective - This directive, if non-null, is used to declare a
263 /// global or function as having hidden visibility.
264 const char *HiddenDirective; // Defaults to "\t.hidden\t".
266 /// ProtectedDirective - This directive, if non-null, is used to declare a
267 /// global or function as having protected visibility.
268 const char *ProtectedDirective; // Defaults to "\t.protected\t".
270 //===--- Dwarf Emission Directives -----------------------------------===//
272 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
273 /// offsets for debug information. Defaults to false.
274 bool AbsoluteDebugSectionOffsets;
276 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
277 /// offsets for EH information. Defaults to false.
278 bool AbsoluteEHSectionOffsets;
280 /// HasLEB128 - True if target asm supports leb128 directives.
282 bool HasLEB128; // Defaults to false.
284 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
285 /// directives for emitting debugging information.
287 bool HasDotLocAndDotFile; // Defaults to false.
289 /// SupportsDebugInformation - True if target supports emission of debugging
291 bool SupportsDebugInformation;
293 /// SupportsExceptionHandling - True if target supports
294 /// exception handling.
296 bool SupportsExceptionHandling; // Defaults to false.
298 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
300 bool DwarfRequiresFrameSection; // Defaults to true.
302 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
303 /// encode inline subroutine information.
304 bool DwarfUsesInlineInfoSection; // Defaults to false.
306 /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
307 /// doesn't show up in the symbol table of the object file.
308 bool Is_EHSymbolPrivate; // Defaults to true.
310 /// GlobalEHDirective - This is the directive used to make exception frame
311 /// tables globally visible.
313 const char *GlobalEHDirective; // Defaults to NULL.
315 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
316 /// handle a weak_definition of constant 0 for an omitted EH frame.
317 bool SupportsWeakOmittedEHFrame; // Defaults to true.
319 /// DwarfSectionOffsetDirective - Special section offset directive.
320 const char* DwarfSectionOffsetDirective; // Defaults to NULL
322 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
324 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
326 /// DwarfInfoSection - Section directive for Dwarf info.
328 const char *DwarfInfoSection; // Defaults to ".debug_info".
330 /// DwarfLineSection - Section directive for Dwarf info.
332 const char *DwarfLineSection; // Defaults to ".debug_line".
334 /// DwarfFrameSection - Section directive for Dwarf info.
336 const char *DwarfFrameSection; // Defaults to ".debug_frame".
338 /// DwarfPubNamesSection - Section directive for Dwarf info.
340 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
342 /// DwarfPubTypesSection - Section directive for Dwarf info.
344 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
346 /// DwarfDebugInlineSection - Section directive for inline info.
348 const char *DwarfDebugInlineSection; // Defaults to ".debug_inlined"
350 /// DwarfStrSection - Section directive for Dwarf info.
352 const char *DwarfStrSection; // Defaults to ".debug_str".
354 /// DwarfLocSection - Section directive for Dwarf info.
356 const char *DwarfLocSection; // Defaults to ".debug_loc".
358 /// DwarfARangesSection - Section directive for Dwarf info.
360 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
362 /// DwarfRangesSection - Section directive for Dwarf info.
364 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
366 /// DwarfMacroInfoSection - Section directive for DWARF macro info.
368 const char *DwarfMacroInfoSection; // Defaults to ".debug_macinfo".
370 /// DwarfEHFrameSection - Section directive for Exception frames.
372 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
374 /// DwarfExceptionSection - Section directive for Exception table.
376 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
378 //===--- CBE Asm Translation Table -----------------------------------===//
380 const char *const *AsmTransCBE; // Defaults to empty
383 explicit TargetAsmInfo(const TargetMachine &TM);
384 virtual ~TargetAsmInfo();
386 /// Measure the specified inline asm to determine an approximation of its
388 virtual unsigned getInlineAsmLength(const char *Str) const;
390 /// PreferredEHDataFormat - This hook allows the target to select data
391 /// format used for encoding pointers in exception handling data.
392 virtual unsigned PreferredEHDataFormat() const;
395 /// getSLEB128Size - Compute the number of bytes required for a signed
397 static unsigned getSLEB128Size(int Value);
399 /// getULEB128Size - Compute the number of bytes required for an unsigned
401 static unsigned getULEB128Size(unsigned Value);
403 // Data directive accessors.
405 const char *getData8bitsDirective(unsigned AS = 0) const {
406 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
408 const char *getData16bitsDirective(unsigned AS = 0) const {
409 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
411 const char *getData32bitsDirective(unsigned AS = 0) const {
412 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
414 const char *getData64bitsDirective(unsigned AS = 0) const {
415 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
421 const char *getZeroFillDirective() const {
422 return ZeroFillDirective;
424 const char *getNonexecutableStackDirective() const {
425 return NonexecutableStackDirective;
427 bool needsSet() const {
430 const char *getPCSymbol() const {
433 char getSeparatorChar() const {
434 return SeparatorChar;
436 unsigned getCommentColumn() const {
437 return CommentColumn;
439 const char *getCommentString() const {
440 return CommentString;
442 unsigned getOperandColumn(int operand) const {
443 return FirstOperandColumn + (MaxOperandLength+1)*(operand-1);
445 const char *getGlobalPrefix() const {
448 const char *getPrivateGlobalPrefix() const {
449 return PrivateGlobalPrefix;
451 const char *getLinkerPrivateGlobalPrefix() const {
452 return LinkerPrivateGlobalPrefix;
454 const char *getJumpTableSpecialLabelPrefix() const {
455 return JumpTableSpecialLabelPrefix;
457 const char *getGlobalVarAddrPrefix() const {
458 return GlobalVarAddrPrefix;
460 const char *getGlobalVarAddrSuffix() const {
461 return GlobalVarAddrSuffix;
463 const char *getFunctionAddrPrefix() const {
464 return FunctionAddrPrefix;
466 const char *getFunctionAddrSuffix() const {
467 return FunctionAddrSuffix;
469 const char *getPersonalityPrefix() const {
470 return PersonalityPrefix;
472 const char *getPersonalitySuffix() const {
473 return PersonalitySuffix;
475 bool getNeedsIndirectEncoding() const {
476 return NeedsIndirectEncoding;
478 const char *getInlineAsmStart() const {
479 return InlineAsmStart;
481 const char *getInlineAsmEnd() const {
484 unsigned getAssemblerDialect() const {
485 return AssemblerDialect;
487 bool doesAllowQuotesInName() const {
488 return AllowQuotesInName;
490 const char *getZeroDirective() const {
491 return ZeroDirective;
493 const char *getZeroDirectiveSuffix() const {
494 return ZeroDirectiveSuffix;
496 const char *getAsciiDirective() const {
497 return AsciiDirective;
499 const char *getAscizDirective() const {
500 return AscizDirective;
502 const char *getJumpTableDirective() const {
503 return JumpTableDirective;
505 const char *getAlignDirective() const {
506 return AlignDirective;
508 bool getAlignmentIsInBytes() const {
509 return AlignmentIsInBytes;
511 unsigned getTextAlignFillValue() const {
512 return TextAlignFillValue;
514 const char *getSwitchToSectionDirective() const {
515 return SwitchToSectionDirective;
517 const char *getTextSectionStartSuffix() const {
518 return TextSectionStartSuffix;
520 const char *getDataSectionStartSuffix() const {
521 return DataSectionStartSuffix;
523 const char *getSectionEndDirectiveSuffix() const {
524 return SectionEndDirectiveSuffix;
526 const char *getGlobalDirective() const {
527 return GlobalDirective;
529 const char *getExternDirective() const {
530 return ExternDirective;
532 const char *getSetDirective() const {
535 const char *getLCOMMDirective() const {
536 return LCOMMDirective;
538 const char *getCOMMDirective() const {
539 return COMMDirective;
541 bool getCOMMDirectiveTakesAlignment() const {
542 return COMMDirectiveTakesAlignment;
544 bool hasDotTypeDotSizeDirective() const {
545 return HasDotTypeDotSizeDirective;
547 bool hasSingleParameterDotFile() const {
548 return HasSingleParameterDotFile;
550 const char *getUsedDirective() const {
551 return UsedDirective;
553 const char *getWeakRefDirective() const {
554 return WeakRefDirective;
556 const char *getWeakDefDirective() const {
557 return WeakDefDirective;
559 const char *getHiddenDirective() const {
560 return HiddenDirective;
562 const char *getProtectedDirective() const {
563 return ProtectedDirective;
565 bool isAbsoluteDebugSectionOffsets() const {
566 return AbsoluteDebugSectionOffsets;
568 bool isAbsoluteEHSectionOffsets() const {
569 return AbsoluteEHSectionOffsets;
571 bool hasLEB128() const {
574 bool hasDotLocAndDotFile() const {
575 return HasDotLocAndDotFile;
577 bool doesSupportDebugInformation() const {
578 return SupportsDebugInformation;
580 bool doesSupportExceptionHandling() const {
581 return SupportsExceptionHandling;
583 bool doesDwarfRequireFrameSection() const {
584 return DwarfRequiresFrameSection;
586 bool doesDwarfUsesInlineInfoSection() const {
587 return DwarfUsesInlineInfoSection;
589 bool is_EHSymbolPrivate() const {
590 return Is_EHSymbolPrivate;
592 const char *getGlobalEHDirective() const {
593 return GlobalEHDirective;
595 bool getSupportsWeakOmittedEHFrame() const {
596 return SupportsWeakOmittedEHFrame;
598 const char *getDwarfSectionOffsetDirective() const {
599 return DwarfSectionOffsetDirective;
601 const char *getDwarfAbbrevSection() const {
602 return DwarfAbbrevSection;
604 const char *getDwarfInfoSection() const {
605 return DwarfInfoSection;
607 const char *getDwarfLineSection() const {
608 return DwarfLineSection;
610 const char *getDwarfFrameSection() const {
611 return DwarfFrameSection;
613 const char *getDwarfPubNamesSection() const {
614 return DwarfPubNamesSection;
616 const char *getDwarfPubTypesSection() const {
617 return DwarfPubTypesSection;
619 const char *getDwarfDebugInlineSection() const {
620 return DwarfDebugInlineSection;
622 const char *getDwarfStrSection() const {
623 return DwarfStrSection;
625 const char *getDwarfLocSection() const {
626 return DwarfLocSection;
628 const char *getDwarfARangesSection() const {
629 return DwarfARangesSection;
631 const char *getDwarfRangesSection() const {
632 return DwarfRangesSection;
634 const char *getDwarfMacroInfoSection() const {
635 return DwarfMacroInfoSection;
637 const char *getDwarfEHFrameSection() const {
638 return DwarfEHFrameSection;
640 const char *getDwarfExceptionSection() const {
641 return DwarfExceptionSection;
643 const char *const *getAsmCBE() const {