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