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