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 /// SeparatorChar - This character, if specified, is used to separate
64 /// instructions from each other when on the same line. This is used to
65 /// measure inline asm instructions.
66 char SeparatorChar; // Defaults to ';'
68 /// CommentString - This indicates the comment character used by the
70 const char *CommentString; // Defaults to "#"
72 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
73 /// onto all global symbols. This is often used for "_" or ".".
74 const char *GlobalPrefix; // Defaults to ""
76 /// PrivateGlobalPrefix - This prefix is used for globals like constant
77 /// pool entries that are completely private to the .o file and should not
78 /// have names in the .o file. This is often "." or "L".
79 const char *PrivateGlobalPrefix; // Defaults to "."
81 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
82 /// emitted before jump tables with the specified prefix.
83 const char *JumpTableSpecialLabelPrefix; // Default to null.
85 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
86 /// will enclose any GlobalVariable (that isn't a function)
88 const char *GlobalVarAddrPrefix; // Defaults to ""
89 const char *GlobalVarAddrSuffix; // Defaults to ""
91 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
92 /// will enclose any GlobalVariable that points to a function.
93 /// For example, this is used by the IA64 backend to materialize
94 /// function descriptors, by decorating the ".data8" object with the
95 /// \literal @fptr( ) \endliteral
96 /// link-relocation operator.
98 const char *FunctionAddrPrefix; // Defaults to ""
99 const char *FunctionAddrSuffix; // Defaults to ""
101 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
102 /// emit before and after an inline assembly statement.
103 const char *InlineAsmStart; // Defaults to "#APP\n"
104 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
106 /// AssemblerDialect - Which dialect of an assembler variant to use.
107 unsigned AssemblerDialect; // Defaults to 0
109 //===--- Data Emission Directives -------------------------------------===//
111 /// ZeroDirective - this should be set to the directive used to get some
112 /// number of zero bytes emitted to the current section. Common cases are
113 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
114 /// Data*bitsDirective's will be used to emit zero bytes.
115 const char *ZeroDirective; // Defaults to "\t.zero\t"
116 const char *ZeroDirectiveSuffix; // Defaults to ""
118 /// AsciiDirective - This directive allows emission of an ascii string with
119 /// the standard C escape characters embedded into it.
120 const char *AsciiDirective; // Defaults to "\t.ascii\t"
122 /// AscizDirective - If not null, this allows for special handling of
123 /// zero terminated strings on this target. This is commonly supported as
124 /// ".asciz". If a target doesn't support this, it can be set to null.
125 const char *AscizDirective; // Defaults to "\t.asciz\t"
127 /// DataDirectives - These directives are used to output some unit of
128 /// integer data to the current section. If a data directive is set to
129 /// null, smaller data directives will be used to emit the large sizes.
130 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
131 const char *Data16bitsDirective; // Defaults to "\t.short\t"
132 const char *Data32bitsDirective; // Defaults to "\t.long\t"
133 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
135 //===--- Alignment Information ----------------------------------------===//
137 /// AlignDirective - The directive used to emit round up to an alignment
140 const char *AlignDirective; // Defaults to "\t.align\t"
142 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
143 /// emits ".align N" directives, where N is the number of bytes to align to.
144 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
146 bool AlignmentIsInBytes; // Defaults to true
148 //===--- Section Switching Directives ---------------------------------===//
150 /// SwitchToSectionDirective - This is the directive used when we want to
151 /// emit a global to an arbitrary section. The section name is emited after
153 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
155 /// TextSectionStartSuffix - This is printed after each start of section
156 /// directive for text sections.
157 const char *TextSectionStartSuffix; // Defaults to "".
159 /// DataSectionStartSuffix - This is printed after each start of section
160 /// directive for data sections.
161 const char *DataSectionStartSuffix; // Defaults to "".
163 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
164 /// section with the section name and this suffix printed.
165 const char *SectionEndDirectiveSuffix;// Defaults to null.
167 /// ConstantPoolSection - This is the section that we SwitchToSection right
168 /// before emitting the constant pool for a function.
169 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
171 /// JumpTableDataSection - This is the section that we SwitchToSection right
172 /// before emitting the jump tables for a function when the relocation model
174 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
176 /// JumpTableDirective - if non-null, the directive to emit before a jump
178 const char *JumpTableDirective;
180 /// CStringSection - If not null, this allows for special handling of
181 /// cstring constants (\0 terminated string that does not contain any
182 /// other null bytes) on this target. This is commonly supported as
184 const char *CStringSection; // Defaults to NULL
186 /// StaticCtorsSection - This is the directive that is emitted to switch to
187 /// a section to emit the static constructor list.
188 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
189 const char *StaticCtorsSection;
191 /// StaticDtorsSection - This is the directive that is emitted to switch to
192 /// a section to emit the static destructor list.
193 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
194 const char *StaticDtorsSection;
196 /// FourByteConstantSection, EightByteConstantSection,
197 /// SixteenByteConstantSection - These are special sections where we place
198 /// 4-, 8-, and 16- byte constant literals.
199 const char *FourByteConstantSection;
200 const char *EightByteConstantSection;
201 const char *SixteenByteConstantSection;
203 //===--- Global Variable Emission Directives --------------------------===//
205 /// GlobalDirective - This is the directive used to declare a global entity.
207 const char *GlobalDirective; // Defaults to NULL.
209 /// SetDirective - This is the name of a directive that can be used to tell
210 /// the assembler to set the value of a variable to some expression.
211 const char *SetDirective; // Defaults to null.
213 /// LCOMMDirective - This is the name of a directive (if supported) that can
214 /// be used to efficiently declare a local (internal) block of zero
215 /// initialized data in the .bss/.data section. The syntax expected is:
216 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
218 const char *LCOMMDirective; // Defaults to null.
220 const char *COMMDirective; // Defaults to "\t.comm\t".
222 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
223 /// argument that specifies the alignment of the declaration.
224 bool COMMDirectiveTakesAlignment; // Defaults to true.
226 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
227 /// directives, this is true for most ELF targets.
228 bool HasDotTypeDotSizeDirective; // Defaults to true.
230 /// UsedDirective - This directive, if non-null, is used to declare a global
231 /// as being used somehow that the assembler can't see. This prevents dead
232 /// code elimination on some targets.
233 const char *UsedDirective; // Defaults to null.
235 /// WeakRefDirective - This directive, if non-null, is used to declare a
236 /// global as being a weak undefined symbol.
237 const char *WeakRefDirective; // Defaults to null.
239 /// HiddenDirective - This directive, if non-null, is used to declare a
240 /// global or function as having hidden visibility.
241 const char *HiddenDirective; // Defaults to "\t.hidden\t".
243 //===--- Dwarf Emission Directives -----------------------------------===//
245 /// HasLEB128 - True if target asm supports leb128 directives.
247 bool HasLEB128; // Defaults to false.
249 /// hasDotLoc - True if target asm supports .loc directives.
251 bool HasDotLoc; // Defaults to false.
253 /// HasDotFile - True if target asm supports .file directives.
255 bool HasDotFile; // Defaults to false.
257 /// SupportsExceptionHandling - True if target supports exception handling.
259 bool SupportsExceptionHandling; // Defaults to false.
261 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
263 bool DwarfRequiresFrameSection; // Defaults to true.
265 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
267 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
269 /// DwarfInfoSection - Section directive for Dwarf info.
271 const char *DwarfInfoSection; // Defaults to ".debug_info".
273 /// DwarfLineSection - Section directive for Dwarf info.
275 const char *DwarfLineSection; // Defaults to ".debug_line".
277 /// DwarfFrameSection - Section directive for Dwarf info.
279 const char *DwarfFrameSection; // Defaults to ".debug_frame".
281 /// DwarfPubNamesSection - Section directive for Dwarf info.
283 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
285 /// DwarfPubTypesSection - Section directive for Dwarf info.
287 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
289 /// DwarfStrSection - Section directive for Dwarf info.
291 const char *DwarfStrSection; // Defaults to ".debug_str".
293 /// DwarfLocSection - Section directive for Dwarf info.
295 const char *DwarfLocSection; // Defaults to ".debug_loc".
297 /// DwarfARangesSection - Section directive for Dwarf info.
299 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
301 /// DwarfRangesSection - Section directive for Dwarf info.
303 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
305 /// DwarfMacInfoSection - Section directive for Dwarf info.
307 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
309 //===--- CBE Asm Translation Table -----------------------------------===//
311 const char** AsmTransCBE; // Defaults to empty
315 virtual ~TargetAsmInfo();
317 /// Measure the specified inline asm to determine an approximation of its
319 unsigned getInlineAsmLength(const char *Str) const;
321 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
322 /// call to be explicit llvm code if it wants to. This is useful for
323 /// turning simple inline asms into LLVM intrinsics, which gives the
324 /// compiler more information about the behavior of the code.
325 virtual bool ExpandInlineAsm(CallInst *CI) const {
331 const char *getTextSection() const {
334 const char *getDataSection() const {
337 const char *getBSSSection() const {
340 const char *getZeroFillDirective() const {
341 return ZeroFillDirective;
343 unsigned getAddressSize() const {
346 bool needsSet() const {
349 const char *getCommentString() const {
350 return CommentString;
352 const char *getGlobalPrefix() const {
355 const char *getPrivateGlobalPrefix() const {
356 return PrivateGlobalPrefix;
358 const char *getJumpTableSpecialLabelPrefix() const {
359 return JumpTableSpecialLabelPrefix;
361 const char *getGlobalVarAddrPrefix() const {
362 return GlobalVarAddrPrefix;
364 const char *getGlobalVarAddrSuffix() const {
365 return GlobalVarAddrSuffix;
367 const char *getFunctionAddrPrefix() const {
368 return FunctionAddrPrefix;
370 const char *getFunctionAddrSuffix() const {
371 return FunctionAddrSuffix;
373 const char *getInlineAsmStart() const {
374 return InlineAsmStart;
376 const char *getInlineAsmEnd() const {
379 unsigned getAssemblerDialect() const {
380 return AssemblerDialect;
382 const char *getZeroDirective() const {
383 return ZeroDirective;
385 const char *getZeroDirectiveSuffix() const {
386 return ZeroDirectiveSuffix;
388 const char *getAsciiDirective() const {
389 return AsciiDirective;
391 const char *getAscizDirective() const {
392 return AscizDirective;
394 const char *getData8bitsDirective() const {
395 return Data8bitsDirective;
397 const char *getData16bitsDirective() const {
398 return Data16bitsDirective;
400 const char *getData32bitsDirective() const {
401 return Data32bitsDirective;
403 const char *getData64bitsDirective() const {
404 return Data64bitsDirective;
406 const char *getJumpTableDirective() const {
407 return JumpTableDirective;
409 const char *getAlignDirective() const {
410 return AlignDirective;
412 bool getAlignmentIsInBytes() const {
413 return AlignmentIsInBytes;
415 const char *getSwitchToSectionDirective() const {
416 return SwitchToSectionDirective;
418 const char *getTextSectionStartSuffix() const {
419 return TextSectionStartSuffix;
421 const char *getDataSectionStartSuffix() const {
422 return DataSectionStartSuffix;
424 const char *getSectionEndDirectiveSuffix() const {
425 return SectionEndDirectiveSuffix;
427 const char *getConstantPoolSection() const {
428 return ConstantPoolSection;
430 const char *getJumpTableDataSection() const {
431 return JumpTableDataSection;
433 const char *getCStringSection() const {
434 return CStringSection;
436 const char *getStaticCtorsSection() const {
437 return StaticCtorsSection;
439 const char *getStaticDtorsSection() const {
440 return StaticDtorsSection;
442 const char *getFourByteConstantSection() const {
443 return FourByteConstantSection;
445 const char *getEightByteConstantSection() const {
446 return EightByteConstantSection;
448 const char *getSixteenByteConstantSection() const {
449 return SixteenByteConstantSection;
451 const char *getGlobalDirective() const {
452 return GlobalDirective;
454 const char *getSetDirective() const {
457 const char *getLCOMMDirective() const {
458 return LCOMMDirective;
460 const char *getCOMMDirective() const {
461 return COMMDirective;
463 bool getCOMMDirectiveTakesAlignment() const {
464 return COMMDirectiveTakesAlignment;
466 bool hasDotTypeDotSizeDirective() const {
467 return HasDotTypeDotSizeDirective;
469 const char *getUsedDirective() const {
470 return UsedDirective;
472 const char *getWeakRefDirective() const {
473 return WeakRefDirective;
475 const char *getHiddenDirective() const {
476 return HiddenDirective;
478 bool hasLEB128() const {
481 bool hasDotLoc() const {
484 bool hasDotFile() const {
487 bool getSupportsExceptionHandling() const {
488 return SupportsExceptionHandling;
490 bool getDwarfRequiresFrameSection() const {
491 return DwarfRequiresFrameSection;
493 const char *getDwarfAbbrevSection() const {
494 return DwarfAbbrevSection;
496 const char *getDwarfInfoSection() const {
497 return DwarfInfoSection;
499 const char *getDwarfLineSection() const {
500 return DwarfLineSection;
502 const char *getDwarfFrameSection() const {
503 return DwarfFrameSection;
505 const char *getDwarfPubNamesSection() const {
506 return DwarfPubNamesSection;
508 const char *getDwarfPubTypesSection() const {
509 return DwarfPubTypesSection;
511 const char *getDwarfStrSection() const {
512 return DwarfStrSection;
514 const char *getDwarfLocSection() const {
515 return DwarfLocSection;
517 const char *getDwarfARangesSection() const {
518 return DwarfARangesSection;
520 const char *getDwarfRangesSection() const {
521 return DwarfRangesSection;
523 const char *getDwarfMacInfoSection() const {
524 return DwarfMacInfoSection;
526 const char** getAsmCBE() const {