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