Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / MC / MCSectionWasm.cpp
blobe25af1c3133fd593c3ee1db49193d57731ac4740
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 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCSectionWasm.h"
10 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCSymbolWasm.h"
13 #include "llvm/Support/raw_ostream.h"
15 using namespace llvm;
17 // Decides whether a '.section' directive
18 // should be printed before the section name.
19 bool MCSectionWasm::shouldOmitSectionDirective(StringRef Name,
20 const MCAsmInfo &MAI) const {
21 return MAI.shouldOmitSectionDirective(Name);
24 static void printName(raw_ostream &OS, StringRef Name) {
25 if (Name.find_first_not_of("0123456789_."
26 "abcdefghijklmnopqrstuvwxyz"
27 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
28 OS << Name;
29 return;
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;
44 OS << '"';
47 void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
48 raw_ostream &OS,
49 uint32_t Subsection) const {
51 if (shouldOmitSectionDirective(getName(), MAI)) {
52 OS << '\t' << getName();
53 if (Subsection)
54 OS << '\t' << Subsection;
55 OS << '\n';
56 return;
59 OS << "\t.section\t";
60 printName(OS, getName());
61 OS << ",\"";
63 if (IsPassive)
64 OS << 'p';
65 if (Group)
66 OS << 'G';
67 if (SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
68 OS << 'S';
69 if (SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
70 OS << 'T';
71 if (SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN)
72 OS << 'R';
74 OS << '"';
76 OS << ',';
78 // If comment string is '@', e.g. as on ARM - use '%' instead
79 if (MAI.getCommentString()[0] == '@')
80 OS << '%';
81 else
82 OS << '@';
84 // TODO: Print section type.
86 if (Group) {
87 OS << ",";
88 printName(OS, Group->getName());
89 OS << ",comdat";
92 if (isUnique())
93 OS << ",unique," << UniqueID;
95 OS << '\n';
97 if (Subsection)
98 OS << "\t.subsection\t" << Subsection << '\n';
101 bool MCSectionWasm::useCodeAlign() const { return false; }