a6fa6582abe829043631e12279fd8f7916418c32
[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   DebugLabelSuffix = ":";
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   AllowUTF8 = true;
54   UseDataRegionDirectives = false;
55   ZeroDirective = "\t.zero\t";
56   AsciiDirective = "\t.ascii\t";
57   AscizDirective = "\t.asciz\t";
58   Data8bitsDirective = "\t.byte\t";
59   Data16bitsDirective = "\t.short\t";
60   Data32bitsDirective = "\t.long\t";
61   Data64bitsDirective = "\t.quad\t";
62   SunStyleELFSectionSwitchSyntax = false;
63   UsesELFSectionDirectiveForBSS = false;
64   AlignDirective = "\t.align\t";
65   AlignmentIsInBytes = true;
66   TextAlignFillValue = 0;
67   GPRel64Directive = 0;
68   GPRel32Directive = 0;
69   GlobalDirective = "\t.globl\t";
70   HasSetDirective = true;
71   HasAggressiveSymbolFolding = true;
72   COMMDirectiveAlignmentIsInBytes = true;
73   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
74   HasDotTypeDotSizeDirective = true;
75   HasSingleParameterDotFile = true;
76   HasNoDeadStrip = false;
77   HasSymbolResolver = false;
78   WeakRefDirective = 0;
79   WeakDefDirective = 0;
80   LinkOnceDirective = 0;
81   HiddenVisibilityAttr = MCSA_Hidden;
82   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
83   ProtectedVisibilityAttr = MCSA_Protected;
84   HasLEB128 = false;
85   SupportsDebugInformation = false;
86   ExceptionsType = ExceptionHandling::None;
87   DwarfUsesInlineInfoSection = false;
88   DwarfSectionOffsetDirective = 0;
89   DwarfUsesRelocationsAcrossSections = 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 }