Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WasmBinaryReader: Consistent internal naming #6812

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/parser/context-decls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace wasm::WATParser {

namespace {

Name makeName(std::string prefix, size_t counter) {
return Name(prefix + std::to_string(counter));
}

void applyImportNames(Importable& item, ImportNames* names) {
if (names) {
item.module = names->mod;
Expand Down Expand Up @@ -55,7 +59,7 @@ ParseDeclsCtx::addFuncDecl(Index pos, Name name, ImportNames* importNames) {
}
f->setExplicitName(name);
} else {
name = (importNames ? "fimport$" : "") + std::to_string(funcCounter++);
name = makeName(importNames ? "fimport$" : "f", funcCounter++);
name = Names::getValidFunctionName(wasm, name);
f->name = name;
}
Expand Down Expand Up @@ -95,7 +99,7 @@ Result<Table*> ParseDeclsCtx::addTableDecl(Index pos,
}
t->setExplicitName(name);
} else {
name = (importNames ? "timport$" : "") + std::to_string(tableCounter++);
name = makeName(importNames ? "timport$" : "t", tableCounter++);
name = Names::getValidTableName(wasm, name);
t->name = name;
}
Expand Down Expand Up @@ -151,7 +155,7 @@ Result<Memory*> ParseDeclsCtx::addMemoryDecl(Index pos,
}
m->setExplicitName(name);
} else {
name = (importNames ? "mimport$" : "") + std::to_string(memoryCounter++);
name = makeName(importNames ? "mimport$" : "m", memoryCounter++);
name = Names::getValidMemoryName(wasm, name);
m->name = name;
}
Expand Down Expand Up @@ -196,8 +200,7 @@ ParseDeclsCtx::addGlobalDecl(Index pos, Name name, ImportNames* importNames) {
}
g->setExplicitName(name);
} else {
name =
(importNames ? "gimport$" : "global$") + std::to_string(globalCounter++);
name = makeName(importNames ? "gimport$" : "g", globalCounter++);
name = Names::getValidGlobalName(wasm, name);
g->name = name;
}
Expand Down Expand Up @@ -277,7 +280,7 @@ ParseDeclsCtx::addTagDecl(Index pos, Name name, ImportNames* importNames) {
}
t->setExplicitName(name);
} else {
name = (importNames ? "eimport$" : "tag$") + std::to_string(tagCounter++);
name = makeName(importNames ? "eimport$" : "tag$", tagCounter++);
name = Names::getValidTagName(wasm, name);
t->name = name;
}
Expand Down
8 changes: 4 additions & 4 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ void WasmBinaryReader::readMemories() {
BYN_TRACE("num: " << num << std::endl);
for (size_t i = 0; i < num; i++) {
BYN_TRACE("read one\n");
auto memory = Builder::makeMemory(makeName("", i));
auto memory = Builder::makeMemory(makeName("m", i));
getResizableLimits(memory->initial,
memory->max,
memory->shared,
Expand Down Expand Up @@ -2689,7 +2689,7 @@ void WasmBinaryReader::readFunctions() {
endOfFunction = pos + size;

auto func = std::make_unique<Function>();
func->name = makeName("", i);
func->name = makeName("f", i);
func->type = getTypeByFunctionIndex(numImports + i);
currFunction = func.get();

Expand Down Expand Up @@ -3047,7 +3047,7 @@ void WasmBinaryReader::readGlobals() {
}
auto* init = readExpression();
wasm.addGlobal(
Builder::makeGlobal(makeName("global$", i),
Builder::makeGlobal(makeName("g", i),
type,
init,
mutable_ ? Builder::Mutable : Builder::Immutable));
Expand Down Expand Up @@ -3367,7 +3367,7 @@ void WasmBinaryReader::readTableDeclarations() {
if (!elemType.isRef()) {
throwError("Table type must be a reference type");
}
auto table = Builder::makeTable(makeName("", i), elemType);
auto table = Builder::makeTable(makeName("t", i), elemType);
bool is_shared;
getResizableLimits(table->initial,
table->max,
Expand Down
2 changes: 1 addition & 1 deletion test/br_to_exit.wasm.fromBinary
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $0 (func))
(func $0
(func $f0
(block $label$0
(br $label$0)
)
Expand Down
2 changes: 1 addition & 1 deletion test/br_to_try.wasm.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(type $0 (func (param i32)))
(type $1 (func))
(tag $tag$0 (param i32))
(func $0
(func $f0
(try $label$3
(do
(block $label$1
Expand Down
6 changes: 3 additions & 3 deletions test/break-to-return.wasm.fromBinary
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(module
(type $0 (func (param i32 i32) (result i32)))
(memory $0 256 256)
(export "add" (func $0))
(func $0 (param $0 i32) (param $1 i32) (result i32)
(memory $m0 256 256)
(export "add" (func $f0))
(func $f0 (param $0 i32) (param $1 i32) (result i32)
(block $label$0 (result i32)
(br $label$0
(i32.add
Expand Down
2 changes: 1 addition & 1 deletion test/break-within-catch.wasm.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(type $0 (func (param i32)))
(type $1 (func))
(tag $tag$0 (param i32))
(func $0
(func $f0
(block $label$2
(try $label$3
(do
Expand Down
4 changes: 2 additions & 2 deletions test/consume-stacky.wasm.fromBinary
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(type $0 (func (result i32)))
(memory $0 1 1)
(func $0 (result i32)
(memory $m0 1 1)
(func $f0 (result i32)
(local $0 i32)
(local.set $0
(i32.const 1)
Expand Down
6 changes: 3 additions & 3 deletions test/ctor-eval/bad-indirect-call.wast.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(module
(type $v (func))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "waka waka waka waka waka")
(table $0 1 1 funcref)
(table $t0 1 1 funcref)
(elem $0 (i32.const 0) $call-indirect)
(export "test1" (func $test1))
(func $test1 (type $v)
(call_indirect $0 (type $v)
(call_indirect $t0 (type $v)
(i32.const 1)
)
(i32.store8
Expand Down
6 changes: 3 additions & 3 deletions test/ctor-eval/bad-indirect-call2.wast.out
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(module
(type $v (func))
(import "env" "_abort" (func $_abort (type $v)))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "waka waka waka waka waka")
(table $0 2 2 funcref)
(table $t0 2 2 funcref)
(elem $0 (i32.const 0) $_abort $call-indirect)
(export "test1" (func $test1))
(func $test1 (type $v)
(call_indirect $0 (type $v)
(call_indirect $t0 (type $v)
(i32.const 0)
)
(i32.store8
Expand Down
6 changes: 3 additions & 3 deletions test/ctor-eval/bad-indirect-call3.wast.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
(type $0 (func (param externref)))
(type $1 (func))
(type $funcref_=>_none (func (param funcref)))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "waka waka waka waka waka")
(table $0 1 1 funcref)
(table $t0 1 1 funcref)
(elem $implicit-elem (i32.const 0) $callee)
(export "sig_mismatch" (func $sig_mismatch))
(func $callee (type $0) (param $0 externref)
Expand All @@ -14,7 +14,7 @@
)
)
(func $sig_mismatch (type $1)
(call_indirect $0 (type $funcref_=>_none)
(call_indirect $t0 (type $funcref_=>_none)
(ref.null nofunc)
(i32.const 0)
)
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/basics-flatten.wast.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $v (func))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "nas\00\00\00aka\00yzkx waka wakm\00\00\00\00\00\00C")
(func $call-indirect (type $v)
(i32.store8
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/basics.wast.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $v (func))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "nas\00\00\00aka yzkx waka wakm\00\00\00\00\00\00C")
(func $call-indirect (type $v)
(i32.store8
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/ignore-external-input.wast.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(type $0 (func (result i32)))
(type $1 (func))
(import "wasi_snapshot_preview1" "something_else" (func $wasi_something_else (type $0) (result i32)))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 28) "aaaa")
(export "test3" (func $test3))
(func $test3 (type $1)
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/imported-global-2.wast.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(type $0 (func (result i32)))
(import "env" "imported" (global $imported i32))
(memory $0 256 256)
(memory $m0 256 256)
(export "test1" (func $test1))
(export "keepalive" (func $keepalive))
(func $test1 (type $0) (result i32)
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/imported-global.wast.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $0 (func))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "waka waka waka waka waka")
(export "test1" (func $test1))
(func $test1 (type $0)
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/indirect-call3.wast.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(type $v (func))
(import "env" "_abort" (func $_abort (type $v)))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "waka waka xaka waka waka\00\00\00\00\00\00C")
(func $call-indirect (type $v)
(i32.store8
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/just_some.wast.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $0 (func))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "wasa waka waka waka waka")
(export "test2" (func $test2))
(export "test3" (func $test3))
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/partial-locals-tee.wast.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(type $0 (func (param i32 i32)))
(type $1 (func))
(import "import" "import" (func $import (type $0) (param i32 i32)))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "__s______________")
(export "test1" (func $test1_2))
(func $test1_2 (type $1)
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/partial-locals.wast.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(type $0 (func))
(import "import" "import" (func $import (type $0)))
(global $sp (mut i32) (i32.const 104))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "__s______________")
(export "test1" (func $test1_2))
(func $test1_2 (type $0)
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/partial-return.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(data (i32.const 10) "_________________")

(export "test1" (func $test1))
(export "memory" (memory $0))
(export "memory" (memory 0))

(func $test1
;; A safe store, should alter memory
Expand Down
4 changes: 2 additions & 2 deletions test/ctor-eval/partial-return.wast.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "__s______________")
(export "memory" (memory $0))
(export "memory" (memory $m0))
)
2 changes: 1 addition & 1 deletion test/ctor-eval/partial.wast.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(type $0 (func))
(import "import" "import" (func $import (type $0)))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "__s______________")
(export "test1" (func $test1_2))
(export "keepalive" (func $test1))
Expand Down
2 changes: 1 addition & 1 deletion test/ctor-eval/unsafe_call.wast.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(type $0 (func))
(memory $0 256 256)
(memory $m0 256 256)
(data $0 (i32.const 10) "waka waka waka waka waka")
(export "test1" (func $test1))
(func $test1 (type $0)
Expand Down
Loading
Loading