add new JumpTableSpecialLabelPrefix hook to asmprinter for jumptable emission.
[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     /// SetDirective - This is the name of a directive that can be used to tell
206     /// the assembler to set the value of a variable to some expression.
207     const char *SetDirective;             // Defaults to null.
208     
209     /// LCOMMDirective - This is the name of a directive (if supported) that can
210     /// be used to efficiently declare a local (internal) block of zero
211     /// initialized data in the .bss/.data section.  The syntax expected is:
212     /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
213     /// \endliteral
214     const char *LCOMMDirective;           // Defaults to null.
215     
216     const char *COMMDirective;            // Defaults to "\t.comm\t".
217
218     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
219     /// argument that specifies the alignment of the declaration.
220     bool COMMDirectiveTakesAlignment;     // Defaults to true.
221     
222     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
223     /// directives, this is true for most ELF targets.
224     bool HasDotTypeDotSizeDirective;      // Defaults to true.
225     
226     /// UsedDirective - This directive, if non-null, is used to declare a global
227     /// as being used somehow that the assembler can't see.  This prevents dead
228     /// code elimination on some targets.
229     const char *UsedDirective;            // Defaults to null.
230
231     /// WeakRefDirective - This directive, if non-null, is used to declare a
232     /// global as being a weak undefined symbol.
233     const char *WeakRefDirective;         // Defaults to null.
234     
235     /// HiddenDirective - This directive, if non-null, is used to declare a
236     /// global or function as having hidden visibility.
237     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
238     
239     //===--- Dwarf Emission Directives -----------------------------------===//
240
241     /// HasLEB128 - True if target asm supports leb128 directives.
242     ///
243     bool HasLEB128; // Defaults to false.
244     
245     /// hasDotLoc - True if target asm supports .loc directives.
246     ///
247     bool HasDotLoc; // Defaults to false.
248     
249     /// HasDotFile - True if target asm supports .file directives.
250     ///
251     bool HasDotFile; // Defaults to false.
252     
253     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
254     ///
255     bool DwarfRequiresFrameSection; // Defaults to true.
256
257     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
258     ///
259     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
260
261     /// DwarfInfoSection - Section directive for Dwarf info.
262     ///
263     const char *DwarfInfoSection; // Defaults to ".debug_info".
264
265     /// DwarfLineSection - Section directive for Dwarf info.
266     ///
267     const char *DwarfLineSection; // Defaults to ".debug_line".
268     
269     /// DwarfFrameSection - Section directive for Dwarf info.
270     ///
271     const char *DwarfFrameSection; // Defaults to ".debug_frame".
272     
273     /// DwarfPubNamesSection - Section directive for Dwarf info.
274     ///
275     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
276     
277     /// DwarfPubTypesSection - Section directive for Dwarf info.
278     ///
279     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
280     
281     /// DwarfStrSection - Section directive for Dwarf info.
282     ///
283     const char *DwarfStrSection; // Defaults to ".debug_str".
284
285     /// DwarfLocSection - Section directive for Dwarf info.
286     ///
287     const char *DwarfLocSection; // Defaults to ".debug_loc".
288
289     /// DwarfARangesSection - Section directive for Dwarf info.
290     ///
291     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
292
293     /// DwarfRangesSection - Section directive for Dwarf info.
294     ///
295     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
296
297     /// DwarfMacInfoSection - Section directive for Dwarf info.
298     ///
299     const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
300
301     //===--- CBE Asm Translation Table -----------------------------------===//
302
303     const char** AsmTransCBE; // Defaults to empty
304
305   public:
306     TargetAsmInfo();
307     virtual ~TargetAsmInfo();
308
309     /// Measure the specified inline asm to determine an approximation of its
310     /// length.
311     unsigned getInlineAsmLength(const char *Str) const;
312
313     /// ExpandInlineAsm - This hook allows the target to expand an inline asm
314     /// call to be explicit llvm code if it wants to.  This is useful for
315     /// turning simple inline asms into LLVM intrinsics, which gives the
316     /// compiler more information about the behavior of the code.
317     virtual bool ExpandInlineAsm(CallInst *CI) const {
318       return false;
319     }
320     
321     // Accessors.
322     //
323     const char *getTextSection() const {
324       return TextSection;
325     }
326     const char *getDataSection() const {
327       return DataSection;
328     }
329     const char *getBSSSection() const {
330       return BSSSection;
331     }
332     const char *getZeroFillDirective() const {
333       return ZeroFillDirective;
334     }
335     unsigned getAddressSize() const {
336       return AddressSize;
337     }
338     bool needsSet() const {
339       return NeedsSet;
340     }
341     const char *getCommentString() const {
342       return CommentString;
343     }
344     const char *getGlobalPrefix() const {
345       return GlobalPrefix;
346     }
347     const char *getPrivateGlobalPrefix() const {
348       return PrivateGlobalPrefix;
349     }
350     const char *getJumpTableSpecialLabelPrefix() const {
351       return JumpTableSpecialLabelPrefix;
352     }
353     const char *getGlobalVarAddrPrefix() const {
354       return GlobalVarAddrPrefix;
355     }
356     const char *getGlobalVarAddrSuffix() const {
357       return GlobalVarAddrSuffix;
358     }
359     const char *getFunctionAddrPrefix() const {
360       return FunctionAddrPrefix;
361     }
362     const char *getFunctionAddrSuffix() const {
363       return FunctionAddrSuffix;
364     }
365     const char *getInlineAsmStart() const {
366       return InlineAsmStart;
367     }
368     const char *getInlineAsmEnd() const {
369       return InlineAsmEnd;
370     }
371     unsigned getAssemblerDialect() const {
372       return AssemblerDialect;
373     }
374     const char *getZeroDirective() const {
375       return ZeroDirective;
376     }
377     const char *getZeroDirectiveSuffix() const {
378       return ZeroDirectiveSuffix;
379     }
380     const char *getAsciiDirective() const {
381       return AsciiDirective;
382     }
383     const char *getAscizDirective() const {
384       return AscizDirective;
385     }
386     const char *getData8bitsDirective() const {
387       return Data8bitsDirective;
388     }
389     const char *getData16bitsDirective() const {
390       return Data16bitsDirective;
391     }
392     const char *getData32bitsDirective() const {
393       return Data32bitsDirective;
394     }
395     const char *getData64bitsDirective() const {
396       return Data64bitsDirective;
397     }
398     const char *getJumpTableDirective() const {
399       return JumpTableDirective;
400     }
401     const char *getAlignDirective() const {
402       return AlignDirective;
403     }
404     bool getAlignmentIsInBytes() const {
405       return AlignmentIsInBytes;
406     }
407     const char *getSwitchToSectionDirective() const {
408       return SwitchToSectionDirective;
409     }
410     const char *getTextSectionStartSuffix() const {
411       return TextSectionStartSuffix;
412     }
413     const char *getDataSectionStartSuffix() const {
414       return DataSectionStartSuffix;
415     }
416     const char *getSectionEndDirectiveSuffix() const {
417       return SectionEndDirectiveSuffix;
418     }
419     const char *getConstantPoolSection() const {
420       return ConstantPoolSection;
421     }
422     const char *getJumpTableDataSection() const {
423       return JumpTableDataSection;
424     }
425     const char *getCStringSection() const {
426       return CStringSection;
427     }
428     const char *getStaticCtorsSection() const {
429       return StaticCtorsSection;
430     }
431     const char *getStaticDtorsSection() const {
432       return StaticDtorsSection;
433     }
434     const char *getFourByteConstantSection() const {
435       return FourByteConstantSection;
436     }
437     const char *getEightByteConstantSection() const {
438       return EightByteConstantSection;
439     }
440     const char *getSixteenByteConstantSection() const {
441       return SixteenByteConstantSection;
442     }
443     const char *getSetDirective() const {
444       return SetDirective;
445     }
446     const char *getLCOMMDirective() const {
447       return LCOMMDirective;
448     }
449     const char *getCOMMDirective() const {
450       return COMMDirective;
451     }
452     bool getCOMMDirectiveTakesAlignment() const {
453       return COMMDirectiveTakesAlignment;
454     }
455     bool hasDotTypeDotSizeDirective() const {
456       return HasDotTypeDotSizeDirective;
457     }
458     const char *getUsedDirective() const {
459       return UsedDirective;
460     }
461     const char *getWeakRefDirective() const {
462       return WeakRefDirective;
463     }
464     const char *getHiddenDirective() const {
465       return HiddenDirective;
466     }
467     bool hasLEB128() const {
468       return HasLEB128;
469     }
470     bool hasDotLoc() const {
471       return HasDotLoc;
472     }
473     bool hasDotFile() const {
474       return HasDotFile;
475     }
476     bool getDwarfRequiresFrameSection() const {
477       return DwarfRequiresFrameSection;
478     }
479     const char *getDwarfAbbrevSection() const {
480       return DwarfAbbrevSection;
481     }
482     const char *getDwarfInfoSection() const {
483       return DwarfInfoSection;
484     }
485     const char *getDwarfLineSection() const {
486       return DwarfLineSection;
487     }
488     const char *getDwarfFrameSection() const {
489       return DwarfFrameSection;
490     }
491     const char *getDwarfPubNamesSection() const {
492       return DwarfPubNamesSection;
493     }
494     const char *getDwarfPubTypesSection() const {
495       return DwarfPubTypesSection;
496     }
497     const char *getDwarfStrSection() const {
498       return DwarfStrSection;
499     }
500     const char *getDwarfLocSection() const {
501       return DwarfLocSection;
502     }
503     const char *getDwarfARangesSection() const {
504       return DwarfARangesSection;
505     }
506     const char *getDwarfRangesSection() const {
507       return DwarfRangesSection;
508     }
509     const char *getDwarfMacInfoSection() const {
510       return DwarfMacInfoSection;
511     }
512     const char** getAsmCBE() const {
513       return AsmTransCBE;
514     }
515   };
516 }
517
518 #endif
519