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