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