LLVM  5.0.0
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"
20 
21 using namespace llvm;
22 
24  SeparatorString = ";";
25  CommentString = "#";
26  LabelSuffix = ":";
27  PrivateGlobalPrefix = "L";
30  InlineAsmStart = "APP";
31  InlineAsmEnd = "NO_APP";
32  Code16Directive = ".code16";
33  Code32Directive = ".code32";
34  Code64Directive = ".code64";
35  ZeroDirective = "\t.zero\t";
36  AsciiDirective = "\t.ascii\t";
37  AscizDirective = "\t.asciz\t";
38  Data8bitsDirective = "\t.byte\t";
39  Data16bitsDirective = "\t.short\t";
40  Data32bitsDirective = "\t.long\t";
41  Data64bitsDirective = "\t.quad\t";
42  GlobalDirective = "\t.globl\t";
43  WeakDirective = "\t.weak\t";
44 
45  // FIXME: Clang's logic should be synced with the logic used to initialize
46  // this member and the two implementations should be merged.
47  // For reference:
48  // - Solaris always enables the integrated assembler by default
49  // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
50  // - Windows always enables the integrated assembler by default
51  // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
52  // - MachO targets always enables the integrated assembler by default
53  // - MCAsmInfoDarwin is handling this case
54  // - Generic_GCC toolchains enable the integrated assembler on a per
55  // architecture basis.
56  // - The target subclasses for AArch64, ARM, and X86 handle these cases
57  UseIntegratedAssembler = false;
58  PreserveAsmComments = true;
59 }
60 
61 MCAsmInfo::~MCAsmInfo() = default;
62 
64  return false;
65 }
66 
67 const MCExpr *
69  unsigned Encoding,
70  MCStreamer &Streamer) const {
71  return getExprForFDESymbol(Sym, Encoding, Streamer);
72 }
73 
74 const MCExpr *
76  unsigned Encoding,
77  MCStreamer &Streamer) const {
78  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
79  return MCSymbolRefExpr::create(Sym, Streamer.getContext());
80 
81  MCContext &Context = Streamer.getContext();
82  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
83  MCSymbol *PCSym = Context.createTempSymbol();
84  Streamer.EmitLabel(PCSym);
85  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
86  return MCBinaryExpr::createSub(Res, PC, Context);
87 }
88 
89 static bool isAcceptableChar(char C) {
90  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
91  (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
92 }
93 
95  if (Name.empty())
96  return false;
97 
98  // If any of the characters in the string is an unacceptable character, force
99  // quotes.
100  for (char C : Name) {
101  if (!isAcceptableChar(C))
102  return false;
103  }
104 
105  return true;
106 }
107 
109  // FIXME: Does .section .bss/.data/.text work everywhere??
110  return SectionName == ".text" || SectionName == ".data" ||
111  (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
112 }
const char * Code16Directive
These are assembly directives that tells the assembler to interpret the following instructions differ...
Definition: MCAsmInfo.h:139
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:94
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:357
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:123
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:288
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:305
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:183
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:165
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:231
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
Definition: MCAsmInfo.cpp:63
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:169
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line...
Definition: MCAsmInfo.h:101
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:68
StringRef CommentString
This indicates the comment character used by the assembler.
Definition: MCAsmInfo.h:105
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:180
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
MCContext & getContext() const
Definition: MCStreamer.h:226
Context object for machine code objects.
Definition: MCContext.h:59
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:528
const char * Code32Directive
Definition: MCAsmInfo.h:140
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:174
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:108
const char * Name
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:133
Streaming machine code generation interface.
Definition: MCStreamer.h:167
const char * Data16bitsDirective
Definition: MCAsmInfo.h:181
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:449
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:108
virtual ~MCAsmInfo()
const char * InlineAsmEnd
Definition: MCAsmInfo.h:134
const char * Data32bitsDirective
Definition: MCAsmInfo.h:182
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:360
#define C
Definition: LargeTest.cpp:25
StringRef LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition: MCAsmInfo.h:129
static bool isAcceptableChar(char C)
Definition: MCAsmInfo.cpp:89
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:75
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:301
const char SectionName[]
Definition: AMDGPUPTNote.h:24
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:119
const char * Code64Directive
Definition: MCAsmInfo.h:141