9d37d49a46713e88ad5bb20d71264d8c403c6533
[oota-llvm.git] / include / llvm / Target / TargetAsmInfo.h
1 //===-- llvm/Target/TargetAsmInfo.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   /// TargetAsmInfo - This class is intended to be used as a base class for asm
27   /// properties and features specific to the target.
28   class TargetAsmInfo {
29   protected:
30     //===------------------------------------------------------------------===//
31     // Properties to be set by the target writer, used to configure asm printer.
32     //
33
34     /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
35     /// section on this target.  Null if this target doesn't support zerofill.
36     const char *ZeroFillDirective;        // Default is null.
37
38     /// NonexecutableStackDirective - Directive for declaring to the
39     /// linker and beyond that the emitted code does not require stack
40     /// memory to be executable.
41     const char *NonexecutableStackDirective; // Default is null.
42
43     /// NeedsSet - True if target asm treats expressions in data directives
44     /// as linktime-relocatable.  For assembly-time computation, we need to
45     /// use a .set.  Thus:
46     /// .set w, x-y
47     /// .long w
48     /// is computed at assembly time, while
49     /// .long x-y
50     /// is relocated if the relative locations of x and y change at linktime.
51     /// We want both these things in different places.
52     bool NeedsSet;                        // Defaults to false.
53     
54     /// MaxInstLength - This is the maximum possible length of an instruction,
55     /// which is needed to compute the size of an inline asm.
56     unsigned MaxInstLength;               // Defaults to 4.
57     
58     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
59     /// relative expressions.
60     const char *PCSymbol;                 // Defaults to "$".
61
62     /// SeparatorChar - This character, if specified, is used to separate
63     /// instructions from each other when on the same line.  This is used to
64     /// measure inline asm instructions.
65     char SeparatorChar;                   // Defaults to ';'
66
67     /// CommentColumn - This indicates the comment num (zero-based) at
68     /// which asm comments should be printed.
69     unsigned CommentColumn;               // Defaults to 60
70
71     /// CommentString - This indicates the comment character used by the
72     /// assembler.
73     const char *CommentString;            // Defaults to "#"
74
75     /// FirstOperandColumn - The output column where the first operand
76     /// should be printed
77     unsigned FirstOperandColumn;          // Defaults to 0 (ignored)
78
79     /// MaxOperandLength - The maximum length of any printed asm
80     /// operand
81     unsigned MaxOperandLength;            // Defaults to 0 (ignored)
82
83     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
84     /// onto all global symbols.  This is often used for "_" or ".".
85     const char *GlobalPrefix;             // Defaults to ""
86
87     /// PrivateGlobalPrefix - This prefix is used for globals like constant
88     /// pool entries that are completely private to the .s file and should not
89     /// have names in the .o file.  This is often "." or "L".
90     const char *PrivateGlobalPrefix;      // Defaults to "."
91     
92     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
93     /// be passed through the assembler but be removed by the linker.  This
94     /// is "l" on Darwin, currently used for some ObjC metadata.
95     const char *LinkerPrivateGlobalPrefix;      // Defaults to ""
96     
97     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
98     /// emitted before jump tables with the specified prefix.
99     const char *JumpTableSpecialLabelPrefix;  // Default to null.
100     
101     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
102     /// will enclose any GlobalVariable (that isn't a function)
103     ///
104     const char *GlobalVarAddrPrefix;      // Defaults to ""
105     const char *GlobalVarAddrSuffix;      // Defaults to ""
106
107     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
108     /// will enclose any GlobalVariable that points to a function.
109     ///
110     const char *FunctionAddrPrefix;       // Defaults to ""
111     const char *FunctionAddrSuffix;       // Defaults to ""
112
113     /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
114     /// enclose any personality function in the common frame section.
115     /// 
116     const char *PersonalityPrefix;        // Defaults to ""
117     const char *PersonalitySuffix;        // Defaults to ""
118
119     /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
120     /// for EH in Dwarf.
121     /// 
122     bool NeedsIndirectEncoding;           // Defaults to false
123
124     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
125     /// emit before and after an inline assembly statement.
126     const char *InlineAsmStart;           // Defaults to "#APP\n"
127     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
128
129     /// AssemblerDialect - Which dialect of an assembler variant to use.
130     unsigned AssemblerDialect;            // Defaults to 0
131
132     /// AllowQuotesInName - This is true if the assembler allows for complex
133     /// symbol names to be surrounded in quotes.  This defaults to false.
134     bool AllowQuotesInName;
135     
136     //===--- Data Emission Directives -------------------------------------===//
137
138     /// ZeroDirective - this should be set to the directive used to get some
139     /// number of zero bytes emitted to the current section.  Common cases are
140     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
141     /// Data*bitsDirective's will be used to emit zero bytes.
142     const char *ZeroDirective;            // Defaults to "\t.zero\t"
143     const char *ZeroDirectiveSuffix;      // Defaults to ""
144
145     /// AsciiDirective - This directive allows emission of an ascii string with
146     /// the standard C escape characters embedded into it.
147     const char *AsciiDirective;           // Defaults to "\t.ascii\t"
148     
149     /// AscizDirective - If not null, this allows for special handling of
150     /// zero terminated strings on this target.  This is commonly supported as
151     /// ".asciz".  If a target doesn't support this, it can be set to null.
152     const char *AscizDirective;           // Defaults to "\t.asciz\t"
153
154     /// DataDirectives - These directives are used to output some unit of
155     /// integer data to the current section.  If a data directive is set to
156     /// null, smaller data directives will be used to emit the large sizes.
157     const char *Data8bitsDirective;       // Defaults to "\t.byte\t"
158     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
159     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
160     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
161
162     /// getDataASDirective - Return the directive that should be used to emit
163     /// data of the specified size to the specified numeric address space.
164     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
165       assert(AS != 0 && "Don't know the directives for default addr space");
166       return NULL;
167     }
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;
185
186     //===--- Section Switching Directives ---------------------------------===//
187     
188     /// SwitchToSectionDirective - This is the directive used when we want to
189     /// emit a global to an arbitrary section.  The section name is emited after
190     /// this.
191     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
192     
193     /// TextSectionStartSuffix - This is printed after each start of section
194     /// directive for text sections.
195     const char *TextSectionStartSuffix;   // Defaults to "".
196
197     /// DataSectionStartSuffix - This is printed after each start of section
198     /// directive for data sections.
199     const char *DataSectionStartSuffix;   // Defaults to "".
200     
201     /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
202     /// section with the section name and this suffix printed.
203     const char *SectionEndDirectiveSuffix;// Defaults to null.
204     
205     /// JumpTableDirective - if non-null, the directive to emit before a jump
206     /// table.
207     const char *JumpTableDirective;
208
209     //===--- Global Variable Emission Directives --------------------------===//
210     
211     /// GlobalDirective - This is the directive used to declare a global entity.
212     ///
213     const char *GlobalDirective;          // Defaults to NULL.
214
215     /// ExternDirective - This is the directive used to declare external 
216     /// globals.
217     ///
218     const char *ExternDirective;          // Defaults to NULL.
219     
220     /// SetDirective - This is the name of a directive that can be used to tell
221     /// the assembler to set the value of a variable to some expression.
222     const char *SetDirective;             // Defaults to null.
223     
224     /// LCOMMDirective - This is the name of a directive (if supported) that can
225     /// be used to efficiently declare a local (internal) block of zero
226     /// initialized data in the .bss/.data section.  The syntax expected is:
227     /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
228     /// @endverbatim
229     const char *LCOMMDirective;           // Defaults to null.
230     
231     const char *COMMDirective;            // Defaults to "\t.comm\t".
232
233     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
234     /// argument that specifies the alignment of the declaration.
235     bool COMMDirectiveTakesAlignment;     // Defaults to true.
236     
237     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
238     /// directives, this is true for most ELF targets.
239     bool HasDotTypeDotSizeDirective;      // Defaults to true.
240
241     /// HasSingleParameterDotFile - True if the target has a single parameter
242     /// .file directive, this is true for ELF targets.
243     bool HasSingleParameterDotFile;      // Defaults to true.
244
245     /// UsedDirective - This directive, if non-null, is used to declare a global
246     /// as being used somehow that the assembler can't see.  This prevents dead
247     /// code elimination on some targets.
248     const char *UsedDirective;            // Defaults to null.
249
250     /// WeakRefDirective - This directive, if non-null, is used to declare a
251     /// global as being a weak undefined symbol.
252     const char *WeakRefDirective;         // Defaults to null.
253     
254     /// WeakDefDirective - This directive, if non-null, is used to declare a
255     /// global as being a weak defined symbol.
256     const char *WeakDefDirective;         // Defaults to null.
257     
258     /// HiddenDirective - This directive, if non-null, is used to declare a
259     /// global or function as having hidden visibility.
260     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
261
262     /// ProtectedDirective - This directive, if non-null, is used to declare a
263     /// global or function as having protected visibility.
264     const char *ProtectedDirective;       // Defaults to "\t.protected\t".
265
266     //===--- Dwarf Emission Directives -----------------------------------===//
267
268     /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
269     /// offsets for debug information. Defaults to false.
270     bool AbsoluteDebugSectionOffsets;
271
272     /// AbsoluteEHSectionOffsets - True if we should emit abolute section
273     /// offsets for EH information. Defaults to false.
274     bool AbsoluteEHSectionOffsets;
275
276     /// HasLEB128 - True if target asm supports leb128 directives.
277     ///
278     bool HasLEB128; // Defaults to false.
279
280     /// hasDotLocAndDotFile - True if target asm supports .loc and .file
281     /// directives for emitting debugging information.
282     ///
283     bool HasDotLocAndDotFile; // Defaults to false.
284
285     /// SupportsDebugInformation - True if target supports emission of debugging
286     /// information.
287     bool SupportsDebugInformation;
288
289     /// SupportsExceptionHandling - True if target supports
290     /// exception handling.
291     ///
292     bool SupportsExceptionHandling; // Defaults to false.
293
294     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
295     ///
296     bool DwarfRequiresFrameSection; // Defaults to true.
297
298     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
299     /// encode inline subroutine information.
300     bool DwarfUsesInlineInfoSection; // Defaults to false.
301
302     /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
303     /// doesn't show up in the symbol table of the object file.
304     bool Is_EHSymbolPrivate;                // Defaults to true.
305
306     /// GlobalEHDirective - This is the directive used to make exception frame
307     /// tables globally visible.
308     ///
309     const char *GlobalEHDirective;          // Defaults to NULL.
310
311     /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
312     /// handle a weak_definition of constant 0 for an omitted EH frame.
313     bool SupportsWeakOmittedEHFrame;  // Defaults to true.
314
315     /// DwarfSectionOffsetDirective - Special section offset directive.
316     const char* DwarfSectionOffsetDirective; // Defaults to NULL
317     
318     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
319     ///
320     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
321
322     /// DwarfInfoSection - Section directive for Dwarf info.
323     ///
324     const char *DwarfInfoSection; // Defaults to ".debug_info".
325
326     /// DwarfLineSection - Section directive for Dwarf info.
327     ///
328     const char *DwarfLineSection; // Defaults to ".debug_line".
329     
330     /// DwarfFrameSection - Section directive for Dwarf info.
331     ///
332     const char *DwarfFrameSection; // Defaults to ".debug_frame".
333     
334     /// DwarfPubNamesSection - Section directive for Dwarf info.
335     ///
336     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
337     
338     /// DwarfPubTypesSection - Section directive for Dwarf info.
339     ///
340     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
341
342     /// DwarfDebugInlineSection - Section directive for inline info.
343     ///
344     const char *DwarfDebugInlineSection; // Defaults to ".debug_inlined"
345
346     /// DwarfStrSection - Section directive for Dwarf info.
347     ///
348     const char *DwarfStrSection; // Defaults to ".debug_str".
349
350     /// DwarfLocSection - Section directive for Dwarf info.
351     ///
352     const char *DwarfLocSection; // Defaults to ".debug_loc".
353
354     /// DwarfARangesSection - Section directive for Dwarf info.
355     ///
356     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
357
358     /// DwarfRangesSection - Section directive for Dwarf info.
359     ///
360     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
361
362     /// DwarfMacroInfoSection - Section directive for DWARF macro info.
363     ///
364     const char *DwarfMacroInfoSection; // Defaults to ".debug_macinfo".
365     
366     /// DwarfEHFrameSection - Section directive for Exception frames.
367     ///
368     const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
369     
370     //===--- CBE Asm Translation Table -----------------------------------===//
371
372     const char *const *AsmTransCBE; // Defaults to empty
373
374   public:
375     explicit TargetAsmInfo();
376     virtual ~TargetAsmInfo();
377
378     /// Measure the specified inline asm to determine an approximation of its
379     /// length.
380     virtual unsigned getInlineAsmLength(const char *Str) const;
381
382     /// getSLEB128Size - Compute the number of bytes required for a signed
383     /// leb128 value.
384     static unsigned getSLEB128Size(int Value);
385
386     /// getULEB128Size - Compute the number of bytes required for an unsigned
387     /// leb128 value.
388     static unsigned getULEB128Size(unsigned Value);
389
390     // Data directive accessors.
391     //
392     const char *getData8bitsDirective(unsigned AS = 0) const {
393       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
394     }
395     const char *getData16bitsDirective(unsigned AS = 0) const {
396       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
397     }
398     const char *getData32bitsDirective(unsigned AS = 0) const {
399       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
400     }
401     const char *getData64bitsDirective(unsigned AS = 0) const {
402       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
403     }
404
405
406     // Accessors.
407     //
408     const char *getZeroFillDirective() const {
409       return ZeroFillDirective;
410     }
411     const char *getNonexecutableStackDirective() const {
412       return NonexecutableStackDirective;
413     }
414     bool needsSet() const {
415       return NeedsSet;
416     }
417     const char *getPCSymbol() const {
418       return PCSymbol;
419     }
420     char getSeparatorChar() const {
421       return SeparatorChar;
422     }
423     unsigned getCommentColumn() const {
424       return CommentColumn;
425     }
426     const char *getCommentString() const {
427       return CommentString;
428     }
429     unsigned getOperandColumn(int operand) const {
430       return FirstOperandColumn + (MaxOperandLength+1)*(operand-1);
431     }
432     const char *getGlobalPrefix() const {
433       return GlobalPrefix;
434     }
435     const char *getPrivateGlobalPrefix() const {
436       return PrivateGlobalPrefix;
437     }
438     const char *getLinkerPrivateGlobalPrefix() const {
439       return LinkerPrivateGlobalPrefix;
440     }
441     const char *getJumpTableSpecialLabelPrefix() const {
442       return JumpTableSpecialLabelPrefix;
443     }
444     const char *getGlobalVarAddrPrefix() const {
445       return GlobalVarAddrPrefix;
446     }
447     const char *getGlobalVarAddrSuffix() const {
448       return GlobalVarAddrSuffix;
449     }
450     const char *getFunctionAddrPrefix() const {
451       return FunctionAddrPrefix;
452     }
453     const char *getFunctionAddrSuffix() const {
454       return FunctionAddrSuffix;
455     }
456     const char *getPersonalityPrefix() const {
457       return PersonalityPrefix;
458     }
459     const char *getPersonalitySuffix() const {
460       return PersonalitySuffix;
461     }
462     bool getNeedsIndirectEncoding() const {
463       return NeedsIndirectEncoding;
464     }
465     const char *getInlineAsmStart() const {
466       return InlineAsmStart;
467     }
468     const char *getInlineAsmEnd() const {
469       return InlineAsmEnd;
470     }
471     unsigned getAssemblerDialect() const {
472       return AssemblerDialect;
473     }
474     bool doesAllowQuotesInName() const {
475       return AllowQuotesInName;
476     }
477     const char *getZeroDirective() const {
478       return ZeroDirective;
479     }
480     const char *getZeroDirectiveSuffix() const {
481       return ZeroDirectiveSuffix;
482     }
483     const char *getAsciiDirective() const {
484       return AsciiDirective;
485     }
486     const char *getAscizDirective() const {
487       return AscizDirective;
488     }
489     const char *getJumpTableDirective() const {
490       return JumpTableDirective;
491     }
492     const char *getAlignDirective() const {
493       return AlignDirective;
494     }
495     bool getAlignmentIsInBytes() const {
496       return AlignmentIsInBytes;
497     }
498     unsigned getTextAlignFillValue() const {
499       return TextAlignFillValue;
500     }
501     const char *getSwitchToSectionDirective() const {
502       return SwitchToSectionDirective;
503     }
504     const char *getTextSectionStartSuffix() const {
505       return TextSectionStartSuffix;
506     }
507     const char *getDataSectionStartSuffix() const {
508       return DataSectionStartSuffix;
509     }
510     const char *getSectionEndDirectiveSuffix() const {
511       return SectionEndDirectiveSuffix;
512     }
513     const char *getGlobalDirective() const {
514       return GlobalDirective;
515     }
516     const char *getExternDirective() const {
517       return ExternDirective;
518     }
519     const char *getSetDirective() const {
520       return SetDirective;
521     }
522     const char *getLCOMMDirective() const {
523       return LCOMMDirective;
524     }
525     const char *getCOMMDirective() const {
526       return COMMDirective;
527     }
528     bool getCOMMDirectiveTakesAlignment() const {
529       return COMMDirectiveTakesAlignment;
530     }
531     bool hasDotTypeDotSizeDirective() const {
532       return HasDotTypeDotSizeDirective;
533     }
534     bool hasSingleParameterDotFile() const {
535       return HasSingleParameterDotFile;
536     }
537     const char *getUsedDirective() const {
538       return UsedDirective;
539     }
540     const char *getWeakRefDirective() const {
541       return WeakRefDirective;
542     }
543     const char *getWeakDefDirective() const {
544       return WeakDefDirective;
545     }
546     const char *getHiddenDirective() const {
547       return HiddenDirective;
548     }
549     const char *getProtectedDirective() const {
550       return ProtectedDirective;
551     }
552     bool isAbsoluteDebugSectionOffsets() const {
553       return AbsoluteDebugSectionOffsets;
554     }
555     bool isAbsoluteEHSectionOffsets() const {
556       return AbsoluteEHSectionOffsets;
557     }
558     bool hasLEB128() const {
559       return HasLEB128;
560     }
561     bool hasDotLocAndDotFile() const {
562       return HasDotLocAndDotFile;
563     }
564     bool doesSupportDebugInformation() const {
565       return SupportsDebugInformation;
566     }
567     bool doesSupportExceptionHandling() const {
568       return SupportsExceptionHandling;
569     }
570     bool doesDwarfRequireFrameSection() const {
571       return DwarfRequiresFrameSection;
572     }
573     bool doesDwarfUsesInlineInfoSection() const {
574       return DwarfUsesInlineInfoSection;
575     }
576     bool is_EHSymbolPrivate() const {
577       return Is_EHSymbolPrivate;
578     }
579     const char *getGlobalEHDirective() const {
580       return GlobalEHDirective;
581     }
582     bool getSupportsWeakOmittedEHFrame() const {
583       return SupportsWeakOmittedEHFrame;
584     }
585     const char *getDwarfSectionOffsetDirective() const {
586       return DwarfSectionOffsetDirective;
587     }
588     const char *getDwarfAbbrevSection() const {
589       return DwarfAbbrevSection;
590     }
591     const char *getDwarfInfoSection() const {
592       return DwarfInfoSection;
593     }
594     const char *getDwarfLineSection() const {
595       return DwarfLineSection;
596     }
597     const char *getDwarfFrameSection() const {
598       return DwarfFrameSection;
599     }
600     const char *getDwarfPubNamesSection() const {
601       return DwarfPubNamesSection;
602     }
603     const char *getDwarfPubTypesSection() const {
604       return DwarfPubTypesSection;
605     }
606     const char *getDwarfDebugInlineSection() const {
607       return DwarfDebugInlineSection;
608     }
609     const char *getDwarfStrSection() const {
610       return DwarfStrSection;
611     }
612     const char *getDwarfLocSection() const {
613       return DwarfLocSection;
614     }
615     const char *getDwarfARangesSection() const {
616       return DwarfARangesSection;
617     }
618     const char *getDwarfRangesSection() const {
619       return DwarfRangesSection;
620     }
621     const char *getDwarfMacroInfoSection() const {
622       return DwarfMacroInfoSection;
623     }
624     const char *getDwarfEHFrameSection() const {
625       return DwarfEHFrameSection;
626     }
627     const char *const *getAsmCBE() const {
628       return AsmTransCBE;
629     }
630   };
631 }
632
633 #endif