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 /// AddressSize - Size of addresses used in file.
44 unsigned AddressSize; // Defaults to 4.
46 /// NeedsSet - True if target asm can't compute addresses on data
48 bool NeedsSet; // Defaults to false.
50 /// MaxInstLength - This is the maximum possible length of an instruction,
51 /// which is needed to compute the size of an inline asm.
52 unsigned MaxInstLength; // Defaults to 4.
54 /// SeparatorChar - This character, if specified, is used to separate
55 /// instructions from each other when on the same line. This is used to
56 /// measure inline asm instructions.
57 char SeparatorChar; // Defaults to ';'
59 /// CommentString - This indicates the comment character used by the
61 const char *CommentString; // Defaults to "#"
63 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
64 /// onto all global symbols. This is often used for "_" or ".".
65 const char *GlobalPrefix; // Defaults to ""
67 /// PrivateGlobalPrefix - This prefix is used for globals like constant
68 /// pool entries that are completely private to the .o file and should not
69 /// have names in the .o file. This is often "." or "L".
70 const char *PrivateGlobalPrefix; // Defaults to "."
72 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
73 /// will enclose any GlobalVariable (that isn't a function)
75 const char *GlobalVarAddrPrefix; // Defaults to ""
76 const char *GlobalVarAddrSuffix; // Defaults to ""
78 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
79 /// will enclose any GlobalVariable that points to a function.
80 /// For example, this is used by the IA64 backend to materialize
81 /// function descriptors, by decorating the ".data8" object with the
82 /// \literal @fptr( ) \endliteral
83 /// link-relocation operator.
85 const char *FunctionAddrPrefix; // Defaults to ""
86 const char *FunctionAddrSuffix; // Defaults to ""
88 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
89 /// emit before and after an inline assembly statement.
90 const char *InlineAsmStart; // Defaults to "#APP\n"
91 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
93 /// AssemblerDialect - Which dialect of an assembler variant to use.
94 unsigned AssemblerDialect; // Defaults to 0
96 //===--- Data Emission Directives -------------------------------------===//
98 /// ZeroDirective - this should be set to the directive used to get some
99 /// number of zero bytes emitted to the current section. Common cases are
100 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
101 /// Data*bitsDirective's will be used to emit zero bytes.
102 const char *ZeroDirective; // Defaults to "\t.zero\t"
103 const char *ZeroDirectiveSuffix; // Defaults to ""
105 /// AsciiDirective - This directive allows emission of an ascii string with
106 /// the standard C escape characters embedded into it.
107 const char *AsciiDirective; // Defaults to "\t.ascii\t"
109 /// AscizDirective - If not null, this allows for special handling of
110 /// zero terminated strings on this target. This is commonly supported as
111 /// ".asciz". If a target doesn't support this, it can be set to null.
112 const char *AscizDirective; // Defaults to "\t.asciz\t"
114 /// DataDirectives - These directives are used to output some unit of
115 /// integer data to the current section. If a data directive is set to
116 /// null, smaller data directives will be used to emit the large sizes.
117 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
118 const char *Data16bitsDirective; // Defaults to "\t.short\t"
119 const char *Data32bitsDirective; // Defaults to "\t.long\t"
120 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
122 //===--- Alignment Information ----------------------------------------===//
124 /// AlignDirective - The directive used to emit round up to an alignment
127 const char *AlignDirective; // Defaults to "\t.align\t"
129 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
130 /// emits ".align N" directives, where N is the number of bytes to align to.
131 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
133 bool AlignmentIsInBytes; // Defaults to true
135 //===--- Section Switching Directives ---------------------------------===//
137 /// SwitchToSectionDirective - This is the directive used when we want to
138 /// emit a global to an arbitrary section. The section name is emited after
140 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
142 /// TextSectionStartSuffix - This is printed after each start of section
143 /// directive for text sections.
144 const char *TextSectionStartSuffix; // Defaults to "".
146 /// DataSectionStartSuffix - This is printed after each start of section
147 /// directive for data sections.
148 const char *DataSectionStartSuffix; // Defaults to "".
150 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
151 /// section with the section name and this suffix printed.
152 const char *SectionEndDirectiveSuffix;// Defaults to null.
154 /// ConstantPoolSection - This is the section that we SwitchToSection right
155 /// before emitting the constant pool for a function.
156 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
158 /// JumpTableDataSection - This is the section that we SwitchToSection right
159 /// before emitting the jump tables for a function when the relocation model
161 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
163 /// JumpTableDirective - if non-null, the directive to emit before a jump
165 const char *JumpTableDirective;
167 /// CStringSection - If not null, this allows for special handling of
168 /// cstring constants (\0 terminated string that does not contain any
169 /// other null bytes) on this target. This is commonly supported as
171 const char *CStringSection; // Defaults to NULL
173 /// StaticCtorsSection - This is the directive that is emitted to switch to
174 /// a section to emit the static constructor list.
175 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
176 const char *StaticCtorsSection;
178 /// StaticDtorsSection - This is the directive that is emitted to switch to
179 /// a section to emit the static destructor list.
180 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
181 const char *StaticDtorsSection;
183 /// FourByteConstantSection, EightByteConstantSection,
184 /// SixteenByteConstantSection - These are special sections where we place
185 /// 4-, 8-, and 16- byte constant literals.
186 const char *FourByteConstantSection;
187 const char *EightByteConstantSection;
188 const char *SixteenByteConstantSection;
190 //===--- Global Variable Emission Directives --------------------------===//
192 /// SetDirective - This is the name of a directive that can be used to tell
193 /// the assembler to set the value of a variable to some expression.
194 const char *SetDirective; // Defaults to null.
196 /// LCOMMDirective - This is the name of a directive (if supported) that can
197 /// be used to efficiently declare a local (internal) block of zero
198 /// initialized data in the .bss/.data section. The syntax expected is:
199 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
201 const char *LCOMMDirective; // Defaults to null.
203 const char *COMMDirective; // Defaults to "\t.comm\t".
205 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
206 /// argument that specifies the alignment of the declaration.
207 bool COMMDirectiveTakesAlignment; // Defaults to true.
209 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
210 /// directives, this is true for most ELF targets.
211 bool HasDotTypeDotSizeDirective; // Defaults to true.
213 /// UsedDirective - This directive, if non-null, is used to declare a global
214 /// as being used somehow that the assembler can't see. This prevents dead
215 /// code elimination on some targets.
216 const char *UsedDirective; // Defaults to null.
218 /// WeakRefDirective - This directive, if non-null, is used to declare a
219 /// global as being a weak undefined symbol.
220 const char *WeakRefDirective; // Defaults to null.
222 /// HiddenDirective - This directive, if non-null, is used to declare a
223 /// global or function as having hidden visibility.
224 const char *HiddenDirective; // Defaults to "\t.hidden\t".
226 //===--- Dwarf Emission Directives -----------------------------------===//
228 /// HasLEB128 - True if target asm supports leb128 directives.
230 bool HasLEB128; // Defaults to false.
232 /// hasDotLoc - True if target asm supports .loc directives.
234 bool HasDotLoc; // Defaults to false.
236 /// HasDotFile - True if target asm supports .file directives.
238 bool HasDotFile; // Defaults to false.
240 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
242 bool DwarfRequiresFrameSection; // Defaults to true.
244 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
246 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
248 /// DwarfInfoSection - Section directive for Dwarf info.
250 const char *DwarfInfoSection; // Defaults to ".debug_info".
252 /// DwarfLineSection - Section directive for Dwarf info.
254 const char *DwarfLineSection; // Defaults to ".debug_line".
256 /// DwarfFrameSection - Section directive for Dwarf info.
258 const char *DwarfFrameSection; // Defaults to ".debug_frame".
260 /// DwarfPubNamesSection - Section directive for Dwarf info.
262 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
264 /// DwarfPubTypesSection - Section directive for Dwarf info.
266 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
268 /// DwarfStrSection - Section directive for Dwarf info.
270 const char *DwarfStrSection; // Defaults to ".debug_str".
272 /// DwarfLocSection - Section directive for Dwarf info.
274 const char *DwarfLocSection; // Defaults to ".debug_loc".
276 /// DwarfARangesSection - Section directive for Dwarf info.
278 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
280 /// DwarfRangesSection - Section directive for Dwarf info.
282 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
284 /// DwarfMacInfoSection - Section directive for Dwarf info.
286 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
288 //===--- CBE Asm Translation Table -----------------------------------===//
290 const char** AsmTransCBE; // Defaults to empty
294 virtual ~TargetAsmInfo();
296 /// Measure the specified inline asm to determine an approximation of its
298 unsigned getInlineAsmLength(const char *Str) const;
300 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
301 /// call to be explicit llvm code if it wants to. This is useful for
302 /// turning simple inline asms into LLVM intrinsics, which gives the
303 /// compiler more information about the behavior of the code.
304 virtual bool ExpandInlineAsm(CallInst *CI) const {
310 const char *getTextSection() const {
313 const char *getDataSection() const {
316 unsigned getAddressSize() const {
319 bool needsSet() const {
322 const char *getCommentString() const {
323 return CommentString;
325 const char *getGlobalPrefix() const {
328 const char *getPrivateGlobalPrefix() const {
329 return PrivateGlobalPrefix;
331 const char *getGlobalVarAddrPrefix() const {
332 return GlobalVarAddrPrefix;
334 const char *getGlobalVarAddrSuffix() const {
335 return GlobalVarAddrSuffix;
337 const char *getFunctionAddrPrefix() const {
338 return FunctionAddrPrefix;
340 const char *getFunctionAddrSuffix() const {
341 return FunctionAddrSuffix;
343 const char *getInlineAsmStart() const {
344 return InlineAsmStart;
346 const char *getInlineAsmEnd() const {
349 unsigned getAssemblerDialect() const {
350 return AssemblerDialect;
352 const char *getZeroDirective() const {
353 return ZeroDirective;
355 const char *getZeroDirectiveSuffix() const {
356 return ZeroDirectiveSuffix;
358 const char *getAsciiDirective() const {
359 return AsciiDirective;
361 const char *getAscizDirective() const {
362 return AscizDirective;
364 const char *getData8bitsDirective() const {
365 return Data8bitsDirective;
367 const char *getData16bitsDirective() const {
368 return Data16bitsDirective;
370 const char *getData32bitsDirective() const {
371 return Data32bitsDirective;
373 const char *getData64bitsDirective() const {
374 return Data64bitsDirective;
376 const char *getJumpTableDirective() const {
377 return JumpTableDirective;
379 const char *getAlignDirective() const {
380 return AlignDirective;
382 bool getAlignmentIsInBytes() const {
383 return AlignmentIsInBytes;
385 const char *getSwitchToSectionDirective() const {
386 return SwitchToSectionDirective;
388 const char *getTextSectionStartSuffix() const {
389 return TextSectionStartSuffix;
391 const char *getDataSectionStartSuffix() const {
392 return DataSectionStartSuffix;
394 const char *getSectionEndDirectiveSuffix() const {
395 return SectionEndDirectiveSuffix;
397 const char *getConstantPoolSection() const {
398 return ConstantPoolSection;
400 const char *getJumpTableDataSection() const {
401 return JumpTableDataSection;
403 const char *getCStringSection() const {
404 return CStringSection;
406 const char *getStaticCtorsSection() const {
407 return StaticCtorsSection;
409 const char *getStaticDtorsSection() const {
410 return StaticDtorsSection;
412 const char *getFourByteConstantSection() const {
413 return FourByteConstantSection;
415 const char *getEightByteConstantSection() const {
416 return EightByteConstantSection;
418 const char *getSixteenByteConstantSection() const {
419 return SixteenByteConstantSection;
421 const char *getSetDirective() const {
424 const char *getLCOMMDirective() const {
425 return LCOMMDirective;
427 const char *getCOMMDirective() const {
428 return COMMDirective;
430 bool getCOMMDirectiveTakesAlignment() const {
431 return COMMDirectiveTakesAlignment;
433 bool hasDotTypeDotSizeDirective() const {
434 return HasDotTypeDotSizeDirective;
436 const char *getUsedDirective() const {
437 return UsedDirective;
439 const char *getWeakRefDirective() const {
440 return WeakRefDirective;
442 const char *getHiddenDirective() const {
443 return HiddenDirective;
445 bool hasLEB128() const {
448 bool hasDotLoc() const {
451 bool hasDotFile() const {
454 bool getDwarfRequiresFrameSection() const {
455 return DwarfRequiresFrameSection;
457 const char *getDwarfAbbrevSection() const {
458 return DwarfAbbrevSection;
460 const char *getDwarfInfoSection() const {
461 return DwarfInfoSection;
463 const char *getDwarfLineSection() const {
464 return DwarfLineSection;
466 const char *getDwarfFrameSection() const {
467 return DwarfFrameSection;
469 const char *getDwarfPubNamesSection() const {
470 return DwarfPubNamesSection;
472 const char *getDwarfPubTypesSection() const {
473 return DwarfPubTypesSection;
475 const char *getDwarfStrSection() const {
476 return DwarfStrSection;
478 const char *getDwarfLocSection() const {
479 return DwarfLocSection;
481 const char *getDwarfARangesSection() const {
482 return DwarfARangesSection;
484 const char *getDwarfRangesSection() const {
485 return DwarfRangesSection;
487 const char *getDwarfMacInfoSection() const {
488 return DwarfMacInfoSection;
490 const char** getAsmCBE() const {