LLVM  14.0.0git
MCSectionWasm.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCSectionWasm.cpp - Wasm Code Section Representation --------===//
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 
10 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCSymbol.h"
13 #include "llvm/MC/MCSymbolWasm.h"
15 
16 using namespace llvm;
17 
18 // Decides whether a '.section' directive
19 // should be printed before the section name.
21  const MCAsmInfo &MAI) const {
22  return MAI.shouldOmitSectionDirective(Name);
23 }
24 
25 static void printName(raw_ostream &OS, StringRef Name) {
26  if (Name.find_first_not_of("0123456789_."
27  "abcdefghijklmnopqrstuvwxyz"
28  "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
29  OS << Name;
30  return;
31  }
32  OS << '"';
33  for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
34  if (*B == '"') // Unquoted "
35  OS << "\\\"";
36  else if (*B != '\\') // Neither " or backslash
37  OS << *B;
38  else if (B + 1 == E) // Trailing backslash
39  OS << "\\\\";
40  else {
41  OS << B[0] << B[1]; // Quoted character
42  ++B;
43  }
44  }
45  OS << '"';
46 }
47 
49  raw_ostream &OS,
50  const MCExpr *Subsection) const {
51 
52  if (shouldOmitSectionDirective(getName(), MAI)) {
53  OS << '\t' << getName();
54  if (Subsection) {
55  OS << '\t';
56  Subsection->print(OS, &MAI);
57  }
58  OS << '\n';
59  return;
60  }
61 
62  OS << "\t.section\t";
63  printName(OS, getName());
64  OS << ",\"";
65 
66  if (IsPassive)
67  OS << 'p';
68  if (Group)
69  OS << 'G';
70  if (SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
71  OS << 'S';
72  if (SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
73  OS << 'T';
74 
75  OS << '"';
76 
77  OS << ',';
78 
79  // If comment string is '@', e.g. as on ARM - use '%' instead
80  if (MAI.getCommentString()[0] == '@')
81  OS << '%';
82  else
83  OS << '@';
84 
85  // TODO: Print section type.
86 
87  if (Group) {
88  OS << ",";
89  printName(OS, Group->getName());
90  OS << ",comdat";
91  }
92 
93  if (isUnique())
94  OS << ",unique," << UniqueID;
95 
96  OS << '\n';
97 
98  if (Subsection) {
99  OS << "\t.subsection\t";
100  Subsection->print(OS, &MAI);
101  OS << '\n';
102  }
103 }
104 
105 bool MCSectionWasm::UseCodeAlign() const { return false; }
106 
107 bool MCSectionWasm::isVirtualSection() const { return false; }
llvm::MCSection::Name
StringRef Name
Definition: MCSection.h:111
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCAsmInfo::getCommentString
StringRef getCommentString() const
Definition: MCAsmInfo.h:641
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::MCSectionWasm::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionWasm.cpp:48
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
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
MCSymbolWasm.h
MCSymbol.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSectionWasm::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionWasm.cpp:107
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:198
llvm::MCSectionWasm::shouldOmitSectionDirective
bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name.
Definition: MCSectionWasm.cpp:20
llvm::wasm::WASM_SEG_FLAG_TLS
@ WASM_SEG_FLAG_TLS
Definition: Wasm.h:377
printName
static void printName(raw_ostream &OS, StringRef Name)
Definition: MCSectionWasm.cpp:25
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:122
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MCExpr::print
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
llvm::MCSectionWasm::UseCodeAlign
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
Definition: MCSectionWasm.cpp:105
llvm::MCSectionWasm::isUnique
bool isUnique() const
Definition: MCSectionWasm.h:72
raw_ostream.h
MCExpr.h
llvm::wasm::WASM_SEG_FLAG_STRINGS
@ WASM_SEG_FLAG_STRINGS
Definition: Wasm.h:376
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCSectionWasm.h