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   IsLittleEndian = true;
     28   StackGrowsUp = false;
     29   HasSubsectionsViaSymbols = false;
     30   HasMachoZeroFillDirective = false;
     31   HasMachoTBSSDirective = false;
     32   HasStaticCtorDtorReferenceInStaticMode = false;
     33   LinkerRequiresNonEmptyDwarfLines = false;
     34   MaxInstLength = 4;
     35   PCSymbol = "$";
     36   SeparatorString = ";";
     37   CommentColumn = 40;
     38   CommentString = "#";
     39   LabelSuffix = ":";
     40   GlobalPrefix = "";
     41   PrivateGlobalPrefix = ".";
     42   LinkerPrivateGlobalPrefix = "";
     43   InlineAsmStart = "APP";
     44   InlineAsmEnd = "NO_APP";
     45   Code16Directive = ".code16";
     46   Code32Directive = ".code32";
     47   Code64Directive = ".code64";
     48   AssemblerDialect = 0;
     49   AllowQuotesInName = false;
     50   AllowNameToStartWithDigit = false;
     51   AllowPeriodsInName = true;
     52   AllowUTF8 = true;
     53   ZeroDirective = "\t.zero\t";
     54   AsciiDirective = "\t.ascii\t";
     55   AscizDirective = "\t.asciz\t";
     56   Data8bitsDirective = "\t.byte\t";
     57   Data16bitsDirective = "\t.short\t";
     58   Data32bitsDirective = "\t.long\t";
     59   Data64bitsDirective = "\t.quad\t";
     60   DataBegin = "$d.";
     61   CodeBegin = "$a.";
     62   JT8Begin = "$d.";
     63   JT16Begin = "$d.";
     64   JT32Begin = "$d.";
     65   SupportsDataRegions = false;
     66   SunStyleELFSectionSwitchSyntax = false;
     67   UsesELFSectionDirectiveForBSS = false;
     68   AlignDirective = "\t.align\t";
     69   AlignmentIsInBytes = true;
     70   TextAlignFillValue = 0;
     71   GPRel64Directive = 0;
     72   GPRel32Directive = 0;
     73   GlobalDirective = "\t.globl\t";
     74   HasSetDirective = true;
     75   HasAggressiveSymbolFolding = true;
     76   LCOMMDirectiveType = LCOMM::None;
     77   COMMDirectiveAlignmentIsInBytes = true;
     78   HasDotTypeDotSizeDirective = true;
     79   HasSingleParameterDotFile = true;
     80   HasNoDeadStrip = false;
     81   HasSymbolResolver = false;
     82   WeakRefDirective = 0;
     83   WeakDefDirective = 0;
     84   LinkOnceDirective = 0;
     85   HiddenVisibilityAttr = MCSA_Hidden;
     86   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
     87   ProtectedVisibilityAttr = MCSA_Protected;
     88   HasLEB128 = false;
     89   SupportsDebugInformation = false;
     90   ExceptionsType = ExceptionHandling::None;
     91   DwarfUsesInlineInfoSection = false;
     92   DwarfRequiresRelocationForSectionOffset = true;
     93   DwarfSectionOffsetDirective = 0;
     94   DwarfUsesLabelOffsetForRanges = true;
     95   DwarfUsesRelocationsForStringPool = true;
     96   DwarfRegNumForCFI = false;
     97   HasMicrosoftFastStdCallMangling = false;
     98 
     99   AsmTransCBE = 0;
    100 }
    101 
    102 MCAsmInfo::~MCAsmInfo() {
    103 }
    104 
    105 
    106 unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
    107   unsigned Size = 0;
    108   do {
    109     Value >>= 7;
    110     Size += sizeof(int8_t);
    111   } while (Value);
    112   return Size;
    113 }
    114 
    115 unsigned MCAsmInfo::getSLEB128Size(int Value) {
    116   unsigned Size = 0;
    117   int Sign = Value >> (8 * sizeof(Value) - 1);
    118   bool IsMore;
    119 
    120   do {
    121     unsigned Byte = Value & 0x7f;
    122     Value >>= 7;
    123     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
    124     Size += sizeof(int8_t);
    125   } while (IsMore);
    126   return Size;
    127 }
    128 
    129 const MCExpr *
    130 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
    131                                        unsigned Encoding,
    132                                        MCStreamer &Streamer) const {
    133   return getExprForFDESymbol(Sym, Encoding, Streamer);
    134 }
    135 
    136 const MCExpr *
    137 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
    138                                unsigned Encoding,
    139                                MCStreamer &Streamer) const {
    140   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
    141     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
    142 
    143   MCContext &Context = Streamer.getContext();
    144   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
    145   MCSymbol *PCSym = Context.CreateTempSymbol();
    146   Streamer.EmitLabel(PCSym);
    147   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
    148   return MCBinaryExpr::CreateSub(Res, PC, Context);
    149 }
    150