Move get[S|U]LEB128Size() to LEB128.h.
[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   CommentString = "#";
41   LabelSuffix = ":";
42   DebugLabelSuffix = ":";
43   PrivateGlobalPrefix = "L";
44   InlineAsmStart = "APP";
45   InlineAsmEnd = "NO_APP";
46   Code16Directive = ".code16";
47   Code32Directive = ".code32";
48   Code64Directive = ".code64";
49   AssemblerDialect = 0;
50   AllowAtInName = false;
51   UseDataRegionDirectives = false;
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   SunStyleELFSectionSwitchSyntax = false;
60   UsesELFSectionDirectiveForBSS = false;
61   AlignmentIsInBytes = true;
62   TextAlignFillValue = 0;
63   GPRel64Directive = 0;
64   GPRel32Directive = 0;
65   GlobalDirective = "\t.globl\t";
66   HasSetDirective = true;
67   HasAggressiveSymbolFolding = true;
68   COMMDirectiveAlignmentIsInBytes = true;
69   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
70   HasDotTypeDotSizeDirective = true;
71   HasSingleParameterDotFile = true;
72   HasIdentDirective = false;
73   HasNoDeadStrip = false;
74   WeakRefDirective = 0;
75   HasWeakDefDirective = false;
76   HasWeakDefCanBeHiddenDirective = false;
77   HasLinkOnceDirective = false;
78   HiddenVisibilityAttr = MCSA_Hidden;
79   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
80   ProtectedVisibilityAttr = MCSA_Protected;
81   HasLEB128 = false;
82   SupportsDebugInformation = false;
83   ExceptionsType = ExceptionHandling::None;
84   DwarfUsesRelocationsAcrossSections = true;
85   DwarfFDESymbolsUseAbsDiff = false;
86   DwarfRegNumForCFI = false;
87   NeedsDwarfSectionOffsetDirective = false;
88   UseParensForSymbolVariant = false;
89
90   // FIXME: Clang's logic should be synced with the logic used to initialize
91   //        this member and the two implementations should be merged.
92   // For reference:
93   // - Solaris always enables the integrated assembler by default
94   //   - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
95   // - Windows always enables the integrated assembler by default
96   //   - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
97   // - MachO targets always enables the integrated assembler by default
98   //   - MCAsmInfoDarwin is handling this case
99   // - Generic_GCC toolchains enable the integrated assembler on a per
100   //   architecture basis.
101   //   - The target subclasses for AArch64, ARM, and X86  handle these cases
102   UseIntegratedAssembler = false;
103 }
104
105 MCAsmInfo::~MCAsmInfo() {
106 }
107
108 const MCExpr *
109 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
110                                        unsigned Encoding,
111                                        MCStreamer &Streamer) const {
112   return getExprForFDESymbol(Sym, Encoding, Streamer);
113 }
114
115 const MCExpr *
116 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
117                                unsigned Encoding,
118                                MCStreamer &Streamer) const {
119   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
120     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
121
122   MCContext &Context = Streamer.getContext();
123   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
124   MCSymbol *PCSym = Context.CreateTempSymbol();
125   Streamer.EmitLabel(PCSym);
126   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
127   return MCBinaryExpr::CreateSub(Res, PC, Context);
128 }