Make the llvm mangler depend only on DataLayout.
[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   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   DollarIsPC = false;
39   SeparatorString = ";";
40   CommentColumn = 40;
41   CommentString = "#";
42   LabelSuffix = ":";
43   DebugLabelSuffix = ":";
44   PrivateGlobalPrefix = "L";
45   InlineAsmStart = "APP";
46   InlineAsmEnd = "NO_APP";
47   Code16Directive = ".code16";
48   Code32Directive = ".code32";
49   Code64Directive = ".code64";
50   AssemblerDialect = 0;
51   AllowAtInName = false;
52   UseDataRegionDirectives = false;
53   ZeroDirective = "\t.zero\t";
54   AsciiDirective = "\t.ascii\t";
55   AscizDirective = "\t.asciz\t";
56   Data8bitsDirective = "\t.byte\t";
57   Data16bitsDirective = "\t.short\t";
58   Data32bitsDirective = "\t.long\t";
59   Data64bitsDirective = "\t.quad\t";
60   SunStyleELFSectionSwitchSyntax = false;
61   UsesELFSectionDirectiveForBSS = false;
62   AlignDirective = "\t.align\t";
63   AlignmentIsInBytes = true;
64   TextAlignFillValue = 0;
65   GPRel64Directive = 0;
66   GPRel32Directive = 0;
67   GlobalDirective = "\t.globl\t";
68   HasSetDirective = true;
69   HasAggressiveSymbolFolding = true;
70   COMMDirectiveAlignmentIsInBytes = true;
71   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
72   HasDotTypeDotSizeDirective = true;
73   HasSingleParameterDotFile = true;
74   HasIdentDirective = false;
75   HasNoDeadStrip = false;
76   WeakRefDirective = 0;
77   HasWeakDefDirective = false;
78   HasWeakDefCanBeHiddenDirective = false;
79   HasLinkOnceDirective = false;
80   HiddenVisibilityAttr = MCSA_Hidden;
81   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
82   ProtectedVisibilityAttr = MCSA_Protected;
83   HasLEB128 = false;
84   SupportsDebugInformation = false;
85   ExceptionsType = ExceptionHandling::None;
86   DwarfUsesRelocationsAcrossSections = true;
87   DwarfRegNumForCFI = false;
88   NeedsDwarfSectionOffsetDirective = false;
89   UseParensForSymbolVariant = false;
90 }
91
92 MCAsmInfo::~MCAsmInfo() {
93 }
94
95
96 unsigned MCAsmInfo::getULEB128Size(uint64_t Value) {
97   unsigned Size = 0;
98   do {
99     Value >>= 7;
100     Size += sizeof(int8_t);
101   } while (Value);
102   return Size;
103 }
104
105 unsigned MCAsmInfo::getSLEB128Size(int64_t Value) {
106   unsigned Size = 0;
107   int Sign = Value >> (8 * sizeof(Value) - 1);
108   bool IsMore;
109
110   do {
111     unsigned Byte = Value & 0x7f;
112     Value >>= 7;
113     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
114     Size += sizeof(int8_t);
115   } while (IsMore);
116   return Size;
117 }
118
119 const MCExpr *
120 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
121                                        unsigned Encoding,
122                                        MCStreamer &Streamer) const {
123   return getExprForFDESymbol(Sym, Encoding, Streamer);
124 }
125
126 const MCExpr *
127 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
128                                unsigned Encoding,
129                                MCStreamer &Streamer) const {
130   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
131     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
132
133   MCContext &Context = Streamer.getContext();
134   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
135   MCSymbol *PCSym = Context.CreateTempSymbol();
136   Streamer.EmitLabel(PCSym);
137   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
138   return MCBinaryExpr::CreateSub(Res, PC, Context);
139 }