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.
44 const char *BSSSection; // Default to ".bss".
46 /// AddressSize - Size of addresses used in file.
48 unsigned AddressSize; // Defaults to 4.
50 /// NeedsSet - True if target asm can't compute addresses on data
52 bool NeedsSet; // Defaults to false.
54 /// MaxInstLength - This is the maximum possible length of an instruction,
55 /// which is needed to compute the size of an inline asm.
56 unsigned MaxInstLength; // Defaults to 4.
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 /// CommentString - This indicates the comment character used by the
65 const char *CommentString; // Defaults to "#"
67 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
68 /// onto all global symbols. This is often used for "_" or ".".
69 const char *GlobalPrefix; // Defaults to ""
71 /// PrivateGlobalPrefix - This prefix is used for globals like constant
72 /// pool entries that are completely private to the .o file and should not
73 /// have names in the .o file. This is often "." or "L".
74 const char *PrivateGlobalPrefix; // Defaults to "."
76 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
77 /// will enclose any GlobalVariable (that isn't a function)
79 const char *GlobalVarAddrPrefix; // Defaults to ""
80 const char *GlobalVarAddrSuffix; // Defaults to ""
82 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
83 /// will enclose any GlobalVariable that points to a function.
84 /// For example, this is used by the IA64 backend to materialize
85 /// function descriptors, by decorating the ".data8" object with the
86 /// \literal @fptr( ) \endliteral
87 /// link-relocation operator.
89 const char *FunctionAddrPrefix; // Defaults to ""
90 const char *FunctionAddrSuffix; // Defaults to ""
92 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
93 /// emit before and after an inline assembly statement.
94 const char *InlineAsmStart; // Defaults to "#APP\n"
95 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
97 /// AssemblerDialect - Which dialect of an assembler variant to use.
98 unsigned AssemblerDialect; // Defaults to 0
100 //===--- Data Emission Directives -------------------------------------===//
102 /// ZeroDirective - this should be set to the directive used to get some
103 /// number of zero bytes emitted to the current section. Common cases are
104 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
105 /// Data*bitsDirective's will be used to emit zero bytes.
106 const char *ZeroDirective; // Defaults to "\t.zero\t"
107 const char *ZeroDirectiveSuffix; // Defaults to ""
109 /// AsciiDirective - This directive allows emission of an ascii string with
110 /// the standard C escape characters embedded into it.
111 const char *AsciiDirective; // Defaults to "\t.ascii\t"
113 /// AscizDirective - If not null, this allows for special handling of
114 /// zero terminated strings on this target. This is commonly supported as
115 /// ".asciz". If a target doesn't support this, it can be set to null.
116 const char *AscizDirective; // Defaults to "\t.asciz\t"
118 /// DataDirectives - These directives are used to output some unit of
119 /// integer data to the current section. If a data directive is set to
120 /// null, smaller data directives will be used to emit the large sizes.
121 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
122 const char *Data16bitsDirective; // Defaults to "\t.short\t"
123 const char *Data32bitsDirective; // Defaults to "\t.long\t"
124 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
126 //===--- Alignment Information ----------------------------------------===//
128 /// AlignDirective - The directive used to emit round up to an alignment
131 const char *AlignDirective; // Defaults to "\t.align\t"
133 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
134 /// emits ".align N" directives, where N is the number of bytes to align to.
135 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
137 bool AlignmentIsInBytes; // Defaults to true
139 //===--- Section Switching Directives ---------------------------------===//
141 /// SwitchToSectionDirective - This is the directive used when we want to
142 /// emit a global to an arbitrary section. The section name is emited after
144 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
146 /// TextSectionStartSuffix - This is printed after each start of section
147 /// directive for text sections.
148 const char *TextSectionStartSuffix; // Defaults to "".
150 /// DataSectionStartSuffix - This is printed after each start of section
151 /// directive for data sections.
152 const char *DataSectionStartSuffix; // Defaults to "".
154 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
155 /// section with the section name and this suffix printed.
156 const char *SectionEndDirectiveSuffix;// Defaults to null.
158 /// ConstantPoolSection - This is the section that we SwitchToSection right
159 /// before emitting the constant pool for a function.
160 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
162 /// JumpTableDataSection - This is the section that we SwitchToSection right
163 /// before emitting the jump tables for a function when the relocation model
165 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
167 /// JumpTableDirective - if non-null, the directive to emit before a jump
169 const char *JumpTableDirective;
171 /// CStringSection - If not null, this allows for special handling of
172 /// cstring constants (\0 terminated string that does not contain any
173 /// other null bytes) on this target. This is commonly supported as
175 const char *CStringSection; // Defaults to NULL
177 /// StaticCtorsSection - This is the directive that is emitted to switch to
178 /// a section to emit the static constructor list.
179 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
180 const char *StaticCtorsSection;
182 /// StaticDtorsSection - This is the directive that is emitted to switch to
183 /// a section to emit the static destructor list.
184 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
185 const char *StaticDtorsSection;
187 /// FourByteConstantSection, EightByteConstantSection,
188 /// SixteenByteConstantSection - These are special sections where we place
189 /// 4-, 8-, and 16- byte constant literals.
190 const char *FourByteConstantSection;
191 const char *EightByteConstantSection;
192 const char *SixteenByteConstantSection;
194 //===--- Global Variable Emission Directives --------------------------===//
196 /// SetDirective - This is the name of a directive that can be used to tell
197 /// the assembler to set the value of a variable to some expression.
198 const char *SetDirective; // Defaults to null.
200 /// LCOMMDirective - This is the name of a directive (if supported) that can
201 /// be used to efficiently declare a local (internal) block of zero
202 /// initialized data in the .bss/.data section. The syntax expected is:
203 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
205 const char *LCOMMDirective; // Defaults to null.
207 const char *COMMDirective; // Defaults to "\t.comm\t".
209 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
210 /// argument that specifies the alignment of the declaration.
211 bool COMMDirectiveTakesAlignment; // Defaults to true.
213 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
214 /// directives, this is true for most ELF targets.
215 bool HasDotTypeDotSizeDirective; // Defaults to true.
217 /// UsedDirective - This directive, if non-null, is used to declare a global
218 /// as being used somehow that the assembler can't see. This prevents dead
219 /// code elimination on some targets.
220 const char *UsedDirective; // Defaults to null.
222 /// WeakRefDirective - This directive, if non-null, is used to declare a
223 /// global as being a weak undefined symbol.
224 const char *WeakRefDirective; // Defaults to null.
226 /// HiddenDirective - This directive, if non-null, is used to declare a
227 /// global or function as having hidden visibility.
228 const char *HiddenDirective; // Defaults to "\t.hidden\t".
230 //===--- Dwarf Emission Directives -----------------------------------===//
232 /// HasLEB128 - True if target asm supports leb128 directives.
234 bool HasLEB128; // Defaults to false.
236 /// hasDotLoc - True if target asm supports .loc directives.
238 bool HasDotLoc; // Defaults to false.
240 /// HasDotFile - True if target asm supports .file directives.
242 bool HasDotFile; // Defaults to false.
244 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
246 bool DwarfRequiresFrameSection; // Defaults to true.
248 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
250 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
252 /// DwarfInfoSection - Section directive for Dwarf info.
254 const char *DwarfInfoSection; // Defaults to ".debug_info".
256 /// DwarfLineSection - Section directive for Dwarf info.
258 const char *DwarfLineSection; // Defaults to ".debug_line".
260 /// DwarfFrameSection - Section directive for Dwarf info.
262 const char *DwarfFrameSection; // Defaults to ".debug_frame".
264 /// DwarfPubNamesSection - Section directive for Dwarf info.
266 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
268 /// DwarfPubTypesSection - Section directive for Dwarf info.
270 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
272 /// DwarfStrSection - Section directive for Dwarf info.
274 const char *DwarfStrSection; // Defaults to ".debug_str".
276 /// DwarfLocSection - Section directive for Dwarf info.
278 const char *DwarfLocSection; // Defaults to ".debug_loc".
280 /// DwarfARangesSection - Section directive for Dwarf info.
282 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
284 /// DwarfRangesSection - Section directive for Dwarf info.
286 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
288 /// DwarfMacInfoSection - Section directive for Dwarf info.
290 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
292 //===--- CBE Asm Translation Table -----------------------------------===//
294 const char** AsmTransCBE; // Defaults to empty
298 virtual ~TargetAsmInfo();
300 /// Measure the specified inline asm to determine an approximation of its
302 unsigned getInlineAsmLength(const char *Str) const;
304 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
305 /// call to be explicit llvm code if it wants to. This is useful for
306 /// turning simple inline asms into LLVM intrinsics, which gives the
307 /// compiler more information about the behavior of the code.
308 virtual bool ExpandInlineAsm(CallInst *CI) const {
314 const char *getTextSection() const {
317 const char *getDataSection() const {
320 const char *getBSSSection() const {
323 unsigned getAddressSize() const {
326 bool needsSet() const {
329 const char *getCommentString() const {
330 return CommentString;
332 const char *getGlobalPrefix() const {
335 const char *getPrivateGlobalPrefix() const {
336 return PrivateGlobalPrefix;
338 const char *getGlobalVarAddrPrefix() const {
339 return GlobalVarAddrPrefix;
341 const char *getGlobalVarAddrSuffix() const {
342 return GlobalVarAddrSuffix;
344 const char *getFunctionAddrPrefix() const {
345 return FunctionAddrPrefix;
347 const char *getFunctionAddrSuffix() const {
348 return FunctionAddrSuffix;
350 const char *getInlineAsmStart() const {
351 return InlineAsmStart;
353 const char *getInlineAsmEnd() const {
356 unsigned getAssemblerDialect() const {
357 return AssemblerDialect;
359 const char *getZeroDirective() const {
360 return ZeroDirective;
362 const char *getZeroDirectiveSuffix() const {
363 return ZeroDirectiveSuffix;
365 const char *getAsciiDirective() const {
366 return AsciiDirective;
368 const char *getAscizDirective() const {
369 return AscizDirective;
371 const char *getData8bitsDirective() const {
372 return Data8bitsDirective;
374 const char *getData16bitsDirective() const {
375 return Data16bitsDirective;
377 const char *getData32bitsDirective() const {
378 return Data32bitsDirective;
380 const char *getData64bitsDirective() const {
381 return Data64bitsDirective;
383 const char *getJumpTableDirective() const {
384 return JumpTableDirective;
386 const char *getAlignDirective() const {
387 return AlignDirective;
389 bool getAlignmentIsInBytes() const {
390 return AlignmentIsInBytes;
392 const char *getSwitchToSectionDirective() const {
393 return SwitchToSectionDirective;
395 const char *getTextSectionStartSuffix() const {
396 return TextSectionStartSuffix;
398 const char *getDataSectionStartSuffix() const {
399 return DataSectionStartSuffix;
401 const char *getSectionEndDirectiveSuffix() const {
402 return SectionEndDirectiveSuffix;
404 const char *getConstantPoolSection() const {
405 return ConstantPoolSection;
407 const char *getJumpTableDataSection() const {
408 return JumpTableDataSection;
410 const char *getCStringSection() const {
411 return CStringSection;
413 const char *getStaticCtorsSection() const {
414 return StaticCtorsSection;
416 const char *getStaticDtorsSection() const {
417 return StaticDtorsSection;
419 const char *getFourByteConstantSection() const {
420 return FourByteConstantSection;
422 const char *getEightByteConstantSection() const {
423 return EightByteConstantSection;
425 const char *getSixteenByteConstantSection() const {
426 return SixteenByteConstantSection;
428 const char *getSetDirective() const {
431 const char *getLCOMMDirective() const {
432 return LCOMMDirective;
434 const char *getCOMMDirective() const {
435 return COMMDirective;
437 bool getCOMMDirectiveTakesAlignment() const {
438 return COMMDirectiveTakesAlignment;
440 bool hasDotTypeDotSizeDirective() const {
441 return HasDotTypeDotSizeDirective;
443 const char *getUsedDirective() const {
444 return UsedDirective;
446 const char *getWeakRefDirective() const {
447 return WeakRefDirective;
449 const char *getHiddenDirective() const {
450 return HiddenDirective;
452 bool hasLEB128() const {
455 bool hasDotLoc() const {
458 bool hasDotFile() const {
461 bool getDwarfRequiresFrameSection() const {
462 return DwarfRequiresFrameSection;
464 const char *getDwarfAbbrevSection() const {
465 return DwarfAbbrevSection;
467 const char *getDwarfInfoSection() const {
468 return DwarfInfoSection;
470 const char *getDwarfLineSection() const {
471 return DwarfLineSection;
473 const char *getDwarfFrameSection() const {
474 return DwarfFrameSection;
476 const char *getDwarfPubNamesSection() const {
477 return DwarfPubNamesSection;
479 const char *getDwarfPubTypesSection() const {
480 return DwarfPubTypesSection;
482 const char *getDwarfStrSection() const {
483 return DwarfStrSection;
485 const char *getDwarfLocSection() const {
486 return DwarfLocSection;
488 const char *getDwarfARangesSection() const {
489 return DwarfARangesSection;
491 const char *getDwarfRangesSection() const {
492 return DwarfRangesSection;
494 const char *getDwarfMacInfoSection() const {
495 return DwarfMacInfoSection;
497 const char** getAsmCBE() const {