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