Home | History | Annotate | Line # | Download | only in MC
      1 //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 //
      9 // This file contains a class to be used as the basis for target specific
     10 // asm writers.  This class primarily takes care of global printing constants,
     11 // which are used in very similar ways across all targets.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_MC_MCASMINFO_H
     16 #define LLVM_MC_MCASMINFO_H
     17 
     18 #include "llvm/ADT/StringRef.h"
     19 #include "llvm/MC/MCDirectives.h"
     20 #include "llvm/MC/MCTargetOptions.h"
     21 #include <vector>
     22 
     23 namespace llvm {
     24 
     25 class MCContext;
     26 class MCCFIInstruction;
     27 class MCExpr;
     28 class MCSection;
     29 class MCStreamer;
     30 class MCSubtargetInfo;
     31 class MCSymbol;
     32 
     33 namespace WinEH {
     34 
     35 enum class EncodingType {
     36   Invalid, /// Invalid
     37   Alpha,   /// Windows Alpha
     38   Alpha64, /// Windows AXP64
     39   ARM,     /// Windows NT (Windows on ARM)
     40   CE,      /// Windows CE ARM, PowerPC, SH3, SH4
     41   Itanium, /// Windows x64, Windows Itanium (IA-64)
     42   X86,     /// Windows x86, uses no CFI, just EH tables
     43   MIPS = Alpha,
     44 };
     45 
     46 } // end namespace WinEH
     47 
     48 namespace LCOMM {
     49 
     50 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
     51 
     52 } // end namespace LCOMM
     53 
     54 /// This class is intended to be used as a base class for asm
     55 /// properties and features specific to the target.
     56 class MCAsmInfo {
     57 public:
     58   /// Assembly character literal syntax types.
     59   enum AsmCharLiteralSyntax {
     60     ACLS_Unknown, /// Unknown; character literals not used by LLVM for this
     61                   /// target.
     62     ACLS_SingleQuotePrefix, /// The desired character is prefixed by a single
     63                             /// quote, e.g., `'A`.
     64   };
     65 
     66 protected:
     67   //===------------------------------------------------------------------===//
     68   // Properties to be set by the target writer, used to configure asm printer.
     69   //
     70 
     71   /// Code pointer size in bytes.  Default is 4.
     72   unsigned CodePointerSize = 4;
     73 
     74   /// Size of the stack slot reserved for callee-saved registers, in bytes.
     75   /// Default is same as pointer size.
     76   unsigned CalleeSaveStackSlotSize = 4;
     77 
     78   /// True if target is little endian.  Default is true.
     79   bool IsLittleEndian = true;
     80 
     81   /// True if target stack grow up.  Default is false.
     82   bool StackGrowsUp = false;
     83 
     84   /// True if this target has the MachO .subsections_via_symbols directive.
     85   /// Default is false.
     86   bool HasSubsectionsViaSymbols = false;
     87 
     88   /// True if this is a MachO target that supports the macho-specific .zerofill
     89   /// directive for emitting BSS Symbols.  Default is false.
     90   bool HasMachoZeroFillDirective = false;
     91 
     92   /// True if this is a MachO target that supports the macho-specific .tbss
     93   /// directive for emitting thread local BSS Symbols.  Default is false.
     94   bool HasMachoTBSSDirective = false;
     95 
     96   /// True if this is a non-GNU COFF target. The COFF port of the GNU linker
     97   /// doesn't handle associative comdats in the way that we would like to use
     98   /// them.
     99   bool HasCOFFAssociativeComdats = false;
    100 
    101   /// True if this is a non-GNU COFF target. For GNU targets, we don't generate
    102   /// constants into comdat sections.
    103   bool HasCOFFComdatConstants = false;
    104 
    105   /// True if this is an XCOFF target that supports visibility attributes as
    106   /// part of .global, .weak, .extern, and .comm. Default is false.
    107   bool HasVisibilityOnlyWithLinkage = false;
    108 
    109   /// This is the maximum possible length of an instruction, which is needed to
    110   /// compute the size of an inline asm.  Defaults to 4.
    111   unsigned MaxInstLength = 4;
    112 
    113   /// Every possible instruction length is a multiple of this value.  Factored
    114   /// out in .debug_frame and .debug_line.  Defaults to 1.
    115   unsigned MinInstAlignment = 1;
    116 
    117   /// The '$' token, when not referencing an identifier or constant, refers to
    118   /// the current PC.  Defaults to false.
    119   bool DollarIsPC = false;
    120 
    121   /// Allow '.' token, when not referencing an identifier or constant, to refer
    122   /// to the current PC. Defaults to true.
    123   bool DotIsPC = true;
    124 
    125   /// Whether the '*' token refers to the current PC. This is used for the
    126   /// HLASM dialect.
    127   bool StarIsPC = false;
    128 
    129   /// This string, if specified, is used to separate instructions from each
    130   /// other when on the same line.  Defaults to ';'
    131   const char *SeparatorString;
    132 
    133   /// This indicates the comment string used by the assembler.  Defaults to
    134   /// "#"
    135   StringRef CommentString;
    136 
    137   /// This indicates whether the comment string is only accepted as a comment
    138   /// at the beginning of statements. Defaults to false.
    139   bool RestrictCommentStringToStartOfStatement = false;
    140 
    141   /// This indicates whether to allow additional "comment strings" to be lexed
    142   /// as a comment. Setting this attribute to true, will ensure that C-style
    143   /// line comments (// ..), C-style block comments (/* .. */), and "#" are
    144   /// all treated as comments in addition to the string specified by the
    145   /// CommentString attribute.
    146   /// Default is true.
    147   bool AllowAdditionalComments = true;
    148 
    149   /// Should we emit the '\t' as the starting indentation marker for GNU inline
    150   /// asm statements. Defaults to true.
    151   bool EmitGNUAsmStartIndentationMarker = true;
    152 
    153   /// This is appended to emitted labels.  Defaults to ":"
    154   const char *LabelSuffix;
    155 
    156   // Print the EH begin symbol with an assignment. Defaults to false.
    157   bool UseAssignmentForEHBegin = false;
    158 
    159   // Do we need to create a local symbol for .size?
    160   bool NeedsLocalForSize = false;
    161 
    162   /// This prefix is used for globals like constant pool entries that are
    163   /// completely private to the .s file and should not have names in the .o
    164   /// file.  Defaults to "L"
    165   StringRef PrivateGlobalPrefix;
    166 
    167   /// This prefix is used for labels for basic blocks. Defaults to the same as
    168   /// PrivateGlobalPrefix.
    169   StringRef PrivateLabelPrefix;
    170 
    171   /// This prefix is used for symbols that should be passed through the
    172   /// assembler but be removed by the linker.  This is 'l' on Darwin, currently
    173   /// used for some ObjC metadata.  The default of "" meast that for this system
    174   /// a plain private symbol should be used.  Defaults to "".
    175   StringRef LinkerPrivateGlobalPrefix;
    176 
    177   /// If these are nonempty, they contain a directive to emit before and after
    178   /// an inline assembly statement.  Defaults to "#APP\n", "#NO_APP\n"
    179   const char *InlineAsmStart;
    180   const char *InlineAsmEnd;
    181 
    182   /// These are assembly directives that tells the assembler to interpret the
    183   /// following instructions differently.  Defaults to ".code16", ".code32",
    184   /// ".code64".
    185   const char *Code16Directive;
    186   const char *Code32Directive;
    187   const char *Code64Directive;
    188 
    189   /// Which dialect of an assembler variant to use.  Defaults to 0
    190   unsigned AssemblerDialect = 0;
    191 
    192   /// This is true if the assembler allows @ characters in symbol names.
    193   /// Defaults to false.
    194   bool AllowAtInName = false;
    195 
    196   /// This is true if the assembler allows the "?" character at the start of
    197   /// of a string to be lexed as an AsmToken::Identifier.
    198   /// If the AsmLexer determines that the string can be lexed as a possible
    199   /// comment, setting this option will have no effect, and the string will
    200   /// still be lexed as a comment.
    201   bool AllowQuestionAtStartOfIdentifier = false;
    202 
    203   /// This is true if the assembler allows the "$" character at the start of
    204   /// of a string to be lexed as an AsmToken::Identifier.
    205   /// If the AsmLexer determines that the string can be lexed as a possible
    206   /// comment, setting this option will have no effect, and the string will
    207   /// still be lexed as a comment.
    208   bool AllowDollarAtStartOfIdentifier = false;
    209 
    210   /// This is true if the assembler allows the "@" character at the start of
    211   /// a string to be lexed as an AsmToken::Identifier.
    212   /// If the AsmLexer determines that the string can be lexed as a possible
    213   /// comment, setting this option will have no effect, and the string will
    214   /// still be lexed as a comment.
    215   bool AllowAtAtStartOfIdentifier = false;
    216 
    217   /// This is true if the assembler allows the "#" character at the start of
    218   /// a string to be lexed as an AsmToken::Identifier.
    219   /// If the AsmLexer determines that the string can be lexed as a possible
    220   /// comment, setting this option will have no effect, and the string will
    221   /// still be lexed as a comment.
    222   bool AllowHashAtStartOfIdentifier = false;
    223 
    224   /// If this is true, symbol names with invalid characters will be printed in
    225   /// quotes.
    226   bool SupportsQuotedNames = true;
    227 
    228   /// This is true if data region markers should be printed as
    229   /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
    230   /// instead.
    231   bool UseDataRegionDirectives = false;
    232 
    233   /// True if .align is to be used for alignment. Only power-of-two
    234   /// alignment is supported.
    235   bool UseDotAlignForAlignment = false;
    236 
    237   /// True if the target supports LEB128 directives.
    238   bool HasLEB128Directives = true;
    239 
    240   //===--- Data Emission Directives -------------------------------------===//
    241 
    242   /// This should be set to the directive used to get some number of zero (and
    243   /// non-zero if supported by the directive) bytes emitted to the current
    244   /// section. Common cases are "\t.zero\t" and "\t.space\t". Defaults to
    245   /// "\t.zero\t"
    246   const char *ZeroDirective;
    247 
    248   /// This should be set to true if the zero directive supports a value to emit
    249   /// other than zero. If this is set to false, the Data*bitsDirective's will be
    250   /// used to emit these bytes. Defaults to true.
    251   bool ZeroDirectiveSupportsNonZeroValue = true;
    252 
    253   /// This directive allows emission of an ascii string with the standard C
    254   /// escape characters embedded into it.  If a target doesn't support this, it
    255   /// can be set to null. Defaults to "\t.ascii\t"
    256   const char *AsciiDirective;
    257 
    258   /// If not null, this allows for special handling of zero terminated strings
    259   /// on this target.  This is commonly supported as ".asciz".  If a target
    260   /// doesn't support this, it can be set to null.  Defaults to "\t.asciz\t"
    261   const char *AscizDirective;
    262 
    263   /// This directive accepts a comma-separated list of bytes for emission as a
    264   /// string of bytes.  For targets that do not support this, it shall be set to
    265   /// null.  Defaults to null.
    266   const char *ByteListDirective = nullptr;
    267 
    268   /// This directive allows emission of a zero-terminated ascii string without
    269   /// the standard C escape characters embedded into it.  If a target doesn't
    270   /// support this, it can be set to null. Defaults to null.
    271   const char *PlainStringDirective = nullptr;
    272 
    273   /// Form used for character literals in the assembly syntax.  Useful for
    274   /// producing strings as byte lists.  If a target does not use or support
    275   /// this, it shall be set to ACLS_Unknown.  Defaults to ACLS_Unknown.
    276   AsmCharLiteralSyntax CharacterLiteralSyntax = ACLS_Unknown;
    277 
    278   /// These directives are used to output some unit of integer data to the
    279   /// current section.  If a data directive is set to null, smaller data
    280   /// directives will be used to emit the large sizes.  Defaults to "\t.byte\t",
    281   /// "\t.short\t", "\t.long\t", "\t.quad\t"
    282   const char *Data8bitsDirective;
    283   const char *Data16bitsDirective;
    284   const char *Data32bitsDirective;
    285   const char *Data64bitsDirective;
    286 
    287   /// True if data directives support signed values
    288   bool SupportsSignedData = true;
    289 
    290   /// If non-null, a directive that is used to emit a word which should be
    291   /// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips.  Defaults
    292   /// to nullptr.
    293   const char *GPRel64Directive = nullptr;
    294 
    295   /// If non-null, a directive that is used to emit a word which should be
    296   /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
    297   /// on Alpha.  Defaults to nullptr.
    298   const char *GPRel32Directive = nullptr;
    299 
    300   /// If non-null, directives that are used to emit a word/dword which should
    301   /// be relocated as a 32/64-bit DTP/TP-relative offset, e.g. .dtprelword/
    302   /// .dtpreldword/.tprelword/.tpreldword on Mips.
    303   const char *DTPRel32Directive = nullptr;
    304   const char *DTPRel64Directive = nullptr;
    305   const char *TPRel32Directive = nullptr;
    306   const char *TPRel64Directive = nullptr;
    307 
    308   /// This is true if this target uses "Sun Style" syntax for section switching
    309   /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
    310   /// .section directives.  Defaults to false.
    311   bool SunStyleELFSectionSwitchSyntax = false;
    312 
    313   /// This is true if this target uses ELF '.section' directive before the
    314   /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
    315   /// directive only.  Defaults to false.
    316   bool UsesELFSectionDirectiveForBSS = false;
    317 
    318   bool NeedsDwarfSectionOffsetDirective = false;
    319 
    320   //===--- Alignment Information ----------------------------------------===//
    321 
    322   /// If this is true (the default) then the asmprinter emits ".align N"
    323   /// directives, where N is the number of bytes to align to.  Otherwise, it
    324   /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary.  Defaults
    325   /// to true.
    326   bool AlignmentIsInBytes = true;
    327 
    328   /// If non-zero, this is used to fill the executable space created as the
    329   /// result of a alignment directive.  Defaults to 0
    330   unsigned TextAlignFillValue = 0;
    331 
    332   //===--- Global Variable Emission Directives --------------------------===//
    333 
    334   /// This is the directive used to declare a global entity. Defaults to
    335   /// ".globl".
    336   const char *GlobalDirective;
    337 
    338   /// True if the expression
    339   ///   .long f - g
    340   /// uses a relocation but it can be suppressed by writing
    341   ///   a = f - g
    342   ///   .long a
    343   bool SetDirectiveSuppressesReloc = false;
    344 
    345   /// False if the assembler requires that we use
    346   /// \code
    347   ///   Lc = a - b
    348   ///   .long Lc
    349   /// \endcode
    350   //
    351   /// instead of
    352   //
    353   /// \code
    354   ///   .long a - b
    355   /// \endcode
    356   ///
    357   ///  Defaults to true.
    358   bool HasAggressiveSymbolFolding = true;
    359 
    360   /// True is .comm's and .lcomms optional alignment is to be specified in bytes
    361   /// instead of log2(n).  Defaults to true.
    362   bool COMMDirectiveAlignmentIsInBytes = true;
    363 
    364   /// Describes if the .lcomm directive for the target supports an alignment
    365   /// argument and how it is interpreted.  Defaults to NoAlignment.
    366   LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
    367 
    368   /// True if the target only has basename for .file directive. False if the
    369   /// target also needs the directory along with the basename. Defaults to true.
    370   bool HasBasenameOnlyForFileDirective = true;
    371 
    372   /// True if the target represents string constants as mostly raw characters in
    373   /// paired double quotation with paired double quotation marks as the escape
    374   /// mechanism to represent a double quotation mark within the string. Defaults
    375   /// to false.
    376   bool HasPairedDoubleQuoteStringConstants = false;
    377 
    378   // True if the target allows .align directives on functions. This is true for
    379   // most targets, so defaults to true.
    380   bool HasFunctionAlignment = true;
    381 
    382   /// True if the target has .type and .size directives, this is true for most
    383   /// ELF targets.  Defaults to true.
    384   bool HasDotTypeDotSizeDirective = true;
    385 
    386   /// True if the target has a single parameter .file directive, this is true
    387   /// for ELF targets.  Defaults to true.
    388   bool HasSingleParameterDotFile = true;
    389 
    390   /// True if the target has a .ident directive, this is true for ELF targets.
    391   /// Defaults to false.
    392   bool HasIdentDirective = false;
    393 
    394   /// True if this target supports the MachO .no_dead_strip directive.  Defaults
    395   /// to false.
    396   bool HasNoDeadStrip = false;
    397 
    398   /// True if this target supports the MachO .alt_entry directive.  Defaults to
    399   /// false.
    400   bool HasAltEntry = false;
    401 
    402   /// Used to declare a global as being a weak symbol. Defaults to ".weak".
    403   const char *WeakDirective;
    404 
    405   /// This directive, if non-null, is used to declare a global as being a weak
    406   /// undefined symbol.  Defaults to nullptr.
    407   const char *WeakRefDirective = nullptr;
    408 
    409   /// True if we have a directive to declare a global as being a weak defined
    410   /// symbol.  Defaults to false.
    411   bool HasWeakDefDirective = false;
    412 
    413   /// True if we have a directive to declare a global as being a weak defined
    414   /// symbol that can be hidden (unexported).  Defaults to false.
    415   bool HasWeakDefCanBeHiddenDirective = false;
    416 
    417   /// True if we should mark symbols as global instead of weak, for
    418   /// weak*/linkonce*, if the symbol has a comdat.
    419   /// Defaults to false.
    420   bool AvoidWeakIfComdat = false;
    421 
    422   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
    423   /// hidden visibility.  Defaults to MCSA_Hidden.
    424   MCSymbolAttr HiddenVisibilityAttr = MCSA_Hidden;
    425 
    426   /// This attribute, if not MCSA_Invalid, is used to declare an undefined
    427   /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
    428   MCSymbolAttr HiddenDeclarationVisibilityAttr = MCSA_Hidden;
    429 
    430   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
    431   /// protected visibility.  Defaults to MCSA_Protected
    432   MCSymbolAttr ProtectedVisibilityAttr = MCSA_Protected;
    433 
    434   //===--- Dwarf Emission Directives -----------------------------------===//
    435 
    436   /// True if target supports emission of debugging information.  Defaults to
    437   /// false.
    438   bool SupportsDebugInformation = false;
    439 
    440   /// Exception handling format for the target.  Defaults to None.
    441   ExceptionHandling ExceptionsType = ExceptionHandling::None;
    442 
    443   /// True if target uses CFI unwind information for debugging purpose when
    444   /// `ExceptionsType == ExceptionHandling::None`.
    445   bool UsesCFIForDebug = false;
    446 
    447   /// Windows exception handling data (.pdata) encoding.  Defaults to Invalid.
    448   WinEH::EncodingType WinEHEncodingType = WinEH::EncodingType::Invalid;
    449 
    450   /// True if Dwarf2 output generally uses relocations for references to other
    451   /// .debug_* sections.
    452   bool DwarfUsesRelocationsAcrossSections = true;
    453 
    454   /// True if DWARF FDE symbol reference relocations should be replaced by an
    455   /// absolute difference.
    456   bool DwarfFDESymbolsUseAbsDiff = false;
    457 
    458   /// True if the target supports generating the DWARF line table through using
    459   /// the .loc/.file directives. Defaults to true.
    460   bool UsesDwarfFileAndLocDirectives = true;
    461 
    462   /// True if the target needs the DWARF section length in the header (if any)
    463   /// of the DWARF section in the assembly file. Defaults to true.
    464   bool DwarfSectionSizeRequired = true;
    465 
    466   /// True if dwarf register numbers are printed instead of symbolic register
    467   /// names in .cfi_* directives.  Defaults to false.
    468   bool DwarfRegNumForCFI = false;
    469 
    470   /// True if target uses parens to indicate the symbol variant instead of @.
    471   /// For example, foo(plt) instead of foo@plt.  Defaults to false.
    472   bool UseParensForSymbolVariant = false;
    473 
    474   /// True if the target supports flags in ".loc" directive, false if only
    475   /// location is allowed.
    476   bool SupportsExtendedDwarfLocDirective = true;
    477 
    478   //===--- Prologue State ----------------------------------------------===//
    479 
    480   std::vector<MCCFIInstruction> InitialFrameState;
    481 
    482   //===--- Integrated Assembler Information ----------------------------===//
    483 
    484   // Generated object files can use all ELF features supported by GNU ld of
    485   // this binutils version and later. INT_MAX means all features can be used,
    486   // regardless of GNU ld support. The default value is referenced by
    487   // clang/Driver/Options.td.
    488   std::pair<int, int> BinutilsVersion = {2, 26};
    489 
    490   /// Should we use the integrated assembler?
    491   /// The integrated assembler should be enabled by default (by the
    492   /// constructors) when failing to parse a valid piece of assembly (inline
    493   /// or otherwise) is considered a bug. It may then be overridden after
    494   /// construction (see LLVMTargetMachine::initAsmInfo()).
    495   bool UseIntegratedAssembler;
    496 
    497   /// Preserve Comments in assembly
    498   bool PreserveAsmComments;
    499 
    500   /// Compress DWARF debug sections. Defaults to no compression.
    501   DebugCompressionType CompressDebugSections = DebugCompressionType::None;
    502 
    503   /// True if the integrated assembler should interpret 'a >> b' constant
    504   /// expressions as logical rather than arithmetic.
    505   bool UseLogicalShr = true;
    506 
    507   // If true, emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL, on
    508   // X86_64 ELF.
    509   bool RelaxELFRelocations = true;
    510 
    511   // If true, then the lexer and expression parser will support %neg(),
    512   // %hi(), and similar unary operators.
    513   bool HasMipsExpressions = false;
    514 
    515   // If true, use Motorola-style integers in Assembly (ex. $0ac).
    516   bool UseMotorolaIntegers = false;
    517 
    518   // If true, emit function descriptor symbol on AIX.
    519   bool NeedsFunctionDescriptors = false;
    520 
    521 public:
    522   explicit MCAsmInfo();
    523   virtual ~MCAsmInfo();
    524 
    525   /// Get the code pointer size in bytes.
    526   unsigned getCodePointerSize() const { return CodePointerSize; }
    527 
    528   /// Get the callee-saved register stack slot
    529   /// size in bytes.
    530   unsigned getCalleeSaveStackSlotSize() const {
    531     return CalleeSaveStackSlotSize;
    532   }
    533 
    534   /// True if the target is little endian.
    535   bool isLittleEndian() const { return IsLittleEndian; }
    536 
    537   /// True if target stack grow up.
    538   bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
    539 
    540   bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
    541 
    542   // Data directive accessors.
    543 
    544   const char *getData8bitsDirective() const { return Data8bitsDirective; }
    545   const char *getData16bitsDirective() const { return Data16bitsDirective; }
    546   const char *getData32bitsDirective() const { return Data32bitsDirective; }
    547   const char *getData64bitsDirective() const { return Data64bitsDirective; }
    548   bool supportsSignedData() const { return SupportsSignedData; }
    549   const char *getGPRel64Directive() const { return GPRel64Directive; }
    550   const char *getGPRel32Directive() const { return GPRel32Directive; }
    551   const char *getDTPRel64Directive() const { return DTPRel64Directive; }
    552   const char *getDTPRel32Directive() const { return DTPRel32Directive; }
    553   const char *getTPRel64Directive() const { return TPRel64Directive; }
    554   const char *getTPRel32Directive() const { return TPRel32Directive; }
    555 
    556   /// Targets can implement this method to specify a section to switch to if the
    557   /// translation unit doesn't have any trampolines that require an executable
    558   /// stack.
    559   virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
    560     return nullptr;
    561   }
    562 
    563   /// True if the section is atomized using the symbols in it.
    564   /// This is false if the section is not atomized at all (most ELF sections) or
    565   /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
    566   /// example).
    567   virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
    568 
    569   virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
    570                                                     unsigned Encoding,
    571                                                     MCStreamer &Streamer) const;
    572 
    573   virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
    574                                             unsigned Encoding,
    575                                             MCStreamer &Streamer) const;
    576 
    577   /// Return true if C is an acceptable character inside a symbol name.
    578   virtual bool isAcceptableChar(char C) const;
    579 
    580   /// Return true if the identifier \p Name does not need quotes to be
    581   /// syntactically correct.
    582   virtual bool isValidUnquotedName(StringRef Name) const;
    583 
    584   /// Return true if the .section directive should be omitted when
    585   /// emitting \p SectionName.  For example:
    586   ///
    587   /// shouldOmitSectionDirective(".text")
    588   ///
    589   /// returns false => .section .text,#alloc,#execinstr
    590   /// returns true  => .text
    591   virtual bool shouldOmitSectionDirective(StringRef SectionName) const;
    592 
    593   bool usesSunStyleELFSectionSwitchSyntax() const {
    594     return SunStyleELFSectionSwitchSyntax;
    595   }
    596 
    597   bool usesELFSectionDirectiveForBSS() const {
    598     return UsesELFSectionDirectiveForBSS;
    599   }
    600 
    601   bool needsDwarfSectionOffsetDirective() const {
    602     return NeedsDwarfSectionOffsetDirective;
    603   }
    604 
    605   // Accessors.
    606 
    607   bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
    608   bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
    609   bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
    610   bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
    611   bool hasVisibilityOnlyWithLinkage() const {
    612     return HasVisibilityOnlyWithLinkage;
    613   }
    614 
    615   /// Returns the maximum possible encoded instruction size in bytes. If \p STI
    616   /// is null, this should be the maximum size for any subtarget.
    617   virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI = nullptr) const {
    618     return MaxInstLength;
    619   }
    620 
    621   unsigned getMinInstAlignment() const { return MinInstAlignment; }
    622   bool getDollarIsPC() const { return DollarIsPC; }
    623   bool getDotIsPC() const { return DotIsPC; }
    624   bool getStarIsPC() const { return StarIsPC; }
    625   const char *getSeparatorString() const { return SeparatorString; }
    626 
    627   /// This indicates the column (zero-based) at which asm comments should be
    628   /// printed.
    629   unsigned getCommentColumn() const { return 40; }
    630 
    631   StringRef getCommentString() const { return CommentString; }
    632   bool getRestrictCommentStringToStartOfStatement() const {
    633     return RestrictCommentStringToStartOfStatement;
    634   }
    635   bool shouldAllowAdditionalComments() const { return AllowAdditionalComments; }
    636   bool getEmitGNUAsmStartIndentationMarker() const {
    637     return EmitGNUAsmStartIndentationMarker;
    638   }
    639   const char *getLabelSuffix() const { return LabelSuffix; }
    640 
    641   bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
    642   bool needsLocalForSize() const { return NeedsLocalForSize; }
    643   StringRef getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
    644   StringRef getPrivateLabelPrefix() const { return PrivateLabelPrefix; }
    645 
    646   bool hasLinkerPrivateGlobalPrefix() const {
    647     return !LinkerPrivateGlobalPrefix.empty();
    648   }
    649 
    650   StringRef getLinkerPrivateGlobalPrefix() const {
    651     if (hasLinkerPrivateGlobalPrefix())
    652       return LinkerPrivateGlobalPrefix;
    653     return getPrivateGlobalPrefix();
    654   }
    655 
    656   const char *getInlineAsmStart() const { return InlineAsmStart; }
    657   const char *getInlineAsmEnd() const { return InlineAsmEnd; }
    658   const char *getCode16Directive() const { return Code16Directive; }
    659   const char *getCode32Directive() const { return Code32Directive; }
    660   const char *getCode64Directive() const { return Code64Directive; }
    661   unsigned getAssemblerDialect() const { return AssemblerDialect; }
    662   bool doesAllowAtInName() const { return AllowAtInName; }
    663   bool doesAllowQuestionAtStartOfIdentifier() const {
    664     return AllowQuestionAtStartOfIdentifier;
    665   }
    666   bool doesAllowAtAtStartOfIdentifier() const {
    667     return AllowAtAtStartOfIdentifier;
    668   }
    669   bool doesAllowDollarAtStartOfIdentifier() const {
    670     return AllowDollarAtStartOfIdentifier;
    671   }
    672   bool doesAllowHashAtStartOfIdentifier() const {
    673     return AllowHashAtStartOfIdentifier;
    674   }
    675   bool supportsNameQuoting() const { return SupportsQuotedNames; }
    676 
    677   bool doesSupportDataRegionDirectives() const {
    678     return UseDataRegionDirectives;
    679   }
    680 
    681   bool useDotAlignForAlignment() const {
    682     return UseDotAlignForAlignment;
    683   }
    684 
    685   bool hasLEB128Directives() const { return HasLEB128Directives; }
    686 
    687   const char *getZeroDirective() const { return ZeroDirective; }
    688   bool doesZeroDirectiveSupportNonZeroValue() const {
    689     return ZeroDirectiveSupportsNonZeroValue;
    690   }
    691   const char *getAsciiDirective() const { return AsciiDirective; }
    692   const char *getAscizDirective() const { return AscizDirective; }
    693   const char *getByteListDirective() const { return ByteListDirective; }
    694   const char *getPlainStringDirective() const { return PlainStringDirective; }
    695   AsmCharLiteralSyntax characterLiteralSyntax() const {
    696     return CharacterLiteralSyntax;
    697   }
    698   bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
    699   unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
    700   const char *getGlobalDirective() const { return GlobalDirective; }
    701 
    702   bool doesSetDirectiveSuppressReloc() const {
    703     return SetDirectiveSuppressesReloc;
    704   }
    705 
    706   bool hasAggressiveSymbolFolding() const { return HasAggressiveSymbolFolding; }
    707 
    708   bool getCOMMDirectiveAlignmentIsInBytes() const {
    709     return COMMDirectiveAlignmentIsInBytes;
    710   }
    711 
    712   LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
    713     return LCOMMDirectiveAlignmentType;
    714   }
    715 
    716   bool hasBasenameOnlyForFileDirective() const {
    717     return HasBasenameOnlyForFileDirective;
    718   }
    719   bool hasPairedDoubleQuoteStringConstants() const {
    720     return HasPairedDoubleQuoteStringConstants;
    721   }
    722   bool hasFunctionAlignment() const { return HasFunctionAlignment; }
    723   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
    724   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
    725   bool hasIdentDirective() const { return HasIdentDirective; }
    726   bool hasNoDeadStrip() const { return HasNoDeadStrip; }
    727   bool hasAltEntry() const { return HasAltEntry; }
    728   const char *getWeakDirective() const { return WeakDirective; }
    729   const char *getWeakRefDirective() const { return WeakRefDirective; }
    730   bool hasWeakDefDirective() const { return HasWeakDefDirective; }
    731 
    732   bool hasWeakDefCanBeHiddenDirective() const {
    733     return HasWeakDefCanBeHiddenDirective;
    734   }
    735 
    736   bool avoidWeakIfComdat() const { return AvoidWeakIfComdat; }
    737 
    738   MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
    739 
    740   MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
    741     return HiddenDeclarationVisibilityAttr;
    742   }
    743 
    744   MCSymbolAttr getProtectedVisibilityAttr() const {
    745     return ProtectedVisibilityAttr;
    746   }
    747 
    748   bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
    749 
    750   ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
    751   WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
    752 
    753   void setExceptionsType(ExceptionHandling EH) {
    754     ExceptionsType = EH;
    755   }
    756 
    757   bool doesUseCFIForDebug() const { return UsesCFIForDebug; }
    758 
    759   /// Returns true if the exception handling method for the platform uses call
    760   /// frame information to unwind.
    761   bool usesCFIForEH() const {
    762     return (ExceptionsType == ExceptionHandling::DwarfCFI ||
    763             ExceptionsType == ExceptionHandling::ARM || usesWindowsCFI());
    764   }
    765 
    766   bool usesWindowsCFI() const {
    767     return ExceptionsType == ExceptionHandling::WinEH &&
    768            (WinEHEncodingType != WinEH::EncodingType::Invalid &&
    769             WinEHEncodingType != WinEH::EncodingType::X86);
    770   }
    771 
    772   bool doesDwarfUseRelocationsAcrossSections() const {
    773     return DwarfUsesRelocationsAcrossSections;
    774   }
    775 
    776   bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
    777   bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
    778   bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
    779   bool supportsExtendedDwarfLocDirective() const {
    780     return SupportsExtendedDwarfLocDirective;
    781   }
    782 
    783   bool usesDwarfFileAndLocDirectives() const {
    784     return UsesDwarfFileAndLocDirectives;
    785   }
    786 
    787   bool needsDwarfSectionSizeInHeader() const {
    788     return DwarfSectionSizeRequired;
    789   }
    790 
    791   void addInitialFrameState(const MCCFIInstruction &Inst);
    792 
    793   const std::vector<MCCFIInstruction> &getInitialFrameState() const {
    794     return InitialFrameState;
    795   }
    796 
    797   void setBinutilsVersion(std::pair<int, int> Value) {
    798     BinutilsVersion = Value;
    799   }
    800 
    801   /// Return true if assembly (inline or otherwise) should be parsed.
    802   bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
    803 
    804   bool binutilsIsAtLeast(int Major, int Minor) const {
    805     return BinutilsVersion >= std::make_pair(Major, Minor);
    806   }
    807 
    808   /// Set whether assembly (inline or otherwise) should be parsed.
    809   virtual void setUseIntegratedAssembler(bool Value) {
    810     UseIntegratedAssembler = Value;
    811   }
    812 
    813   /// Return true if assembly (inline or otherwise) should be parsed.
    814   bool preserveAsmComments() const { return PreserveAsmComments; }
    815 
    816   /// Set whether assembly (inline or otherwise) should be parsed.
    817   virtual void setPreserveAsmComments(bool Value) {
    818     PreserveAsmComments = Value;
    819   }
    820 
    821   DebugCompressionType compressDebugSections() const {
    822     return CompressDebugSections;
    823   }
    824 
    825   void setCompressDebugSections(DebugCompressionType CompressDebugSections) {
    826     this->CompressDebugSections = CompressDebugSections;
    827   }
    828 
    829   bool shouldUseLogicalShr() const { return UseLogicalShr; }
    830 
    831   bool canRelaxRelocations() const { return RelaxELFRelocations; }
    832   void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; }
    833   bool hasMipsExpressions() const { return HasMipsExpressions; }
    834   bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
    835   bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
    836 };
    837 
    838 } // end namespace llvm
    839 
    840 #endif // LLVM_MC_MCASMINFO_H
    841