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".
280 virtual ~TargetAsmInfo();
282 /// Measure the specified inline asm to determine an approximation of its
284 unsigned getInlineAsmLength(const char *Str) const;
289 const char *getTextSection() const {
292 const char *getDataSection() const {
295 unsigned getAddressSize() const {
298 bool needsSet() const {
301 const char *getCommentString() const {
302 return CommentString;
304 const char *getGlobalPrefix() const {
307 const char *getPrivateGlobalPrefix() const {
308 return PrivateGlobalPrefix;
310 const char *getGlobalVarAddrPrefix() const {
311 return GlobalVarAddrPrefix;
313 const char *getGlobalVarAddrSuffix() const {
314 return GlobalVarAddrSuffix;
316 const char *getFunctionAddrPrefix() const {
317 return FunctionAddrPrefix;
319 const char *getFunctionAddrSuffix() const {
320 return FunctionAddrSuffix;
322 const char *getInlineAsmStart() const {
323 return InlineAsmStart;
325 const char *getInlineAsmEnd() const {
328 const char *getZeroDirective() const {
329 return ZeroDirective;
331 const char *getZeroDirectiveSuffix() const {
332 return ZeroDirectiveSuffix;
334 const char *getAsciiDirective() const {
335 return AsciiDirective;
337 const char *getAscizDirective() const {
338 return AscizDirective;
340 const char *getData8bitsDirective() const {
341 return Data8bitsDirective;
343 const char *getData16bitsDirective() const {
344 return Data16bitsDirective;
346 const char *getData32bitsDirective() const {
347 return Data32bitsDirective;
349 const char *getData64bitsDirective() const {
350 return Data64bitsDirective;
352 const char *getJumpTableDirective() const {
353 return JumpTableDirective;
355 const char *getAlignDirective() const {
356 return AlignDirective;
358 bool getAlignmentIsInBytes() const {
359 return AlignmentIsInBytes;
361 const char *getSwitchToSectionDirective() const {
362 return SwitchToSectionDirective;
364 const char *getTextSectionStartSuffix() const {
365 return TextSectionStartSuffix;
367 const char *getDataSectionStartSuffix() const {
368 return DataSectionStartSuffix;
370 const char *getSectionEndDirectiveSuffix() const {
371 return SectionEndDirectiveSuffix;
373 const char *getConstantPoolSection() const {
374 return ConstantPoolSection;
376 const char *getJumpTableDataSection() const {
377 return JumpTableDataSection;
379 const char *getCStringSection() const {
380 return CStringSection;
382 const char *getStaticCtorsSection() const {
383 return StaticCtorsSection;
385 const char *getStaticDtorsSection() const {
386 return StaticDtorsSection;
388 const char *getFourByteConstantSection() const {
389 return FourByteConstantSection;
391 const char *getEightByteConstantSection() const {
392 return EightByteConstantSection;
394 const char *getSixteenByteConstantSection() const {
395 return SixteenByteConstantSection;
397 const char *getSetDirective() const {
400 const char *getLCOMMDirective() const {
401 return LCOMMDirective;
403 const char *getCOMMDirective() const {
404 return COMMDirective;
406 bool getCOMMDirectiveTakesAlignment() const {
407 return COMMDirectiveTakesAlignment;
409 bool hasDotTypeDotSizeDirective() const {
410 return HasDotTypeDotSizeDirective;
412 const char *getUsedDirective() const {
413 return UsedDirective;
415 bool hasLEB128() const {
418 bool hasDotLoc() const {
421 bool hasDotFile() const {
424 bool getDwarfRequiresFrameSection() const {
425 return DwarfRequiresFrameSection;
427 const char *getDwarfAbbrevSection() const {
428 return DwarfAbbrevSection;
430 const char *getDwarfInfoSection() const {
431 return DwarfInfoSection;
433 const char *getDwarfLineSection() const {
434 return DwarfLineSection;
436 const char *getDwarfFrameSection() const {
437 return DwarfFrameSection;
439 const char *getDwarfPubNamesSection() const {
440 return DwarfPubNamesSection;
442 const char *getDwarfPubTypesSection() const {
443 return DwarfPubTypesSection;
445 const char *getDwarfStrSection() const {
446 return DwarfStrSection;
448 const char *getDwarfLocSection() const {
449 return DwarfLocSection;
451 const char *getDwarfARangesSection() const {
452 return DwarfARangesSection;
454 const char *getDwarfRangesSection() const {
455 return DwarfRangesSection;
457 const char *getDwarfMacInfoSection() const {
458 return DwarfMacInfoSection;