LLVM API Documentation

MCAsmInfo.cpp
Go to the documentation of this file.
00001 //===-- MCAsmInfo.cpp - Asm Info -------------------------------------------==//
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 defines target asm properties related what form asm statements
00011 // should take.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "llvm/MC/MCAsmInfo.h"
00016 #include "llvm/MC/MCContext.h"
00017 #include "llvm/MC/MCExpr.h"
00018 #include "llvm/MC/MCStreamer.h"
00019 #include "llvm/Support/DataTypes.h"
00020 #include "llvm/Support/Dwarf.h"
00021 #include <cctype>
00022 #include <cstring>
00023 using namespace llvm;
00024 
00025 MCAsmInfo::MCAsmInfo() {
00026   PointerSize = 4;
00027   CalleeSaveStackSlotSize = 4;
00028 
00029   IsLittleEndian = true;
00030   StackGrowsUp = false;
00031   HasSubsectionsViaSymbols = false;
00032   HasMachoZeroFillDirective = false;
00033   HasMachoTBSSDirective = false;
00034   HasStaticCtorDtorReferenceInStaticMode = false;
00035   LinkerRequiresNonEmptyDwarfLines = false;
00036   MaxInstLength = 4;
00037   PCSymbol = "$";
00038   SeparatorString = ";";
00039   CommentColumn = 40;
00040   CommentString = "#";
00041   LabelSuffix = ":";
00042   DebugLabelSuffix = ":";
00043   GlobalPrefix = "";
00044   PrivateGlobalPrefix = ".";
00045   LinkerPrivateGlobalPrefix = "";
00046   InlineAsmStart = "APP";
00047   InlineAsmEnd = "NO_APP";
00048   Code16Directive = ".code16";
00049   Code32Directive = ".code32";
00050   Code64Directive = ".code64";
00051   AssemblerDialect = 0;
00052   AllowQuotesInName = false;
00053   AllowNameToStartWithDigit = false;
00054   AllowPeriodsInName = true;
00055   AllowUTF8 = true;
00056   UseDataRegionDirectives = false;
00057   ZeroDirective = "\t.zero\t";
00058   AsciiDirective = "\t.ascii\t";
00059   AscizDirective = "\t.asciz\t";
00060   Data8bitsDirective = "\t.byte\t";
00061   Data16bitsDirective = "\t.short\t";
00062   Data32bitsDirective = "\t.long\t";
00063   Data64bitsDirective = "\t.quad\t";
00064   SunStyleELFSectionSwitchSyntax = false;
00065   UsesELFSectionDirectiveForBSS = false;
00066   AlignDirective = "\t.align\t";
00067   AlignmentIsInBytes = true;
00068   TextAlignFillValue = 0;
00069   GPRel64Directive = 0;
00070   GPRel32Directive = 0;
00071   GlobalDirective = "\t.globl\t";
00072   HasSetDirective = true;
00073   HasAggressiveSymbolFolding = true;
00074   COMMDirectiveAlignmentIsInBytes = true;
00075   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
00076   HasDotTypeDotSizeDirective = true;
00077   HasSingleParameterDotFile = true;
00078   HasNoDeadStrip = false;
00079   HasSymbolResolver = false;
00080   WeakRefDirective = 0;
00081   WeakDefDirective = 0;
00082   LinkOnceDirective = 0;
00083   HiddenVisibilityAttr = MCSA_Hidden;
00084   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
00085   ProtectedVisibilityAttr = MCSA_Protected;
00086   HasLEB128 = false;
00087   SupportsDebugInformation = false;
00088   ExceptionsType = ExceptionHandling::None;
00089   DwarfUsesInlineInfoSection = false;
00090   DwarfUsesRelocationsAcrossSections = true;
00091   DwarfRegNumForCFI = false;
00092   HasMicrosoftFastStdCallMangling = false;
00093   NeedsDwarfSectionOffsetDirective = false;
00094 }
00095 
00096 MCAsmInfo::~MCAsmInfo() {
00097 }
00098 
00099 
00100 unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
00101   unsigned Size = 0;
00102   do {
00103     Value >>= 7;
00104     Size += sizeof(int8_t);
00105   } while (Value);
00106   return Size;
00107 }
00108 
00109 unsigned MCAsmInfo::getSLEB128Size(int Value) {
00110   unsigned Size = 0;
00111   int Sign = Value >> (8 * sizeof(Value) - 1);
00112   bool IsMore;
00113 
00114   do {
00115     unsigned Byte = Value & 0x7f;
00116     Value >>= 7;
00117     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
00118     Size += sizeof(int8_t);
00119   } while (IsMore);
00120   return Size;
00121 }
00122 
00123 const MCExpr *
00124 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
00125                                        unsigned Encoding,
00126                                        MCStreamer &Streamer) const {
00127   return getExprForFDESymbol(Sym, Encoding, Streamer);
00128 }
00129 
00130 const MCExpr *
00131 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
00132                                unsigned Encoding,
00133                                MCStreamer &Streamer) const {
00134   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
00135     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
00136 
00137   MCContext &Context = Streamer.getContext();
00138   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
00139   MCSymbol *PCSym = Context.CreateTempSymbol();
00140   Streamer.EmitLabel(PCSym);
00141   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
00142   return MCBinaryExpr::CreateSub(Res, PC, Context);
00143 }