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/Support/raw_ostream.h"
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
) {
32 for (const char *B
= Name
.begin(), *E
= Name
.end(); B
< E
; ++B
) {
33 if (*B
== '"') // Unquoted "
35 else if (*B
!= '\\') // Neither " or backslash
37 else if (B
+ 1 == E
) // Trailing backslash
40 OS
<< B
[0] << B
[1]; // Quoted character
47 void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo
&MAI
, const Triple
&T
,
49 const MCExpr
*Subsection
) const {
51 if (shouldOmitSectionDirective(SectionName
, MAI
)) {
52 OS
<< '\t' << getSectionName();
55 Subsection
->print(OS
, &MAI
);
62 printName(OS
, getSectionName());
72 // If comment string is '@', e.g. as on ARM - use '%' instead
73 if (MAI
.getCommentString()[0] == '@')
78 // TODO: Print section type.
81 OS
<< ",unique," << UniqueID
;
86 OS
<< "\t.subsection\t";
87 Subsection
->print(OS
, &MAI
);
92 bool MCSectionWasm::UseCodeAlign() const { return false; }
94 bool MCSectionWasm::isVirtualSection() const { return false; }