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 /// StaticCtorsSection - This is the directive that is emitted to switch to
166 /// a section to emit the static constructor list.
167 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
168 const char *StaticCtorsSection;
170 /// StaticDtorsSection - This is the directive that is emitted to switch to
171 /// a section to emit the static destructor list.
172 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
173 const char *StaticDtorsSection;
175 /// FourByteConstantSection, EightByteConstantSection,
176 /// SixteenByteConstantSection - These are special sections where we place
177 /// 4-, 8-, and 16- byte constant literals.
178 const char *FourByteConstantSection;
179 const char *EightByteConstantSection;
180 const char *SixteenByteConstantSection;
182 //===--- Global Variable Emission Directives --------------------------===//
184 /// SetDirective - This is the name of a directive that can be used to tell
185 /// the assembler to set the value of a variable to some expression.
186 const char *SetDirective; // Defaults to null.
188 /// LCOMMDirective - This is the name of a directive (if supported) that can
189 /// be used to efficiently declare a local (internal) block of zero
190 /// initialized data in the .bss/.data section. The syntax expected is:
191 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
193 const char *LCOMMDirective; // Defaults to null.
195 const char *COMMDirective; // Defaults to "\t.comm\t".
197 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
198 /// argument that specifies the alignment of the declaration.
199 bool COMMDirectiveTakesAlignment; // Defaults to true.
201 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
202 /// directives, this is true for most ELF targets.
203 bool HasDotTypeDotSizeDirective; // Defaults to true.
205 /// UsedDirective - This directive, if non-null, is used to declare a global
206 /// as being used somehow that the assembler can't see. This prevents dead
207 /// code elimination on some targets.
208 const char *UsedDirective; // Defaults to null.
210 //===--- Dwarf Emission Directives -----------------------------------===//
212 /// HasLEB128 - True if target asm supports leb128 directives.
214 bool HasLEB128; // Defaults to false.
216 /// hasDotLoc - True if target asm supports .loc directives.
218 bool HasDotLoc; // Defaults to false.
220 /// HasDotFile - True if target asm supports .file directives.
222 bool HasDotFile; // Defaults to false.
224 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
226 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
228 /// DwarfInfoSection - Section directive for Dwarf info.
230 const char *DwarfInfoSection; // Defaults to ".debug_info".
232 /// DwarfLineSection - Section directive for Dwarf info.
234 const char *DwarfLineSection; // Defaults to ".debug_line".
236 /// DwarfFrameSection - Section directive for Dwarf info.
238 const char *DwarfFrameSection; // Defaults to ".debug_frame".
240 /// DwarfPubNamesSection - Section directive for Dwarf info.
242 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
244 /// DwarfPubTypesSection - Section directive for Dwarf info.
246 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
248 /// DwarfStrSection - Section directive for Dwarf info.
250 const char *DwarfStrSection; // Defaults to ".debug_str".
252 /// DwarfLocSection - Section directive for Dwarf info.
254 const char *DwarfLocSection; // Defaults to ".debug_loc".
256 /// DwarfARangesSection - Section directive for Dwarf info.
258 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
260 /// DwarfRangesSection - Section directive for Dwarf info.
262 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
264 /// DwarfMacInfoSection - Section directive for Dwarf info.
266 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
270 virtual ~TargetAsmInfo();
272 /// Measure the specified inline asm to determine an approximation of its
274 unsigned getInlineAsmLength(const char *Str) const;
279 const char *getTextSection() const {
282 const char *getDataSection() const {
285 unsigned getAddressSize() const {
288 bool needsSet() const {
291 const char *getCommentString() const {
292 return CommentString;
294 const char *getGlobalPrefix() const {
297 const char *getPrivateGlobalPrefix() const {
298 return PrivateGlobalPrefix;
300 const char *getGlobalVarAddrPrefix() const {
301 return GlobalVarAddrPrefix;
303 const char *getGlobalVarAddrSuffix() const {
304 return GlobalVarAddrSuffix;
306 const char *getFunctionAddrPrefix() const {
307 return FunctionAddrPrefix;
309 const char *getFunctionAddrSuffix() const {
310 return FunctionAddrSuffix;
312 const char *getInlineAsmStart() const {
313 return InlineAsmStart;
315 const char *getInlineAsmEnd() const {
318 const char *getZeroDirective() const {
319 return ZeroDirective;
321 const char *getZeroDirectiveSuffix() const {
322 return ZeroDirectiveSuffix;
324 const char *getAsciiDirective() const {
325 return AsciiDirective;
327 const char *getAscizDirective() const {
328 return AscizDirective;
330 const char *getData8bitsDirective() const {
331 return Data8bitsDirective;
333 const char *getData16bitsDirective() const {
334 return Data16bitsDirective;
336 const char *getData32bitsDirective() const {
337 return Data32bitsDirective;
339 const char *getData64bitsDirective() const {
340 return Data64bitsDirective;
342 const char *getJumpTableDirective() const {
343 return JumpTableDirective;
345 const char *getAlignDirective() const {
346 return AlignDirective;
348 bool getAlignmentIsInBytes() const {
349 return AlignmentIsInBytes;
351 const char *getSwitchToSectionDirective() const {
352 return SwitchToSectionDirective;
354 const char *getTextSectionStartSuffix() const {
355 return TextSectionStartSuffix;
357 const char *getDataSectionStartSuffix() const {
358 return DataSectionStartSuffix;
360 const char *getSectionEndDirectiveSuffix() const {
361 return SectionEndDirectiveSuffix;
363 const char *getConstantPoolSection() const {
364 return ConstantPoolSection;
366 const char *getJumpTableDataSection() const {
367 return JumpTableDataSection;
369 const char *getStaticCtorsSection() const {
370 return StaticCtorsSection;
372 const char *getStaticDtorsSection() const {
373 return StaticDtorsSection;
375 const char *getFourByteConstantSection() const {
376 return FourByteConstantSection;
378 const char *getEightByteConstantSection() const {
379 return EightByteConstantSection;
381 const char *getSixteenByteConstantSection() const {
382 return SixteenByteConstantSection;
384 const char *getSetDirective() const {
387 const char *getLCOMMDirective() const {
388 return LCOMMDirective;
390 const char *getCOMMDirective() const {
391 return COMMDirective;
393 bool getCOMMDirectiveTakesAlignment() const {
394 return COMMDirectiveTakesAlignment;
396 bool hasDotTypeDotSizeDirective() const {
397 return HasDotTypeDotSizeDirective;
399 const char *getUsedDirective() const {
400 return UsedDirective;
402 bool hasLEB128() const {
405 bool hasDotLoc() const {
408 bool hasDotFile() const {
411 const char *getDwarfAbbrevSection() const {
412 return DwarfAbbrevSection;
414 const char *getDwarfInfoSection() const {
415 return DwarfInfoSection;
417 const char *getDwarfLineSection() const {
418 return DwarfLineSection;
420 const char *getDwarfFrameSection() const {
421 return DwarfFrameSection;
423 const char *getDwarfPubNamesSection() const {
424 return DwarfPubNamesSection;
426 const char *getDwarfPubTypesSection() const {
427 return DwarfPubTypesSection;
429 const char *getDwarfStrSection() const {
430 return DwarfStrSection;
432 const char *getDwarfLocSection() const {
433 return DwarfLocSection;
435 const char *getDwarfARangesSection() const {
436 return DwarfARangesSection;
438 const char *getDwarfRangesSection() const {
439 return DwarfRangesSection;
441 const char *getDwarfMacInfoSection() const {
442 return DwarfMacInfoSection;