remove a bunch of now-dead crud from the asmprinter and TAI interfaces.
[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 is distributed under the University of Illinois Open Source
6 // 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/Support/DataTypes.h"
20 #include <cassert>
21 #include <string>
22
23 namespace llvm {
24   template <typename T> class SmallVectorImpl;
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     /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
35     /// section on this target.  Null if this target doesn't support zerofill.
36     const char *ZeroFillDirective;        // Default is null.
37
38     /// NonexecutableStackDirective - Directive for declaring to the
39     /// linker and beyond that the emitted code does not require stack
40     /// memory to be executable.
41     const char *NonexecutableStackDirective; // Default is null.
42
43     /// NeedsSet - True if target asm treats expressions in data directives
44     /// as linktime-relocatable.  For assembly-time computation, we need to
45     /// use a .set.  Thus:
46     /// .set w, x-y
47     /// .long w
48     /// is computed at assembly time, while
49     /// .long x-y
50     /// is relocated if the relative locations of x and y change at linktime.
51     /// We want both these things in different places.
52     bool NeedsSet;                        // Defaults to false.
53     
54     /// MaxInstLength - This is the maximum possible length of an instruction,
55     /// which is needed to compute the size of an inline asm.
56     unsigned MaxInstLength;               // Defaults to 4.
57     
58     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
59     /// relative expressions.
60     const char *PCSymbol;                 // Defaults to "$".
61
62     /// SeparatorChar - This character, if specified, is used to separate
63     /// instructions from each other when on the same line.  This is used to
64     /// measure inline asm instructions.
65     char SeparatorChar;                   // Defaults to ';'
66
67     /// CommentColumn - This indicates the comment num (zero-based) at
68     /// which asm comments should be printed.
69     unsigned CommentColumn;               // Defaults to 60
70
71     /// CommentString - This indicates the comment character used by the
72     /// assembler.
73     const char *CommentString;            // Defaults to "#"
74
75     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
76     /// onto all global symbols.  This is often used for "_" or ".".
77     const char *GlobalPrefix;             // Defaults to ""
78
79     /// PrivateGlobalPrefix - This prefix is used for globals like constant
80     /// pool entries that are completely private to the .s file and should not
81     /// have names in the .o file.  This is often "." or "L".
82     const char *PrivateGlobalPrefix;      // Defaults to "."
83     
84     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
85     /// be passed through the assembler but be removed by the linker.  This
86     /// is "l" on Darwin, currently used for some ObjC metadata.
87     const char *LinkerPrivateGlobalPrefix;      // Defaults to ""
88     
89     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
90     /// emitted before jump tables with the specified prefix.
91     const char *JumpTableSpecialLabelPrefix;  // Default to null.
92     
93     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
94     /// will enclose any GlobalVariable (that isn't a function)
95     ///
96     const char *GlobalVarAddrPrefix;      // Defaults to ""
97     const char *GlobalVarAddrSuffix;      // Defaults to ""
98
99     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
100     /// will enclose any GlobalVariable that points to a function.
101     ///
102     const char *FunctionAddrPrefix;       // Defaults to ""
103     const char *FunctionAddrSuffix;       // Defaults to ""
104
105     /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
106     /// enclose any personality function in the common frame section.
107     /// 
108     const char *PersonalityPrefix;        // Defaults to ""
109     const char *PersonalitySuffix;        // Defaults to ""
110
111     /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
112     /// for EH in Dwarf.
113     /// 
114     bool NeedsIndirectEncoding;           // Defaults to false
115
116     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
117     /// emit before and after an inline assembly statement.
118     const char *InlineAsmStart;           // Defaults to "#APP\n"
119     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
120
121     /// AssemblerDialect - Which dialect of an assembler variant to use.
122     unsigned AssemblerDialect;            // Defaults to 0
123
124     /// AllowQuotesInName - This is true if the assembler allows for complex
125     /// symbol names to be surrounded in quotes.  This defaults to false.
126     bool AllowQuotesInName;
127     
128     //===--- Data Emission Directives -------------------------------------===//
129
130     /// ZeroDirective - this should be set to the directive used to get some
131     /// number of zero bytes emitted to the current section.  Common cases are
132     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
133     /// Data*bitsDirective's will be used to emit zero bytes.
134     const char *ZeroDirective;            // Defaults to "\t.zero\t"
135     const char *ZeroDirectiveSuffix;      // Defaults to ""
136
137     /// AsciiDirective - This directive allows emission of an ascii string with
138     /// the standard C escape characters embedded into it.
139     const char *AsciiDirective;           // Defaults to "\t.ascii\t"
140     
141     /// AscizDirective - If not null, this allows for special handling of
142     /// zero terminated strings on this target.  This is commonly supported as
143     /// ".asciz".  If a target doesn't support this, it can be set to null.
144     const char *AscizDirective;           // Defaults to "\t.asciz\t"
145
146     /// DataDirectives - These directives are used to output some unit of
147     /// integer data to the current section.  If a data directive is set to
148     /// null, smaller data directives will be used to emit the large sizes.
149     const char *Data8bitsDirective;       // Defaults to "\t.byte\t"
150     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
151     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
152     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
153
154     /// getDataASDirective - Return the directive that should be used to emit
155     /// data of the specified size to the specified numeric address space.
156     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
157       assert(AS != 0 && "Don't know the directives for default addr space");
158       return NULL;
159     }
160
161     //===--- Alignment Information ----------------------------------------===//
162
163     /// AlignDirective - The directive used to emit round up to an alignment
164     /// boundary.
165     ///
166     const char *AlignDirective;           // Defaults to "\t.align\t"
167
168     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
169     /// emits ".align N" directives, where N is the number of bytes to align to.
170     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
171     /// boundary.
172     bool AlignmentIsInBytes;              // Defaults to true
173
174     /// TextAlignFillValue - If non-zero, this is used to fill the executable
175     /// space created as the result of a alignment directive.
176     unsigned TextAlignFillValue;
177
178     //===--- Section Switching Directives ---------------------------------===//
179     
180     /// SwitchToSectionDirective - This is the directive used when we want to
181     /// emit a global to an arbitrary section.  The section name is emited after
182     /// this.
183     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
184     
185     /// JumpTableDirective - if non-null, the directive to emit before a jump
186     /// table.
187     const char *JumpTableDirective;
188
189     //===--- Global Variable Emission Directives --------------------------===//
190     
191     /// GlobalDirective - This is the directive used to declare a global entity.
192     ///
193     const char *GlobalDirective;          // Defaults to NULL.
194
195     /// ExternDirective - This is the directive used to declare external 
196     /// globals.
197     ///
198     const char *ExternDirective;          // Defaults to NULL.
199     
200     /// SetDirective - This is the name of a directive that can be used to tell
201     /// the assembler to set the value of a variable to some expression.
202     const char *SetDirective;             // Defaults to null.
203     
204     /// LCOMMDirective - This is the name of a directive (if supported) that can
205     /// be used to efficiently declare a local (internal) block of zero
206     /// initialized data in the .bss/.data section.  The syntax expected is:
207     /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
208     /// @endverbatim
209     const char *LCOMMDirective;           // Defaults to null.
210     
211     const char *COMMDirective;            // Defaults to "\t.comm\t".
212
213     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
214     /// argument that specifies the alignment of the declaration.
215     bool COMMDirectiveTakesAlignment;     // Defaults to true.
216     
217     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
218     /// directives, this is true for most ELF targets.
219     bool HasDotTypeDotSizeDirective;      // Defaults to true.
220
221     /// HasSingleParameterDotFile - True if the target has a single parameter
222     /// .file directive, this is true for ELF targets.
223     bool HasSingleParameterDotFile;      // Defaults to true.
224
225     /// UsedDirective - This directive, if non-null, is used to declare a global
226     /// as being used somehow that the assembler can't see.  This prevents dead
227     /// code elimination on some targets.
228     const char *UsedDirective;            // Defaults to null.
229
230     /// WeakRefDirective - This directive, if non-null, is used to declare a
231     /// global as being a weak undefined symbol.
232     const char *WeakRefDirective;         // Defaults to null.
233     
234     /// WeakDefDirective - This directive, if non-null, is used to declare a
235     /// global as being a weak defined symbol.
236     const char *WeakDefDirective;         // Defaults to null.
237     
238     /// HiddenDirective - This directive, if non-null, is used to declare a
239     /// global or function as having hidden visibility.
240     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
241
242     /// ProtectedDirective - This directive, if non-null, is used to declare a
243     /// global or function as having protected visibility.
244     const char *ProtectedDirective;       // Defaults to "\t.protected\t".
245
246     //===--- Dwarf Emission Directives -----------------------------------===//
247
248     /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
249     /// offsets for debug information. Defaults to false.
250     bool AbsoluteDebugSectionOffsets;
251
252     /// AbsoluteEHSectionOffsets - True if we should emit abolute section
253     /// offsets for EH information. Defaults to false.
254     bool AbsoluteEHSectionOffsets;
255
256     /// HasLEB128 - True if target asm supports leb128 directives.
257     ///
258     bool HasLEB128; // Defaults to false.
259
260     /// hasDotLocAndDotFile - True if target asm supports .loc and .file
261     /// directives for emitting debugging information.
262     ///
263     bool HasDotLocAndDotFile; // Defaults to false.
264
265     /// SupportsDebugInformation - True if target supports emission of debugging
266     /// information.
267     bool SupportsDebugInformation;
268
269     /// SupportsExceptionHandling - True if target supports
270     /// exception handling.
271     ///
272     bool SupportsExceptionHandling; // Defaults to false.
273
274     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
275     ///
276     bool DwarfRequiresFrameSection; // Defaults to true.
277
278     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
279     /// encode inline subroutine information.
280     bool DwarfUsesInlineInfoSection; // Defaults to false.
281
282     /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
283     /// doesn't show up in the symbol table of the object file.
284     bool Is_EHSymbolPrivate;                // Defaults to true.
285
286     /// GlobalEHDirective - This is the directive used to make exception frame
287     /// tables globally visible.
288     ///
289     const char *GlobalEHDirective;          // Defaults to NULL.
290
291     /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
292     /// handle a weak_definition of constant 0 for an omitted EH frame.
293     bool SupportsWeakOmittedEHFrame;  // Defaults to true.
294
295     /// DwarfSectionOffsetDirective - Special section offset directive.
296     const char* DwarfSectionOffsetDirective; // Defaults to NULL
297     
298     //===--- CBE Asm Translation Table -----------------------------------===//
299
300     const char *const *AsmTransCBE; // Defaults to empty
301
302   public:
303     explicit TargetAsmInfo();
304     virtual ~TargetAsmInfo();
305
306     /// getSLEB128Size - Compute the number of bytes required for a signed
307     /// leb128 value.
308     static unsigned getSLEB128Size(int Value);
309
310     /// getULEB128Size - Compute the number of bytes required for an unsigned
311     /// leb128 value.
312     static unsigned getULEB128Size(unsigned Value);
313
314     // Data directive accessors.
315     //
316     const char *getData8bitsDirective(unsigned AS = 0) const {
317       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
318     }
319     const char *getData16bitsDirective(unsigned AS = 0) const {
320       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
321     }
322     const char *getData32bitsDirective(unsigned AS = 0) const {
323       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
324     }
325     const char *getData64bitsDirective(unsigned AS = 0) const {
326       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
327     }
328
329
330     // Accessors.
331     //
332     const char *getZeroFillDirective() const {
333       return ZeroFillDirective;
334     }
335     const char *getNonexecutableStackDirective() const {
336       return NonexecutableStackDirective;
337     }
338     bool needsSet() const {
339       return NeedsSet;
340     }
341     unsigned getMaxInstLength() const {
342       return MaxInstLength;
343     }
344     const char *getPCSymbol() const {
345       return PCSymbol;
346     }
347     char getSeparatorChar() const {
348       return SeparatorChar;
349     }
350     unsigned getCommentColumn() const {
351       return CommentColumn;
352     }
353     const char *getCommentString() const {
354       return CommentString;
355     }
356     const char *getGlobalPrefix() const {
357       return GlobalPrefix;
358     }
359     const char *getPrivateGlobalPrefix() const {
360       return PrivateGlobalPrefix;
361     }
362     const char *getLinkerPrivateGlobalPrefix() const {
363       return LinkerPrivateGlobalPrefix;
364     }
365     const char *getJumpTableSpecialLabelPrefix() const {
366       return JumpTableSpecialLabelPrefix;
367     }
368     const char *getGlobalVarAddrPrefix() const {
369       return GlobalVarAddrPrefix;
370     }
371     const char *getGlobalVarAddrSuffix() const {
372       return GlobalVarAddrSuffix;
373     }
374     const char *getFunctionAddrPrefix() const {
375       return FunctionAddrPrefix;
376     }
377     const char *getFunctionAddrSuffix() const {
378       return FunctionAddrSuffix;
379     }
380     const char *getPersonalityPrefix() const {
381       return PersonalityPrefix;
382     }
383     const char *getPersonalitySuffix() const {
384       return PersonalitySuffix;
385     }
386     bool getNeedsIndirectEncoding() const {
387       return NeedsIndirectEncoding;
388     }
389     const char *getInlineAsmStart() const {
390       return InlineAsmStart;
391     }
392     const char *getInlineAsmEnd() const {
393       return InlineAsmEnd;
394     }
395     unsigned getAssemblerDialect() const {
396       return AssemblerDialect;
397     }
398     bool doesAllowQuotesInName() const {
399       return AllowQuotesInName;
400     }
401     const char *getZeroDirective() const {
402       return ZeroDirective;
403     }
404     const char *getZeroDirectiveSuffix() const {
405       return ZeroDirectiveSuffix;
406     }
407     const char *getAsciiDirective() const {
408       return AsciiDirective;
409     }
410     const char *getAscizDirective() const {
411       return AscizDirective;
412     }
413     const char *getJumpTableDirective() const {
414       return JumpTableDirective;
415     }
416     const char *getAlignDirective() const {
417       return AlignDirective;
418     }
419     bool getAlignmentIsInBytes() const {
420       return AlignmentIsInBytes;
421     }
422     unsigned getTextAlignFillValue() const {
423       return TextAlignFillValue;
424     }
425     const char *getSwitchToSectionDirective() const {
426       return SwitchToSectionDirective;
427     }
428     const char *getGlobalDirective() const {
429       return GlobalDirective;
430     }
431     const char *getExternDirective() const {
432       return ExternDirective;
433     }
434     const char *getSetDirective() const {
435       return SetDirective;
436     }
437     const char *getLCOMMDirective() const {
438       return LCOMMDirective;
439     }
440     const char *getCOMMDirective() const {
441       return COMMDirective;
442     }
443     bool getCOMMDirectiveTakesAlignment() const {
444       return COMMDirectiveTakesAlignment;
445     }
446     bool hasDotTypeDotSizeDirective() const {
447       return HasDotTypeDotSizeDirective;
448     }
449     bool hasSingleParameterDotFile() const {
450       return HasSingleParameterDotFile;
451     }
452     const char *getUsedDirective() const {
453       return UsedDirective;
454     }
455     const char *getWeakRefDirective() const {
456       return WeakRefDirective;
457     }
458     const char *getWeakDefDirective() const {
459       return WeakDefDirective;
460     }
461     const char *getHiddenDirective() const {
462       return HiddenDirective;
463     }
464     const char *getProtectedDirective() const {
465       return ProtectedDirective;
466     }
467     bool isAbsoluteDebugSectionOffsets() const {
468       return AbsoluteDebugSectionOffsets;
469     }
470     bool isAbsoluteEHSectionOffsets() const {
471       return AbsoluteEHSectionOffsets;
472     }
473     bool hasLEB128() const {
474       return HasLEB128;
475     }
476     bool hasDotLocAndDotFile() const {
477       return HasDotLocAndDotFile;
478     }
479     bool doesSupportDebugInformation() const {
480       return SupportsDebugInformation;
481     }
482     bool doesSupportExceptionHandling() const {
483       return SupportsExceptionHandling;
484     }
485     bool doesDwarfRequireFrameSection() const {
486       return DwarfRequiresFrameSection;
487     }
488     bool doesDwarfUsesInlineInfoSection() const {
489       return DwarfUsesInlineInfoSection;
490     }
491     bool is_EHSymbolPrivate() const {
492       return Is_EHSymbolPrivate;
493     }
494     const char *getGlobalEHDirective() const {
495       return GlobalEHDirective;
496     }
497     bool getSupportsWeakOmittedEHFrame() const {
498       return SupportsWeakOmittedEHFrame;
499     }
500     const char *getDwarfSectionOffsetDirective() const {
501       return DwarfSectionOffsetDirective;
502     }
503     const char *const *getAsmCBE() const {
504       return AsmTransCBE;
505     }
506   };
507 }
508
509 #endif