1 //===-- llvm/Target/TargetAsmInfo.h - Asm info ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source 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/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DataTypes.h"
26 /// TargetAsmInfo - This class is intended to be used as a base class for asm
27 /// properties and features specific to the target.
30 //===------------------------------------------------------------------===//
31 // Properties to be set by the target writer, used to configure asm printer.
34 /// TextSection - Section directive for standard text.
36 const char *TextSection; // Defaults to ".text".
38 /// DataSection - Section directive for standard data.
40 const char *DataSection; // Defaults to ".data".
42 /// BSSSection - Section directive for uninitialized data. Null if this
43 /// target doesn't support a BSS section.
45 const char *BSSSection; // Default to ".bss".
47 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
48 /// section on this target. Null if this target doesn't support zerofill.
49 const char *ZeroFillDirective; // Default is null.
51 /// AddressSize - Size of addresses used in file.
53 unsigned AddressSize; // Defaults to 4.
55 /// NeedsSet - True if target asm can't compute addresses on data
57 bool NeedsSet; // Defaults to false.
59 /// MaxInstLength - This is the maximum possible length of an instruction,
60 /// which is needed to compute the size of an inline asm.
61 unsigned MaxInstLength; // Defaults to 4.
63 /// PCSymbol - The symbol used to represent the current PC. Used in PC
64 /// relative expressions.
65 const char *PCSymbol; // Defaults to "$".
67 /// SeparatorChar - This character, if specified, is used to separate
68 /// instructions from each other when on the same line. This is used to
69 /// measure inline asm instructions.
70 char SeparatorChar; // Defaults to ';'
72 /// CommentString - This indicates the comment character used by the
74 const char *CommentString; // Defaults to "#"
76 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
77 /// onto all global symbols. This is often used for "_" or ".".
78 const char *GlobalPrefix; // Defaults to ""
80 /// PrivateGlobalPrefix - This prefix is used for globals like constant
81 /// pool entries that are completely private to the .o file and should not
82 /// have names in the .o file. This is often "." or "L".
83 const char *PrivateGlobalPrefix; // Defaults to "."
85 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
86 /// emitted before jump tables with the specified prefix.
87 const char *JumpTableSpecialLabelPrefix; // Default to null.
89 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
90 /// will enclose any GlobalVariable (that isn't a function)
92 const char *GlobalVarAddrPrefix; // Defaults to ""
93 const char *GlobalVarAddrSuffix; // Defaults to ""
95 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
96 /// will enclose any GlobalVariable that points to a function.
97 /// For example, this is used by the IA64 backend to materialize
98 /// function descriptors, by decorating the ".data8" object with the
99 /// \literal @fptr( ) \endliteral
100 /// link-relocation operator.
102 const char *FunctionAddrPrefix; // Defaults to ""
103 const char *FunctionAddrSuffix; // Defaults to ""
105 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
106 /// emit before and after an inline assembly statement.
107 const char *InlineAsmStart; // Defaults to "#APP\n"
108 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
110 /// AssemblerDialect - Which dialect of an assembler variant to use.
111 unsigned AssemblerDialect; // Defaults to 0
113 //===--- Data Emission Directives -------------------------------------===//
115 /// ZeroDirective - this should be set to the directive used to get some
116 /// number of zero bytes emitted to the current section. Common cases are
117 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
118 /// Data*bitsDirective's will be used to emit zero bytes.
119 const char *ZeroDirective; // Defaults to "\t.zero\t"
120 const char *ZeroDirectiveSuffix; // Defaults to ""
122 /// AsciiDirective - This directive allows emission of an ascii string with
123 /// the standard C escape characters embedded into it.
124 const char *AsciiDirective; // Defaults to "\t.ascii\t"
126 /// AscizDirective - If not null, this allows for special handling of
127 /// zero terminated strings on this target. This is commonly supported as
128 /// ".asciz". If a target doesn't support this, it can be set to null.
129 const char *AscizDirective; // Defaults to "\t.asciz\t"
131 /// DataDirectives - These directives are used to output some unit of
132 /// integer data to the current section. If a data directive is set to
133 /// null, smaller data directives will be used to emit the large sizes.
134 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
135 const char *Data16bitsDirective; // Defaults to "\t.short\t"
136 const char *Data32bitsDirective; // Defaults to "\t.long\t"
137 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
139 //===--- Alignment Information ----------------------------------------===//
141 /// AlignDirective - The directive used to emit round up to an alignment
144 const char *AlignDirective; // Defaults to "\t.align\t"
146 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
147 /// emits ".align N" directives, where N is the number of bytes to align to.
148 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
150 bool AlignmentIsInBytes; // Defaults to true
152 //===--- Section Switching Directives ---------------------------------===//
154 /// SwitchToSectionDirective - This is the directive used when we want to
155 /// emit a global to an arbitrary section. The section name is emited after
157 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
159 /// TextSectionStartSuffix - This is printed after each start of section
160 /// directive for text sections.
161 const char *TextSectionStartSuffix; // Defaults to "".
163 /// DataSectionStartSuffix - This is printed after each start of section
164 /// directive for data sections.
165 const char *DataSectionStartSuffix; // Defaults to "".
167 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
168 /// section with the section name and this suffix printed.
169 const char *SectionEndDirectiveSuffix;// Defaults to null.
171 /// ConstantPoolSection - This is the section that we SwitchToSection right
172 /// before emitting the constant pool for a function.
173 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
175 /// JumpTableDataSection - This is the section that we SwitchToSection right
176 /// before emitting the jump tables for a function when the relocation model
178 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
180 /// JumpTableDirective - if non-null, the directive to emit before a jump
182 const char *JumpTableDirective;
184 /// CStringSection - If not null, this allows for special handling of
185 /// cstring constants (\0 terminated string that does not contain any
186 /// other null bytes) on this target. This is commonly supported as
188 const char *CStringSection; // Defaults to NULL
190 /// StaticCtorsSection - This is the directive that is emitted to switch to
191 /// a section to emit the static constructor list.
192 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
193 const char *StaticCtorsSection;
195 /// StaticDtorsSection - This is the directive that is emitted to switch to
196 /// a section to emit the static destructor list.
197 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
198 const char *StaticDtorsSection;
200 /// FourByteConstantSection, EightByteConstantSection,
201 /// SixteenByteConstantSection - These are special sections where we place
202 /// 4-, 8-, and 16- byte constant literals.
203 const char *FourByteConstantSection;
204 const char *EightByteConstantSection;
205 const char *SixteenByteConstantSection;
207 //===--- Global Variable Emission Directives --------------------------===//
209 /// GlobalDirective - This is the directive used to declare a global entity.
211 const char *GlobalDirective; // Defaults to NULL.
213 /// SetDirective - This is the name of a directive that can be used to tell
214 /// the assembler to set the value of a variable to some expression.
215 const char *SetDirective; // Defaults to null.
217 /// LCOMMDirective - This is the name of a directive (if supported) that can
218 /// be used to efficiently declare a local (internal) block of zero
219 /// initialized data in the .bss/.data section. The syntax expected is:
220 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
222 const char *LCOMMDirective; // Defaults to null.
224 const char *COMMDirective; // Defaults to "\t.comm\t".
226 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
227 /// argument that specifies the alignment of the declaration.
228 bool COMMDirectiveTakesAlignment; // Defaults to true.
230 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
231 /// directives, this is true for most ELF targets.
232 bool HasDotTypeDotSizeDirective; // Defaults to true.
234 /// UsedDirective - This directive, if non-null, is used to declare a global
235 /// as being used somehow that the assembler can't see. This prevents dead
236 /// code elimination on some targets.
237 const char *UsedDirective; // Defaults to null.
239 /// WeakRefDirective - This directive, if non-null, is used to declare a
240 /// global as being a weak undefined symbol.
241 const char *WeakRefDirective; // Defaults to null.
243 /// HiddenDirective - This directive, if non-null, is used to declare a
244 /// global or function as having hidden visibility.
245 const char *HiddenDirective; // Defaults to "\t.hidden\t".
247 //===--- Dwarf Emission Directives -----------------------------------===//
249 /// HasLEB128 - True if target asm supports leb128 directives.
251 bool HasLEB128; // Defaults to false.
253 /// hasDotLoc - True if target asm supports .loc directives.
255 bool HasDotLoc; // Defaults to false.
257 /// HasDotFile - True if target asm supports .file directives.
259 bool HasDotFile; // Defaults to false.
261 /// SupportsExceptionHandling - True if target supports exception handling.
263 bool SupportsExceptionHandling; // Defaults to false.
265 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
267 bool DwarfRequiresFrameSection; // Defaults to true.
269 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
271 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
273 /// DwarfInfoSection - Section directive for Dwarf info.
275 const char *DwarfInfoSection; // Defaults to ".debug_info".
277 /// DwarfLineSection - Section directive for Dwarf info.
279 const char *DwarfLineSection; // Defaults to ".debug_line".
281 /// DwarfFrameSection - Section directive for Dwarf info.
283 const char *DwarfFrameSection; // Defaults to ".debug_frame".
285 /// DwarfPubNamesSection - Section directive for Dwarf info.
287 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
289 /// DwarfPubTypesSection - Section directive for Dwarf info.
291 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
293 /// DwarfStrSection - Section directive for Dwarf info.
295 const char *DwarfStrSection; // Defaults to ".debug_str".
297 /// DwarfLocSection - Section directive for Dwarf info.
299 const char *DwarfLocSection; // Defaults to ".debug_loc".
301 /// DwarfARangesSection - Section directive for Dwarf info.
303 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
305 /// DwarfRangesSection - Section directive for Dwarf info.
307 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
309 /// DwarfMacInfoSection - Section directive for Dwarf info.
311 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
313 /// DwarfEHFrameSection - Section directive for Exception frames.
315 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
317 //===--- CBE Asm Translation Table -----------------------------------===//
319 const char** AsmTransCBE; // Defaults to empty
323 virtual ~TargetAsmInfo();
325 /// Measure the specified inline asm to determine an approximation of its
327 unsigned getInlineAsmLength(const char *Str) const;
329 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
330 /// call to be explicit llvm code if it wants to. This is useful for
331 /// turning simple inline asms into LLVM intrinsics, which gives the
332 /// compiler more information about the behavior of the code.
333 virtual bool ExpandInlineAsm(CallInst *CI) const {
339 const char *getTextSection() const {
342 const char *getDataSection() const {
345 const char *getBSSSection() const {
348 const char *getZeroFillDirective() const {
349 return ZeroFillDirective;
351 unsigned getAddressSize() const {
354 bool needsSet() const {
357 const char *getPCSymbol() const {
360 char getSeparatorChar() const {
361 return SeparatorChar;
363 const char *getCommentString() const {
364 return CommentString;
366 const char *getGlobalPrefix() const {
369 const char *getPrivateGlobalPrefix() const {
370 return PrivateGlobalPrefix;
372 const char *getJumpTableSpecialLabelPrefix() const {
373 return JumpTableSpecialLabelPrefix;
375 const char *getGlobalVarAddrPrefix() const {
376 return GlobalVarAddrPrefix;
378 const char *getGlobalVarAddrSuffix() const {
379 return GlobalVarAddrSuffix;
381 const char *getFunctionAddrPrefix() const {
382 return FunctionAddrPrefix;
384 const char *getFunctionAddrSuffix() const {
385 return FunctionAddrSuffix;
387 const char *getInlineAsmStart() const {
388 return InlineAsmStart;
390 const char *getInlineAsmEnd() const {
393 unsigned getAssemblerDialect() const {
394 return AssemblerDialect;
396 const char *getZeroDirective() const {
397 return ZeroDirective;
399 const char *getZeroDirectiveSuffix() const {
400 return ZeroDirectiveSuffix;
402 const char *getAsciiDirective() const {
403 return AsciiDirective;
405 const char *getAscizDirective() const {
406 return AscizDirective;
408 const char *getData8bitsDirective() const {
409 return Data8bitsDirective;
411 const char *getData16bitsDirective() const {
412 return Data16bitsDirective;
414 const char *getData32bitsDirective() const {
415 return Data32bitsDirective;
417 const char *getData64bitsDirective() const {
418 return Data64bitsDirective;
420 const char *getJumpTableDirective() const {
421 return JumpTableDirective;
423 const char *getAlignDirective() const {
424 return AlignDirective;
426 bool getAlignmentIsInBytes() const {
427 return AlignmentIsInBytes;
429 const char *getSwitchToSectionDirective() const {
430 return SwitchToSectionDirective;
432 const char *getTextSectionStartSuffix() const {
433 return TextSectionStartSuffix;
435 const char *getDataSectionStartSuffix() const {
436 return DataSectionStartSuffix;
438 const char *getSectionEndDirectiveSuffix() const {
439 return SectionEndDirectiveSuffix;
441 const char *getConstantPoolSection() const {
442 return ConstantPoolSection;
444 const char *getJumpTableDataSection() const {
445 return JumpTableDataSection;
447 const char *getCStringSection() const {
448 return CStringSection;
450 const char *getStaticCtorsSection() const {
451 return StaticCtorsSection;
453 const char *getStaticDtorsSection() const {
454 return StaticDtorsSection;
456 const char *getFourByteConstantSection() const {
457 return FourByteConstantSection;
459 const char *getEightByteConstantSection() const {
460 return EightByteConstantSection;
462 const char *getSixteenByteConstantSection() const {
463 return SixteenByteConstantSection;
465 const char *getGlobalDirective() const {
466 return GlobalDirective;
468 const char *getSetDirective() const {
471 const char *getLCOMMDirective() const {
472 return LCOMMDirective;
474 const char *getCOMMDirective() const {
475 return COMMDirective;
477 bool getCOMMDirectiveTakesAlignment() const {
478 return COMMDirectiveTakesAlignment;
480 bool hasDotTypeDotSizeDirective() const {
481 return HasDotTypeDotSizeDirective;
483 const char *getUsedDirective() const {
484 return UsedDirective;
486 const char *getWeakRefDirective() const {
487 return WeakRefDirective;
489 const char *getHiddenDirective() const {
490 return HiddenDirective;
492 bool hasLEB128() const {
495 bool hasDotLoc() const {
498 bool hasDotFile() const {
501 bool getSupportsExceptionHandling() const {
502 return SupportsExceptionHandling;
504 bool getDwarfRequiresFrameSection() const {
505 return DwarfRequiresFrameSection;
507 const char *getDwarfAbbrevSection() const {
508 return DwarfAbbrevSection;
510 const char *getDwarfInfoSection() const {
511 return DwarfInfoSection;
513 const char *getDwarfLineSection() const {
514 return DwarfLineSection;
516 const char *getDwarfFrameSection() const {
517 return DwarfFrameSection;
519 const char *getDwarfPubNamesSection() const {
520 return DwarfPubNamesSection;
522 const char *getDwarfPubTypesSection() const {
523 return DwarfPubTypesSection;
525 const char *getDwarfStrSection() const {
526 return DwarfStrSection;
528 const char *getDwarfLocSection() const {
529 return DwarfLocSection;
531 const char *getDwarfARangesSection() const {
532 return DwarfARangesSection;
534 const char *getDwarfRangesSection() const {
535 return DwarfRangesSection;
537 const char *getDwarfMacInfoSection() const {
538 return DwarfMacInfoSection;
540 const char *getDwarfEHFrameSection() const {
541 return DwarfEHFrameSection;
543 const char** getAsmCBE() const {