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