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 MinInstAlignment = 1; 38 PCSymbol = "$"; 39 SeparatorString = ";"; 40 CommentColumn = 40; 41 CommentString = "#"; 42 LabelSuffix = ":"; 43 DebugLabelSuffix = ":"; 44 GlobalPrefix = ""; 45 PrivateGlobalPrefix = "."; 46 LinkerPrivateGlobalPrefix = ""; 47 InlineAsmStart = "APP"; 48 InlineAsmEnd = "NO_APP"; 49 Code16Directive = ".code16"; 50 Code32Directive = ".code32"; 51 Code64Directive = ".code64"; 52 AssemblerDialect = 0; 53 AllowQuotesInName = false; 54 AllowNameToStartWithDigit = false; 55 AllowPeriodsInName = true; 56 AllowUTF8 = true; 57 UseDataRegionDirectives = false; 58 ZeroDirective = "\t.zero\t"; 59 AsciiDirective = "\t.ascii\t"; 60 AscizDirective = "\t.asciz\t"; 61 Data8bitsDirective = "\t.byte\t"; 62 Data16bitsDirective = "\t.short\t"; 63 Data32bitsDirective = "\t.long\t"; 64 Data64bitsDirective = "\t.quad\t"; 65 SunStyleELFSectionSwitchSyntax = false; 66 UsesELFSectionDirectiveForBSS = false; 67 AlignDirective = "\t.align\t"; 68 AlignmentIsInBytes = true; 69 TextAlignFillValue = 0; 70 GPRel64Directive = 0; 71 GPRel32Directive = 0; 72 GlobalDirective = "\t.globl\t"; 73 HasSetDirective = true; 74 HasAggressiveSymbolFolding = true; 75 COMMDirectiveAlignmentIsInBytes = true; 76 LCOMMDirectiveAlignmentType = LCOMM::NoAlignment; 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 DwarfUsesRelocationsAcrossSections = true; 92 DwarfRegNumForCFI = false; 93 HasMicrosoftFastStdCallMangling = false; 94 NeedsDwarfSectionOffsetDirective = false; 95 } 96 97 MCAsmInfo::~MCAsmInfo() { 98 } 99 100 101 unsigned MCAsmInfo::getULEB128Size(uint64_t Value) { 102 unsigned Size = 0; 103 do { 104 Value >>= 7; 105 Size += sizeof(int8_t); 106 } while (Value); 107 return Size; 108 } 109 110 unsigned MCAsmInfo::getSLEB128Size(int64_t Value) { 111 unsigned Size = 0; 112 int Sign = Value >> (8 * sizeof(Value) - 1); 113 bool IsMore; 114 115 do { 116 unsigned Byte = Value & 0x7f; 117 Value >>= 7; 118 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; 119 Size += sizeof(int8_t); 120 } while (IsMore); 121 return Size; 122 } 123 124 const MCExpr * 125 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym, 126 unsigned Encoding, 127 MCStreamer &Streamer) const { 128 return getExprForFDESymbol(Sym, Encoding, Streamer); 129 } 130 131 const MCExpr * 132 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym, 133 unsigned Encoding, 134 MCStreamer &Streamer) const { 135 if (!(Encoding & dwarf::DW_EH_PE_pcrel)) 136 return MCSymbolRefExpr::Create(Sym, Streamer.getContext()); 137 138 MCContext &Context = Streamer.getContext(); 139 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context); 140 MCSymbol *PCSym = Context.CreateTempSymbol(); 141 Streamer.EmitLabel(PCSym); 142 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context); 143 return MCBinaryExpr::CreateSub(Res, PC, Context); 144 } 145