efc2f1b14883a6adc7f0b1e5b471e33b27b23854
[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     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
88     /// will enclose any GlobalVariable (that isn't a function)
89     ///
90     const char *GlobalVarAddrPrefix;         // Defaults to ""
91     const char *GlobalVarAddrSuffix;         // Defaults to ""
92
93     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
94     /// will enclose any GlobalVariable that points to a function.
95     ///
96     const char *FunctionAddrPrefix;          // Defaults to ""
97     const char *FunctionAddrSuffix;          // Defaults to ""
98
99     /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
100     /// enclose any personality function in the common frame section.
101     /// 
102     const char *PersonalityPrefix;           // Defaults to ""
103     const char *PersonalitySuffix;           // Defaults to ""
104
105     /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
106     /// for EH in Dwarf.
107     /// 
108     bool NeedsIndirectEncoding;              // Defaults to false
109
110     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
111     /// emit before and after an inline assembly statement.
112     const char *InlineAsmStart;              // Defaults to "#APP\n"
113     const char *InlineAsmEnd;                // Defaults to "#NO_APP\n"
114
115     /// AssemblerDialect - Which dialect of an assembler variant to use.
116     unsigned AssemblerDialect;               // Defaults to 0
117
118     /// AllowQuotesInName - This is true if the assembler allows for complex
119     /// symbol names to be surrounded in quotes.  This defaults to false.
120     bool AllowQuotesInName;
121     
122     //===--- Data Emission Directives -------------------------------------===//
123
124     /// ZeroDirective - this should be set to the directive used to get some
125     /// number of zero bytes emitted to the current section.  Common cases are
126     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
127     /// Data*bitsDirective's will be used to emit zero bytes.
128     const char *ZeroDirective;               // Defaults to "\t.zero\t"
129     const char *ZeroDirectiveSuffix;         // Defaults to ""
130
131     /// AsciiDirective - This directive allows emission of an ascii string with
132     /// the standard C escape characters embedded into it.
133     const char *AsciiDirective;              // Defaults to "\t.ascii\t"
134     
135     /// AscizDirective - If not null, this allows for special handling of
136     /// zero terminated strings on this target.  This is commonly supported as
137     /// ".asciz".  If a target doesn't support this, it can be set to null.
138     const char *AscizDirective;              // Defaults to "\t.asciz\t"
139
140     /// DataDirectives - These directives are used to output some unit of
141     /// integer data to the current section.  If a data directive is set to
142     /// null, smaller data directives will be used to emit the large sizes.
143     const char *Data8bitsDirective;          // Defaults to "\t.byte\t"
144     const char *Data16bitsDirective;         // Defaults to "\t.short\t"
145     const char *Data32bitsDirective;         // Defaults to "\t.long\t"
146     const char *Data64bitsDirective;         // Defaults to "\t.quad\t"
147
148     /// getDataASDirective - Return the directive that should be used to emit
149     /// data of the specified size to the specified numeric address space.
150     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
151       assert(AS != 0 && "Don't know the directives for default addr space");
152       return 0;
153     }
154
155     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
156     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
157     /// normal ELF syntax (,"a,w") in .section directives.
158     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
159
160     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
161     /// '.section' directive before the '.bss' one. It's used for PPC/Linux 
162     /// which doesn't support the '.bss' directive only.
163     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
164     
165     //===--- Alignment Information ----------------------------------------===//
166
167     /// AlignDirective - The directive used to emit round up to an alignment
168     /// boundary.
169     ///
170     const char *AlignDirective;              // Defaults to "\t.align\t"
171
172     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
173     /// emits ".align N" directives, where N is the number of bytes to align to.
174     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
175     /// boundary.
176     bool AlignmentIsInBytes;                 // Defaults to true
177
178     /// TextAlignFillValue - If non-zero, this is used to fill the executable
179     /// space created as the result of a alignment directive.
180     unsigned TextAlignFillValue;             // Defaults to 0
181
182     //===--- Section Switching Directives ---------------------------------===//
183     
184     /// JumpTableDirective - if non-null, the directive to emit before jump
185     /// table entries.  FIXME: REMOVE THIS.
186     const char *JumpTableDirective;          // Defaults to NULL.
187     const char *PICJumpTableDirective;       // Defaults to NULL.
188
189
190     //===--- Global Variable Emission Directives --------------------------===//
191     
192     /// GlobalDirective - This is the directive used to declare a global entity.
193     ///
194     const char *GlobalDirective;             // Defaults to NULL.
195
196     /// ExternDirective - This is the directive used to declare external 
197     /// globals.
198     ///
199     const char *ExternDirective;             // Defaults to NULL.
200     
201     /// SetDirective - This is the name of a directive that can be used to tell
202     /// the assembler to set the value of a variable to some expression.
203     const char *SetDirective;                // Defaults to null.
204     
205     /// LCOMMDirective - This is the name of a directive (if supported) that can
206     /// be used to efficiently declare a local (internal) block of zero
207     /// initialized data in the .bss/.data section.  The syntax expected is:
208     /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
209     /// @endverbatim
210     const char *LCOMMDirective;              // Defaults to null.
211     
212     const char *COMMDirective;               // Defaults to "\t.comm\t".
213
214     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
215     /// argument that specifies the alignment of the declaration.
216     bool COMMDirectiveTakesAlignment;        // Defaults to true.
217     
218     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
219     /// directives, this is true for most ELF targets.
220     bool HasDotTypeDotSizeDirective;         // Defaults to true.
221
222     /// HasSingleParameterDotFile - True if the target has a single parameter
223     /// .file directive, this is true for ELF targets.
224     bool HasSingleParameterDotFile;          // 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     /// WeakDefDirective - This directive, if non-null, is used to declare a
236     /// global as being a weak defined symbol.
237     const char *WeakDefDirective;            // Defaults to NULL.
238     
239     /// HiddenDirective - This directive, if non-null, is used to declare a
240     /// global or function as having hidden visibility.
241     const char *HiddenDirective;             // Defaults to "\t.hidden\t".
242
243     /// ProtectedDirective - This directive, if non-null, is used to declare a
244     /// global or function as having protected visibility.
245     const char *ProtectedDirective;          // Defaults to "\t.protected\t".
246
247     //===--- Dwarf Emission Directives -----------------------------------===//
248
249     /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
250     /// offsets for debug information.
251     bool AbsoluteDebugSectionOffsets;        // Defaults to false.
252
253     /// AbsoluteEHSectionOffsets - True if we should emit abolute section
254     /// offsets for EH information. Defaults to false.
255     bool AbsoluteEHSectionOffsets;
256
257     /// HasLEB128 - True if target asm supports leb128 directives.
258     bool HasLEB128;                          // Defaults to false.
259
260     /// hasDotLocAndDotFile - True if target asm supports .loc and .file
261     /// directives for emitting debugging information.
262     bool HasDotLocAndDotFile;                // Defaults to false.
263
264     /// SupportsDebugInformation - True if target supports emission of debugging
265     /// information.
266     bool SupportsDebugInformation;           // Defaults to false.
267
268     /// SupportsExceptionHandling - True if target supports exception handling.
269     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
270
271     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
272     bool DwarfRequiresFrameSection;          // Defaults to true.
273
274     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
275     /// encode inline subroutine information.
276     bool DwarfUsesInlineInfoSection;         // Defaults to false.
277
278     /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
279     /// doesn't show up in the symbol table of the object file.
280     bool Is_EHSymbolPrivate;                 // Defaults to true.
281
282     /// GlobalEHDirective - This is the directive used to make exception frame
283     /// tables globally visible.
284     const char *GlobalEHDirective;           // Defaults to NULL.
285
286     /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
287     /// handle a weak_definition of constant 0 for an omitted EH frame.
288     bool SupportsWeakOmittedEHFrame;         // Defaults to true.
289
290     /// DwarfSectionOffsetDirective - Special section offset directive.
291     const char* DwarfSectionOffsetDirective; // Defaults to NULL
292     
293     //===--- CBE Asm Translation Table -----------------------------------===//
294
295     const char *const *AsmTransCBE;          // Defaults to empty
296
297   public:
298     explicit MCAsmInfo();
299     virtual ~MCAsmInfo();
300
301     /// getSLEB128Size - Compute the number of bytes required for a signed
302     /// leb128 value.
303     static unsigned getSLEB128Size(int Value);
304
305     /// getULEB128Size - Compute the number of bytes required for an unsigned
306     /// leb128 value.
307     static unsigned getULEB128Size(unsigned Value);
308
309     // Data directive accessors.
310     //
311     const char *getData8bitsDirective(unsigned AS = 0) const {
312       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
313     }
314     const char *getData16bitsDirective(unsigned AS = 0) const {
315       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
316     }
317     const char *getData32bitsDirective(unsigned AS = 0) const {
318       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
319     }
320     const char *getData64bitsDirective(unsigned AS = 0) const {
321       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
322     }
323
324     
325     bool usesSunStyleELFSectionSwitchSyntax() const {
326       return SunStyleELFSectionSwitchSyntax;
327     }
328     
329     bool usesELFSectionDirectiveForBSS() const {
330       return UsesELFSectionDirectiveForBSS;
331     }
332
333     // Accessors.
334     //
335     const char *getZeroFillDirective() const {
336       return ZeroFillDirective;
337     }
338     const char *getNonexecutableStackDirective() const {
339       return NonexecutableStackDirective;
340     }
341     bool needsSet() const {
342       return NeedsSet;
343     }
344     unsigned getMaxInstLength() const {
345       return MaxInstLength;
346     }
347     const char *getPCSymbol() const {
348       return PCSymbol;
349     }
350     char getSeparatorChar() const {
351       return SeparatorChar;
352     }
353     unsigned getCommentColumn() const {
354       return CommentColumn;
355     }
356     const char *getCommentString() const {
357       return CommentString;
358     }
359     const char *getGlobalPrefix() const {
360       return GlobalPrefix;
361     }
362     const char *getPrivateGlobalPrefix() const {
363       return PrivateGlobalPrefix;
364     }
365     const char *getLinkerPrivateGlobalPrefix() const {
366       return LinkerPrivateGlobalPrefix;
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(bool isPIC) const {
414       return isPIC ? PICJumpTableDirective : 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 *getGlobalDirective() const {
426       return GlobalDirective;
427     }
428     const char *getExternDirective() const {
429       return ExternDirective;
430     }
431     const char *getSetDirective() const {
432       return SetDirective;
433     }
434     const char *getLCOMMDirective() const {
435       return LCOMMDirective;
436     }
437     const char *getCOMMDirective() const {
438       return COMMDirective;
439     }
440     bool getCOMMDirectiveTakesAlignment() const {
441       return COMMDirectiveTakesAlignment;
442     }
443     bool hasDotTypeDotSizeDirective() const {
444       return HasDotTypeDotSizeDirective;
445     }
446     bool hasSingleParameterDotFile() const {
447       return HasSingleParameterDotFile;
448     }
449     const char *getUsedDirective() const {
450       return UsedDirective;
451     }
452     const char *getWeakRefDirective() const {
453       return WeakRefDirective;
454     }
455     const char *getWeakDefDirective() const {
456       return WeakDefDirective;
457     }
458     const char *getHiddenDirective() const {
459       return HiddenDirective;
460     }
461     const char *getProtectedDirective() const {
462       return ProtectedDirective;
463     }
464     bool isAbsoluteDebugSectionOffsets() const {
465       return AbsoluteDebugSectionOffsets;
466     }
467     bool isAbsoluteEHSectionOffsets() const {
468       return AbsoluteEHSectionOffsets;
469     }
470     bool hasLEB128() const {
471       return HasLEB128;
472     }
473     bool hasDotLocAndDotFile() const {
474       return HasDotLocAndDotFile;
475     }
476     bool doesSupportDebugInformation() const {
477       return SupportsDebugInformation;
478     }
479     bool doesSupportExceptionHandling() const {
480       return ExceptionsType != ExceptionHandling::None;
481     }
482     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
483       return ExceptionsType;
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