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