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