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