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"
24 enum DefaultOnOff
{ Default
, Enable
, Disable
};
26 static cl::opt
<DefaultOnOff
> DwarfExtendedLoc(
27 "dwarf-extended-loc", cl::Hidden
,
28 cl::desc("Disable emission of the extended flags in .loc directives."),
29 cl::values(clEnumVal(Default
, "Default for platform"),
30 clEnumVal(Enable
, "Enabled"), clEnumVal(Disable
, "Disabled")),
34 cl::opt
<cl::boolOrDefault
> UseLEB128Directives(
35 "use-leb128-directives", cl::Hidden
,
37 "Disable the usage of LEB128 directives, and generate .byte instead."),
38 cl::init(cl::BOU_UNSET
));
41 MCAsmInfo::MCAsmInfo() {
42 SeparatorString
= ";";
45 PrivateGlobalPrefix
= "L";
46 PrivateLabelPrefix
= PrivateGlobalPrefix
;
47 LinkerPrivateGlobalPrefix
= "";
48 InlineAsmStart
= "APP";
49 InlineAsmEnd
= "NO_APP";
50 Code16Directive
= ".code16";
51 Code32Directive
= ".code32";
52 Code64Directive
= ".code64";
53 ZeroDirective
= "\t.zero\t";
54 AsciiDirective
= "\t.ascii\t";
55 AscizDirective
= "\t.asciz\t";
56 Data8bitsDirective
= "\t.byte\t";
57 Data16bitsDirective
= "\t.short\t";
58 Data32bitsDirective
= "\t.long\t";
59 Data64bitsDirective
= "\t.quad\t";
60 GlobalDirective
= "\t.globl\t";
61 WeakDirective
= "\t.weak\t";
62 if (DwarfExtendedLoc
!= Default
)
63 SupportsExtendedDwarfLocDirective
= DwarfExtendedLoc
== Enable
;
64 if (UseLEB128Directives
!= cl::BOU_UNSET
)
65 HasLEB128Directives
= UseLEB128Directives
== cl::BOU_TRUE
;
67 // FIXME: Clang's logic should be synced with the logic used to initialize
68 // this member and the two implementations should be merged.
70 // - Solaris always enables the integrated assembler by default
71 // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
72 // - Windows always enables the integrated assembler by default
73 // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
74 // - MachO targets always enables the integrated assembler by default
75 // - MCAsmInfoDarwin is handling this case
76 // - Generic_GCC toolchains enable the integrated assembler on a per
77 // architecture basis.
78 // - The target subclasses for AArch64, ARM, and X86 handle these cases
79 UseIntegratedAssembler
= true;
80 ParseInlineAsmUsingAsmParser
= false;
81 PreserveAsmComments
= true;
84 MCAsmInfo::~MCAsmInfo() = default;
86 void MCAsmInfo::addInitialFrameState(const MCCFIInstruction
&Inst
) {
87 InitialFrameState
.push_back(Inst
);
90 bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection
&Section
) const {
95 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol
*Sym
,
97 MCStreamer
&Streamer
) const {
98 return getExprForFDESymbol(Sym
, Encoding
, Streamer
);
102 MCAsmInfo::getExprForFDESymbol(const MCSymbol
*Sym
,
104 MCStreamer
&Streamer
) const {
105 if (!(Encoding
& dwarf::DW_EH_PE_pcrel
))
106 return MCSymbolRefExpr::create(Sym
, Streamer
.getContext());
108 MCContext
&Context
= Streamer
.getContext();
109 const MCExpr
*Res
= MCSymbolRefExpr::create(Sym
, Context
);
110 MCSymbol
*PCSym
= Context
.createTempSymbol();
111 Streamer
.emitLabel(PCSym
);
112 const MCExpr
*PC
= MCSymbolRefExpr::create(PCSym
, Context
);
113 return MCBinaryExpr::createSub(Res
, PC
, Context
);
116 bool MCAsmInfo::isAcceptableChar(char C
) const {
117 return isAlnum(C
) || C
== '_' || C
== '$' || C
== '.' || C
== '@';
120 bool MCAsmInfo::isValidUnquotedName(StringRef Name
) const {
124 // If any of the characters in the string is an unacceptable character, force
126 for (char C
: Name
) {
127 if (!isAcceptableChar(C
))
134 bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName
) const {
135 // FIXME: Does .section .bss/.data/.text work everywhere??
136 return SectionName
== ".text" || SectionName
== ".data" ||
137 (SectionName
== ".bss" && !usesELFSectionDirectiveForBSS());