LLVM  8.0.1
MCAsmInfo.cpp
Go to the documentation of this file.
1 //===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines target asm properties related what form asm statements
11 // should take.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCStreamer.h"
21 
22 using namespace llvm;
23 
26  "dwarf-extended-loc", cl::Hidden,
27  cl::desc("Disable emission of the extended flags in .loc directives."),
28  cl::values(clEnumVal(Default, "Default for platform"),
29  clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
30  cl::init(Default));
31 
33  SeparatorString = ";";
34  CommentString = "#";
35  LabelSuffix = ":";
36  PrivateGlobalPrefix = "L";
39  InlineAsmStart = "APP";
40  InlineAsmEnd = "NO_APP";
41  Code16Directive = ".code16";
42  Code32Directive = ".code32";
43  Code64Directive = ".code64";
44  ZeroDirective = "\t.zero\t";
45  AsciiDirective = "\t.ascii\t";
46  AscizDirective = "\t.asciz\t";
47  Data8bitsDirective = "\t.byte\t";
48  Data16bitsDirective = "\t.short\t";
49  Data32bitsDirective = "\t.long\t";
50  Data64bitsDirective = "\t.quad\t";
51  GlobalDirective = "\t.globl\t";
52  WeakDirective = "\t.weak\t";
53  if (DwarfExtendedLoc != Default)
54  SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
55 
56  // FIXME: Clang's logic should be synced with the logic used to initialize
57  // this member and the two implementations should be merged.
58  // For reference:
59  // - Solaris always enables the integrated assembler by default
60  // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
61  // - Windows always enables the integrated assembler by default
62  // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
63  // - MachO targets always enables the integrated assembler by default
64  // - MCAsmInfoDarwin is handling this case
65  // - Generic_GCC toolchains enable the integrated assembler on a per
66  // architecture basis.
67  // - The target subclasses for AArch64, ARM, and X86 handle these cases
68  UseIntegratedAssembler = false;
69  PreserveAsmComments = true;
70 }
71 
72 MCAsmInfo::~MCAsmInfo() = default;
73 
75  return false;
76 }
77 
78 const MCExpr *
80  unsigned Encoding,
81  MCStreamer &Streamer) const {
82  return getExprForFDESymbol(Sym, Encoding, Streamer);
83 }
84 
85 const 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 
100 static bool isAcceptableChar(char C) {
101  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
102  (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
103 }
104 
106  if (Name.empty())
107  return false;
108 
109  // If any of the characters in the string is an unacceptable character, force
110  // quotes.
111  for (char C : Name) {
112  if (!isAcceptableChar(C))
113  return false;
114  }
115 
116  return true;
117 }
118 
120  // FIXME: Does .section .bss/.data/.text work everywhere??
121  return SectionName == ".text" || SectionName == ".data" ||
122  (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
123 }
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:39
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:323
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:79
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:36
#define clEnumVal(ENUMVAL, DESC)
Definition: CommandLine.h:616
Context object for machine code objects.
Definition: MCContext.h:63
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:546
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:119
const char * Code32Directive
Definition: MCAsmInfo.h:149
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
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:423
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:643
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:74
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:105
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:117
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:100
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:347
DefaultOnOff
Definition: DwarfDebug.cpp:107
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
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:86
const char * Code64Directive
Definition: MCAsmInfo.h:150