CommentColumn is always 40. Simplify.
[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   AlignDirective = "\t.align\t";
62   AlignmentIsInBytes = true;
63   TextAlignFillValue = 0;
64   GPRel64Directive = 0;
65   GPRel32Directive = 0;
66   GlobalDirective = "\t.globl\t";
67   HasSetDirective = true;
68   HasAggressiveSymbolFolding = true;
69   COMMDirectiveAlignmentIsInBytes = true;
70   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
71   HasDotTypeDotSizeDirective = true;
72   HasSingleParameterDotFile = true;
73   HasIdentDirective = false;
74   HasNoDeadStrip = false;
75   WeakRefDirective = 0;
76   HasWeakDefDirective = false;
77   HasWeakDefCanBeHiddenDirective = false;
78   HasLinkOnceDirective = false;
79   HiddenVisibilityAttr = MCSA_Hidden;
80   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
81   ProtectedVisibilityAttr = MCSA_Protected;
82   HasLEB128 = false;
83   SupportsDebugInformation = false;
84   ExceptionsType = ExceptionHandling::None;
85   DwarfUsesRelocationsAcrossSections = true;
86   DwarfFDESymbolsUseAbsDiff = false;
87   DwarfRegNumForCFI = false;
88   NeedsDwarfSectionOffsetDirective = false;
89   UseParensForSymbolVariant = false;
90 }
91
92 MCAsmInfo::~MCAsmInfo() {
93 }
94
95
96 unsigned MCAsmInfo::getULEB128Size(uint64_t Value) {
97   unsigned Size = 0;
98   do {
99     Value >>= 7;
100     Size += sizeof(int8_t);
101   } while (Value);
102   return Size;
103 }
104
105 unsigned MCAsmInfo::getSLEB128Size(int64_t Value) {
106   unsigned Size = 0;
107   int Sign = Value >> (8 * sizeof(Value) - 1);
108   bool IsMore;
109
110   do {
111     unsigned Byte = Value & 0x7f;
112     Value >>= 7;
113     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
114     Size += sizeof(int8_t);
115   } while (IsMore);
116   return Size;
117 }
118
119 const MCExpr *
120 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
121                                        unsigned Encoding,
122                                        MCStreamer &Streamer) const {
123   return getExprForFDESymbol(Sym, Encoding, Streamer);
124 }
125
126 const MCExpr *
127 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
128                                unsigned Encoding,
129                                MCStreamer &Streamer) const {
130   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
131     return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
132
133   MCContext &Context = Streamer.getContext();
134   const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
135   MCSymbol *PCSym = Context.CreateTempSymbol();
136   Streamer.EmitLabel(PCSym);
137   const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
138   return MCBinaryExpr::CreateSub(Res, PC, Context);
139 }