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 //===--- Data Emission Directives -------------------------------------===//
95 /// ZeroDirective - this should be set to the directive used to get some
96 /// number of zero bytes emitted to the current section. Common cases are
97 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
98 /// Data*bitsDirective's will be used to emit zero bytes.
99 const char *ZeroDirective; // Defaults to "\t.zero\t"
100 const char *ZeroDirectiveSuffix; // Defaults to ""
102 /// AsciiDirective - This directive allows emission of an ascii string with
103 /// the standard C escape characters embedded into it.
104 const char *AsciiDirective; // Defaults to "\t.ascii\t"
106 /// AscizDirective - If not null, this allows for special handling of
107 /// zero terminated strings on this target. This is commonly supported as
108 /// ".asciz". If a target doesn't support this, it can be set to null.
109 const char *AscizDirective; // Defaults to "\t.asciz\t"
111 /// DataDirectives - These directives are used to output some unit of
112 /// integer data to the current section. If a data directive is set to
113 /// null, smaller data directives will be used to emit the large sizes.
114 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
115 const char *Data16bitsDirective; // Defaults to "\t.short\t"
116 const char *Data32bitsDirective; // Defaults to "\t.long\t"
117 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
119 //===--- Alignment Information ----------------------------------------===//
121 /// AlignDirective - The directive used to emit round up to an alignment
124 const char *AlignDirective; // Defaults to "\t.align\t"
126 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
127 /// emits ".align N" directives, where N is the number of bytes to align to.
128 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
130 bool AlignmentIsInBytes; // Defaults to true
132 //===--- Section Switching Directives ---------------------------------===//
134 /// SwitchToSectionDirective - This is the directive used when we want to
135 /// emit a global to an arbitrary section. The section name is emited after
137 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
139 /// TextSectionStartSuffix - This is printed after each start of section
140 /// directive for text sections.
141 const char *TextSectionStartSuffix; // Defaults to "".
143 /// DataSectionStartSuffix - This is printed after each start of section
144 /// directive for data sections.
145 const char *DataSectionStartSuffix; // Defaults to "".
147 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
148 /// section with the section name and this suffix printed.
149 const char *SectionEndDirectiveSuffix;// Defaults to null.
151 /// ConstantPoolSection - This is the section that we SwitchToSection right
152 /// before emitting the constant pool for a function.
153 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
155 /// JumpTableDataSection - This is the section that we SwitchToSection right
156 /// before emitting the jump tables for a function when the relocation model
158 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
160 /// JumpTableDirective - if non-null, the directive to emit before a jump
162 const char *JumpTableDirective;
164 /// CStringSection - If not null, this allows for special handling of
165 /// cstring constants (\0 terminated string that does not contain any
166 /// other null bytes) on this target. This is commonly supported as
168 const char *CStringSection; // Defaults to NULL
170 /// StaticCtorsSection - This is the directive that is emitted to switch to
171 /// a section to emit the static constructor list.
172 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
173 const char *StaticCtorsSection;
175 /// StaticDtorsSection - This is the directive that is emitted to switch to
176 /// a section to emit the static destructor list.
177 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
178 const char *StaticDtorsSection;
180 /// FourByteConstantSection, EightByteConstantSection,
181 /// SixteenByteConstantSection - These are special sections where we place
182 /// 4-, 8-, and 16- byte constant literals.
183 const char *FourByteConstantSection;
184 const char *EightByteConstantSection;
185 const char *SixteenByteConstantSection;
187 //===--- Global Variable Emission Directives --------------------------===//
189 /// SetDirective - This is the name of a directive that can be used to tell
190 /// the assembler to set the value of a variable to some expression.
191 const char *SetDirective; // Defaults to null.
193 /// LCOMMDirective - This is the name of a directive (if supported) that can
194 /// be used to efficiently declare a local (internal) block of zero
195 /// initialized data in the .bss/.data section. The syntax expected is:
196 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
198 const char *LCOMMDirective; // Defaults to null.
200 const char *COMMDirective; // Defaults to "\t.comm\t".
202 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
203 /// argument that specifies the alignment of the declaration.
204 bool COMMDirectiveTakesAlignment; // Defaults to true.
206 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
207 /// directives, this is true for most ELF targets.
208 bool HasDotTypeDotSizeDirective; // Defaults to true.
210 /// UsedDirective - This directive, if non-null, is used to declare a global
211 /// as being used somehow that the assembler can't see. This prevents dead
212 /// code elimination on some targets.
213 const char *UsedDirective; // Defaults to null.
215 //===--- Dwarf Emission Directives -----------------------------------===//
217 /// HasLEB128 - True if target asm supports leb128 directives.
219 bool HasLEB128; // Defaults to false.
221 /// hasDotLoc - True if target asm supports .loc directives.
223 bool HasDotLoc; // Defaults to false.
225 /// HasDotFile - True if target asm supports .file directives.
227 bool HasDotFile; // Defaults to false.
229 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
231 bool DwarfRequiresFrameSection; // Defaults to true.
233 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
235 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
237 /// DwarfInfoSection - Section directive for Dwarf info.
239 const char *DwarfInfoSection; // Defaults to ".debug_info".
241 /// DwarfLineSection - Section directive for Dwarf info.
243 const char *DwarfLineSection; // Defaults to ".debug_line".
245 /// DwarfFrameSection - Section directive for Dwarf info.
247 const char *DwarfFrameSection; // Defaults to ".debug_frame".
249 /// DwarfPubNamesSection - Section directive for Dwarf info.
251 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
253 /// DwarfPubTypesSection - Section directive for Dwarf info.
255 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
257 /// DwarfStrSection - Section directive for Dwarf info.
259 const char *DwarfStrSection; // Defaults to ".debug_str".
261 /// DwarfLocSection - Section directive for Dwarf info.
263 const char *DwarfLocSection; // Defaults to ".debug_loc".
265 /// DwarfARangesSection - Section directive for Dwarf info.
267 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
269 /// DwarfRangesSection - Section directive for Dwarf info.
271 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
273 /// DwarfMacInfoSection - Section directive for Dwarf info.
275 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
277 //===--- CBE Asm Translation Table -----------------------------------===//
279 const char** AsmTransCBE; // Defaults to empty
283 virtual ~TargetAsmInfo();
285 /// Measure the specified inline asm to determine an approximation of its
287 unsigned getInlineAsmLength(const char *Str) const;
289 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
290 /// call to be explicit llvm code if it wants to. This is useful for
291 /// turning simple inline asms into LLVM intrinsics, which gives the
292 /// compiler more information about the behavior of the code.
293 virtual bool ExpandInlineAsm(CallInst *CI) const {
299 const char *getTextSection() const {
302 const char *getDataSection() const {
305 unsigned getAddressSize() const {
308 bool needsSet() const {
311 const char *getCommentString() const {
312 return CommentString;
314 const char *getGlobalPrefix() const {
317 const char *getPrivateGlobalPrefix() const {
318 return PrivateGlobalPrefix;
320 const char *getGlobalVarAddrPrefix() const {
321 return GlobalVarAddrPrefix;
323 const char *getGlobalVarAddrSuffix() const {
324 return GlobalVarAddrSuffix;
326 const char *getFunctionAddrPrefix() const {
327 return FunctionAddrPrefix;
329 const char *getFunctionAddrSuffix() const {
330 return FunctionAddrSuffix;
332 const char *getInlineAsmStart() const {
333 return InlineAsmStart;
335 const char *getInlineAsmEnd() const {
338 const char *getZeroDirective() const {
339 return ZeroDirective;
341 const char *getZeroDirectiveSuffix() const {
342 return ZeroDirectiveSuffix;
344 const char *getAsciiDirective() const {
345 return AsciiDirective;
347 const char *getAscizDirective() const {
348 return AscizDirective;
350 const char *getData8bitsDirective() const {
351 return Data8bitsDirective;
353 const char *getData16bitsDirective() const {
354 return Data16bitsDirective;
356 const char *getData32bitsDirective() const {
357 return Data32bitsDirective;
359 const char *getData64bitsDirective() const {
360 return Data64bitsDirective;
362 const char *getJumpTableDirective() const {
363 return JumpTableDirective;
365 const char *getAlignDirective() const {
366 return AlignDirective;
368 bool getAlignmentIsInBytes() const {
369 return AlignmentIsInBytes;
371 const char *getSwitchToSectionDirective() const {
372 return SwitchToSectionDirective;
374 const char *getTextSectionStartSuffix() const {
375 return TextSectionStartSuffix;
377 const char *getDataSectionStartSuffix() const {
378 return DataSectionStartSuffix;
380 const char *getSectionEndDirectiveSuffix() const {
381 return SectionEndDirectiveSuffix;
383 const char *getConstantPoolSection() const {
384 return ConstantPoolSection;
386 const char *getJumpTableDataSection() const {
387 return JumpTableDataSection;
389 const char *getCStringSection() const {
390 return CStringSection;
392 const char *getStaticCtorsSection() const {
393 return StaticCtorsSection;
395 const char *getStaticDtorsSection() const {
396 return StaticDtorsSection;
398 const char *getFourByteConstantSection() const {
399 return FourByteConstantSection;
401 const char *getEightByteConstantSection() const {
402 return EightByteConstantSection;
404 const char *getSixteenByteConstantSection() const {
405 return SixteenByteConstantSection;
407 const char *getSetDirective() const {
410 const char *getLCOMMDirective() const {
411 return LCOMMDirective;
413 const char *getCOMMDirective() const {
414 return COMMDirective;
416 bool getCOMMDirectiveTakesAlignment() const {
417 return COMMDirectiveTakesAlignment;
419 bool hasDotTypeDotSizeDirective() const {
420 return HasDotTypeDotSizeDirective;
422 const char *getUsedDirective() const {
423 return UsedDirective;
425 bool hasLEB128() const {
428 bool hasDotLoc() const {
431 bool hasDotFile() const {
434 bool getDwarfRequiresFrameSection() const {
435 return DwarfRequiresFrameSection;
437 const char *getDwarfAbbrevSection() const {
438 return DwarfAbbrevSection;
440 const char *getDwarfInfoSection() const {
441 return DwarfInfoSection;
443 const char *getDwarfLineSection() const {
444 return DwarfLineSection;
446 const char *getDwarfFrameSection() const {
447 return DwarfFrameSection;
449 const char *getDwarfPubNamesSection() const {
450 return DwarfPubNamesSection;
452 const char *getDwarfPubTypesSection() const {
453 return DwarfPubTypesSection;
455 const char *getDwarfStrSection() const {
456 return DwarfStrSection;
458 const char *getDwarfLocSection() const {
459 return DwarfLocSection;
461 const char *getDwarfARangesSection() const {
462 return DwarfARangesSection;
464 const char *getDwarfRangesSection() const {
465 return DwarfRangesSection;
467 const char *getDwarfMacInfoSection() const {
468 return DwarfMacInfoSection;
470 const char** getAsmCBE() const {