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"
24 // Forward declaration.
27 /// TargetAsmInfo - This class is intended to be used as a base class for asm
28 /// properties and features specific to the target.
31 //===------------------------------------------------------------------===//
32 // Properties to be set by the target writer, used to configure asm printer.
35 /// TextSection - Section directive for standard text.
37 const char *TextSection; // Defaults to ".text".
39 /// DataSection - Section directive for standard data.
41 const char *DataSection; // Defaults to ".data".
43 /// AddressSize - Size of addresses used in file.
45 unsigned AddressSize; // Defaults to 4.
47 /// NeedsSet - True if target asm can't compute addresses on data
49 bool NeedsSet; // Defaults to false.
51 /// MaxInstLength - This is the maximum possible length of an instruction,
52 /// which is needed to compute the size of an inline asm.
53 unsigned MaxInstLength; // Defaults to 4.
55 /// SeparatorChar - This character, if specified, is used to separate
56 /// instructions from each other when on the same line. This is used to
57 /// measure inline asm instructions.
58 char SeparatorChar; // Defaults to ';'
60 /// CommentString - This indicates the comment character used by the
62 const char *CommentString; // Defaults to "#"
64 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
65 /// onto all global symbols. This is often used for "_" or ".".
66 const char *GlobalPrefix; // Defaults to ""
68 /// PrivateGlobalPrefix - This prefix is used for globals like constant
69 /// pool entries that are completely private to the .o file and should not
70 /// have names in the .o file. This is often "." or "L".
71 const char *PrivateGlobalPrefix; // Defaults to "."
73 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
74 /// will enclose any GlobalVariable (that isn't a function)
76 const char *GlobalVarAddrPrefix; // Defaults to ""
77 const char *GlobalVarAddrSuffix; // Defaults to ""
79 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
80 /// will enclose any GlobalVariable that points to a function.
81 /// For example, this is used by the IA64 backend to materialize
82 /// function descriptors, by decorating the ".data8" object with the
83 /// \literal @fptr( ) \endliteral
84 /// link-relocation operator.
86 const char *FunctionAddrPrefix; // Defaults to ""
87 const char *FunctionAddrSuffix; // Defaults to ""
89 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
90 /// emit before and after an inline assembly statement.
91 const char *InlineAsmStart; // Defaults to "#APP\n"
92 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
94 //===--- Data Emission Directives -------------------------------------===//
96 /// ZeroDirective - this should be set to the directive used to get some
97 /// number of zero bytes emitted to the current section. Common cases are
98 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
99 /// Data*bitsDirective's will be used to emit zero bytes.
100 const char *ZeroDirective; // Defaults to "\t.zero\t"
101 const char *ZeroDirectiveSuffix; // Defaults to ""
103 /// AsciiDirective - This directive allows emission of an ascii string with
104 /// the standard C escape characters embedded into it.
105 const char *AsciiDirective; // Defaults to "\t.ascii\t"
107 /// AscizDirective - If not null, this allows for special handling of
108 /// zero terminated strings on this target. This is commonly supported as
109 /// ".asciz". If a target doesn't support this, it can be set to null.
110 const char *AscizDirective; // Defaults to "\t.asciz\t"
112 /// DataDirectives - These directives are used to output some unit of
113 /// integer data to the current section. If a data directive is set to
114 /// null, smaller data directives will be used to emit the large sizes.
115 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
116 const char *Data16bitsDirective; // Defaults to "\t.short\t"
117 const char *Data32bitsDirective; // Defaults to "\t.long\t"
118 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
120 //===--- Alignment Information ----------------------------------------===//
122 /// AlignDirective - The directive used to emit round up to an alignment
125 const char *AlignDirective; // Defaults to "\t.align\t"
127 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
128 /// emits ".align N" directives, where N is the number of bytes to align to.
129 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
131 bool AlignmentIsInBytes; // Defaults to true
133 //===--- Section Switching Directives ---------------------------------===//
135 /// SwitchToSectionDirective - This is the directive used when we want to
136 /// emit a global to an arbitrary section. The section name is emited after
138 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
140 /// TextSectionStartSuffix - This is printed after each start of section
141 /// directive for text sections.
142 const char *TextSectionStartSuffix; // Defaults to "".
144 /// DataSectionStartSuffix - This is printed after each start of section
145 /// directive for data sections.
146 const char *DataSectionStartSuffix; // Defaults to "".
148 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
149 /// section with the section name and this suffix printed.
150 const char *SectionEndDirectiveSuffix;// Defaults to null.
152 /// ConstantPoolSection - This is the section that we SwitchToSection right
153 /// before emitting the constant pool for a function.
154 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
156 /// JumpTableDataSection - This is the section that we SwitchToSection right
157 /// before emitting the jump tables for a function when the relocation model
159 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
161 /// JumpTableDirective - if non-null, the directive to emit before a jump
163 const char *JumpTableDirective;
165 /// CStringSection - If not null, this allows for special handling of
166 /// cstring constants (\0 terminated string that does not contain any
167 /// other null bytes) on this target. This is commonly supported as
169 const char *CStringSection; // Defaults to NULL
171 /// StaticCtorsSection - This is the directive that is emitted to switch to
172 /// a section to emit the static constructor list.
173 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
174 const char *StaticCtorsSection;
176 /// StaticDtorsSection - This is the directive that is emitted to switch to
177 /// a section to emit the static destructor list.
178 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
179 const char *StaticDtorsSection;
181 /// FourByteConstantSection, EightByteConstantSection,
182 /// SixteenByteConstantSection - These are special sections where we place
183 /// 4-, 8-, and 16- byte constant literals.
184 const char *FourByteConstantSection;
185 const char *EightByteConstantSection;
186 const char *SixteenByteConstantSection;
188 //===--- Global Variable Emission Directives --------------------------===//
190 /// SetDirective - This is the name of a directive that can be used to tell
191 /// the assembler to set the value of a variable to some expression.
192 const char *SetDirective; // Defaults to null.
194 /// LCOMMDirective - This is the name of a directive (if supported) that can
195 /// be used to efficiently declare a local (internal) block of zero
196 /// initialized data in the .bss/.data section. The syntax expected is:
197 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
199 const char *LCOMMDirective; // Defaults to null.
201 const char *COMMDirective; // Defaults to "\t.comm\t".
203 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
204 /// argument that specifies the alignment of the declaration.
205 bool COMMDirectiveTakesAlignment; // Defaults to true.
207 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
208 /// directives, this is true for most ELF targets.
209 bool HasDotTypeDotSizeDirective; // Defaults to true.
211 /// UsedDirective - This directive, if non-null, is used to declare a global
212 /// as being used somehow that the assembler can't see. This prevents dead
213 /// code elimination on some targets.
214 const char *UsedDirective; // Defaults to null.
216 //===--- Dwarf Emission Directives -----------------------------------===//
218 /// HasLEB128 - True if target asm supports leb128 directives.
220 bool HasLEB128; // Defaults to false.
222 /// hasDotLoc - True if target asm supports .loc directives.
224 bool HasDotLoc; // Defaults to false.
226 /// HasDotFile - True if target asm supports .file directives.
228 bool HasDotFile; // Defaults to false.
230 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
232 bool DwarfRequiresFrameSection; // Defaults to true.
234 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
236 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
238 /// DwarfInfoSection - Section directive for Dwarf info.
240 const char *DwarfInfoSection; // Defaults to ".debug_info".
242 /// DwarfLineSection - Section directive for Dwarf info.
244 const char *DwarfLineSection; // Defaults to ".debug_line".
246 /// DwarfFrameSection - Section directive for Dwarf info.
248 const char *DwarfFrameSection; // Defaults to ".debug_frame".
250 /// DwarfPubNamesSection - Section directive for Dwarf info.
252 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
254 /// DwarfPubTypesSection - Section directive for Dwarf info.
256 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
258 /// DwarfStrSection - Section directive for Dwarf info.
260 const char *DwarfStrSection; // Defaults to ".debug_str".
262 /// DwarfLocSection - Section directive for Dwarf info.
264 const char *DwarfLocSection; // Defaults to ".debug_loc".
266 /// DwarfARangesSection - Section directive for Dwarf info.
268 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
270 /// DwarfRangesSection - Section directive for Dwarf info.
272 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
274 /// DwarfMacInfoSection - Section directive for Dwarf info.
276 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
278 //===--- CBE Asm Translation Table -----------------------------------===//
280 const char** AsmTransCBE; // Defaults to empty
284 virtual ~TargetAsmInfo();
286 /// Measure the specified inline asm to determine an approximation of its
288 unsigned getInlineAsmLength(const char *Str) const;
293 const char *getTextSection() const {
296 const char *getDataSection() const {
299 unsigned getAddressSize() const {
302 bool needsSet() const {
305 const char *getCommentString() const {
306 return CommentString;
308 const char *getGlobalPrefix() const {
311 const char *getPrivateGlobalPrefix() const {
312 return PrivateGlobalPrefix;
314 const char *getGlobalVarAddrPrefix() const {
315 return GlobalVarAddrPrefix;
317 const char *getGlobalVarAddrSuffix() const {
318 return GlobalVarAddrSuffix;
320 const char *getFunctionAddrPrefix() const {
321 return FunctionAddrPrefix;
323 const char *getFunctionAddrSuffix() const {
324 return FunctionAddrSuffix;
326 const char *getInlineAsmStart() const {
327 return InlineAsmStart;
329 const char *getInlineAsmEnd() const {
332 const char *getZeroDirective() const {
333 return ZeroDirective;
335 const char *getZeroDirectiveSuffix() const {
336 return ZeroDirectiveSuffix;
338 const char *getAsciiDirective() const {
339 return AsciiDirective;
341 const char *getAscizDirective() const {
342 return AscizDirective;
344 const char *getData8bitsDirective() const {
345 return Data8bitsDirective;
347 const char *getData16bitsDirective() const {
348 return Data16bitsDirective;
350 const char *getData32bitsDirective() const {
351 return Data32bitsDirective;
353 const char *getData64bitsDirective() const {
354 return Data64bitsDirective;
356 const char *getJumpTableDirective() const {
357 return JumpTableDirective;
359 const char *getAlignDirective() const {
360 return AlignDirective;
362 bool getAlignmentIsInBytes() const {
363 return AlignmentIsInBytes;
365 const char *getSwitchToSectionDirective() const {
366 return SwitchToSectionDirective;
368 const char *getTextSectionStartSuffix() const {
369 return TextSectionStartSuffix;
371 const char *getDataSectionStartSuffix() const {
372 return DataSectionStartSuffix;
374 const char *getSectionEndDirectiveSuffix() const {
375 return SectionEndDirectiveSuffix;
377 const char *getConstantPoolSection() const {
378 return ConstantPoolSection;
380 const char *getJumpTableDataSection() const {
381 return JumpTableDataSection;
383 const char *getCStringSection() const {
384 return CStringSection;
386 const char *getStaticCtorsSection() const {
387 return StaticCtorsSection;
389 const char *getStaticDtorsSection() const {
390 return StaticDtorsSection;
392 const char *getFourByteConstantSection() const {
393 return FourByteConstantSection;
395 const char *getEightByteConstantSection() const {
396 return EightByteConstantSection;
398 const char *getSixteenByteConstantSection() const {
399 return SixteenByteConstantSection;
401 const char *getSetDirective() const {
404 const char *getLCOMMDirective() const {
405 return LCOMMDirective;
407 const char *getCOMMDirective() const {
408 return COMMDirective;
410 bool getCOMMDirectiveTakesAlignment() const {
411 return COMMDirectiveTakesAlignment;
413 bool hasDotTypeDotSizeDirective() const {
414 return HasDotTypeDotSizeDirective;
416 const char *getUsedDirective() const {
417 return UsedDirective;
419 bool hasLEB128() const {
422 bool hasDotLoc() const {
425 bool hasDotFile() const {
428 bool getDwarfRequiresFrameSection() const {
429 return DwarfRequiresFrameSection;
431 const char *getDwarfAbbrevSection() const {
432 return DwarfAbbrevSection;
434 const char *getDwarfInfoSection() const {
435 return DwarfInfoSection;
437 const char *getDwarfLineSection() const {
438 return DwarfLineSection;
440 const char *getDwarfFrameSection() const {
441 return DwarfFrameSection;
443 const char *getDwarfPubNamesSection() const {
444 return DwarfPubNamesSection;
446 const char *getDwarfPubTypesSection() const {
447 return DwarfPubTypesSection;
449 const char *getDwarfStrSection() const {
450 return DwarfStrSection;
452 const char *getDwarfLocSection() const {
453 return DwarfLocSection;
455 const char *getDwarfARangesSection() const {
456 return DwarfARangesSection;
458 const char *getDwarfRangesSection() const {
459 return DwarfRangesSection;
461 const char *getDwarfMacInfoSection() const {
462 return DwarfMacInfoSection;
464 const char** getAsmCBE() const {