Home | History | Annotate | Download | only in MC
      1 //===-- MCAsmInfo.cpp - Asm Info -------------------------------------------==//
      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 defines target asm properties related what form asm statements
     11 // should take.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #include "llvm/MC/MCAsmInfo.h"
     16 #include "llvm/MC/MCContext.h"
     17 #include "llvm/MC/MCExpr.h"
     18 #include "llvm/MC/MCStreamer.h"
     19 #include "llvm/Support/DataTypes.h"
     20 #include "llvm/Support/Dwarf.h"
     21 #include <cctype>
     22 #include <cstring>
     23 using namespace llvm;
     24 
     25 MCAsmInfo::MCAsmInfo() {
     26   PointerSize = 4;
     27   CalleeSaveStackSlotSize = 4;
     28 
     29   IsLittleEndian = true;
     30   StackGrowsUp = false;
     31   HasSubsectionsViaSymbols = false;
     32   HasMachoZeroFillDirective = false;
     33   HasMachoTBSSDirective = false;
     34   HasStaticCtorDtorReferenceInStaticMode = false;
     35   LinkerRequiresNonEmptyDwarfLines = false;
     36   MaxInstLength = 4;
     37   PCSymbol = "$";
     38   SeparatorString = ";";
     39   CommentColumn = 40;
     40   CommentString = "#";
     41   LabelSuffix = ":";
     42   DebugLabelSuffix = ":";
     43   GlobalPrefix = "";
     44   PrivateGlobalPrefix = ".";
     45   LinkerPrivateGlobalPrefix = "";
     46   InlineAsmStart = "APP";
     47   InlineAsmEnd = "NO_APP";
     48   Code16Directive = ".code16";
     49   Code32Directive = ".code32";
     50   Code64Directive = ".code64";
     51   AssemblerDialect = 0;
     52   AllowQuotesInName = false;
     53   AllowNameToStartWithDigit = false;
     54   AllowPeriodsInName = true;
     55   AllowUTF8 = true;
     56   UseDataRegionDirectives = false;
     57   ZeroDirective = "\t.zero\t";
     58   AsciiDirective = "\t.ascii\t";
     59   AscizDirective = "\t.asciz\t";
     60   Data8bitsDirective = "\t.byte\t";
     61   Data16bitsDirective = "\t.short\t";
     62   Data32bitsDirective = "\t.long\t";
     63   Data64bitsDirective = "\t.quad\t";
     64   SunStyleELFSectionSwitchSyntax = false;
     65   UsesELFSectionDirectiveForBSS = false;
     66   AlignDirective = "\t.align\t";
     67   AlignmentIsInBytes = true;
     68   TextAlignFillValue = 0;
     69   GPRel64Directive = 0;
     70   GPRel32Directive = 0;
     71   GlobalDirective = "\t.globl\t";
     72   HasSetDirective = true;
     73   HasAggressiveSymbolFolding = true;
     74   COMMDirectiveAlignmentIsInBytes = true;
     75   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
     76   HasDotTypeDotSizeDirective = true;
     77   HasSingleParameterDotFile = true;
     78   HasNoDeadStrip = false;
     79   HasSymbolResolver = false;
     80   WeakRefDirective = 0;
     81   WeakDefDirective = 0;
     82   LinkOnceDirective = 0;
     83   HiddenVisibilityAttr = MCSA_Hidden;
     84   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
     85   ProtectedVisibilityAttr = MCSA_Protected;
     86   HasLEB128 = false;
     87   SupportsDebugInformation = false;
     88   ExceptionsType = ExceptionHandling::None;
     89   DwarfUsesInlineInfoSection = false;
     90   DwarfSectionOffsetDirective = 0;
     91   DwarfUsesRelocationsAcrossSections = true;
     92   DwarfRegNumForCFI = false;
     93   HasMicrosoftFastStdCallMangling = false;
     94 }
     95 
     96 MCAsmInfo::~MCAsmInfo() {
     97 }
     98 
     99 
    100 unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
    101   unsigned Size = 0;
    102   do {
    103     Value >>= 7;
    104     Size += sizeof(int8_t);
    105   } while (Value);
    106   return Size;
    107 }
    108 
    109 unsigned MCAsmInfo::getSLEB128Size(int Value) {
    110   unsigned Size = 0;
    111   int Sign = Value >> (8 * sizeof(Value) - 1);
    112   bool IsMore;
    113 
    114   do {
    115     unsigned Byte = Value & 0x7f;
    116     Value >>= 7;
    117     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
    118     Size += sizeof(int8_t);
    119   } while (IsMore);
    120   return Size;
    121 }
    122 
    123 const MCExpr *
    124 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
    125                                        unsigned Encoding,
    126                                        MCStreamer &Streamer) const {
    127   return getExprForFDESymbol(Sym, Encoding, Streamer);
    128 }
    129 
    130 const MCExpr *
    131 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
    132                                unsigned Encoding,
    133                                MCStreamer &Streamer) const {
    134   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
    135     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
    136 
    137   MCContext &Context = Streamer.getContext();
    138   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
    139   MCSymbol *PCSym = Context.CreateTempSymbol();
    140   Streamer.EmitLabel(PCSym);
    141   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
    142   return MCBinaryExpr::CreateSub(Res, PC, Context);
    143 }
    144