LLVM API Documentation

TargetAsmInfo.h

Go to the documentation of this file.
00001 //===-- llvm/Target/TargetAsmInfo.h - Asm info ------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains a class to be used as the basis for target specific
00011 // asm writers.  This class primarily takes care of global printing constants,
00012 // which are used in very similar ways across all targets.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_TARGET_ASM_INFO_H
00017 #define LLVM_TARGET_ASM_INFO_H
00018 
00019 #include "llvm/Support/DataTypes.h"
00020 #include <cassert>
00021 #include <string>
00022 
00023 namespace llvm {
00024   template <typename T> class SmallVectorImpl;
00025   
00026   /// TargetAsmInfo - This class is intended to be used as a base class for asm
00027   /// properties and features specific to the target.
00028   namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
00029 
00030   class TargetAsmInfo {
00031   protected:
00032     //===------------------------------------------------------------------===//
00033     // Properties to be set by the target writer, used to configure asm printer.
00034     //
00035 
00036     /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
00037     /// section on this target.  Null if this target doesn't support zerofill.
00038     const char *ZeroFillDirective;        // Default is null.
00039 
00040     /// NonexecutableStackDirective - Directive for declaring to the
00041     /// linker and beyond that the emitted code does not require stack
00042     /// memory to be executable.
00043     const char *NonexecutableStackDirective; // Default is null.
00044 
00045     /// NeedsSet - True if target asm treats expressions in data directives
00046     /// as linktime-relocatable.  For assembly-time computation, we need to
00047     /// use a .set.  Thus:
00048     /// .set w, x-y
00049     /// .long w
00050     /// is computed at assembly time, while
00051     /// .long x-y
00052     /// is relocated if the relative locations of x and y change at linktime.
00053     /// We want both these things in different places.
00054     bool NeedsSet;                        // Defaults to false.
00055     
00056     /// MaxInstLength - This is the maximum possible length of an instruction,
00057     /// which is needed to compute the size of an inline asm.
00058     unsigned MaxInstLength;               // Defaults to 4.
00059     
00060     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
00061     /// relative expressions.
00062     const char *PCSymbol;                 // Defaults to "$".
00063 
00064     /// SeparatorChar - This character, if specified, is used to separate
00065     /// instructions from each other when on the same line.  This is used to
00066     /// measure inline asm instructions.
00067     char SeparatorChar;                   // Defaults to ';'
00068 
00069     /// CommentColumn - This indicates the comment num (zero-based) at
00070     /// which asm comments should be printed.
00071     unsigned CommentColumn;               // Defaults to 60
00072 
00073     /// CommentString - This indicates the comment character used by the
00074     /// assembler.
00075     const char *CommentString;            // Defaults to "#"
00076 
00077     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
00078     /// onto all global symbols.  This is often used for "_" or ".".
00079     const char *GlobalPrefix;             // Defaults to ""
00080 
00081     /// PrivateGlobalPrefix - This prefix is used for globals like constant
00082     /// pool entries that are completely private to the .s file and should not
00083     /// have names in the .o file.  This is often "." or "L".
00084     const char *PrivateGlobalPrefix;      // Defaults to "."
00085     
00086     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
00087     /// be passed through the assembler but be removed by the linker.  This
00088     /// is "l" on Darwin, currently used for some ObjC metadata.
00089     const char *LinkerPrivateGlobalPrefix;      // Defaults to ""
00090     
00091     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
00092     /// emitted before jump tables with the specified prefix.
00093     const char *JumpTableSpecialLabelPrefix;  // Default to null.
00094     
00095     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
00096     /// will enclose any GlobalVariable (that isn't a function)
00097     ///
00098     const char *GlobalVarAddrPrefix;      // Defaults to ""
00099     const char *GlobalVarAddrSuffix;      // Defaults to ""
00100 
00101     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
00102     /// will enclose any GlobalVariable that points to a function.
00103     ///
00104     const char *FunctionAddrPrefix;       // Defaults to ""
00105     const char *FunctionAddrSuffix;       // Defaults to ""
00106 
00107     /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
00108     /// enclose any personality function in the common frame section.
00109     /// 
00110     const char *PersonalityPrefix;        // Defaults to ""
00111     const char *PersonalitySuffix;        // Defaults to ""
00112 
00113     /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
00114     /// for EH in Dwarf.
00115     /// 
00116     bool NeedsIndirectEncoding;           // Defaults to false
00117 
00118     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
00119     /// emit before and after an inline assembly statement.
00120     const char *InlineAsmStart;           // Defaults to "#APP\n"
00121     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
00122 
00123     /// AssemblerDialect - Which dialect of an assembler variant to use.
00124     unsigned AssemblerDialect;            // Defaults to 0
00125 
00126     /// AllowQuotesInName - This is true if the assembler allows for complex
00127     /// symbol names to be surrounded in quotes.  This defaults to false.
00128     bool AllowQuotesInName;
00129     
00130     //===--- Data Emission Directives -------------------------------------===//
00131 
00132     /// ZeroDirective - this should be set to the directive used to get some
00133     /// number of zero bytes emitted to the current section.  Common cases are
00134     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
00135     /// Data*bitsDirective's will be used to emit zero bytes.
00136     const char *ZeroDirective;            // Defaults to "\t.zero\t"
00137     const char *ZeroDirectiveSuffix;      // Defaults to ""
00138 
00139     /// AsciiDirective - This directive allows emission of an ascii string with
00140     /// the standard C escape characters embedded into it.
00141     const char *AsciiDirective;           // Defaults to "\t.ascii\t"
00142     
00143     /// AscizDirective - If not null, this allows for special handling of
00144     /// zero terminated strings on this target.  This is commonly supported as
00145     /// ".asciz".  If a target doesn't support this, it can be set to null.
00146     const char *AscizDirective;           // Defaults to "\t.asciz\t"
00147 
00148     /// DataDirectives - These directives are used to output some unit of
00149     /// integer data to the current section.  If a data directive is set to
00150     /// null, smaller data directives will be used to emit the large sizes.
00151     const char *Data8bitsDirective;       // Defaults to "\t.byte\t"
00152     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
00153     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
00154     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
00155 
00156     /// getDataASDirective - Return the directive that should be used to emit
00157     /// data of the specified size to the specified numeric address space.
00158     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
00159       assert(AS != 0 && "Don't know the directives for default addr space");
00160       return NULL;
00161     }
00162 
00163     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
00164     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
00165     /// normal ELF syntax (,"a,w") in .section directives.
00166     bool SunStyleELFSectionSwitchSyntax;   // Defaults to false.
00167 
00168     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
00169     /// '.section' directive before the '.bss' one. It's used for PPC/Linux 
00170     /// which doesn't support the '.bss' directive only.
00171     bool UsesELFSectionDirectiveForBSS;  // Defaults to false.
00172     
00173     //===--- Alignment Information ----------------------------------------===//
00174 
00175     /// AlignDirective - The directive used to emit round up to an alignment
00176     /// boundary.
00177     ///
00178     const char *AlignDirective;           // Defaults to "\t.align\t"
00179 
00180     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
00181     /// emits ".align N" directives, where N is the number of bytes to align to.
00182     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
00183     /// boundary.
00184     bool AlignmentIsInBytes;              // Defaults to true
00185 
00186     /// TextAlignFillValue - If non-zero, this is used to fill the executable
00187     /// space created as the result of a alignment directive.
00188     unsigned TextAlignFillValue;
00189 
00190     //===--- Section Switching Directives ---------------------------------===//
00191     
00192     /// JumpTableDirective - if non-null, the directive to emit before jump
00193     /// table entries.  FIXME: REMOVE THIS.
00194     const char *JumpTableDirective;
00195     const char *PICJumpTableDirective;
00196 
00197 
00198     //===--- Global Variable Emission Directives --------------------------===//
00199     
00200     /// GlobalDirective - This is the directive used to declare a global entity.
00201     ///
00202     const char *GlobalDirective;          // Defaults to NULL.
00203 
00204     /// ExternDirective - This is the directive used to declare external 
00205     /// globals.
00206     ///
00207     const char *ExternDirective;          // Defaults to NULL.
00208     
00209     /// SetDirective - This is the name of a directive that can be used to tell
00210     /// the assembler to set the value of a variable to some expression.
00211     const char *SetDirective;             // Defaults to null.
00212     
00213     /// LCOMMDirective - This is the name of a directive (if supported) that can
00214     /// be used to efficiently declare a local (internal) block of zero
00215     /// initialized data in the .bss/.data section.  The syntax expected is:
00216     /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
00217     /// @endverbatim
00218     const char *LCOMMDirective;           // Defaults to null.
00219     
00220     const char *COMMDirective;            // Defaults to "\t.comm\t".
00221 
00222     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
00223     /// argument that specifies the alignment of the declaration.
00224     bool COMMDirectiveTakesAlignment;     // Defaults to true.
00225     
00226     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
00227     /// directives, this is true for most ELF targets.
00228     bool HasDotTypeDotSizeDirective;      // Defaults to true.
00229 
00230     /// HasSingleParameterDotFile - True if the target has a single parameter
00231     /// .file directive, this is true for ELF targets.
00232     bool HasSingleParameterDotFile;      // Defaults to true.
00233 
00234     /// UsedDirective - This directive, if non-null, is used to declare a global
00235     /// as being used somehow that the assembler can't see.  This prevents dead
00236     /// code elimination on some targets.
00237     const char *UsedDirective;            // Defaults to null.
00238 
00239     /// WeakRefDirective - This directive, if non-null, is used to declare a
00240     /// global as being a weak undefined symbol.
00241     const char *WeakRefDirective;         // Defaults to null.
00242     
00243     /// WeakDefDirective - This directive, if non-null, is used to declare a
00244     /// global as being a weak defined symbol.
00245     const char *WeakDefDirective;         // Defaults to null.
00246     
00247     /// HiddenDirective - This directive, if non-null, is used to declare a
00248     /// global or function as having hidden visibility.
00249     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
00250 
00251     /// ProtectedDirective - This directive, if non-null, is used to declare a
00252     /// global or function as having protected visibility.
00253     const char *ProtectedDirective;       // Defaults to "\t.protected\t".
00254 
00255     //===--- Dwarf Emission Directives -----------------------------------===//
00256 
00257     /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
00258     /// offsets for debug information. Defaults to false.
00259     bool AbsoluteDebugSectionOffsets;
00260 
00261     /// AbsoluteEHSectionOffsets - True if we should emit abolute section
00262     /// offsets for EH information. Defaults to false.
00263     bool AbsoluteEHSectionOffsets;
00264 
00265     /// HasLEB128 - True if target asm supports leb128 directives.
00266     ///
00267     bool HasLEB128; // Defaults to false.
00268 
00269     /// hasDotLocAndDotFile - True if target asm supports .loc and .file
00270     /// directives for emitting debugging information.
00271     ///
00272     bool HasDotLocAndDotFile; // Defaults to false.
00273 
00274     /// SupportsDebugInformation - True if target supports emission of debugging
00275     /// information.
00276     bool SupportsDebugInformation;
00277 
00278     /// SupportsExceptionHandling - True if target supports
00279     /// exception handling.
00280     ///
00281     // Defaults to None
00282     ExceptionHandling::ExceptionsType ExceptionsType;
00283 
00284     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
00285     ///
00286     bool DwarfRequiresFrameSection; // Defaults to true.
00287 
00288     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
00289     /// encode inline subroutine information.
00290     bool DwarfUsesInlineInfoSection; // Defaults to false.
00291 
00292     /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
00293     /// doesn't show up in the symbol table of the object file.
00294     bool Is_EHSymbolPrivate;                // Defaults to true.
00295 
00296     /// GlobalEHDirective - This is the directive used to make exception frame
00297     /// tables globally visible.
00298     ///
00299     const char *GlobalEHDirective;          // Defaults to NULL.
00300 
00301     /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
00302     /// handle a weak_definition of constant 0 for an omitted EH frame.
00303     bool SupportsWeakOmittedEHFrame;  // Defaults to true.
00304 
00305     /// DwarfSectionOffsetDirective - Special section offset directive.
00306     const char* DwarfSectionOffsetDirective; // Defaults to NULL
00307     
00308     //===--- CBE Asm Translation Table -----------------------------------===//
00309 
00310     const char *const *AsmTransCBE; // Defaults to empty
00311 
00312   public:
00313     explicit TargetAsmInfo();
00314     virtual ~TargetAsmInfo();
00315 
00316     /// getSLEB128Size - Compute the number of bytes required for a signed
00317     /// leb128 value.
00318     static unsigned getSLEB128Size(int Value);
00319 
00320     /// getULEB128Size - Compute the number of bytes required for an unsigned
00321     /// leb128 value.
00322     static unsigned getULEB128Size(unsigned Value);
00323 
00324     // Data directive accessors.
00325     //
00326     const char *getData8bitsDirective(unsigned AS = 0) const {
00327       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
00328     }
00329     const char *getData16bitsDirective(unsigned AS = 0) const {
00330       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
00331     }
00332     const char *getData32bitsDirective(unsigned AS = 0) const {
00333       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
00334     }
00335     const char *getData64bitsDirective(unsigned AS = 0) const {
00336       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
00337     }
00338 
00339     
00340     bool usesSunStyleELFSectionSwitchSyntax() const {
00341       return SunStyleELFSectionSwitchSyntax;
00342     }
00343     
00344     bool usesELFSectionDirectiveForBSS() const {
00345       return UsesELFSectionDirectiveForBSS;
00346     }
00347 
00348     // Accessors.
00349     //
00350     const char *getZeroFillDirective() const {
00351       return ZeroFillDirective;
00352     }
00353     const char *getNonexecutableStackDirective() const {
00354       return NonexecutableStackDirective;
00355     }
00356     bool needsSet() const {
00357       return NeedsSet;
00358     }
00359     unsigned getMaxInstLength() const {
00360       return MaxInstLength;
00361     }
00362     const char *getPCSymbol() const {
00363       return PCSymbol;
00364     }
00365     char getSeparatorChar() const {
00366       return SeparatorChar;
00367     }
00368     unsigned getCommentColumn() const {
00369       return CommentColumn;
00370     }
00371     const char *getCommentString() const {
00372       return CommentString;
00373     }
00374     const char *getGlobalPrefix() const {
00375       return GlobalPrefix;
00376     }
00377     const char *getPrivateGlobalPrefix() const {
00378       return PrivateGlobalPrefix;
00379     }
00380     const char *getLinkerPrivateGlobalPrefix() const {
00381       return LinkerPrivateGlobalPrefix;
00382     }
00383     const char *getJumpTableSpecialLabelPrefix() const {
00384       return JumpTableSpecialLabelPrefix;
00385     }
00386     const char *getGlobalVarAddrPrefix() const {
00387       return GlobalVarAddrPrefix;
00388     }
00389     const char *getGlobalVarAddrSuffix() const {
00390       return GlobalVarAddrSuffix;
00391     }
00392     const char *getFunctionAddrPrefix() const {
00393       return FunctionAddrPrefix;
00394     }
00395     const char *getFunctionAddrSuffix() const {
00396       return FunctionAddrSuffix;
00397     }
00398     const char *getPersonalityPrefix() const {
00399       return PersonalityPrefix;
00400     }
00401     const char *getPersonalitySuffix() const {
00402       return PersonalitySuffix;
00403     }
00404     bool getNeedsIndirectEncoding() const {
00405       return NeedsIndirectEncoding;
00406     }
00407     const char *getInlineAsmStart() const {
00408       return InlineAsmStart;
00409     }
00410     const char *getInlineAsmEnd() const {
00411       return InlineAsmEnd;
00412     }
00413     unsigned getAssemblerDialect() const {
00414       return AssemblerDialect;
00415     }
00416     bool doesAllowQuotesInName() const {
00417       return AllowQuotesInName;
00418     }
00419     const char *getZeroDirective() const {
00420       return ZeroDirective;
00421     }
00422     const char *getZeroDirectiveSuffix() const {
00423       return ZeroDirectiveSuffix;
00424     }
00425     const char *getAsciiDirective() const {
00426       return AsciiDirective;
00427     }
00428     const char *getAscizDirective() const {
00429       return AscizDirective;
00430     }
00431     const char *getJumpTableDirective(bool isPIC) const {
00432       return isPIC ? PICJumpTableDirective : JumpTableDirective;
00433     }
00434     const char *getAlignDirective() const {
00435       return AlignDirective;
00436     }
00437     bool getAlignmentIsInBytes() const {
00438       return AlignmentIsInBytes;
00439     }
00440     unsigned getTextAlignFillValue() const {
00441       return TextAlignFillValue;
00442     }
00443     const char *getGlobalDirective() const {
00444       return GlobalDirective;
00445     }
00446     const char *getExternDirective() const {
00447       return ExternDirective;
00448     }
00449     const char *getSetDirective() const {
00450       return SetDirective;
00451     }
00452     const char *getLCOMMDirective() const {
00453       return LCOMMDirective;
00454     }
00455     const char *getCOMMDirective() const {
00456       return COMMDirective;
00457     }
00458     bool getCOMMDirectiveTakesAlignment() const {
00459       return COMMDirectiveTakesAlignment;
00460     }
00461     bool hasDotTypeDotSizeDirective() const {
00462       return HasDotTypeDotSizeDirective;
00463     }
00464     bool hasSingleParameterDotFile() const {
00465       return HasSingleParameterDotFile;
00466     }
00467     const char *getUsedDirective() const {
00468       return UsedDirective;
00469     }
00470     const char *getWeakRefDirective() const {
00471       return WeakRefDirective;
00472     }
00473     const char *getWeakDefDirective() const {
00474       return WeakDefDirective;
00475     }
00476     const char *getHiddenDirective() const {
00477       return HiddenDirective;
00478     }
00479     const char *getProtectedDirective() const {
00480       return ProtectedDirective;
00481     }
00482     bool isAbsoluteDebugSectionOffsets() const {
00483       return AbsoluteDebugSectionOffsets;
00484     }
00485     bool isAbsoluteEHSectionOffsets() const {
00486       return AbsoluteEHSectionOffsets;
00487     }
00488     bool hasLEB128() const {
00489       return HasLEB128;
00490     }
00491     bool hasDotLocAndDotFile() const {
00492       return HasDotLocAndDotFile;
00493     }
00494     bool doesSupportDebugInformation() const {
00495       return SupportsDebugInformation;
00496     }
00497     bool doesSupportExceptionHandling() const {
00498       return ExceptionsType != ExceptionHandling::None;
00499     }
00500     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
00501       return ExceptionsType;
00502     }
00503     bool doesDwarfRequireFrameSection() const {
00504       return DwarfRequiresFrameSection;
00505     }
00506     bool doesDwarfUsesInlineInfoSection() const {
00507       return DwarfUsesInlineInfoSection;
00508     }
00509     bool is_EHSymbolPrivate() const {
00510       return Is_EHSymbolPrivate;
00511     }
00512     const char *getGlobalEHDirective() const {
00513       return GlobalEHDirective;
00514     }
00515     bool getSupportsWeakOmittedEHFrame() const {
00516       return SupportsWeakOmittedEHFrame;
00517     }
00518     const char *getDwarfSectionOffsetDirective() const {
00519       return DwarfSectionOffsetDirective;
00520     }
00521     const char *const *getAsmCBE() const {
00522       return AsmTransCBE;
00523     }
00524   };
00525 }
00526 
00527 #endif