LLVM 20.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"
21
22using namespace llvm;
23
24namespace {
26}
28 "dwarf-extended-loc", cl::Hidden,
29 cl::desc("Disable emission of the extended flags in .loc directives."),
30 cl::values(clEnumVal(Default, "Default for platform"),
31 clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
33
34namespace llvm {
36 "use-leb128-directives", cl::Hidden,
38 "Disable the usage of LEB128 directives, and generate .byte instead."),
40}
41
43 SeparatorString = ";";
44 CommentString = "#";
45 LabelSuffix = ":";
49 InlineAsmStart = "APP";
50 InlineAsmEnd = "NO_APP";
51 Code16Directive = ".code16";
52 Code32Directive = ".code32";
53 Code64Directive = ".code64";
54 ZeroDirective = "\t.zero\t";
55 AsciiDirective = "\t.ascii\t";
56 AscizDirective = "\t.asciz\t";
57 Data8bitsDirective = "\t.byte\t";
58 Data16bitsDirective = "\t.short\t";
59 Data32bitsDirective = "\t.long\t";
60 Data64bitsDirective = "\t.quad\t";
61 GlobalDirective = "\t.globl\t";
62 WeakDirective = "\t.weak\t";
71}
72
73MCAsmInfo::~MCAsmInfo() = default;
74
76 InitialFrameState.push_back(Inst);
77}
78
79const MCExpr *
81 unsigned Encoding,
82 MCStreamer &Streamer) const {
83 return getExprForFDESymbol(Sym, Encoding, Streamer);
84}
85
86const MCExpr *
88 unsigned Encoding,
89 MCStreamer &Streamer) const {
90 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
91 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
92
93 MCContext &Context = Streamer.getContext();
94 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
95 MCSymbol *PCSym = Context.createTempSymbol();
96 Streamer.emitLabel(PCSym);
97 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
98 return MCBinaryExpr::createSub(Res, PC, Context);
99}
100
102 if (C == '@')
103 return doesAllowAtInName();
104
105 return isAlnum(C) || C == '_' || C == '$' || C == '.';
106}
107
109 if (Name.empty())
110 return false;
111
112 // If any of the characters in the string is an unacceptable character, force
113 // quotes.
114 for (char C : Name) {
115 if (!isAcceptableChar(C))
116 return false;
117 }
118
119 return true;
120}
121
123 // FIXME: Does .section .bss/.data/.text work everywhere??
124 return SectionName == ".text" || SectionName == ".data" ||
126}
#define clEnumVal(ENUMVAL, DESC)
Definition: CommandLine.h:684
DefaultOnOff
Definition: DwarfDebug.cpp:87
@ Default
Definition: DwarfDebug.cpp:87
@ Enable
Definition: DwarfDebug.cpp:87
@ Disable
Definition: DwarfDebug.cpp:87
This file contains constants used for implementing Dwarf debug support.
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
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.
const char * Data16bitsDirective
Definition: MCAsmInfo.h:281
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:75
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:254
std::vector< MCCFIInstruction > InitialFrameState
Definition: MCAsmInfo.h:473
const char * Code64Directive
Definition: MCAsmInfo.h:182
const char * Code32Directive
Definition: MCAsmInfo.h:181
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:280
const char * Data64bitsDirective
Definition: MCAsmInfo.h:283
virtual ~MCAsmInfo()
bool doesAllowAtInName() const
Definition: MCAsmInfo.h:647
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:494
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
const char * Data32bitsDirective
Definition: MCAsmInfo.h:282
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:488
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:180
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:334
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:164
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:491
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:87
bool PPCUseFullRegisterNames
True if full register names are printed.
Definition: MCAsmInfo.h:236
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.
Definition: MCAsmInfo.cpp:101
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition: MCAsmInfo.h:123
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:122
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:583
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition: MCAsmInfo.h:469
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:244
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:259
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:80
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition: MCAsmInfo.h:233
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:108
StringRef CommentString
This indicates the comment string used by the assembler.
Definition: MCAsmInfo.h:127
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:386
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:622
Context object for machine code objects.
Definition: MCContext.h:83
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:345
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Streaming machine code generation interface.
Definition: MCStreamer.h:213
MCContext & getContext() const
Definition: MCStreamer.h:300
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:420
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:398
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:51
@ 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:711
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
@ DW_EH_PE_pcrel
Definition: Dwarf.h:858
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.