1 //===- lib/MC/MCSectionWasm.cpp - Wasm Code Section Representation --------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCSectionWasm.h"
10 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCSymbol.h"
13 #include "llvm/MC/MCSymbolWasm.h"
14 #include "llvm/Support/raw_ostream.h"
18 // Decides whether a '.section' directive
19 // should be printed before the section name.
20 bool MCSectionWasm::shouldOmitSectionDirective(StringRef Name
,
21 const MCAsmInfo
&MAI
) const {
22 return MAI
.shouldOmitSectionDirective(Name
);
25 static void printName(raw_ostream
&OS
, StringRef Name
) {
26 if (Name
.find_first_not_of("0123456789_."
27 "abcdefghijklmnopqrstuvwxyz"
28 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name
.npos
) {
33 for (const char *B
= Name
.begin(), *E
= Name
.end(); B
< E
; ++B
) {
34 if (*B
== '"') // Unquoted "
36 else if (*B
!= '\\') // Neither " or backslash
38 else if (B
+ 1 == E
) // Trailing backslash
41 OS
<< B
[0] << B
[1]; // Quoted character
48 void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo
&MAI
, const Triple
&T
,
50 const MCExpr
*Subsection
) const {
52 if (shouldOmitSectionDirective(getName(), MAI
)) {
53 OS
<< '\t' << getName();
56 Subsection
->print(OS
, &MAI
);
63 printName(OS
, getName());
70 if (SegmentFlags
& wasm::WASM_SEG_FLAG_STRINGS
)
72 if (SegmentFlags
& wasm::WASM_SEG_FLAG_TLS
)
79 // If comment string is '@', e.g. as on ARM - use '%' instead
80 if (MAI
.getCommentString()[0] == '@')
85 // TODO: Print section type.
89 printName(OS
, Group
->getName());
94 OS
<< ",unique," << UniqueID
;
99 OS
<< "\t.subsection\t";
100 Subsection
->print(OS
, &MAI
);
105 bool MCSectionWasm::UseCodeAlign() const { return false; }
107 bool MCSectionWasm::isVirtualSection() const { return false; }