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