LLVM 17.0.0git
MCAsmInfo.cpp
Go to the documentation of this file.
1//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines target asm properties related what form asm statements
10// should take.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCStreamer.h"
20
21using namespace llvm;
22
23namespace {
25}
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")),
32
33namespace llvm {
35 "use-leb128-directives", cl::Hidden,
37 "Disable the usage of LEB128 directives, and generate .byte instead."),
39}
40
42 SeparatorString = ";";
43 CommentString = "#";
44 LabelSuffix = ":";
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";
66
67 // FIXME: Clang's logic should be synced with the logic used to initialize
68 // this member and the two implementations should be merged.
69 // For reference:
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
82}
83
84MCAsmInfo::~MCAsmInfo() = default;
85
87 InitialFrameState.push_back(Inst);
88}
89
91 return false;
92}
93
94const MCExpr *
96 unsigned Encoding,
97 MCStreamer &Streamer) const {
98 return getExprForFDESymbol(Sym, Encoding, Streamer);
99}
100
101const MCExpr *
103 unsigned Encoding,
104 MCStreamer &Streamer) const {
105 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
106 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
107
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);
114}
115
117 if (C == '@')
118 return doesAllowAtInName();
119
120 return isAlnum(C) || C == '_' || C == '$' || C == '.';
121}
122
124 if (Name.empty())
125 return false;
126
127 // If any of the characters in the string is an unacceptable character, force
128 // quotes.
129 for (char C : Name) {
130 if (!isAcceptableChar(C))
131 return false;
132 }
133
134 return true;
135}
136
138 // FIXME: Does .section .bss/.data/.text work everywhere??
139 return SectionName == ".text" || SectionName == ".data" ||
141}
#define clEnumVal(ENUMVAL, DESC)
Definition: CommandLine.h:676
DefaultOnOff
Definition: DwarfDebug.cpp:86
@ Default
Definition: DwarfDebug.cpp:86
@ Enable
Definition: DwarfDebug.cpp:86
@ Disable
Definition: DwarfDebug.cpp:86
This file contains constants used for implementing Dwarf debug support.
std::string Name
static cl::opt< DefaultOnOff > DwarfExtendedLoc("dwarf-extended-loc", cl::Hidden, cl::desc("Disable emission of the extended flags in .loc directives."), cl::values(clEnumVal(Default, "Default for platform"), clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")), cl::init(Default))
LLVMContext & Context
const char * Data16bitsDirective
Definition: MCAsmInfo.h:286
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:86
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:259
std::vector< MCCFIInstruction > InitialFrameState
Definition: MCAsmInfo.h:501
const char * Code64Directive
Definition: MCAsmInfo.h:190
const char * Code32Directive
Definition: MCAsmInfo.h:189
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:90
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:285
const char * Data64bitsDirective
Definition: MCAsmInfo.h:288
virtual ~MCAsmInfo()
bool doesAllowAtInName() const
Definition: MCAsmInfo.h:687
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:522
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:154
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition: MCAsmInfo.h:168
const char * Data32bitsDirective
Definition: MCAsmInfo.h:287
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:516
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:188
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:339
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:172
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:182
bool ParseInlineAsmUsingAsmParser
Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
Definition: MCAsmInfo.h:519
StringRef LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition: MCAsmInfo.h:178
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:102
const char * InlineAsmEnd
Definition: MCAsmInfo.h:183
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:116
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition: MCAsmInfo.h:131
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:137
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:621
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition: MCAsmInfo.h:497
const char * ZeroDirective
This should be set to the directive used to get some number of zero (and non-zero if supported by the...
Definition: MCAsmInfo.h:249
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:264
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:95
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition: MCAsmInfo.h:241
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:123
StringRef CommentString
This indicates the comment string used by the assembler.
Definition: MCAsmInfo.h:135
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:410
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:610
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
Streaming machine code generation interface.
Definition: MCStreamer.h:212
MCContext & getContext() const
Definition: MCStreamer.h:297
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:423
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:703
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
@ DW_EH_PE_pcrel
Definition: Dwarf.h:526
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
cl::opt< cl::boolOrDefault > UseLEB128Directives("use-leb128-directives", cl::Hidden, cl::desc("Disable the usage of LEB128 directives, and generate .byte instead."), cl::init(cl::BOU_UNSET))
@ Default
The result values are uniform if and only if all operands are uniform.
@ Enable
Enable colors.