2017-02-22 02:23:18 +01:00
|
|
|
//===- lib/MC/MCSectionWasm.cpp - Wasm Code Section Representation --------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-02-22 02:23:18 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCSectionWasm.h"
|
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2020-06-27 10:57:03 +02:00
|
|
|
#include "llvm/MC/MCSymbolWasm.h"
|
2017-02-22 02:23:18 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Decides whether a '.section' directive
|
|
|
|
// should be printed before the section name.
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-04 20:13:39 +01:00
|
|
|
bool MCSectionWasm::shouldOmitSectionDirective(StringRef Name,
|
2017-02-22 02:23:18 +01:00
|
|
|
const MCAsmInfo &MAI) const {
|
|
|
|
return MAI.shouldOmitSectionDirective(Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printName(raw_ostream &OS, StringRef Name) {
|
|
|
|
if (Name.find_first_not_of("0123456789_."
|
|
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
|
|
|
|
OS << Name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OS << '"';
|
|
|
|
for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
|
|
|
|
if (*B == '"') // Unquoted "
|
|
|
|
OS << "\\\"";
|
|
|
|
else if (*B != '\\') // Neither " or backslash
|
|
|
|
OS << *B;
|
|
|
|
else if (B + 1 == E) // Trailing backslash
|
|
|
|
OS << "\\\\";
|
|
|
|
else {
|
|
|
|
OS << B[0] << B[1]; // Quoted character
|
|
|
|
++B;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
|
|
|
|
raw_ostream &OS,
|
|
|
|
const MCExpr *Subsection) const {
|
|
|
|
|
2020-04-16 00:49:05 +02:00
|
|
|
if (shouldOmitSectionDirective(getName(), MAI)) {
|
2020-04-16 00:49:05 +02:00
|
|
|
OS << '\t' << getName();
|
2017-02-22 02:23:18 +01:00
|
|
|
if (Subsection) {
|
|
|
|
OS << '\t';
|
|
|
|
Subsection->print(OS, &MAI);
|
|
|
|
}
|
|
|
|
OS << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\t.section\t";
|
2020-04-16 00:49:05 +02:00
|
|
|
printName(OS, getName());
|
2017-02-22 02:23:18 +01:00
|
|
|
OS << ",\"";
|
|
|
|
|
2019-02-19 23:56:19 +01:00
|
|
|
if (IsPassive)
|
2021-02-27 01:09:32 +01:00
|
|
|
OS << 'p';
|
2020-12-11 01:40:08 +01:00
|
|
|
if (Group)
|
2021-02-27 01:09:32 +01:00
|
|
|
OS << 'G';
|
|
|
|
if (SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
|
|
|
|
OS << 'S';
|
2021-05-10 23:58:47 +02:00
|
|
|
if (SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
|
|
|
|
OS << 'T';
|
2017-02-22 02:23:18 +01:00
|
|
|
|
|
|
|
OS << '"';
|
|
|
|
|
|
|
|
OS << ',';
|
|
|
|
|
|
|
|
// If comment string is '@', e.g. as on ARM - use '%' instead
|
|
|
|
if (MAI.getCommentString()[0] == '@')
|
|
|
|
OS << '%';
|
|
|
|
else
|
|
|
|
OS << '@';
|
|
|
|
|
|
|
|
// TODO: Print section type.
|
|
|
|
|
2020-12-11 01:40:08 +01:00
|
|
|
if (Group) {
|
|
|
|
OS << ",";
|
|
|
|
printName(OS, Group->getName());
|
|
|
|
OS << ",comdat";
|
|
|
|
}
|
|
|
|
|
2017-02-22 02:23:18 +01:00
|
|
|
if (isUnique())
|
|
|
|
OS << ",unique," << UniqueID;
|
|
|
|
|
|
|
|
OS << '\n';
|
|
|
|
|
|
|
|
if (Subsection) {
|
|
|
|
OS << "\t.subsection\t";
|
|
|
|
Subsection->print(OS, &MAI);
|
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCSectionWasm::UseCodeAlign() const { return false; }
|
|
|
|
|
|
|
|
bool MCSectionWasm::isVirtualSection() const { return false; }
|