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