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