summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-10-15 13:13:10 -0500
committerGitHub <noreply@github.com>2020-10-15 11:13:10 -0700
commitd0dae28c05dd9ef4da0d77fee42cf15cd1d94e3c (patch)
tree99b017777034208d60a3f09593e4acae81c9a1c6 /src/wasm
parentc2e6cb0b5530b0d4e1a3161de319fc8373476578 (diff)
downloadbinaryen-d0dae28c05dd9ef4da0d77fee42cf15cd1d94e3c.tar.gz
binaryen-d0dae28c05dd9ef4da0d77fee42cf15cd1d94e3c.tar.bz2
binaryen-d0dae28c05dd9ef4da0d77fee42cf15cd1d94e3c.zip
Only write explicit names to name section (#3241)
Fixes: #3226
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp18
-rw-r--r--src/wasm/wasm-s-parser.cpp24
2 files changed, 22 insertions, 20 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 9376c88ad..b6e926f6a 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -628,7 +628,7 @@ void WasmBinaryWriter::writeNames() {
}
// table names
- if (wasm->table.exists && wasm->table.name.is()) {
+ if (wasm->table.exists && wasm->table.hasExplicitName) {
auto substart =
startSubsection(BinaryConsts::UserSections::Subsection::NameTable);
o << U32LEB(1) << U32LEB(0); // currently exactly 1 table at index 0
@@ -637,7 +637,7 @@ void WasmBinaryWriter::writeNames() {
}
// memory names
- if (wasm->memory.exists && wasm->memory.name.is()) {
+ if (wasm->memory.exists && wasm->memory.hasExplicitName) {
auto substart =
startSubsection(BinaryConsts::UserSections::Subsection::NameMemory);
o << U32LEB(1) << U32LEB(0); // currently exactly 1 memory at index 0
@@ -650,7 +650,7 @@ void WasmBinaryWriter::writeNames() {
std::vector<std::pair<Index, Global*>> globalsWithNames;
Index checked = 0;
auto check = [&](Global* curr) {
- if (curr->name.is()) {
+ if (curr->hasExplicitName) {
globalsWithNames.push_back({checked, curr});
}
checked++;
@@ -2301,9 +2301,9 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
}
auto numFunctionImports = functionImports.size();
if (index < numFunctionImports) {
- functionImports[index]->name = name;
+ functionImports[index]->setExplicitName(name);
} else if (index - numFunctionImports < functions.size()) {
- functions[index - numFunctionImports]->name = name;
+ functions[index - numFunctionImports]->setExplicitName(name);
} else {
std::cerr << "warning: function index out of bounds in name section, "
"function subsection: "
@@ -2358,7 +2358,7 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
auto index = getU32LEB();
auto rawName = getInlineString();
if (index == 0) {
- wasm.table.name = escape(rawName);
+ wasm.table.setExplicitName(escape(rawName));
} else {
std::cerr << "warning: table index out of bounds in name section, "
"table subsection: "
@@ -2372,7 +2372,7 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
auto index = getU32LEB();
auto rawName = getInlineString();
if (index == 0) {
- wasm.memory.name = escape(rawName);
+ wasm.memory.setExplicitName(escape(rawName));
} else {
std::cerr << "warning: memory index out of bounds in name section, "
"memory subsection: "
@@ -2394,9 +2394,9 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
}
auto numGlobalImports = globalImports.size();
if (index < numGlobalImports) {
- globalImports[index]->name = name;
+ globalImports[index]->setExplicitName(name);
} else if (index - numGlobalImports < globals.size()) {
- globals[index - numGlobalImports]->name = name;
+ globals[index - numGlobalImports]->setExplicitName(name);
} else {
std::cerr << "warning: global index out of bounds in name section, "
"global subsection: "
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index d3367d3f6..c4de76987 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -714,6 +714,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
Name name, exportName;
size_t i = parseFunctionNames(s, name, exportName);
+ bool hasExplicitName = name.is();
if (!preParseImport) {
if (!name.is()) {
// unnamed, use an index
@@ -762,7 +763,7 @@ void SExpressionWasmBuilder::parseFunction(Element& s, bool preParseImport) {
throw ParseException("!preParseImport in func", s.line, s.col);
}
auto im = make_unique<Function>();
- im->name = name;
+ im->setName(name, hasExplicitName);
im->module = importModule;
im->base = importBase;
im->sig = sig;
@@ -2185,7 +2186,7 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
wasm.memory.shared = false;
Index i = 1;
if (s[i]->dollared()) {
- wasm.memory.name = s[i++]->str();
+ wasm.memory.setExplicitName(s[i++]->str());
}
i = parseMemoryIndex(s, i);
Name importModule, importBase;
@@ -2358,7 +2359,8 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
(*s[3])[newStyleInner]->dollared()) {
name = (*s[3])[newStyleInner++]->str();
}
- if (!name.is()) {
+ bool hasExplicitName = name.is();
+ if (!hasExplicitName) {
if (kind == ExternalKind::Function) {
name = Name("fimport$" + std::to_string(functionCounter++));
functionNames.push_back(name);
@@ -2396,7 +2398,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
auto func = make_unique<Function>();
j = parseTypeUse(inner, j, func->sig);
- func->name = name;
+ func->setName(name, hasExplicitName);
func->module = module;
func->base = base;
functionTypes[name] = func->sig.results;
@@ -2415,14 +2417,14 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
mutable_ = true;
}
auto global = make_unique<Global>();
- global->name = name;
+ global->setName(name, hasExplicitName);
global->module = module;
global->base = base;
global->type = type;
global->mutable_ = mutable_;
wasm.addGlobal(global.release());
} else if (kind == ExternalKind::Table) {
- wasm.table.name = name;
+ wasm.table.setName(name, hasExplicitName);
wasm.table.module = module;
wasm.table.base = base;
if (j < inner.size() - 1) {
@@ -2440,7 +2442,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
j++; // funcref
// ends with the table element type
} else if (kind == ExternalKind::Memory) {
- wasm.memory.name = name;
+ wasm.memory.setName(name, hasExplicitName);
wasm.memory.module = module;
wasm.memory.base = base;
if (inner[j]->isList()) {
@@ -2465,7 +2467,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
}
event->attribute = atoi(attrElem[1]->c_str());
j = parseTypeUse(inner, j, event->sig);
- event->name = name;
+ event->setName(name, hasExplicitName);
event->module = module;
event->base = base;
wasm.addEvent(event.release());
@@ -2480,7 +2482,7 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) {
std::unique_ptr<Global> global = make_unique<Global>();
size_t i = 1;
if (s[i]->dollared() && !(s[i]->isStr() && isType(s[i]->str()))) {
- global->name = s[i++]->str();
+ global->setExplicitName(s[i++]->str());
} else {
global->name = Name::fromInt(globalCounter);
}
@@ -2569,7 +2571,7 @@ void SExpressionWasmBuilder::parseTable(Element& s, bool preParseImport) {
return; // empty table in old notation
}
if (s[i]->dollared()) {
- wasm.table.name = s[i++]->str();
+ wasm.table.setExplicitName(s[i++]->str());
}
if (i == s.size()) {
return;
@@ -2695,7 +2697,7 @@ void SExpressionWasmBuilder::parseEvent(Element& s, bool preParseImport) {
// Parse name
if (s[i]->isStr() && s[i]->dollared()) {
auto& inner = *s[i++];
- event->name = inner.str();
+ event->setExplicitName(inner.str());
if (wasm.getEventOrNull(event->name)) {
throw ParseException("duplicate event", inner.line, inner.col);
}