Skip to content

Commit 0c63d8b

Browse files
authored
[wasm-split] End module names with : in manifests (#8003)
This makes better distinction of module names and function lists. Suggested by by @sbc100 (emscripten-core/emscripten#25577 (comment)). Currently this supports both module names with a `:` and without it for backwards compatibility and also to pass the CI.
1 parent b141e31 commit 0c63d8b

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/support/istring.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ struct IString {
8888
return startsWith(std::string_view(str));
8989
}
9090

91+
bool endsWith(std::string_view suffix) const {
92+
// TODO: Use C++20 `ends_with`.
93+
if (suffix.size() > str.size()) {
94+
return false;
95+
}
96+
return str.substr(str.size() - suffix.size()) == suffix;
97+
}
98+
bool endsWith(IString str) const { return endsWith(str.str); }
99+
100+
// Disambiguate for string literals.
101+
template<int N> bool endsWith(const char (&str)[N]) const {
102+
return endsWith(std::string_view(str));
103+
}
104+
105+
IString substr(size_t pos, size_t len = std::string_view::npos) const {
106+
return IString(str.substr(pos, len));
107+
}
108+
91109
size_t size() const { return str.size(); }
92110
};
93111

src/tools/wasm-split/wasm-split.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ void multiSplitModule(const WasmSplitOptions& options) {
419419
}
420420
Name name = WasmBinaryReader::escape(line);
421421
if (newSection) {
422+
if (name.endsWith(":")) {
423+
name = name.substr(0, name.size() - 1);
424+
if (name.size() == 0) {
425+
Fatal() << "Module name is empty\n";
426+
}
427+
}
422428
if (moduleNameSet.count(name)) {
423429
Fatal() << "Module name " << name << " is listed more than once\n";
424430
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
1
1+
1:
22
wasm::Type::getFeatures() const
33

4-
2
4+
2:
55
wasm::Literal::Literal(std::__2::array<wasm::Literal, 4ul> const&)
66

7-
3
7+
3:
88
std::operator<<(std::__2::basic_ostream<char, std::__2::char_traits<char>>&, wasm::Module&)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
1
1+
1:
22
A
33

4-
2
4+
2:
55
B
66

7-
3
7+
3:
88
C

0 commit comments

Comments
 (0)