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 /// WeakRefDirective - This directive, if non-null, is used to declare a
216 /// global as being a weak undefined symbol.
217 const char *WeakRefDirective; // Defaults to null.
219 //===--- Dwarf Emission Directives -----------------------------------===//
221 /// HasLEB128 - True if target asm supports leb128 directives.
223 bool HasLEB128; // Defaults to false.
225 /// hasDotLoc - True if target asm supports .loc directives.
227 bool HasDotLoc; // Defaults to false.
229 /// HasDotFile - True if target asm supports .file directives.
231 bool HasDotFile; // Defaults to false.
233 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
235 bool DwarfRequiresFrameSection; // Defaults to true.
237 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
239 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
241 /// DwarfInfoSection - Section directive for Dwarf info.
243 const char *DwarfInfoSection; // Defaults to ".debug_info".
245 /// DwarfLineSection - Section directive for Dwarf info.
247 const char *DwarfLineSection; // Defaults to ".debug_line".
249 /// DwarfFrameSection - Section directive for Dwarf info.
251 const char *DwarfFrameSection; // Defaults to ".debug_frame".
253 /// DwarfPubNamesSection - Section directive for Dwarf info.
255 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
257 /// DwarfPubTypesSection - Section directive for Dwarf info.
259 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
261 /// DwarfStrSection - Section directive for Dwarf info.
263 const char *DwarfStrSection; // Defaults to ".debug_str".
265 /// DwarfLocSection - Section directive for Dwarf info.
267 const char *DwarfLocSection; // Defaults to ".debug_loc".
269 /// DwarfARangesSection - Section directive for Dwarf info.
271 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
273 /// DwarfRangesSection - Section directive for Dwarf info.
275 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
277 /// DwarfMacInfoSection - Section directive for Dwarf info.
279 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
281 //===--- CBE Asm Translation Table -----------------------------------===//
283 const char** AsmTransCBE; // Defaults to empty
287 virtual ~TargetAsmInfo();
289 /// Measure the specified inline asm to determine an approximation of its
291 unsigned getInlineAsmLength(const char *Str) const;
293 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
294 /// call to be explicit llvm code if it wants to. This is useful for
295 /// turning simple inline asms into LLVM intrinsics, which gives the
296 /// compiler more information about the behavior of the code.
297 virtual bool ExpandInlineAsm(CallInst *CI) const {
303 const char *getTextSection() const {
306 const char *getDataSection() const {
309 unsigned getAddressSize() const {
312 bool needsSet() const {
315 const char *getCommentString() const {
316 return CommentString;
318 const char *getGlobalPrefix() const {
321 const char *getPrivateGlobalPrefix() const {
322 return PrivateGlobalPrefix;
324 const char *getGlobalVarAddrPrefix() const {
325 return GlobalVarAddrPrefix;
327 const char *getGlobalVarAddrSuffix() const {
328 return GlobalVarAddrSuffix;
330 const char *getFunctionAddrPrefix() const {
331 return FunctionAddrPrefix;
333 const char *getFunctionAddrSuffix() const {
334 return FunctionAddrSuffix;
336 const char *getInlineAsmStart() const {
337 return InlineAsmStart;
339 const char *getInlineAsmEnd() const {
342 const char *getZeroDirective() const {
343 return ZeroDirective;
345 const char *getZeroDirectiveSuffix() const {
346 return ZeroDirectiveSuffix;
348 const char *getAsciiDirective() const {
349 return AsciiDirective;
351 const char *getAscizDirective() const {
352 return AscizDirective;
354 const char *getData8bitsDirective() const {
355 return Data8bitsDirective;
357 const char *getData16bitsDirective() const {
358 return Data16bitsDirective;
360 const char *getData32bitsDirective() const {
361 return Data32bitsDirective;
363 const char *getData64bitsDirective() const {
364 return Data64bitsDirective;
366 const char *getJumpTableDirective() const {
367 return JumpTableDirective;
369 const char *getAlignDirective() const {
370 return AlignDirective;
372 bool getAlignmentIsInBytes() const {
373 return AlignmentIsInBytes;
375 const char *getSwitchToSectionDirective() const {
376 return SwitchToSectionDirective;
378 const char *getTextSectionStartSuffix() const {
379 return TextSectionStartSuffix;
381 const char *getDataSectionStartSuffix() const {
382 return DataSectionStartSuffix;
384 const char *getSectionEndDirectiveSuffix() const {
385 return SectionEndDirectiveSuffix;
387 const char *getConstantPoolSection() const {
388 return ConstantPoolSection;
390 const char *getJumpTableDataSection() const {
391 return JumpTableDataSection;
393 const char *getCStringSection() const {
394 return CStringSection;
396 const char *getStaticCtorsSection() const {
397 return StaticCtorsSection;
399 const char *getStaticDtorsSection() const {
400 return StaticDtorsSection;
402 const char *getFourByteConstantSection() const {
403 return FourByteConstantSection;
405 const char *getEightByteConstantSection() const {
406 return EightByteConstantSection;
408 const char *getSixteenByteConstantSection() const {
409 return SixteenByteConstantSection;
411 const char *getSetDirective() const {
414 const char *getLCOMMDirective() const {
415 return LCOMMDirective;
417 const char *getCOMMDirective() const {
418 return COMMDirective;
420 bool getCOMMDirectiveTakesAlignment() const {
421 return COMMDirectiveTakesAlignment;
423 bool hasDotTypeDotSizeDirective() const {
424 return HasDotTypeDotSizeDirective;
426 const char *getUsedDirective() const {
427 return UsedDirective;
429 const char *getWeakRefDirective() const {
430 return WeakRefDirective;
432 bool hasLEB128() const {
435 bool hasDotLoc() const {
438 bool hasDotFile() const {
441 bool getDwarfRequiresFrameSection() const {
442 return DwarfRequiresFrameSection;
444 const char *getDwarfAbbrevSection() const {
445 return DwarfAbbrevSection;
447 const char *getDwarfInfoSection() const {
448 return DwarfInfoSection;
450 const char *getDwarfLineSection() const {
451 return DwarfLineSection;
453 const char *getDwarfFrameSection() const {
454 return DwarfFrameSection;
456 const char *getDwarfPubNamesSection() const {
457 return DwarfPubNamesSection;
459 const char *getDwarfPubTypesSection() const {
460 return DwarfPubTypesSection;
462 const char *getDwarfStrSection() const {
463 return DwarfStrSection;
465 const char *getDwarfLocSection() const {
466 return DwarfLocSection;
468 const char *getDwarfARangesSection() const {
469 return DwarfARangesSection;
471 const char *getDwarfRangesSection() const {
472 return DwarfRangesSection;
474 const char *getDwarfMacInfoSection() const {
475 return DwarfMacInfoSection;
477 const char** getAsmCBE() const {