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