LLVM  13.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 
25  "dwarf-extended-loc", cl::Hidden,
26  cl::desc("Disable emission of the extended flags in .loc directives."),
27  cl::values(clEnumVal(Default, "Default for platform"),
28  clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
29  cl::init(Default));
30 
32  "use-leb128-directives", cl::Hidden,
33  cl::desc(
34  "Disable the usage of LEB128 directives, and generate .byte instead."),
36 
38  SeparatorString = ";";
39  CommentString = "#";
40  LabelSuffix = ":";
41  PrivateGlobalPrefix = "L";
44  InlineAsmStart = "APP";
45  InlineAsmEnd = "NO_APP";
46  Code16Directive = ".code16";
47  Code32Directive = ".code32";
48  Code64Directive = ".code64";
49  ZeroDirective = "\t.zero\t";
50  AsciiDirective = "\t.ascii\t";
51  AscizDirective = "\t.asciz\t";
52  Data8bitsDirective = "\t.byte\t";
53  Data16bitsDirective = "\t.short\t";
54  Data32bitsDirective = "\t.long\t";
55  Data64bitsDirective = "\t.quad\t";
56  GlobalDirective = "\t.globl\t";
57  WeakDirective = "\t.weak\t";
62 
63  // FIXME: Clang's logic should be synced with the logic used to initialize
64  // this member and the two implementations should be merged.
65  // For reference:
66  // - Solaris always enables the integrated assembler by default
67  // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
68  // - Windows always enables the integrated assembler by default
69  // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
70  // - MachO targets always enables the integrated assembler by default
71  // - MCAsmInfoDarwin is handling this case
72  // - Generic_GCC toolchains enable the integrated assembler on a per
73  // architecture basis.
74  // - The target subclasses for AArch64, ARM, and X86 handle these cases
76  PreserveAsmComments = true;
77 }
78 
79 MCAsmInfo::~MCAsmInfo() = default;
80 
82  InitialFrameState.push_back(Inst);
83 }
84 
86  return false;
87 }
88 
89 const MCExpr *
91  unsigned Encoding,
92  MCStreamer &Streamer) const {
93  return getExprForFDESymbol(Sym, Encoding, Streamer);
94 }
95 
96 const MCExpr *
98  unsigned Encoding,
99  MCStreamer &Streamer) const {
100  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
101  return MCSymbolRefExpr::create(Sym, Streamer.getContext());
102 
103  MCContext &Context = Streamer.getContext();
104  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
105  MCSymbol *PCSym = Context.createTempSymbol();
106  Streamer.emitLabel(PCSym);
107  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
108  return MCBinaryExpr::createSub(Res, PC, Context);
109 }
110 
111 bool MCAsmInfo::isAcceptableChar(char C) const {
112  return isAlnum(C) || C == '_' || C == '$' || C == '.' || C == '@';
113 }
114 
116  if (Name.empty())
117  return false;
118 
119  // If any of the characters in the string is an unacceptable character, force
120  // quotes.
121  for (char C : Name) {
122  if (!isAcceptableChar(C))
123  return false;
124  }
125 
126  return true;
127 }
128 
130  // FIXME: Does .section .bss/.data/.text work everywhere??
131  return SectionName == ".text" || SectionName == ".data" ||
132  (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
133 }
llvm::MCAsmInfo::getExprForFDESymbol
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:97
llvm::MCAsmInfo::SupportsExtendedDwarfLocDirective
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition: MCAsmInfo.h:457
llvm::MCAsmInfo::isAcceptableChar
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:111
Enable
@ Enable
Definition: MCAsmInfo.cpp:23
llvm
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:71
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::MCAsmInfo::InlineAsmEnd
const char * InlineAsmEnd
Definition: MCAsmInfo.h:176
llvm::MCAsmInfo::Data64bitsDirective
const char * Data64bitsDirective
Definition: MCAsmInfo.h:276
llvm::MCAsmInfo::Code32Directive
const char * Code32Directive
Definition: MCAsmInfo.h:182
llvm::MCAsmInfo::PrivateLabelPrefix
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:165
llvm::MCAsmInfo::WeakDirective
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:388
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:181
llvm::MCAsmInfo::usesELFSectionDirectiveForBSS
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:578
llvm::MCAsmInfo::Data32bitsDirective
const char * Data32bitsDirective
Definition: MCAsmInfo.h:275
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:129
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:90
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:161
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
CombinerObjective::Default
@ Default
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:171
llvm::MCAsmInfo::UseIntegratedAssembler
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:476
Disable
@ Disable
Definition: MCAsmInfo.cpp:23
llvm::MCCFIInstruction
Definition: MCDwarf.h:441
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:85
llvm::MCAsmInfo::Code64Directive
const char * Code64Directive
Definition: MCAsmInfo.h:183
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:115
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:242
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))
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:461
llvm::MCAsmInfo::addInitialFrameState
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:81
llvm::MCAsmInfo::Data16bitsDirective
const char * Data16bitsDirective
Definition: MCAsmInfo.h:274
llvm::MCAsmInfo::MCAsmInfo
MCAsmInfo()
Definition: MCAsmInfo.cpp:37
MCAsmInfo.h
llvm::MCAsmInfo::GlobalDirective
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:327
llvm::MCAsmInfo::Data8bitsDirective
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:273
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
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:175
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::MCAsmInfo::AscizDirective
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:257
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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))
DefaultOnOff
DefaultOnOff
Definition: DwarfDebug.cpp:88
llvm::SectionName
Definition: DWARFSection.h:21
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
MCStreamer.h
llvm::MCAsmInfo::PreserveAsmComments
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:479
llvm::MCAsmInfo::LabelSuffix
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:150
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:252
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:234