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