Add a new MachineJumpTableInfo entry type, EK_GPRel64BlockAddress, which is
[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   ZeroDirective = "\t.zero\t";
53   AsciiDirective = "\t.ascii\t";
54   AscizDirective = "\t.asciz\t";
55   Data8bitsDirective = "\t.byte\t";
56   Data16bitsDirective = "\t.short\t";
57   Data32bitsDirective = "\t.long\t";
58   Data64bitsDirective = "\t.quad\t";
59   DataBegin = "$d.";
60   CodeBegin = "$a.";
61   JT8Begin = "$d.";
62   JT16Begin = "$d.";
63   JT32Begin = "$d.";
64   SupportsDataRegions = false;
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   LCOMMDirectiveType = LCOMM::None;
76   COMMDirectiveAlignmentIsInBytes = true;
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   DwarfRequiresRelocationForSectionOffset = true;
92   DwarfSectionOffsetDirective = 0;
93   DwarfUsesLabelOffsetForRanges = true;
94   DwarfUsesRelocationsForStringPool = true;
95   DwarfRegNumForCFI = false;
96   HasMicrosoftFastStdCallMangling = false;
97
98   AsmTransCBE = 0;
99 }
100
101 MCAsmInfo::~MCAsmInfo() {
102 }
103
104
105 unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
106   unsigned Size = 0;
107   do {
108     Value >>= 7;
109     Size += sizeof(int8_t);
110   } while (Value);
111   return Size;
112 }
113
114 unsigned MCAsmInfo::getSLEB128Size(int Value) {
115   unsigned Size = 0;
116   int Sign = Value >> (8 * sizeof(Value) - 1);
117   bool IsMore;
118
119   do {
120     unsigned Byte = Value & 0x7f;
121     Value >>= 7;
122     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
123     Size += sizeof(int8_t);
124   } while (IsMore);
125   return Size;
126 }
127
128 const MCExpr *
129 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
130                                        unsigned Encoding,
131                                        MCStreamer &Streamer) const {
132   return getExprForFDESymbol(Sym, Encoding, Streamer);
133 }
134
135 const MCExpr *
136 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
137                                unsigned Encoding,
138                                MCStreamer &Streamer) const {
139   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
140     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
141
142   MCContext &Context = Streamer.getContext();
143   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
144   MCSymbol *PCSym = Context.CreateTempSymbol();
145   Streamer.EmitLabel(PCSym);
146   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
147   return MCBinaryExpr::CreateSub(Res, PC, Context);
148 }