Fix a FIXME: DwarfRequiresRelocationForSectionOffset is the same as
[oota-llvm.git] / lib / MC / MCAsmInfo.cpp
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   UseDataRegionDirectives = false;
54   ZeroDirective = "\t.zero\t";
55   AsciiDirective = "\t.ascii\t";
56   AscizDirective = "\t.asciz\t";
57   Data8bitsDirective = "\t.byte\t";
58   Data16bitsDirective = "\t.short\t";
59   Data32bitsDirective = "\t.long\t";
60   Data64bitsDirective = "\t.quad\t";
61   SunStyleELFSectionSwitchSyntax = false;
62   UsesELFSectionDirectiveForBSS = false;
63   AlignDirective = "\t.align\t";
64   AlignmentIsInBytes = true;
65   TextAlignFillValue = 0;
66   GPRel64Directive = 0;
67   GPRel32Directive = 0;
68   GlobalDirective = "\t.globl\t";
69   HasSetDirective = true;
70   HasAggressiveSymbolFolding = true;
71   LCOMMDirectiveType = LCOMM::None;
72   COMMDirectiveAlignmentIsInBytes = true;
73   HasDotTypeDotSizeDirective = true;
74   HasSingleParameterDotFile = true;
75   HasNoDeadStrip = false;
76   HasSymbolResolver = false;
77   WeakRefDirective = 0;
78   WeakDefDirective = 0;
79   LinkOnceDirective = 0;
80   HiddenVisibilityAttr = MCSA_Hidden;
81   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
82   ProtectedVisibilityAttr = MCSA_Protected;
83   HasLEB128 = false;
84   SupportsDebugInformation = false;
85   ExceptionsType = ExceptionHandling::None;
86   DwarfUsesInlineInfoSection = false;
87   DwarfSectionOffsetDirective = 0;
88   DwarfUsesRelocationsAcrossSections = true;
89   DwarfUsesRelocationsForStringPool = true;
90   DwarfRegNumForCFI = false;
91   HasMicrosoftFastStdCallMangling = false;
92 }
93
94 MCAsmInfo::~MCAsmInfo() {
95 }
96
97
98 unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
99   unsigned Size = 0;
100   do {
101     Value >>= 7;
102     Size += sizeof(int8_t);
103   } while (Value);
104   return Size;
105 }
106
107 unsigned MCAsmInfo::getSLEB128Size(int Value) {
108   unsigned Size = 0;
109   int Sign = Value >> (8 * sizeof(Value) - 1);
110   bool IsMore;
111
112   do {
113     unsigned Byte = Value & 0x7f;
114     Value >>= 7;
115     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
116     Size += sizeof(int8_t);
117   } while (IsMore);
118   return Size;
119 }
120
121 const MCExpr *
122 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
123                                        unsigned Encoding,
124                                        MCStreamer &Streamer) const {
125   return getExprForFDESymbol(Sym, Encoding, Streamer);
126 }
127
128 const MCExpr *
129 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
130                                unsigned Encoding,
131                                MCStreamer &Streamer) const {
132   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
133     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
134
135   MCContext &Context = Streamer.getContext();
136   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
137   MCSymbol *PCSym = Context.CreateTempSymbol();
138   Streamer.EmitLabel(PCSym);
139   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
140   return MCBinaryExpr::CreateSub(Res, PC, Context);
141 }