MCAsmInfo.cpp revision 239462
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>
23using namespace llvm;
24
25MCAsmInfo::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  AllowUTF8 = true;
53  UseDataRegionDirectives = false;
54  ZeroDirective = "\t.zero\t";
55  AsciiDirective = "\t.ascii\t";
56  AscizDirective = "\t.asciz\t";
57  Data8bitsDirective = "\t.byte\t";
58  Data16bitsDirective = "\t.short\t";
59  Data32bitsDirective = "\t.long\t";
60  Data64bitsDirective = "\t.quad\t";
61  SunStyleELFSectionSwitchSyntax = false;
62  UsesELFSectionDirectiveForBSS = false;
63  AlignDirective = "\t.align\t";
64  AlignmentIsInBytes = true;
65  TextAlignFillValue = 0;
66  GPRel64Directive = 0;
67  GPRel32Directive = 0;
68  GlobalDirective = "\t.globl\t";
69  HasSetDirective = true;
70  HasAggressiveSymbolFolding = true;
71  LCOMMDirectiveType = LCOMM::None;
72  COMMDirectiveAlignmentIsInBytes = true;
73  HasDotTypeDotSizeDirective = true;
74  HasSingleParameterDotFile = true;
75  HasNoDeadStrip = false;
76  HasSymbolResolver = false;
77  WeakRefDirective = 0;
78  WeakDefDirective = 0;
79  LinkOnceDirective = 0;
80  HiddenVisibilityAttr = MCSA_Hidden;
81  HiddenDeclarationVisibilityAttr = MCSA_Hidden;
82  ProtectedVisibilityAttr = MCSA_Protected;
83  HasLEB128 = false;
84  SupportsDebugInformation = false;
85  ExceptionsType = ExceptionHandling::None;
86  DwarfUsesInlineInfoSection = false;
87  DwarfSectionOffsetDirective = 0;
88  DwarfUsesRelocationsAcrossSections = true;
89  DwarfRegNumForCFI = false;
90  HasMicrosoftFastStdCallMangling = false;
91}
92
93MCAsmInfo::~MCAsmInfo() {
94}
95
96
97unsigned MCAsmInfo::getULEB128Size(unsigned Value) {
98  unsigned Size = 0;
99  do {
100    Value >>= 7;
101    Size += sizeof(int8_t);
102  } while (Value);
103  return Size;
104}
105
106unsigned MCAsmInfo::getSLEB128Size(int Value) {
107  unsigned Size = 0;
108  int Sign = Value >> (8 * sizeof(Value) - 1);
109  bool IsMore;
110
111  do {
112    unsigned Byte = Value & 0x7f;
113    Value >>= 7;
114    IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
115    Size += sizeof(int8_t);
116  } while (IsMore);
117  return Size;
118}
119
120const MCExpr *
121MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
122                                       unsigned Encoding,
123                                       MCStreamer &Streamer) const {
124  return getExprForFDESymbol(Sym, Encoding, Streamer);
125}
126
127const MCExpr *
128MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
129                               unsigned Encoding,
130                               MCStreamer &Streamer) const {
131  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
132    return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
133
134  MCContext &Context = Streamer.getContext();
135  const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
136  MCSymbol *PCSym = Context.CreateTempSymbol();
137  Streamer.EmitLabel(PCSym);
138  const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
139  return MCBinaryExpr::CreateSub(Res, PC, Context);
140}
141