LLVM  10.0.0svn
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  SeparatorString = ";";
33  CommentString = "#";
34  LabelSuffix = ":";
35  PrivateGlobalPrefix = "L";
38  InlineAsmStart = "APP";
39  InlineAsmEnd = "NO_APP";
40  Code16Directive = ".code16";
41  Code32Directive = ".code32";
42  Code64Directive = ".code64";
43  ZeroDirective = "\t.zero\t";
44  AsciiDirective = "\t.ascii\t";
45  AscizDirective = "\t.asciz\t";
46  Data8bitsDirective = "\t.byte\t";
47  Data16bitsDirective = "\t.short\t";
48  Data32bitsDirective = "\t.long\t";
49  Data64bitsDirective = "\t.quad\t";
50  GlobalDirective = "\t.globl\t";
51  WeakDirective = "\t.weak\t";
52  if (DwarfExtendedLoc != Default)
53  SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
54 
55  // FIXME: Clang's logic should be synced with the logic used to initialize
56  // this member and the two implementations should be merged.
57  // For reference:
58  // - Solaris always enables the integrated assembler by default
59  // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
60  // - Windows always enables the integrated assembler by default
61  // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
62  // - MachO targets always enables the integrated assembler by default
63  // - MCAsmInfoDarwin is handling this case
64  // - Generic_GCC toolchains enable the integrated assembler on a per
65  // architecture basis.
66  // - The target subclasses for AArch64, ARM, and X86 handle these cases
67  UseIntegratedAssembler = false;
68  PreserveAsmComments = true;
69 }
70 
71 MCAsmInfo::~MCAsmInfo() = default;
72 
74  InitialFrameState.push_back(Inst);
75 }
76 
78  return false;
79 }
80 
81 const MCExpr *
83  unsigned Encoding,
84  MCStreamer &Streamer) const {
85  return getExprForFDESymbol(Sym, Encoding, Streamer);
86 }
87 
88 const MCExpr *
90  unsigned Encoding,
91  MCStreamer &Streamer) const {
92  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
93  return MCSymbolRefExpr::create(Sym, Streamer.getContext());
94 
95  MCContext &Context = Streamer.getContext();
96  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
97  MCSymbol *PCSym = Context.createTempSymbol();
98  Streamer.EmitLabel(PCSym);
99  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
100  return MCBinaryExpr::createSub(Res, PC, Context);
101 }
102 
103 static bool isAcceptableChar(char C) {
104  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
105  (C >= '0' && C <= '9') || 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" ||
125  (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
126 }
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:148
uint64_t CallInst * C
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
LLVMContext & Context
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:371
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:132
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:298
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:327
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
const char * Data64bitsDirective
Definition: MCAsmInfo.h:193
const char * ZeroDirective
This should be set to the directive used to get some number of zero bytes emitted to the current sect...
Definition: MCAsmInfo.h:174
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:241
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:179
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line...
Definition: MCAsmInfo.h:110
MCContext & getContext() const
Definition: MCStreamer.h:251
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:82
StringRef CommentString
This indicates the comment character used by the assembler.
Definition: MCAsmInfo.h:114
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:190
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
#define clEnumVal(ENUMVAL, DESC)
Definition: CommandLine.h:625
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
Context object for machine code objects.
Definition: MCContext.h:65
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:550
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:122
const char * Code32Directive
Definition: MCAsmInfo.h:149
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:184
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))
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:142
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
Streaming machine code generation interface.
Definition: MCStreamer.h:189
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:652
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:77
const char * Data16bitsDirective
Definition: MCAsmInfo.h:191
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:108
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:73
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:117
std::vector< MCCFIInstruction > InitialFrameState
Definition: MCAsmInfo.h:362
virtual ~MCAsmInfo()
const char * InlineAsmEnd
Definition: MCAsmInfo.h:143
const char * Data32bitsDirective
Definition: MCAsmInfo.h:192
This file contains constants used for implementing Dwarf debug support.
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition: MCAsmInfo.h:358
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:374
StringRef LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition: MCAsmInfo.h:138
static bool isAcceptableChar(char C)
Definition: MCAsmInfo.cpp:103
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:463
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:397
DefaultOnOff
Definition: DwarfDebug.cpp:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ...
Definition: MCAsmInfo.h:128
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:89
const char * Code64Directive
Definition: MCAsmInfo.h:150