]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCAsmInfo.cpp
Update lldb to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / 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   MaxInstLength = 4;
35   MinInstAlignment = 1;
36   DollarIsPC = false;
37   SeparatorString = ";";
38   CommentString = "#";
39   LabelSuffix = ":";
40   UseAssignmentForEHBegin = false;
41   NeedsLocalForSize = false;
42   PrivateGlobalPrefix = "L";
43   PrivateLabelPrefix = PrivateGlobalPrefix;
44   LinkerPrivateGlobalPrefix = "";
45   InlineAsmStart = "APP";
46   InlineAsmEnd = "NO_APP";
47   Code16Directive = ".code16";
48   Code32Directive = ".code32";
49   Code64Directive = ".code64";
50   AssemblerDialect = 0;
51   AllowAtInName = false;
52   SupportsQuotedNames = 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   AlignmentIsInBytes = true;
64   TextAlignFillValue = 0;
65   GPRel64Directive = nullptr;
66   GPRel32Directive = nullptr;
67   GlobalDirective = "\t.globl\t";
68   SetDirectiveSuppressesReloc = false;
69   HasAggressiveSymbolFolding = true;
70   COMMDirectiveAlignmentIsInBytes = true;
71   LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
72   HasFunctionAlignment = true;
73   HasDotTypeDotSizeDirective = true;
74   HasSingleParameterDotFile = true;
75   HasIdentDirective = false;
76   HasNoDeadStrip = false;
77   HasAltEntry = false;
78   WeakDirective = "\t.weak\t";
79   WeakRefDirective = nullptr;
80   HasWeakDefDirective = false;
81   HasWeakDefCanBeHiddenDirective = false;
82   HasLinkOnceDirective = false;
83   HiddenVisibilityAttr = MCSA_Hidden;
84   HiddenDeclarationVisibilityAttr = MCSA_Hidden;
85   ProtectedVisibilityAttr = MCSA_Protected;
86   SupportsDebugInformation = false;
87   ExceptionsType = ExceptionHandling::None;
88   WinEHEncodingType = WinEH::EncodingType::Invalid;
89   DwarfUsesRelocationsAcrossSections = true;
90   DwarfFDESymbolsUseAbsDiff = false;
91   DwarfRegNumForCFI = false;
92   NeedsDwarfSectionOffsetDirective = false;
93   UseParensForSymbolVariant = false;
94   UseLogicalShr = true;
95
96   // FIXME: Clang's logic should be synced with the logic used to initialize
97   //        this member and the two implementations should be merged.
98   // For reference:
99   // - Solaris always enables the integrated assembler by default
100   //   - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
101   // - Windows always enables the integrated assembler by default
102   //   - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
103   // - MachO targets always enables the integrated assembler by default
104   //   - MCAsmInfoDarwin is handling this case
105   // - Generic_GCC toolchains enable the integrated assembler on a per
106   //   architecture basis.
107   //   - The target subclasses for AArch64, ARM, and X86 handle these cases
108   UseIntegratedAssembler = false;
109   PreserveAsmComments = true;
110
111   CompressDebugSections = DebugCompressionType::DCT_None;
112 }
113
114 MCAsmInfo::~MCAsmInfo() {
115 }
116
117 bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
118   return false;
119 }
120
121 const MCExpr *
122 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
123                                        unsigned Encoding,
124                                        MCStreamer &Streamer) const {
125   return getExprForFDESymbol(Sym, Encoding, Streamer);
126 }
127
128 const MCExpr *
129 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
130                                unsigned Encoding,
131                                MCStreamer &Streamer) const {
132   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
133     return MCSymbolRefExpr::create(Sym, Streamer.getContext());
134
135   MCContext &Context = Streamer.getContext();
136   const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
137   MCSymbol *PCSym = Context.createTempSymbol();
138   Streamer.EmitLabel(PCSym);
139   const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
140   return MCBinaryExpr::createSub(Res, PC, Context);
141 }
142
143 static bool isAcceptableChar(char C) {
144   return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
145          (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
146 }
147
148 bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
149   if (Name.empty())
150     return false;
151
152   // If any of the characters in the string is an unacceptable character, force
153   // quotes.
154   for (char C : Name) {
155     if (!isAcceptableChar(C))
156       return false;
157   }
158
159   return true;
160 }
161
162 bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
163   // FIXME: Does .section .bss/.data/.text work everywhere??
164   return SectionName == ".text" || SectionName == ".data" ||
165         (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
166 }