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   StructorOutputOrder = Structors::ReversePriorityOrder;
     33   HasStaticCtorDtorReferenceInStaticMode = false;
     34   LinkerRequiresNonEmptyDwarfLines = false;
     35   MaxInstLength = 4;
     36   PCSymbol = "$";
     37   SeparatorString = ";";
     38   CommentColumn = 40;
     39   CommentString = "#";
     40   LabelSuffix = ":";
     41   GlobalPrefix = "";
     42   PrivateGlobalPrefix = ".";
     43   LinkerPrivateGlobalPrefix = "";
     44   InlineAsmStart = "APP";
     45   InlineAsmEnd = "NO_APP";
     46   Code16Directive = ".code16";
     47   Code32Directive = ".code32";
     48   Code64Directive = ".code64";
     49   AssemblerDialect = 0;
     50   AllowQuotesInName = false;
     51   AllowNameToStartWithDigit = false;
     52   AllowPeriodsInName = 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   GPRel32Directive = 0;
     72   GlobalDirective = "\t.globl\t";
     73   HasSetDirective = true;
     74   HasAggressiveSymbolFolding = true;
     75   LCOMMDirectiveType = LCOMM::None;
     76   COMMDirectiveAlignmentIsInBytes = true;
     77   HasDotTypeDotSizeDirective = true;
     78   HasSingleParameterDotFile = true;
     79   HasNoDeadStrip = false;
     80   HasSymbolResolver = false;
     81   WeakRefDirective = 0;
     82   WeakDefDirective = 0;
     83   LinkOnceDirective = 0;
     84   HiddenVisibilityAttr = MCSA_Hidden;
     85   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
     86   ProtectedVisibilityAttr = MCSA_Protected;
     87   HasLEB128 = false;
     88   SupportsDebugInformation = false;
     89   ExceptionsType = ExceptionHandling::None;
     90   DwarfUsesInlineInfoSection = false;
     91   DwarfRequiresRelocationForSectionOffset = true;
     92   DwarfSectionOffsetDirective = 0;
     93   DwarfUsesLabelOffsetForRanges = true;
     94   DwarfRegNumForCFI = false;
     95   HasMicrosoftFastStdCallMangling = false;
     96 
     97   AsmTransCBE = 0;
     98 }
     99 
    100 MCAsmInfo::~MCAsmInfo() {
    101 }
    102 
    103 
    104 unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
    105   unsigned Size = 0;
    106   do {
    107     Value >>= 7;
    108     Size += sizeof(int8_t);
    109   } while (Value);
    110   return Size;
    111 }
    112 
    113 unsigned MCAsmInfo::getSLEB128Size(int Value) {
    114   unsigned Size = 0;
    115   int Sign = Value >> (8 * sizeof(Value) - 1);
    116   bool IsMore;
    117 
    118   do {
    119     unsigned Byte = Value & 0x7f;
    120     Value >>= 7;
    121     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
    122     Size += sizeof(int8_t);
    123   } while (IsMore);
    124   return Size;
    125 }
    126 
    127 const MCExpr *
    128 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
    129                                        unsigned Encoding,
    130                                        MCStreamer &Streamer) const {
    131   return getExprForFDESymbol(Sym, Encoding, Streamer);
    132 }
    133 
    134 const MCExpr *
    135 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
    136                                unsigned Encoding,
    137                                MCStreamer &Streamer) const {
    138   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
    139     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
    140 
    141   MCContext &Context = Streamer.getContext();
    142   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
    143   MCSymbol *PCSym = Context.CreateTempSymbol();
    144   Streamer.EmitLabel(PCSym);
    145   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
    146   return MCBinaryExpr::CreateSub(Res, PC, Context);
    147 }
    148