LLVM  14.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 
21 using namespace llvm;
22 
23 namespace {
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")),
31  cl::init(Default));
32 
33 namespace llvm {
35  "use-leb128-directives", cl::Hidden,
36  cl::desc(
37  "Disable the usage of LEB128 directives, and generate .byte instead."),
39 }
40 
42  SeparatorString = ";";
43  CommentString = "#";
44  LabelSuffix = ":";
45  PrivateGlobalPrefix = "L";
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)
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
81  PreserveAsmComments = true;
82 }
83 
84 MCAsmInfo::~MCAsmInfo() = default;
85 
87  InitialFrameState.push_back(Inst);
88 }
89 
91  return false;
92 }
93 
94 const MCExpr *
96  unsigned Encoding,
97  MCStreamer &Streamer) const {
98  return getExprForFDESymbol(Sym, Encoding, Streamer);
99 }
100 
101 const 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 
116 bool MCAsmInfo::isAcceptableChar(char C) const {
117  return isAlnum(C) || C == '_' || C == '$' || C == '.' || C == '@';
118 }
119 
121  if (Name.empty())
122  return false;
123 
124  // If any of the characters in the string is an unacceptable character, force
125  // quotes.
126  for (char C : Name) {
127  if (!isAcceptableChar(C))
128  return false;
129  }
130 
131  return true;
132 }
133 
135  // FIXME: Does .section .bss/.data/.text work everywhere??
136  return SectionName == ".text" || SectionName == ".data" ||
137  (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
138 }
llvm::MCAsmInfo::getExprForFDESymbol
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:102
llvm::MCAsmInfo::SupportsExtendedDwarfLocDirective
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition: MCAsmInfo.h:483
llvm::MCAsmInfo::isAcceptableChar
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:116
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCAsmInfo::~MCAsmInfo
virtual ~MCAsmInfo()
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::MCAsmInfo::InlineAsmEnd
const char * InlineAsmEnd
Definition: MCAsmInfo.h:183
llvm::MCAsmInfo::ParseInlineAsmUsingAsmParser
bool ParseInlineAsmUsingAsmParser
Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
Definition: MCAsmInfo.h:505
llvm::MCAsmInfo::Data64bitsDirective
const char * Data64bitsDirective
Definition: MCAsmInfo.h:288
llvm::MCAsmInfo::Code32Directive
const char * Code32Directive
Definition: MCAsmInfo.h:189
llvm::MCAsmInfo::PrivateLabelPrefix
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:172
llvm::MCAsmInfo::WeakDirective
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:410
clEnumVal
#define clEnumVal(ENUMVAL, DESC)
Definition: CommandLine.h:672
llvm::MCAsmInfo::Code16Directive
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:188
llvm::MCAsmInfo::usesELFSectionDirectiveForBSS
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:607
llvm::MCAsmInfo::Data32bitsDirective
const char * Data32bitsDirective
Definition: MCAsmInfo.h:287
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MCAsmInfo::shouldOmitSectionDirective
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:134
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
CommandLine.h
llvm::MCAsmInfo::getExprForPersonalitySymbol
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:95
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::MCAsmInfo::PrivateGlobalPrefix
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition: MCAsmInfo.h:168
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
MCContext.h
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:413
llvm::MCAsmInfo::LinkerPrivateGlobalPrefix
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
llvm::MCAsmInfo::UseIntegratedAssembler
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:502
llvm::MCCFIInstruction
Definition: MCDwarf.h:434
llvm::MCAsmInfo::SeparatorString
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition: MCAsmInfo.h:131
llvm::cl::opt
Definition: CommandLine.h:1422
llvm::MCAsmInfo::isSectionAtomizableBySymbols
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:90
llvm::MCAsmInfo::Code64Directive
const char * Code64Directive
Definition: MCAsmInfo.h:190
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:699
llvm::cl::BOU_UNSET
@ BOU_UNSET
Definition: CommandLine.h:625
llvm::dwarf::DW_EH_PE_pcrel
@ DW_EH_PE_pcrel
Definition: Dwarf.h:443
llvm::MCAsmInfo::CommentString
StringRef CommentString
This indicates the comment string used by the assembler.
Definition: MCAsmInfo.h:135
llvm::MCAsmInfo::isValidUnquotedName
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:120
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::MCAsmInfo::ZeroDirective
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
DwarfExtendedLoc
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))
Enable
@ Enable
Definition: DwarfDebug.cpp:88
llvm::MCBinaryExpr::createSub
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:608
llvm::MCAsmInfo::InitialFrameState
std::vector< MCCFIInstruction > InitialFrameState
Definition: MCAsmInfo.h:487
llvm::MCAsmInfo::addInitialFrameState
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:86
llvm::MCAsmInfo::Data16bitsDirective
const char * Data16bitsDirective
Definition: MCAsmInfo.h:286
llvm::MCAsmInfo::MCAsmInfo
MCAsmInfo()
Definition: MCAsmInfo.cpp:41
MCAsmInfo.h
llvm::MCAsmInfo::GlobalDirective
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:339
llvm::MCAsmInfo::Data8bitsDirective
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:285
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Dwarf.h
llvm::MCAsmInfo::InlineAsmStart
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:182
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
Disable
@ Disable
Definition: DwarfDebug.cpp:88
llvm::MCAsmInfo::AscizDirective
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:264
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
DefaultOnOff
DefaultOnOff
Definition: DwarfDebug.cpp:88
llvm::SectionName
Definition: DWARFSection.h:21
llvm::TargetStackID::Default
@ Default
Definition: TargetFrameLowering.h:28
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:384
llvm::cl::BOU_TRUE
@ BOU_TRUE
Definition: CommandLine.h:625
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:278
llvm::UseLEB128Directives
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))
Definition: MCAsmInfoXCOFF.cpp:16
MCStreamer.h
llvm::MCAsmInfo::PreserveAsmComments
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:508
llvm::MCAsmInfo::LabelSuffix
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:154
llvm::cl::desc
Definition: CommandLine.h:414
llvm::MCAsmInfo::AsciiDirective
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:259
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCAsmInfo::HasLEB128Directives
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition: MCAsmInfo.h:241