]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCAsmInfo.cpp
MFV r316875: 7336 vfork and O_CLOEXEC causes zfs_mount EBUSY
[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/BinaryFormat/Dwarf.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCStreamer.h"
20
21 using namespace llvm;
22
23 MCAsmInfo::MCAsmInfo() {
24   SeparatorString = ";";
25   CommentString = "#";
26   LabelSuffix = ":";
27   PrivateGlobalPrefix = "L";
28   PrivateLabelPrefix = PrivateGlobalPrefix;
29   LinkerPrivateGlobalPrefix = "";
30   InlineAsmStart = "APP";
31   InlineAsmEnd = "NO_APP";
32   Code16Directive = ".code16";
33   Code32Directive = ".code32";
34   Code64Directive = ".code64";
35   ZeroDirective = "\t.zero\t";
36   AsciiDirective = "\t.ascii\t";
37   AscizDirective = "\t.asciz\t";
38   Data8bitsDirective = "\t.byte\t";
39   Data16bitsDirective = "\t.short\t";
40   Data32bitsDirective = "\t.long\t";
41   Data64bitsDirective = "\t.quad\t";
42   GlobalDirective = "\t.globl\t";
43   WeakDirective = "\t.weak\t";
44
45   // FIXME: Clang's logic should be synced with the logic used to initialize
46   //        this member and the two implementations should be merged.
47   // For reference:
48   // - Solaris always enables the integrated assembler by default
49   //   - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
50   // - Windows always enables the integrated assembler by default
51   //   - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
52   // - MachO targets always enables the integrated assembler by default
53   //   - MCAsmInfoDarwin is handling this case
54   // - Generic_GCC toolchains enable the integrated assembler on a per
55   //   architecture basis.
56   //   - The target subclasses for AArch64, ARM, and X86 handle these cases
57   UseIntegratedAssembler = false;
58   PreserveAsmComments = true;
59 }
60
61 MCAsmInfo::~MCAsmInfo() = default;
62
63 bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
64   return false;
65 }
66
67 const MCExpr *
68 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
69                                        unsigned Encoding,
70                                        MCStreamer &Streamer) const {
71   return getExprForFDESymbol(Sym, Encoding, Streamer);
72 }
73
74 const MCExpr *
75 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
76                                unsigned Encoding,
77                                MCStreamer &Streamer) const {
78   if (!(Encoding & dwarf::DW_EH_PE_pcrel))
79     return MCSymbolRefExpr::create(Sym, Streamer.getContext());
80
81   MCContext &Context = Streamer.getContext();
82   const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
83   MCSymbol *PCSym = Context.createTempSymbol();
84   Streamer.EmitLabel(PCSym);
85   const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
86   return MCBinaryExpr::createSub(Res, PC, Context);
87 }
88
89 static bool isAcceptableChar(char C) {
90   return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
91          (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
92 }
93
94 bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
95   if (Name.empty())
96     return false;
97
98   // If any of the characters in the string is an unacceptable character, force
99   // quotes.
100   for (char C : Name) {
101     if (!isAcceptableChar(C))
102       return false;
103   }
104
105   return true;
106 }
107
108 bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
109   // FIXME: Does .section .bss/.data/.text work everywhere??
110   return SectionName == ".text" || SectionName == ".data" ||
111         (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
112 }