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