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