Fix DWARF debugging information on x86/Linux and (hopefully)
[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   class TargetMachine;
24   class CallInst;
25
26   /// TargetAsmInfo - This class is intended to be used as a base class for asm
27   /// properties and features specific to the target.
28   class TargetAsmInfo {
29   protected:
30     //===------------------------------------------------------------------===//
31     // Properties to be set by the target writer, used to configure asm printer.
32     //
33     
34     /// TextSection - Section directive for standard text.
35     ///
36     const char *TextSection;              // Defaults to ".text".
37     
38     /// DataSection - Section directive for standard data.
39     ///
40     const char *DataSection;              // Defaults to ".data".
41
42     /// BSSSection - Section directive for uninitialized data.  Null if this
43     /// target doesn't support a BSS section.
44     ///
45     const char *BSSSection;               // Default to ".bss".
46     
47     /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
48     /// section on this target.  Null if this target doesn't support zerofill.
49     const char *ZeroFillDirective;        // Default is null.
50     
51     /// AddressSize - Size of addresses used in file.
52     ///
53     unsigned AddressSize;                 // Defaults to 4.
54     
55     /// NeedsSet - True if target asm can't compute addresses on data
56     /// directives.
57     bool NeedsSet;                        // Defaults to false.
58     
59     /// MaxInstLength - This is the maximum possible length of an instruction,
60     /// which is needed to compute the size of an inline asm.
61     unsigned MaxInstLength;               // Defaults to 4.
62     
63     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
64     /// relative expressions.
65     const char *PCSymbol;                 // Defaults to "$".
66
67     /// SeparatorChar - This character, if specified, is used to separate
68     /// instructions from each other when on the same line.  This is used to
69     /// measure inline asm instructions.
70     char SeparatorChar;                   // Defaults to ';'
71
72     /// CommentString - This indicates the comment character used by the
73     /// assembler.
74     const char *CommentString;            // Defaults to "#"
75
76     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
77     /// onto all global symbols.  This is often used for "_" or ".".
78     const char *GlobalPrefix;             // Defaults to ""
79
80     /// PrivateGlobalPrefix - This prefix is used for globals like constant
81     /// pool entries that are completely private to the .o file and should not
82     /// have names in the .o file.  This is often "." or "L".
83     const char *PrivateGlobalPrefix;      // Defaults to "."
84     
85     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
86     /// emitted before jump tables with the specified prefix.
87     const char *JumpTableSpecialLabelPrefix;  // Default to null.
88     
89     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
90     /// will enclose any GlobalVariable (that isn't a function)
91     ///
92     const char *GlobalVarAddrPrefix;      // Defaults to ""
93     const char *GlobalVarAddrSuffix;      // Defaults to ""
94
95     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
96     /// will enclose any GlobalVariable that points to a function.
97     /// For example, this is used by the IA64 backend to materialize
98     /// function descriptors, by decorating the ".data8" object with the
99     /// \literal @fptr( ) \endliteral
100     /// link-relocation operator.
101     ///
102     const char *FunctionAddrPrefix;       // Defaults to ""
103     const char *FunctionAddrSuffix;       // Defaults to ""
104
105     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
106     /// emit before and after an inline assembly statement.
107     const char *InlineAsmStart;           // Defaults to "#APP\n"
108     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
109
110     /// AssemblerDialect - Which dialect of an assembler variant to use.
111     unsigned AssemblerDialect;            // Defaults to 0
112
113     //===--- Data Emission Directives -------------------------------------===//
114
115     /// ZeroDirective - this should be set to the directive used to get some
116     /// number of zero bytes emitted to the current section.  Common cases are
117     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
118     /// Data*bitsDirective's will be used to emit zero bytes.
119     const char *ZeroDirective;            // Defaults to "\t.zero\t"
120     const char *ZeroDirectiveSuffix;      // Defaults to ""
121
122     /// AsciiDirective - This directive allows emission of an ascii string with
123     /// the standard C escape characters embedded into it.
124     const char *AsciiDirective;           // Defaults to "\t.ascii\t"
125     
126     /// AscizDirective - If not null, this allows for special handling of
127     /// zero terminated strings on this target.  This is commonly supported as
128     /// ".asciz".  If a target doesn't support this, it can be set to null.
129     const char *AscizDirective;           // Defaults to "\t.asciz\t"
130
131     /// DataDirectives - These directives are used to output some unit of
132     /// integer data to the current section.  If a data directive is set to
133     /// null, smaller data directives will be used to emit the large sizes.
134     const char *Data8bitsDirective;       // Defaults to "\t.byte\t"
135     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
136     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
137     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
138
139     //===--- Alignment Information ----------------------------------------===//
140
141     /// AlignDirective - The directive used to emit round up to an alignment
142     /// boundary.
143     ///
144     const char *AlignDirective;           // Defaults to "\t.align\t"
145
146     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
147     /// emits ".align N" directives, where N is the number of bytes to align to.
148     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
149     /// boundary.
150     bool AlignmentIsInBytes;              // Defaults to true
151
152     //===--- Section Switching Directives ---------------------------------===//
153     
154     /// SwitchToSectionDirective - This is the directive used when we want to
155     /// emit a global to an arbitrary section.  The section name is emited after
156     /// this.
157     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
158     
159     /// TextSectionStartSuffix - This is printed after each start of section
160     /// directive for text sections.
161     const char *TextSectionStartSuffix;   // Defaults to "".
162
163     /// DataSectionStartSuffix - This is printed after each start of section
164     /// directive for data sections.
165     const char *DataSectionStartSuffix;   // Defaults to "".
166     
167     /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
168     /// section with the section name and this suffix printed.
169     const char *SectionEndDirectiveSuffix;// Defaults to null.
170     
171     /// ConstantPoolSection - This is the section that we SwitchToSection right
172     /// before emitting the constant pool for a function.
173     const char *ConstantPoolSection;      // Defaults to "\t.section .rodata\n"
174
175     /// JumpTableDataSection - This is the section that we SwitchToSection right
176     /// before emitting the jump tables for a function when the relocation model
177     /// is not PIC.
178     const char *JumpTableDataSection;     // Defaults to "\t.section .rodata\n"
179     
180     /// JumpTableDirective - if non-null, the directive to emit before a jump
181     /// table.
182     const char *JumpTableDirective;
183
184     /// CStringSection - If not null, this allows for special handling of
185     /// cstring constants (\0 terminated string that does not contain any
186     /// other null bytes) on this target. This is commonly supported as
187     /// ".cstring".
188     const char *CStringSection;           // Defaults to NULL
189
190     /// StaticCtorsSection - This is the directive that is emitted to switch to
191     /// a section to emit the static constructor list.
192     /// Defaults to "\t.section .ctors,\"aw\",@progbits".
193     const char *StaticCtorsSection;
194
195     /// StaticDtorsSection - This is the directive that is emitted to switch to
196     /// a section to emit the static destructor list.
197     /// Defaults to "\t.section .dtors,\"aw\",@progbits".
198     const char *StaticDtorsSection;
199
200     /// FourByteConstantSection, EightByteConstantSection,
201     /// SixteenByteConstantSection - These are special sections where we place
202     /// 4-, 8-, and 16- byte constant literals.
203     const char *FourByteConstantSection;
204     const char *EightByteConstantSection;
205     const char *SixteenByteConstantSection;
206     
207     //===--- Global Variable Emission Directives --------------------------===//
208     
209     /// GlobalDirective - This is the directive used to declare a global entity.
210     ///
211     const char *GlobalDirective;          // Defaults to NULL.
212     
213     /// SetDirective - This is the name of a directive that can be used to tell
214     /// the assembler to set the value of a variable to some expression.
215     const char *SetDirective;             // Defaults to null.
216     
217     /// LCOMMDirective - This is the name of a directive (if supported) that can
218     /// be used to efficiently declare a local (internal) block of zero
219     /// initialized data in the .bss/.data section.  The syntax expected is:
220     /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
221     /// \endliteral
222     const char *LCOMMDirective;           // Defaults to null.
223     
224     const char *COMMDirective;            // Defaults to "\t.comm\t".
225
226     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
227     /// argument that specifies the alignment of the declaration.
228     bool COMMDirectiveTakesAlignment;     // Defaults to true.
229     
230     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
231     /// directives, this is true for most ELF targets.
232     bool HasDotTypeDotSizeDirective;      // Defaults to true.
233     
234     /// UsedDirective - This directive, if non-null, is used to declare a global
235     /// as being used somehow that the assembler can't see.  This prevents dead
236     /// code elimination on some targets.
237     const char *UsedDirective;            // Defaults to null.
238
239     /// WeakRefDirective - This directive, if non-null, is used to declare a
240     /// global as being a weak undefined symbol.
241     const char *WeakRefDirective;         // Defaults to null.
242     
243     /// HiddenDirective - This directive, if non-null, is used to declare a
244     /// global or function as having hidden visibility.
245     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
246     
247     //===--- Dwarf Emission Directives -----------------------------------===//
248
249     /// AbsoluteSectionOffsets - True if we should emit abolute section
250     /// offsets. Defaults to false.
251     bool AbsoluteSectionOffsets;
252     
253     /// HasLEB128 - True if target asm supports leb128 directives.
254     ///
255     bool HasLEB128; // Defaults to false.
256     
257     /// hasDotLoc - True if target asm supports .loc directives.
258     ///
259     bool HasDotLoc; // Defaults to false.
260     
261     /// HasDotFile - True if target asm supports .file directives.
262     ///
263     bool HasDotFile; // Defaults to false.
264     
265     /// SupportsExceptionHandling - True if target supports exception handling.
266     ///
267     bool SupportsExceptionHandling; // Defaults to false.
268     
269     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
270     ///
271     bool DwarfRequiresFrameSection; // Defaults to true.
272
273     /// DwarfSectionOffsetDirective - Special section offset directive.
274     const char* DwarfSectionOffsetDirective; // Defaults to NULL
275     
276     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
277     ///
278     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
279
280     /// DwarfInfoSection - Section directive for Dwarf info.
281     ///
282     const char *DwarfInfoSection; // Defaults to ".debug_info".
283
284     /// DwarfLineSection - Section directive for Dwarf info.
285     ///
286     const char *DwarfLineSection; // Defaults to ".debug_line".
287     
288     /// DwarfFrameSection - Section directive for Dwarf info.
289     ///
290     const char *DwarfFrameSection; // Defaults to ".debug_frame".
291     
292     /// DwarfPubNamesSection - Section directive for Dwarf info.
293     ///
294     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
295     
296     /// DwarfPubTypesSection - Section directive for Dwarf info.
297     ///
298     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
299     
300     /// DwarfStrSection - Section directive for Dwarf info.
301     ///
302     const char *DwarfStrSection; // Defaults to ".debug_str".
303
304     /// DwarfLocSection - Section directive for Dwarf info.
305     ///
306     const char *DwarfLocSection; // Defaults to ".debug_loc".
307
308     /// DwarfARangesSection - Section directive for Dwarf info.
309     ///
310     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
311
312     /// DwarfRangesSection - Section directive for Dwarf info.
313     ///
314     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
315
316     /// DwarfMacInfoSection - Section directive for Dwarf info.
317     ///
318     const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
319     
320     /// DwarfEHFrameSection - Section directive for Exception frames.
321     ///
322     const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
323     
324     /// DwarfExceptionSection - Section directive for Exception table.
325     ///
326     const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
327      
328
329     //===--- CBE Asm Translation Table -----------------------------------===//
330
331     const char** AsmTransCBE; // Defaults to empty
332
333   public:
334     TargetAsmInfo();
335     virtual ~TargetAsmInfo();
336
337     /// Measure the specified inline asm to determine an approximation of its
338     /// length.
339     unsigned getInlineAsmLength(const char *Str) const;
340
341     /// ExpandInlineAsm - This hook allows the target to expand an inline asm
342     /// call to be explicit llvm code if it wants to.  This is useful for
343     /// turning simple inline asms into LLVM intrinsics, which gives the
344     /// compiler more information about the behavior of the code.
345     virtual bool ExpandInlineAsm(CallInst *CI) const {
346       return false;
347     }
348     
349     // Accessors.
350     //
351     const char *getTextSection() const {
352       return TextSection;
353     }
354     const char *getDataSection() const {
355       return DataSection;
356     }
357     const char *getBSSSection() const {
358       return BSSSection;
359     }
360     const char *getZeroFillDirective() const {
361       return ZeroFillDirective;
362     }
363     unsigned getAddressSize() const {
364       return AddressSize;
365     }
366     bool needsSet() const {
367       return NeedsSet;
368     }
369     const char *getPCSymbol() const {
370       return PCSymbol;
371     }
372     char getSeparatorChar() const {
373       return SeparatorChar;
374     }
375     const char *getCommentString() const {
376       return CommentString;
377     }
378     const char *getGlobalPrefix() const {
379       return GlobalPrefix;
380     }
381     const char *getPrivateGlobalPrefix() const {
382       return PrivateGlobalPrefix;
383     }
384     const char *getJumpTableSpecialLabelPrefix() const {
385       return JumpTableSpecialLabelPrefix;
386     }
387     const char *getGlobalVarAddrPrefix() const {
388       return GlobalVarAddrPrefix;
389     }
390     const char *getGlobalVarAddrSuffix() const {
391       return GlobalVarAddrSuffix;
392     }
393     const char *getFunctionAddrPrefix() const {
394       return FunctionAddrPrefix;
395     }
396     const char *getFunctionAddrSuffix() const {
397       return FunctionAddrSuffix;
398     }
399     const char *getInlineAsmStart() const {
400       return InlineAsmStart;
401     }
402     const char *getInlineAsmEnd() const {
403       return InlineAsmEnd;
404     }
405     unsigned getAssemblerDialect() const {
406       return AssemblerDialect;
407     }
408     const char *getZeroDirective() const {
409       return ZeroDirective;
410     }
411     const char *getZeroDirectiveSuffix() const {
412       return ZeroDirectiveSuffix;
413     }
414     const char *getAsciiDirective() const {
415       return AsciiDirective;
416     }
417     const char *getAscizDirective() const {
418       return AscizDirective;
419     }
420     const char *getData8bitsDirective() const {
421       return Data8bitsDirective;
422     }
423     const char *getData16bitsDirective() const {
424       return Data16bitsDirective;
425     }
426     const char *getData32bitsDirective() const {
427       return Data32bitsDirective;
428     }
429     const char *getData64bitsDirective() const {
430       return Data64bitsDirective;
431     }
432     const char *getJumpTableDirective() const {
433       return JumpTableDirective;
434     }
435     const char *getAlignDirective() const {
436       return AlignDirective;
437     }
438     bool getAlignmentIsInBytes() const {
439       return AlignmentIsInBytes;
440     }
441     const char *getSwitchToSectionDirective() const {
442       return SwitchToSectionDirective;
443     }
444     const char *getTextSectionStartSuffix() const {
445       return TextSectionStartSuffix;
446     }
447     const char *getDataSectionStartSuffix() const {
448       return DataSectionStartSuffix;
449     }
450     const char *getSectionEndDirectiveSuffix() const {
451       return SectionEndDirectiveSuffix;
452     }
453     const char *getConstantPoolSection() const {
454       return ConstantPoolSection;
455     }
456     const char *getJumpTableDataSection() const {
457       return JumpTableDataSection;
458     }
459     const char *getCStringSection() const {
460       return CStringSection;
461     }
462     const char *getStaticCtorsSection() const {
463       return StaticCtorsSection;
464     }
465     const char *getStaticDtorsSection() const {
466       return StaticDtorsSection;
467     }
468     const char *getFourByteConstantSection() const {
469       return FourByteConstantSection;
470     }
471     const char *getEightByteConstantSection() const {
472       return EightByteConstantSection;
473     }
474     const char *getSixteenByteConstantSection() const {
475       return SixteenByteConstantSection;
476     }
477     const char *getGlobalDirective() const {
478       return GlobalDirective;
479     }
480     const char *getSetDirective() const {
481       return SetDirective;
482     }
483     const char *getLCOMMDirective() const {
484       return LCOMMDirective;
485     }
486     const char *getCOMMDirective() const {
487       return COMMDirective;
488     }
489     bool getCOMMDirectiveTakesAlignment() const {
490       return COMMDirectiveTakesAlignment;
491     }
492     bool hasDotTypeDotSizeDirective() const {
493       return HasDotTypeDotSizeDirective;
494     }
495     const char *getUsedDirective() const {
496       return UsedDirective;
497     }
498     const char *getWeakRefDirective() const {
499       return WeakRefDirective;
500     }
501     const char *getHiddenDirective() const {
502       return HiddenDirective;
503     }
504     bool isAbsoluteSectionOffsets() const {
505       return AbsoluteSectionOffsets;
506     }
507     bool hasLEB128() const {
508       return HasLEB128;
509     }
510     bool hasDotLoc() const {
511       return HasDotLoc;
512     }
513     bool hasDotFile() const {
514       return HasDotFile;
515     }
516     bool getSupportsExceptionHandling() const {
517       return SupportsExceptionHandling;
518     }
519     bool getDwarfRequiresFrameSection() const {
520       return DwarfRequiresFrameSection;
521     }
522     const char *getDwarfSectionOffsetDirective() const {
523       return DwarfSectionOffsetDirective;
524     }    
525     const char *getDwarfAbbrevSection() const {
526       return DwarfAbbrevSection;
527     }
528     const char *getDwarfInfoSection() const {
529       return DwarfInfoSection;
530     }
531     const char *getDwarfLineSection() const {
532       return DwarfLineSection;
533     }
534     const char *getDwarfFrameSection() const {
535       return DwarfFrameSection;
536     }
537     const char *getDwarfPubNamesSection() const {
538       return DwarfPubNamesSection;
539     }
540     const char *getDwarfPubTypesSection() const {
541       return DwarfPubTypesSection;
542     }
543     const char *getDwarfStrSection() const {
544       return DwarfStrSection;
545     }
546     const char *getDwarfLocSection() const {
547       return DwarfLocSection;
548     }
549     const char *getDwarfARangesSection() const {
550       return DwarfARangesSection;
551     }
552     const char *getDwarfRangesSection() const {
553       return DwarfRangesSection;
554     }
555     const char *getDwarfMacInfoSection() const {
556       return DwarfMacInfoSection;
557     }
558     const char *getDwarfEHFrameSection() const {
559       return DwarfEHFrameSection;
560     }
561     const char *getDwarfExceptionSection() const {
562       return DwarfExceptionSection;
563     }
564     const char** getAsmCBE() const {
565       return AsmTransCBE;
566     }
567   };
568 }
569
570 #endif
571