1 //===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines target asm properties related what form asm statements
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/MCAsmInfo.h"
15 #include "llvm/BinaryFormat/Dwarf.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/Support/CommandLine.h"
23 enum DefaultOnOff
{ Default
, Enable
, Disable
};
24 static cl::opt
<DefaultOnOff
> DwarfExtendedLoc(
25 "dwarf-extended-loc", cl::Hidden
,
26 cl::desc("Disable emission of the extended flags in .loc directives."),
27 cl::values(clEnumVal(Default
, "Default for platform"),
28 clEnumVal(Enable
, "Enabled"), clEnumVal(Disable
, "Disabled")),
31 MCAsmInfo::MCAsmInfo() {
32 SeparatorString
= ";";
35 PrivateGlobalPrefix
= "L";
36 PrivateLabelPrefix
= PrivateGlobalPrefix
;
37 LinkerPrivateGlobalPrefix
= "";
38 InlineAsmStart
= "APP";
39 InlineAsmEnd
= "NO_APP";
40 Code16Directive
= ".code16";
41 Code32Directive
= ".code32";
42 Code64Directive
= ".code64";
43 ZeroDirective
= "\t.zero\t";
44 AsciiDirective
= "\t.ascii\t";
45 AscizDirective
= "\t.asciz\t";
46 Data8bitsDirective
= "\t.byte\t";
47 Data16bitsDirective
= "\t.short\t";
48 Data32bitsDirective
= "\t.long\t";
49 Data64bitsDirective
= "\t.quad\t";
50 GlobalDirective
= "\t.globl\t";
51 WeakDirective
= "\t.weak\t";
52 if (DwarfExtendedLoc
!= Default
)
53 SupportsExtendedDwarfLocDirective
= DwarfExtendedLoc
== Enable
;
55 // FIXME: Clang's logic should be synced with the logic used to initialize
56 // this member and the two implementations should be merged.
58 // - Solaris always enables the integrated assembler by default
59 // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
60 // - Windows always enables the integrated assembler by default
61 // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
62 // - MachO targets always enables the integrated assembler by default
63 // - MCAsmInfoDarwin is handling this case
64 // - Generic_GCC toolchains enable the integrated assembler on a per
65 // architecture basis.
66 // - The target subclasses for AArch64, ARM, and X86 handle these cases
67 UseIntegratedAssembler
= false;
68 PreserveAsmComments
= true;
71 MCAsmInfo::~MCAsmInfo() = default;
73 bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection
&Section
) const {
78 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol
*Sym
,
80 MCStreamer
&Streamer
) const {
81 return getExprForFDESymbol(Sym
, Encoding
, Streamer
);
85 MCAsmInfo::getExprForFDESymbol(const MCSymbol
*Sym
,
87 MCStreamer
&Streamer
) const {
88 if (!(Encoding
& dwarf::DW_EH_PE_pcrel
))
89 return MCSymbolRefExpr::create(Sym
, Streamer
.getContext());
91 MCContext
&Context
= Streamer
.getContext();
92 const MCExpr
*Res
= MCSymbolRefExpr::create(Sym
, Context
);
93 MCSymbol
*PCSym
= Context
.createTempSymbol();
94 Streamer
.EmitLabel(PCSym
);
95 const MCExpr
*PC
= MCSymbolRefExpr::create(PCSym
, Context
);
96 return MCBinaryExpr::createSub(Res
, PC
, Context
);
99 static bool isAcceptableChar(char C
) {
100 return (C
>= 'a' && C
<= 'z') || (C
>= 'A' && C
<= 'Z') ||
101 (C
>= '0' && C
<= '9') || C
== '_' || C
== '$' || C
== '.' || C
== '@';
104 bool MCAsmInfo::isValidUnquotedName(StringRef Name
) const {
108 // If any of the characters in the string is an unacceptable character, force
110 for (char C
: Name
) {
111 if (!isAcceptableChar(C
))
118 bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName
) const {
119 // FIXME: Does .section .bss/.data/.text work everywhere??
120 return SectionName
== ".text" || SectionName
== ".data" ||
121 (SectionName
== ".bss" && !usesELFSectionDirectiveForBSS());