make SectionKind be a first-class pod struct instead of just
[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/ADT/DenseMap.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/Support/DataTypes.h"
22 #include <string>
23
24 namespace llvm {
25   // DWARF encoding query type
26   namespace DwarfEncoding {
27     enum Target {
28       Data       = 0,
29       CodeLabels = 1,
30       Functions  = 2
31     };
32   }
33
34   /// SectionKind - This is a simple POD value that classifies the properties of
35   /// a section.
36   struct SectionKind {
37     enum Kind {
38       Unknown = 0,      ///< Custom section.
39       Text,             ///< Text section.
40       BSS,              ///< BSS section.
41
42       Data,             ///< Data section.
43       DataRel,          ///< Data that has relocations.
44       DataRelLocal,     ///< Data that only has local relocations.
45
46       // Readonly data.
47       ROData,           ///< Readonly data section.
48       DataRelRO,        ///< Readonly data with non-local relocations.
49       DataRelROLocal,   ///< Readonly data with local relocations only.
50       
51       /// Mergable sections.
52       RODataMergeStr,   ///< Readonly data section: nul-terminated strings.
53       RODataMergeConst, ///< Readonly data section: fixed-length constants.
54       
55       /// Thread local data.
56       ThreadData,       ///< Initialized TLS data objects
57       ThreadBSS         ///< Uninitialized TLS data objects
58     } K; // This is private.
59     
60     // FIXME: Eliminate.
61     Kind getKind() const { return K; }
62
63     bool isReadOnly() const {
64       return (K == SectionKind::ROData ||
65               K == SectionKind::DataRelRO ||
66               K == SectionKind::DataRelROLocal ||
67               K == SectionKind::RODataMergeConst ||
68               K == SectionKind::RODataMergeStr);
69     }
70
71     bool isBSS() const {
72       return K == BSS || K == ThreadBSS;
73     }
74     
75     bool isTLS() const {
76       return K == ThreadData || K == ThreadBSS;
77     }
78     
79     bool isCode() const {
80       return K == Text;
81     }
82     
83     bool isWritable() const {
84       return isTLS() ||
85              K == SectionKind::Data ||
86              K == SectionKind::DataRel ||
87              K == SectionKind::DataRelLocal ||
88              K == SectionKind::DataRelRO ||
89              K == SectionKind::DataRelROLocal ||
90              K == SectionKind::BSS;
91     }
92     
93     static SectionKind get(Kind K) {
94       SectionKind Res = { K };
95       return Res;
96     }
97     static SectionKind getText()             { return get(Text); }
98     static SectionKind getBSS()              { return get(BSS); }
99     static SectionKind getData()             { return get(Data); }
100     static SectionKind getDataRel()          { return get(DataRel); }
101     static SectionKind getDataRelLocal()     { return get(DataRelLocal); }
102     static SectionKind getROData()           { return get(ROData); }
103     static SectionKind getDataRelRO()        { return get(DataRelRO); }
104     static SectionKind getDataRelROLocal()   { return get(DataRelROLocal); }
105     static SectionKind getRODataMergeStr()   { return get(RODataMergeStr); }
106     static SectionKind getRODataMergeConst() { return get(RODataMergeConst); }
107     static SectionKind getThreadData()       { return get(ThreadData); }
108     static SectionKind getThreadBSS()        { return get(ThreadBSS); }
109 };
110
111   namespace SectionFlags {
112     const unsigned Invalid    = -1U;
113     const unsigned None       = 0;
114     const unsigned Code       = 1 << 0;  ///< Section contains code
115     const unsigned Writable   = 1 << 1;  ///< Section is writable
116     const unsigned BSS        = 1 << 2;  ///< Section contains only zeroes
117     const unsigned Mergeable  = 1 << 3;  ///< Section contains mergeable data
118     const unsigned Strings    = 1 << 4;  ///< Section contains C-type strings
119     const unsigned TLS        = 1 << 5;  ///< Section contains thread-local data
120     const unsigned Debug      = 1 << 6;  ///< Section contains debug data
121     const unsigned Linkonce   = 1 << 7;  ///< Section is linkonce
122     const unsigned TypeFlags  = 0xFF;
123     // Some gap for future flags
124     
125     /// Named - True if this section should be printed with ".section <name>",
126     /// false if the section name is something like ".const".
127     const unsigned Named      = 1 << 23; ///< Section is named
128     const unsigned EntitySize = 0xFF << 24; ///< Entity size for mergeable stuff
129
130     static inline unsigned getEntitySize(unsigned Flags) {
131       return (Flags >> 24) & 0xFF;
132     }
133
134     // FIXME: Why does this return a value?
135     static inline unsigned setEntitySize(unsigned Flags, unsigned Size) {
136       return (Flags & ~EntitySize) | ((Size & 0xFF) << 24);
137     }
138
139     struct KeyInfo {
140       static inline unsigned getEmptyKey() { return Invalid; }
141       static inline unsigned getTombstoneKey() { return Invalid - 1; }
142       static unsigned getHashValue(const unsigned &Key) { return Key; }
143       static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
144       static bool isPod() { return true; }
145     };
146
147     typedef DenseMap<unsigned, std::string, KeyInfo> FlagsStringsMapType;
148   }
149
150   class TargetMachine;
151   class CallInst;
152   class GlobalValue;
153   class Type;
154   class Mangler;
155
156   class Section {
157     friend class TargetAsmInfo;
158     friend class StringMapEntry<Section>;
159     friend class StringMap<Section>;
160
161     std::string Name;
162     unsigned Flags;
163     explicit Section(unsigned F = SectionFlags::Invalid) : Flags(F) { }
164
165   public:
166     
167     unsigned getEntitySize() const { return (Flags >> 24) & 0xFF; }
168
169     const std::string &getName() const { return Name; }
170     unsigned getFlags() const { return Flags; }
171     
172     bool hasFlag(unsigned F) const { return (Flags & F) != 0; }
173   };
174
175   /// TargetAsmInfo - This class is intended to be used as a base class for asm
176   /// properties and features specific to the target.
177   class TargetAsmInfo {
178   private:
179     mutable StringMap<Section> Sections;
180     mutable SectionFlags::FlagsStringsMapType FlagsStrings;
181   protected:
182     /// TM - The current TargetMachine.
183     const TargetMachine &TM;
184
185     //===------------------------------------------------------------------===//
186     // Properties to be set by the target writer, used to configure asm printer.
187     //
188
189     /// TextSection - Section directive for standard text.
190     ///
191     const Section *TextSection;           // Defaults to ".text".
192
193     /// DataSection - Section directive for standard data.
194     ///
195     const Section *DataSection;           // Defaults to ".data".
196
197     /// BSSSection - Section directive for uninitialized data.  Null if this
198     /// target doesn't support a BSS section.
199     ///
200     const char *BSSSection;               // Default to ".bss".
201     const Section *BSSSection_;
202
203     /// ReadOnlySection - This is the directive that is emitted to switch to a
204     /// read-only section for constant data (e.g. data declared const,
205     /// jump tables).
206     const Section *ReadOnlySection;       // Defaults to NULL
207
208     /// TLSDataSection - Section directive for Thread Local data.
209     ///
210     const Section *TLSDataSection;        // Defaults to ".tdata".
211
212     /// TLSBSSSection - Section directive for Thread Local uninitialized data.
213     /// Null if this target doesn't support a BSS section.
214     ///
215     const Section *TLSBSSSection;         // Defaults to ".tbss".
216
217     /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
218     /// section on this target.  Null if this target doesn't support zerofill.
219     const char *ZeroFillDirective;        // Default is null.
220
221     /// NonexecutableStackDirective - Directive for declaring to the
222     /// linker and beyond that the emitted code does not require stack
223     /// memory to be executable.
224     const char *NonexecutableStackDirective; // Default is null.
225
226     /// NeedsSet - True if target asm treats expressions in data directives
227     /// as linktime-relocatable.  For assembly-time computation, we need to
228     /// use a .set.  Thus:
229     /// .set w, x-y
230     /// .long w
231     /// is computed at assembly time, while
232     /// .long x-y
233     /// is relocated if the relative locations of x and y change at linktime.
234     /// We want both these things in different places.
235     bool NeedsSet;                        // Defaults to false.
236     
237     /// MaxInstLength - This is the maximum possible length of an instruction,
238     /// which is needed to compute the size of an inline asm.
239     unsigned MaxInstLength;               // Defaults to 4.
240     
241     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
242     /// relative expressions.
243     const char *PCSymbol;                 // Defaults to "$".
244
245     /// SeparatorChar - This character, if specified, is used to separate
246     /// instructions from each other when on the same line.  This is used to
247     /// measure inline asm instructions.
248     char SeparatorChar;                   // Defaults to ';'
249
250     /// CommentColumn - This indicates the comment num (zero-based) at
251     /// which asm comments should be printed.
252     unsigned CommentColumn;               // Defaults to 60
253
254     /// CommentString - This indicates the comment character used by the
255     /// assembler.
256     const char *CommentString;            // Defaults to "#"
257
258     /// FirstOperandColumn - The output column where the first operand
259     /// should be printed
260     unsigned FirstOperandColumn;          // Defaults to 0 (ignored)
261
262     /// MaxOperandLength - The maximum length of any printed asm
263     /// operand
264     unsigned MaxOperandLength;            // Defaults to 0 (ignored)
265
266     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
267     /// onto all global symbols.  This is often used for "_" or ".".
268     const char *GlobalPrefix;             // Defaults to ""
269
270     /// PrivateGlobalPrefix - This prefix is used for globals like constant
271     /// pool entries that are completely private to the .s file and should not
272     /// have names in the .o file.  This is often "." or "L".
273     const char *PrivateGlobalPrefix;      // Defaults to "."
274     
275     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
276     /// be passed through the assembler but be removed by the linker.  This
277     /// is "l" on Darwin, currently used for some ObjC metadata.
278     const char *LinkerPrivateGlobalPrefix;      // Defaults to ""
279     
280     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
281     /// emitted before jump tables with the specified prefix.
282     const char *JumpTableSpecialLabelPrefix;  // Default to null.
283     
284     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
285     /// will enclose any GlobalVariable (that isn't a function)
286     ///
287     const char *GlobalVarAddrPrefix;      // Defaults to ""
288     const char *GlobalVarAddrSuffix;      // Defaults to ""
289
290     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
291     /// will enclose any GlobalVariable that points to a function.
292     ///
293     const char *FunctionAddrPrefix;       // Defaults to ""
294     const char *FunctionAddrSuffix;       // Defaults to ""
295
296     /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
297     /// enclose any personality function in the common frame section.
298     /// 
299     const char *PersonalityPrefix;        // Defaults to ""
300     const char *PersonalitySuffix;        // Defaults to ""
301
302     /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
303     /// for EH in Dwarf.
304     /// 
305     bool NeedsIndirectEncoding;           // Defaults to false
306
307     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
308     /// emit before and after an inline assembly statement.
309     const char *InlineAsmStart;           // Defaults to "#APP\n"
310     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
311
312     /// AssemblerDialect - Which dialect of an assembler variant to use.
313     unsigned AssemblerDialect;            // Defaults to 0
314
315     /// AllowQuotesInName - This is true if the assembler allows for complex
316     /// symbol names to be surrounded in quotes.  This defaults to false.
317     bool AllowQuotesInName;
318     
319     //===--- Data Emission Directives -------------------------------------===//
320
321     /// ZeroDirective - this should be set to the directive used to get some
322     /// number of zero bytes emitted to the current section.  Common cases are
323     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
324     /// Data*bitsDirective's will be used to emit zero bytes.
325     const char *ZeroDirective;            // Defaults to "\t.zero\t"
326     const char *ZeroDirectiveSuffix;      // Defaults to ""
327
328     /// AsciiDirective - This directive allows emission of an ascii string with
329     /// the standard C escape characters embedded into it.
330     const char *AsciiDirective;           // Defaults to "\t.ascii\t"
331     
332     /// AscizDirective - If not null, this allows for special handling of
333     /// zero terminated strings on this target.  This is commonly supported as
334     /// ".asciz".  If a target doesn't support this, it can be set to null.
335     const char *AscizDirective;           // Defaults to "\t.asciz\t"
336
337     /// DataDirectives - These directives are used to output some unit of
338     /// integer data to the current section.  If a data directive is set to
339     /// null, smaller data directives will be used to emit the large sizes.
340     const char *Data8bitsDirective;       // Defaults to "\t.byte\t"
341     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
342     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
343     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
344
345     /// getDataASDirective - Return the directive that should be used to emit
346     /// data of the specified size to the specified numeric address space.
347     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
348       assert(AS != 0 && "Don't know the directives for default addr space");
349       return NULL;
350     }
351
352     //===--- Alignment Information ----------------------------------------===//
353
354     /// AlignDirective - The directive used to emit round up to an alignment
355     /// boundary.
356     ///
357     const char *AlignDirective;           // Defaults to "\t.align\t"
358
359     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
360     /// emits ".align N" directives, where N is the number of bytes to align to.
361     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
362     /// boundary.
363     bool AlignmentIsInBytes;              // Defaults to true
364
365     /// TextAlignFillValue - If non-zero, this is used to fill the executable
366     /// space created as the result of a alignment directive.
367     unsigned TextAlignFillValue;
368
369     //===--- Section Switching Directives ---------------------------------===//
370     
371     /// SwitchToSectionDirective - This is the directive used when we want to
372     /// emit a global to an arbitrary section.  The section name is emited after
373     /// this.
374     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
375     
376     /// TextSectionStartSuffix - This is printed after each start of section
377     /// directive for text sections.
378     const char *TextSectionStartSuffix;   // Defaults to "".
379
380     /// DataSectionStartSuffix - This is printed after each start of section
381     /// directive for data sections.
382     const char *DataSectionStartSuffix;   // Defaults to "".
383     
384     /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
385     /// section with the section name and this suffix printed.
386     const char *SectionEndDirectiveSuffix;// Defaults to null.
387     
388     /// ConstantPoolSection - This is the section that we SwitchToSection right
389     /// before emitting the constant pool for a function.
390     const char *ConstantPoolSection;      // Defaults to "\t.section .rodata"
391
392     /// JumpTableDataSection - This is the section that we SwitchToSection right
393     /// before emitting the jump tables for a function when the relocation model
394     /// is not PIC.
395     const char *JumpTableDataSection;     // Defaults to "\t.section .rodata"
396     
397     /// JumpTableDirective - if non-null, the directive to emit before a jump
398     /// table.
399     const char *JumpTableDirective;
400
401     /// CStringSection - If not null, this allows for special handling of
402     /// cstring constants (null terminated string that does not contain any
403     /// other null bytes) on this target. This is commonly supported as
404     /// ".cstring".
405     const char *CStringSection;           // Defaults to NULL
406     const Section *CStringSection_;
407
408     /// StaticCtorsSection - This is the directive that is emitted to switch to
409     /// a section to emit the static constructor list.
410     /// Defaults to "\t.section .ctors,\"aw\",@progbits".
411     const char *StaticCtorsSection;
412
413     /// StaticDtorsSection - This is the directive that is emitted to switch to
414     /// a section to emit the static destructor list.
415     /// Defaults to "\t.section .dtors,\"aw\",@progbits".
416     const char *StaticDtorsSection;
417
418     //===--- Global Variable Emission Directives --------------------------===//
419     
420     /// GlobalDirective - This is the directive used to declare a global entity.
421     ///
422     const char *GlobalDirective;          // Defaults to NULL.
423
424     /// ExternDirective - This is the directive used to declare external 
425     /// globals.
426     ///
427     const char *ExternDirective;          // Defaults to NULL.
428     
429     /// SetDirective - This is the name of a directive that can be used to tell
430     /// the assembler to set the value of a variable to some expression.
431     const char *SetDirective;             // Defaults to null.
432     
433     /// LCOMMDirective - This is the name of a directive (if supported) that can
434     /// be used to efficiently declare a local (internal) block of zero
435     /// initialized data in the .bss/.data section.  The syntax expected is:
436     /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
437     /// @endverbatim
438     const char *LCOMMDirective;           // Defaults to null.
439     
440     const char *COMMDirective;            // Defaults to "\t.comm\t".
441
442     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
443     /// argument that specifies the alignment of the declaration.
444     bool COMMDirectiveTakesAlignment;     // Defaults to true.
445     
446     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
447     /// directives, this is true for most ELF targets.
448     bool HasDotTypeDotSizeDirective;      // Defaults to true.
449
450     /// HasSingleParameterDotFile - True if the target has a single parameter
451     /// .file directive, this is true for ELF targets.
452     bool HasSingleParameterDotFile;      // Defaults to true.
453
454     /// UsedDirective - This directive, if non-null, is used to declare a global
455     /// as being used somehow that the assembler can't see.  This prevents dead
456     /// code elimination on some targets.
457     const char *UsedDirective;            // Defaults to null.
458
459     /// WeakRefDirective - This directive, if non-null, is used to declare a
460     /// global as being a weak undefined symbol.
461     const char *WeakRefDirective;         // Defaults to null.
462     
463     /// WeakDefDirective - This directive, if non-null, is used to declare a
464     /// global as being a weak defined symbol.
465     const char *WeakDefDirective;         // Defaults to null.
466     
467     /// HiddenDirective - This directive, if non-null, is used to declare a
468     /// global or function as having hidden visibility.
469     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
470
471     /// ProtectedDirective - This directive, if non-null, is used to declare a
472     /// global or function as having protected visibility.
473     const char *ProtectedDirective;       // Defaults to "\t.protected\t".
474
475     //===--- Dwarf Emission Directives -----------------------------------===//
476
477     /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
478     /// offsets for debug information. Defaults to false.
479     bool AbsoluteDebugSectionOffsets;
480
481     /// AbsoluteEHSectionOffsets - True if we should emit abolute section
482     /// offsets for EH information. Defaults to false.
483     bool AbsoluteEHSectionOffsets;
484
485     /// HasLEB128 - True if target asm supports leb128 directives.
486     ///
487     bool HasLEB128; // Defaults to false.
488
489     /// hasDotLocAndDotFile - True if target asm supports .loc and .file
490     /// directives for emitting debugging information.
491     ///
492     bool HasDotLocAndDotFile; // Defaults to false.
493
494     /// SupportsDebugInformation - True if target supports emission of debugging
495     /// information.
496     bool SupportsDebugInformation;
497
498     /// SupportsExceptionHandling - True if target supports
499     /// exception handling.
500     ///
501     bool SupportsExceptionHandling; // Defaults to false.
502
503     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
504     ///
505     bool DwarfRequiresFrameSection; // Defaults to true.
506
507     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
508     /// encode inline subroutine information.
509     bool DwarfUsesInlineInfoSection; // Defaults to false.
510
511     /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
512     /// doesn't show up in the symbol table of the object file.
513     bool Is_EHSymbolPrivate;                // Defaults to true.
514
515     /// GlobalEHDirective - This is the directive used to make exception frame
516     /// tables globally visible.
517     ///
518     const char *GlobalEHDirective;          // Defaults to NULL.
519
520     /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
521     /// handle a weak_definition of constant 0 for an omitted EH frame.
522     bool SupportsWeakOmittedEHFrame;  // Defaults to true.
523
524     /// DwarfSectionOffsetDirective - Special section offset directive.
525     const char* DwarfSectionOffsetDirective; // Defaults to NULL
526     
527     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
528     ///
529     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
530
531     /// DwarfInfoSection - Section directive for Dwarf info.
532     ///
533     const char *DwarfInfoSection; // Defaults to ".debug_info".
534
535     /// DwarfLineSection - Section directive for Dwarf info.
536     ///
537     const char *DwarfLineSection; // Defaults to ".debug_line".
538     
539     /// DwarfFrameSection - Section directive for Dwarf info.
540     ///
541     const char *DwarfFrameSection; // Defaults to ".debug_frame".
542     
543     /// DwarfPubNamesSection - Section directive for Dwarf info.
544     ///
545     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
546     
547     /// DwarfPubTypesSection - Section directive for Dwarf info.
548     ///
549     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
550
551     /// DwarfDebugInlineSection - Section directive for inline info.
552     ///
553     const char *DwarfDebugInlineSection; // Defaults to ".debug_inlined"
554
555     /// DwarfStrSection - Section directive for Dwarf info.
556     ///
557     const char *DwarfStrSection; // Defaults to ".debug_str".
558
559     /// DwarfLocSection - Section directive for Dwarf info.
560     ///
561     const char *DwarfLocSection; // Defaults to ".debug_loc".
562
563     /// DwarfARangesSection - Section directive for Dwarf info.
564     ///
565     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
566
567     /// DwarfRangesSection - Section directive for Dwarf info.
568     ///
569     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
570
571     /// DwarfMacroInfoSection - Section directive for DWARF macro info.
572     ///
573     const char *DwarfMacroInfoSection; // Defaults to ".debug_macinfo".
574     
575     /// DwarfEHFrameSection - Section directive for Exception frames.
576     ///
577     const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
578     
579     /// DwarfExceptionSection - Section directive for Exception table.
580     ///
581     const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
582
583     //===--- CBE Asm Translation Table -----------------------------------===//
584
585     const char *const *AsmTransCBE; // Defaults to empty
586
587   public:
588     explicit TargetAsmInfo(const TargetMachine &TM);
589     virtual ~TargetAsmInfo();
590
591     const Section* getNamedSection(const char *Name,
592                                    unsigned Flags = SectionFlags::None,
593                                    bool Override = false) const;
594     const Section* getUnnamedSection(const char *Directive,
595                                      unsigned Flags = SectionFlags::None,
596                                      bool Override = false) const;
597
598     /// Measure the specified inline asm to determine an approximation of its
599     /// length.
600     virtual unsigned getInlineAsmLength(const char *Str) const;
601
602     /// emitUsedDirectiveFor - This hook allows targets to selectively decide
603     /// not to emit the UsedDirective for some symbols in llvm.used.
604 // FIXME: REMOVE this (rdar://7071300)
605     virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
606                                       Mangler *Mang) const {
607       return (GV!=0);
608     }
609
610     /// PreferredEHDataFormat - This hook allows the target to select data
611     /// format used for encoding pointers in exception handling data. Reason is
612     /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
613     /// if the symbol can be relocated.
614     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
615                                            bool Global) const;
616
617     
618     /// getSectionForMergableConstant - Given a mergable constant with the
619     /// specified size and relocation information, return a section that it
620     /// should be placed in.
621     virtual const Section *
622     getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
623
624     
625     /// getSectionPrefixForUniqueGlobal - Return a string that we should prepend
626     /// onto a global's name in order to get the unique section name for the
627     /// global.  This is important for globals that need to be merged across
628     /// translation units.
629     virtual const char *
630     getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
631       return 0;
632     }
633     
634     /// getFlagsForNamedSection - If this target wants to be able to infer
635     /// section flags based on the name of the section specified for a global
636     /// variable, it can implement this.  This is used on ELF systems so that
637     /// ".tbss" gets the TLS bit set etc.
638     virtual unsigned getFlagsForNamedSection(const char *Section) const {
639       return 0;
640     }
641     
642     /// SectionForGlobal - This method computes the appropriate section to emit
643     /// the specified global variable or function definition.  This should not
644     /// be passed external (or available externally) globals.
645     // FIXME: MOVE TO ASMPRINTER.
646     const Section* SectionForGlobal(const GlobalValue *GV) const;
647     
648     /// getSpecialCasedSectionGlobals - Allow the target to completely override
649     /// section assignment of a global.
650     /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
651     /// getFlagsForNamedSection.
652     virtual const Section *
653     getSpecialCasedSectionGlobals(const GlobalValue *GV,
654                                   SectionKind Kind) const {
655       return 0;
656     }
657     
658     const std::string &getSectionFlags(unsigned Flags) const;
659     virtual std::string printSectionFlags(unsigned flags) const { return ""; }
660
661 // FIXME: Eliminate this.
662     virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
663                                                   SectionKind Kind) const;
664
665     /// getSLEB128Size - Compute the number of bytes required for a signed
666     /// leb128 value.
667     static unsigned getSLEB128Size(int Value);
668
669     /// getULEB128Size - Compute the number of bytes required for an unsigned
670     /// leb128 value.
671     static unsigned getULEB128Size(unsigned Value);
672
673     // Data directive accessors.
674     //
675     const char *getData8bitsDirective(unsigned AS = 0) const {
676       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
677     }
678     const char *getData16bitsDirective(unsigned AS = 0) const {
679       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
680     }
681     const char *getData32bitsDirective(unsigned AS = 0) const {
682       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
683     }
684     const char *getData64bitsDirective(unsigned AS = 0) const {
685       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
686     }
687
688
689     // Accessors.
690     //
691     const Section *getTextSection() const {
692       return TextSection;
693     }
694     const Section *getDataSection() const {
695       return DataSection;
696     }
697     const char *getBSSSection() const {
698       return BSSSection;
699     }
700     const Section *getBSSSection_() const {
701       return BSSSection_;
702     }
703     const Section *getReadOnlySection() const {
704       return ReadOnlySection;
705     }
706     const Section *getTLSDataSection() const {
707       return TLSDataSection;
708     }
709     const Section *getTLSBSSSection() const {
710       return TLSBSSSection;
711     }
712     const char *getZeroFillDirective() const {
713       return ZeroFillDirective;
714     }
715     const char *getNonexecutableStackDirective() const {
716       return NonexecutableStackDirective;
717     }
718     bool needsSet() const {
719       return NeedsSet;
720     }
721     const char *getPCSymbol() const {
722       return PCSymbol;
723     }
724     char getSeparatorChar() const {
725       return SeparatorChar;
726     }
727     unsigned getCommentColumn() const {
728       return CommentColumn;
729     }
730     const char *getCommentString() const {
731       return CommentString;
732     }
733     unsigned getOperandColumn(int operand) const {
734       return FirstOperandColumn + (MaxOperandLength+1)*(operand-1);
735     }
736     const char *getGlobalPrefix() const {
737       return GlobalPrefix;
738     }
739     const char *getPrivateGlobalPrefix() const {
740       return PrivateGlobalPrefix;
741     }
742     const char *getLinkerPrivateGlobalPrefix() const {
743       return LinkerPrivateGlobalPrefix;
744     }
745     const char *getJumpTableSpecialLabelPrefix() const {
746       return JumpTableSpecialLabelPrefix;
747     }
748     const char *getGlobalVarAddrPrefix() const {
749       return GlobalVarAddrPrefix;
750     }
751     const char *getGlobalVarAddrSuffix() const {
752       return GlobalVarAddrSuffix;
753     }
754     const char *getFunctionAddrPrefix() const {
755       return FunctionAddrPrefix;
756     }
757     const char *getFunctionAddrSuffix() const {
758       return FunctionAddrSuffix;
759     }
760     const char *getPersonalityPrefix() const {
761       return PersonalityPrefix;
762     }
763     const char *getPersonalitySuffix() const {
764       return PersonalitySuffix;
765     }
766     bool getNeedsIndirectEncoding() const {
767       return NeedsIndirectEncoding;
768     }
769     const char *getInlineAsmStart() const {
770       return InlineAsmStart;
771     }
772     const char *getInlineAsmEnd() const {
773       return InlineAsmEnd;
774     }
775     unsigned getAssemblerDialect() const {
776       return AssemblerDialect;
777     }
778     bool doesAllowQuotesInName() const {
779       return AllowQuotesInName;
780     }
781     const char *getZeroDirective() const {
782       return ZeroDirective;
783     }
784     const char *getZeroDirectiveSuffix() const {
785       return ZeroDirectiveSuffix;
786     }
787     const char *getAsciiDirective() const {
788       return AsciiDirective;
789     }
790     const char *getAscizDirective() const {
791       return AscizDirective;
792     }
793     const char *getJumpTableDirective() const {
794       return JumpTableDirective;
795     }
796     const char *getAlignDirective() const {
797       return AlignDirective;
798     }
799     bool getAlignmentIsInBytes() const {
800       return AlignmentIsInBytes;
801     }
802     unsigned getTextAlignFillValue() const {
803       return TextAlignFillValue;
804     }
805     const char *getSwitchToSectionDirective() const {
806       return SwitchToSectionDirective;
807     }
808     const char *getTextSectionStartSuffix() const {
809       return TextSectionStartSuffix;
810     }
811     const char *getDataSectionStartSuffix() const {
812       return DataSectionStartSuffix;
813     }
814     const char *getSectionEndDirectiveSuffix() const {
815       return SectionEndDirectiveSuffix;
816     }
817     const char *getConstantPoolSection() const {
818       return ConstantPoolSection;
819     }
820     const char *getJumpTableDataSection() const {
821       return JumpTableDataSection;
822     }
823     const char *getCStringSection() const {
824       return CStringSection;
825     }
826     const Section *getCStringSection_() const {
827       return CStringSection_;
828     }
829     const char *getStaticCtorsSection() const {
830       return StaticCtorsSection;
831     }
832     const char *getStaticDtorsSection() const {
833       return StaticDtorsSection;
834     }
835     const char *getGlobalDirective() const {
836       return GlobalDirective;
837     }
838     const char *getExternDirective() const {
839       return ExternDirective;
840     }
841     const char *getSetDirective() const {
842       return SetDirective;
843     }
844     const char *getLCOMMDirective() const {
845       return LCOMMDirective;
846     }
847     const char *getCOMMDirective() const {
848       return COMMDirective;
849     }
850     bool getCOMMDirectiveTakesAlignment() const {
851       return COMMDirectiveTakesAlignment;
852     }
853     bool hasDotTypeDotSizeDirective() const {
854       return HasDotTypeDotSizeDirective;
855     }
856     bool hasSingleParameterDotFile() const {
857       return HasSingleParameterDotFile;
858     }
859     const char *getUsedDirective() const {
860       return UsedDirective;
861     }
862     const char *getWeakRefDirective() const {
863       return WeakRefDirective;
864     }
865     const char *getWeakDefDirective() const {
866       return WeakDefDirective;
867     }
868     const char *getHiddenDirective() const {
869       return HiddenDirective;
870     }
871     const char *getProtectedDirective() const {
872       return ProtectedDirective;
873     }
874     bool isAbsoluteDebugSectionOffsets() const {
875       return AbsoluteDebugSectionOffsets;
876     }
877     bool isAbsoluteEHSectionOffsets() const {
878       return AbsoluteEHSectionOffsets;
879     }
880     bool hasLEB128() const {
881       return HasLEB128;
882     }
883     bool hasDotLocAndDotFile() const {
884       return HasDotLocAndDotFile;
885     }
886     bool doesSupportDebugInformation() const {
887       return SupportsDebugInformation;
888     }
889     bool doesSupportExceptionHandling() const {
890       return SupportsExceptionHandling;
891     }
892     bool doesDwarfRequireFrameSection() const {
893       return DwarfRequiresFrameSection;
894     }
895     bool doesDwarfUsesInlineInfoSection() const {
896       return DwarfUsesInlineInfoSection;
897     }
898     bool is_EHSymbolPrivate() const {
899       return Is_EHSymbolPrivate;
900     }
901     const char *getGlobalEHDirective() const {
902       return GlobalEHDirective;
903     }
904     bool getSupportsWeakOmittedEHFrame() const {
905       return SupportsWeakOmittedEHFrame;
906     }
907     const char *getDwarfSectionOffsetDirective() const {
908       return DwarfSectionOffsetDirective;
909     }
910     const char *getDwarfAbbrevSection() const {
911       return DwarfAbbrevSection;
912     }
913     const char *getDwarfInfoSection() const {
914       return DwarfInfoSection;
915     }
916     const char *getDwarfLineSection() const {
917       return DwarfLineSection;
918     }
919     const char *getDwarfFrameSection() const {
920       return DwarfFrameSection;
921     }
922     const char *getDwarfPubNamesSection() const {
923       return DwarfPubNamesSection;
924     }
925     const char *getDwarfPubTypesSection() const {
926       return DwarfPubTypesSection;
927     }
928     const char *getDwarfDebugInlineSection() const {
929       return DwarfDebugInlineSection;
930     }
931     const char *getDwarfStrSection() const {
932       return DwarfStrSection;
933     }
934     const char *getDwarfLocSection() const {
935       return DwarfLocSection;
936     }
937     const char *getDwarfARangesSection() const {
938       return DwarfARangesSection;
939     }
940     const char *getDwarfRangesSection() const {
941       return DwarfRangesSection;
942     }
943     const char *getDwarfMacroInfoSection() const {
944       return DwarfMacroInfoSection;
945     }
946     const char *getDwarfEHFrameSection() const {
947       return DwarfEHFrameSection;
948     }
949     const char *getDwarfExceptionSection() const {
950       return DwarfExceptionSection;
951     }
952     const char *const *getAsmCBE() const {
953       return AsmTransCBE;
954     }
955   };
956 }
957
958 #endif