Add debug support for X86/ELF targets (Linux). This allows llvm-gcc4
[oota-llvm.git] / include / llvm / Target / TargetAsmInfo.h
1 //===-- llvm/Target/TargetAsmInfo.h - Asm info ------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
18
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DataTypes.h"
21
22 namespace llvm {
23
24   // Forward declaration.
25   class TargetMachine;
26
27   /// TargetAsmInfo - This class is intended to be used as a base class for asm
28   /// properties and features specific to the target.
29   class TargetAsmInfo {
30   protected:
31     //===------------------------------------------------------------------===//
32     // Properties to be set by the target writer, used to configure asm printer.
33     // 
34     
35     /// TextSection - Section directive for standard text.
36     ///
37     const char *TextSection;              // Defaults to ".text".
38     
39     /// DataSection - Section directive for standard data.
40     ///
41     const char *DataSection;              // Defaults to ".data".
42     
43     /// AddressSize - Size of addresses used in file.
44     ///
45     unsigned AddressSize;                 // Defaults to 4.
46
47     /// NeedsSet - True if target asm can't compute addresses on data
48     /// directives.
49     bool NeedsSet;                        // Defaults to false.
50     
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.
54     
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 ';'
59
60     /// CommentString - This indicates the comment character used by the
61     /// assembler.
62     const char *CommentString;            // Defaults to "#"
63
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 ""
67
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 "."
72     
73     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
74     /// will enclose any GlobalVariable (that isn't a function)
75     ///
76     const char *GlobalVarAddrPrefix;      // Defaults to ""
77     const char *GlobalVarAddrSuffix;      // Defaults to ""
78
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.
85     ///
86     const char *FunctionAddrPrefix;       // Defaults to ""
87     const char *FunctionAddrSuffix;       // Defaults to ""
88
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"
93     
94     //===--- Data Emission Directives -------------------------------------===//
95
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 ""
102
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"
106     
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"
111
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"
119
120     //===--- Alignment Information ----------------------------------------===//
121
122     /// AlignDirective - The directive used to emit round up to an alignment
123     /// boundary.
124     ///
125     const char *AlignDirective;           // Defaults to "\t.align\t"
126
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
130     /// boundary.
131     bool AlignmentIsInBytes;              // Defaults to true
132     
133     //===--- Section Switching Directives ---------------------------------===//
134     
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
137     /// this.
138     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
139     
140     /// TextSectionStartSuffix - This is printed after each start of section
141     /// directive for text sections.
142     const char *TextSectionStartSuffix;   // Defaults to "".
143
144     /// DataSectionStartSuffix - This is printed after each start of section
145     /// directive for data sections.
146     const char *DataSectionStartSuffix;   // Defaults to "".
147     
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.
151     
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"
155
156     /// JumpTableDataSection - This is the section that we SwitchToSection right
157     /// before emitting the jump tables for a function when the relocation model
158     /// is not PIC.
159     const char *JumpTableDataSection;     // Defaults to "\t.section .rodata\n"
160     
161     /// JumpTableDirective - if non-null, the directive to emit before a jump
162     /// table.
163     const char *JumpTableDirective;
164
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
168     /// ".cstring".
169     const char *CStringSection;           // Defaults to NULL
170
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;
175
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;
180
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;
187     
188     //===--- Global Variable Emission Directives --------------------------===//
189     
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.
193     
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
198     /// \endliteral
199     const char *LCOMMDirective;           // Defaults to null.
200     
201     const char *COMMDirective;            // Defaults to "\t.comm\t".
202
203     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
204     /// argument that specifies the alignment of the declaration.
205     bool COMMDirectiveTakesAlignment;     // Defaults to true.
206     
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.
210     
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.
215     
216     //===--- Dwarf Emission Directives -----------------------------------===//
217
218     /// HasLEB128 - True if target asm supports leb128 directives.
219     ///
220     bool HasLEB128; // Defaults to false.
221     
222     /// hasDotLoc - True if target asm supports .loc directives.
223     ///
224     bool HasDotLoc; // Defaults to false.
225     
226     /// HasDotFile - True if target asm supports .file directives.
227     ///
228     bool HasDotFile; // Defaults to false.
229     
230     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
231     ///
232     bool DwarfRequiresFrameSection; // Defaults to false.
233
234     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
235     ///
236     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
237
238     /// DwarfInfoSection - Section directive for Dwarf info.
239     ///
240     const char *DwarfInfoSection; // Defaults to ".debug_info".
241
242     /// DwarfLineSection - Section directive for Dwarf info.
243     ///
244     const char *DwarfLineSection; // Defaults to ".debug_line".
245     
246     /// DwarfFrameSection - Section directive for Dwarf info.
247     ///
248     const char *DwarfFrameSection; // Defaults to ".debug_frame".
249     
250     /// DwarfPubNamesSection - Section directive for Dwarf info.
251     ///
252     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
253     
254     /// DwarfPubTypesSection - Section directive for Dwarf info.
255     ///
256     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
257     
258     /// DwarfStrSection - Section directive for Dwarf info.
259     ///
260     const char *DwarfStrSection; // Defaults to ".debug_str".
261
262     /// DwarfLocSection - Section directive for Dwarf info.
263     ///
264     const char *DwarfLocSection; // Defaults to ".debug_loc".
265
266     /// DwarfARangesSection - Section directive for Dwarf info.
267     ///
268     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
269
270     /// DwarfRangesSection - Section directive for Dwarf info.
271     ///
272     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
273
274     /// DwarfMacInfoSection - Section directive for Dwarf info.
275     ///
276     const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
277
278   public:
279     TargetAsmInfo();
280     virtual ~TargetAsmInfo();
281
282     /// Measure the specified inline asm to determine an approximation of its
283     /// length.
284     unsigned getInlineAsmLength(const char *Str) const;
285     
286     //
287     // Accessors.
288     //
289     const char *getTextSection() const {
290       return TextSection;
291     }
292     const char *getDataSection() const {
293       return DataSection;
294     }
295     unsigned getAddressSize() const {
296       return AddressSize;
297     }
298     bool needsSet() const {
299       return NeedsSet;
300     }
301     const char *getCommentString() const {
302       return CommentString;
303     }
304     const char *getGlobalPrefix() const {
305       return GlobalPrefix;
306     }
307     const char *getPrivateGlobalPrefix() const {
308       return PrivateGlobalPrefix;
309     }
310     const char *getGlobalVarAddrPrefix() const {
311       return GlobalVarAddrPrefix;
312     }
313     const char *getGlobalVarAddrSuffix() const {
314       return GlobalVarAddrSuffix;
315     }
316     const char *getFunctionAddrPrefix() const {
317       return FunctionAddrPrefix;
318     }
319     const char *getFunctionAddrSuffix() const {
320       return FunctionAddrSuffix;
321     }
322     const char *getInlineAsmStart() const {
323       return InlineAsmStart;
324     }
325     const char *getInlineAsmEnd() const {
326       return InlineAsmEnd;
327     }
328     const char *getZeroDirective() const {
329       return ZeroDirective;
330     }
331     const char *getZeroDirectiveSuffix() const {
332       return ZeroDirectiveSuffix;
333     }
334     const char *getAsciiDirective() const {
335       return AsciiDirective;
336     }
337     const char *getAscizDirective() const {
338       return AscizDirective;
339     }
340     const char *getData8bitsDirective() const {
341       return Data8bitsDirective;
342     }
343     const char *getData16bitsDirective() const {
344       return Data16bitsDirective;
345     }
346     const char *getData32bitsDirective() const {
347       return Data32bitsDirective;
348     }
349     const char *getData64bitsDirective() const {
350       return Data64bitsDirective;
351     }
352     const char *getJumpTableDirective() const {
353       return JumpTableDirective;
354     }
355     const char *getAlignDirective() const {
356       return AlignDirective;
357     }
358     bool getAlignmentIsInBytes() const {
359       return AlignmentIsInBytes;
360     }
361     const char *getSwitchToSectionDirective() const {
362       return SwitchToSectionDirective;
363     }
364     const char *getTextSectionStartSuffix() const {
365       return TextSectionStartSuffix;
366     }
367     const char *getDataSectionStartSuffix() const {
368       return DataSectionStartSuffix;
369     }
370     const char *getSectionEndDirectiveSuffix() const {
371       return SectionEndDirectiveSuffix;
372     }
373     const char *getConstantPoolSection() const {
374       return ConstantPoolSection;
375     }
376     const char *getJumpTableDataSection() const {
377       return JumpTableDataSection;
378     }
379     const char *getCStringSection() const {
380       return CStringSection;
381     }
382     const char *getStaticCtorsSection() const {
383       return StaticCtorsSection;
384     }
385     const char *getStaticDtorsSection() const {
386       return StaticDtorsSection;
387     }
388     const char *getFourByteConstantSection() const {
389       return FourByteConstantSection;
390     }
391     const char *getEightByteConstantSection() const {
392       return EightByteConstantSection;
393     }
394     const char *getSixteenByteConstantSection() const {
395       return SixteenByteConstantSection;
396     }
397     const char *getSetDirective() const {
398       return SetDirective;
399     }
400     const char *getLCOMMDirective() const {
401       return LCOMMDirective;
402     }
403     const char *getCOMMDirective() const {
404       return COMMDirective;
405     }
406     bool getCOMMDirectiveTakesAlignment() const {
407       return COMMDirectiveTakesAlignment;
408     }
409     bool hasDotTypeDotSizeDirective() const {
410       return HasDotTypeDotSizeDirective;
411     }
412     const char *getUsedDirective() const {
413       return UsedDirective;
414     }
415     bool hasLEB128() const {
416       return HasLEB128;
417     }
418     bool hasDotLoc() const {
419       return HasDotLoc;
420     }
421     bool hasDotFile() const {
422       return HasDotFile;
423     }
424     bool getDwarfRequiresFrameSection() const {
425       return DwarfRequiresFrameSection;
426     }
427     const char *getDwarfAbbrevSection() const {
428       return DwarfAbbrevSection;
429     }
430     const char *getDwarfInfoSection() const {
431       return DwarfInfoSection;
432     }
433     const char *getDwarfLineSection() const {
434       return DwarfLineSection;
435     }
436     const char *getDwarfFrameSection() const {
437       return DwarfFrameSection;
438     }
439     const char *getDwarfPubNamesSection() const {
440       return DwarfPubNamesSection;
441     }
442     const char *getDwarfPubTypesSection() const {
443       return DwarfPubTypesSection;
444     }
445     const char *getDwarfStrSection() const {
446       return DwarfStrSection;
447     }
448     const char *getDwarfLocSection() const {
449       return DwarfLocSection;
450     }
451     const char *getDwarfARangesSection() const {
452       return DwarfARangesSection;
453     }
454     const char *getDwarfRangesSection() const {
455       return DwarfRangesSection;
456     }
457     const char *getDwarfMacInfoSection() const {
458       return DwarfMacInfoSection;
459     }
460   };
461 }
462
463 #endif
464