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