Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.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"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCStreamer.h"
20#include "llvm/MC/MCValue.h"
23
24using namespace llvm;
25
26namespace {
28}
30 "dwarf-extended-loc", cl::Hidden,
31 cl::desc("Disable emission of the extended flags in .loc directives."),
32 cl::values(clEnumVal(Default, "Default for platform"),
33 clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
35
36namespace llvm {
38 "use-leb128-directives", cl::Hidden,
40 "Disable the usage of LEB128 directives, and generate .byte instead."),
42}
43
71
72MCAsmInfo::~MCAsmInfo() = default;
73
75 InitialFrameState.push_back(Inst);
76}
77
78const MCExpr *
80 unsigned Encoding,
81 MCStreamer &Streamer) const {
82 return getExprForFDESymbol(Sym, Encoding, Streamer);
83}
84
85const MCExpr *
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
101 if (C == '@')
102 return doesAllowAtInName();
103
104 return isAlnum(C) || C == '_' || C == '$' || C == '.';
105}
106
108 if (Name.empty())
109 return false;
110
111 // If any of the characters in the string is an unacceptable character, force
112 // quotes.
113 for (char C : Name) {
114 if (!isAcceptableChar(C))
115 return false;
116 }
117
118 return true;
119}
120
122 // FIXME: Does .section .bss/.data/.text work everywhere??
123 return SectionName == ".text" || SectionName == ".data" ||
125}
126
128 assert(AtSpecifierToName.empty() && "cannot initialize twice");
129 for (auto Desc : Descs) {
130 [[maybe_unused]] auto It =
131 AtSpecifierToName.try_emplace(Desc.Kind, Desc.Name);
132 assert(It.second && "duplicate Kind");
133 [[maybe_unused]] auto It2 =
134 NameToAtSpecifier.try_emplace(Desc.Name.lower(), Desc.Kind);
135 assert(It2.second);
136 }
137}
138
140 auto It = AtSpecifierToName.find(S);
141 assert(It != AtSpecifierToName.end() &&
142 "ensure the specifier is set in initializeVariantKinds");
143 return It->second;
144}
145
146std::optional<uint32_t> MCAsmInfo::getSpecifierForName(StringRef Name) const {
147 auto It = NameToAtSpecifier.find(Name.lower());
148 if (It != NameToAtSpecifier.end())
149 return It->second;
150 return {};
151}
152
153void MCAsmInfo::printExpr(raw_ostream &OS, const MCExpr &Expr) const {
154 if (auto *SE = dyn_cast<MCSpecifierExpr>(&Expr))
155 printSpecifierExpr(OS, *SE);
156 else
157 Expr.print(OS, this);
158}
159
161 MCValue &Res,
162 const MCAssembler *Asm) const {
163 if (!E.getSubExpr()->evaluateAsRelocatable(Res, Asm))
164 return false;
165
166 Res.setSpecifier(E.getSpecifier());
167 return !Res.getSubSym();
168}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define clEnumVal(ENUMVAL, DESC)
DefaultOnOff
@ Default
@ Enable
@ Disable
This file contains constants used for implementing Dwarf debug support.
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))
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
const char * Data16bitsDirective
Definition MCAsmInfo.h:248
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition MCAsmInfo.cpp:74
virtual void printSpecifierExpr(raw_ostream &, const MCSpecifierExpr &) const
Definition MCAsmInfo.h:725
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition MCAsmInfo.h:231
std::vector< MCCFIInstruction > InitialFrameState
Definition MCAsmInfo.h:397
llvm::StringMap< uint32_t > NameToAtSpecifier
Definition MCAsmInfo.h:431
void initializeAtSpecifiers(ArrayRef< AtSpecifier >)
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition MCAsmInfo.h:247
const char * Data64bitsDirective
Definition MCAsmInfo.h:250
llvm::DenseMap< uint32_t, StringRef > AtSpecifierToName
Definition MCAsmInfo.h:430
virtual ~MCAsmInfo()
virtual bool evaluateAsRelocatableImpl(const MCSpecifierExpr &, MCValue &Res, const MCAssembler *Asm) const
bool doesAllowAtInName() const
Definition MCAsmInfo.h:561
bool PreserveAsmComments
Preserve Comments in assembly.
Definition MCAsmInfo.h:418
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition MCAsmInfo.h:146
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition MCAsmInfo.h:160
StringRef getSpecifierName(uint32_t S) const
const char * Data32bitsDirective
Definition MCAsmInfo.h:249
bool UseIntegratedAssembler
Should we use the integrated assembler?
Definition MCAsmInfo.h:412
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition MCAsmInfo.h:283
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition MCAsmInfo.h:164
void printExpr(raw_ostream &, const MCExpr &) const
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition MCAsmInfo.h:174
bool ParseInlineAsmUsingAsmParser
Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
Definition MCAsmInfo.h:415
StringRef LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition MCAsmInfo.h:170
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition MCAsmInfo.cpp:86
bool PPCUseFullRegisterNames
True if full register names are printed.
Definition MCAsmInfo.h:218
const char * InlineAsmEnd
Definition MCAsmInfo.h:175
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
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.
bool usesELFSectionDirectiveForBSS() const
Definition MCAsmInfo.h:509
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition MCAsmInfo.h:393
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:226
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition MCAsmInfo.h:236
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition MCAsmInfo.cpp:79
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition MCAsmInfo.h:215
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
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:321
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:495
Streaming machine code generation interface.
Definition MCStreamer.h:220
MCContext & getContext() const
Definition MCStreamer.h:314
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
void setSpecifier(uint32_t S)
Definition MCValue.h:47
const MCSymbol * getSubSym() const
Definition MCValue.h:51
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ 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 ...
initializer< Ty > init(const Ty &Val)
@ DW_EH_PE_pcrel
Definition Dwarf.h:872
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
Op::Description Desc
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
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.
Definition Uniformity.h:20
@ Enable
Enable colors.
Definition WithColor.h:47