Skip to content

Commit

Permalink
WasmBinaryReader: Consistent internal naming
Browse files Browse the repository at this point in the history
For defined functions/globals/tables/memories use `f1`, `t2`, `m3` etc.

This matches the longer names used for imports such as `fimport$1`, but
keeps the names nice and short by avoiding the embedded dollar sign.
  • Loading branch information
sbc100 committed Aug 5, 2024
1 parent e2e5b9c commit 52f4e29
Show file tree
Hide file tree
Showing 108 changed files with 1,753 additions and 1,742 deletions.
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
60 changes: 30 additions & 30 deletions test/dylib.wasm.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,72 @@
(import "env" "g$waka_others" (func $fimport$1 (result i32)))
(import "env" "fp$_Z16waka_func_theirsi$ii" (func $fimport$2 (result i32)))
(import "env" "fp$_Z14waka_func_minei$ii" (func $fimport$3 (result i32)))
(global $global$0 (mut i32) (i32.const 0))
(global $global$1 (mut i32) (i32.const 0))
(global $global$2 (mut i32) (i32.const 0))
(global $global$3 (mut i32) (i32.const 0))
(global $global$4 i32 (i32.const 0))
(global $global$5 i32 (i32.const 0))
(global $g0 (mut i32) (i32.const 0))
(global $g1 (mut i32) (i32.const 0))
(global $g2 (mut i32) (i32.const 0))
(global $g3 (mut i32) (i32.const 0))
(global $g4 i32 (i32.const 0))
(global $g5 i32 (i32.const 0))
(data $0 (global.get $gimport$0) "*\00\00\00")
(export "__wasm_apply_relocs" (func $0))
(export "_Z14waka_func_minei" (func $1))
(export "__original_main" (func $2))
(export "waka_mine" (global $global$4))
(export "main" (func $3))
(export "__dso_handle" (global $global$5))
(export "__post_instantiate" (func $4))
(func $0
(export "__wasm_apply_relocs" (func $f0))
(export "_Z14waka_func_minei" (func $f1))
(export "__original_main" (func $f2))
(export "waka_mine" (global $g4))
(export "main" (func $f3))
(export "__dso_handle" (global $g5))
(export "__post_instantiate" (func $f4))
(func $f0
(nop)
)
(func $1 (param $0 i32) (result i32)
(func $f1 (param $0 i32) (result i32)
(i32.add
(local.get $0)
(i32.const 1)
)
)
(func $2 (result i32)
(func $f2 (result i32)
(i32.add
(i32.load
(global.get $global$3)
(global.get $g3)
)
(i32.add
(i32.load
(global.get $global$2)
(global.get $g2)
)
(i32.add
(global.get $global$0)
(global.get $global$1)
(global.get $g0)
(global.get $g1)
)
)
)
)
(func $3 (param $0 i32) (param $1 i32) (result i32)
(func $f3 (param $0 i32) (param $1 i32) (result i32)
(i32.add
(i32.load
(global.get $global$3)
(global.get $g3)
)
(i32.add
(i32.load
(global.get $global$2)
(global.get $g2)
)
(i32.add
(global.get $global$0)
(global.get $global$1)
(global.get $g0)
(global.get $g1)
)
)
)
)
(func $4
(global.set $global$2
(func $f4
(global.set $g2
(call $fimport$0)
)
(global.set $global$3
(global.set $g3
(call $fimport$1)
)
(global.set $global$0
(global.set $g0
(call $fimport$2)
)
(global.set $global$1
(global.set $g1
(call $fimport$3)
)
)
Expand Down
2 changes: 1 addition & 1 deletion test/elided-br.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$1
(unreachable)
)
Expand Down
4 changes: 2 additions & 2 deletions test/example/c-api-unused-mem.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
133
(module
(type $0 (func))
(memory $0 1024 1024)
(export "memory" (memory $0))
(memory $m0 1024 1024)
(export "memory" (memory $m0))
(export "main" (func $main))
(export "rust_entry" (func $__wasm_start))
(func $main
Expand Down
74 changes: 37 additions & 37 deletions test/fib-dbg.wasm.fromBinary
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@
(import "global" "Infinity" (global $gimport$8 f64))
(import "env" "memoryBase" (global $gimport$9 i32))
(import "env" "tableBase" (global $gimport$10 i32))
(global $global$0 (mut i32) (global.get $gimport$0))
(global $global$1 (mut i32) (global.get $gimport$1))
(global $global$2 (mut i32) (global.get $gimport$2))
(global $global$3 (mut i32) (global.get $gimport$3))
(global $global$4 (mut i32) (global.get $gimport$4))
(global $global$5 (mut i32) (global.get $gimport$5))
(global $global$6 (mut i32) (global.get $gimport$6))
(global $global$7 (mut i32) (i32.const 0))
(global $global$8 (mut i32) (i32.const 0))
(global $global$9 (mut i32) (i32.const 0))
(global $global$10 (mut i32) (i32.const 0))
(global $global$11 (mut f64) (global.get $gimport$7))
(global $global$12 (mut f64) (global.get $gimport$8))
(global $global$13 (mut i32) (i32.const 0))
(global $global$14 (mut i32) (i32.const 0))
(global $global$15 (mut i32) (i32.const 0))
(global $global$16 (mut i32) (i32.const 0))
(global $global$17 (mut f64) (f64.const 0))
(global $global$18 (mut i32) (i32.const 0))
(global $global$19 (mut i32) (i32.const 0))
(global $global$20 (mut i32) (i32.const 0))
(global $global$21 (mut f64) (f64.const 0))
(global $global$22 (mut i32) (i32.const 0))
(global $global$23 (mut f64) (f64.const 0))
(global $g0 (mut i32) (global.get $gimport$0))
(global $g1 (mut i32) (global.get $gimport$1))
(global $g2 (mut i32) (global.get $gimport$2))
(global $g3 (mut i32) (global.get $gimport$3))
(global $g4 (mut i32) (global.get $gimport$4))
(global $g5 (mut i32) (global.get $gimport$5))
(global $g6 (mut i32) (global.get $gimport$6))
(global $g7 (mut i32) (i32.const 0))
(global $g8 (mut i32) (i32.const 0))
(global $g9 (mut i32) (i32.const 0))
(global $g10 (mut i32) (i32.const 0))
(global $g11 (mut f64) (global.get $gimport$7))
(global $g12 (mut f64) (global.get $gimport$8))
(global $g13 (mut i32) (i32.const 0))
(global $g14 (mut i32) (i32.const 0))
(global $g15 (mut i32) (i32.const 0))
(global $g16 (mut i32) (i32.const 0))
(global $g17 (mut f64) (f64.const 0))
(global $g18 (mut i32) (i32.const 0))
(global $g19 (mut i32) (i32.const 0))
(global $g20 (mut i32) (i32.const 0))
(global $g21 (mut f64) (f64.const 0))
(global $g22 (mut i32) (i32.const 0))
(global $g23 (mut f64) (f64.const 0))
(export "setThrew" (func $setThrew))
(export "runPostSets" (func $runPostSets))
(export "establishStackSpace" (func $establishStackSpace))
Expand All @@ -52,18 +52,18 @@
(local $1 i32)
(block $label$1
(local.set $1
(global.get $global$3)
(global.get $g3)
)
(global.set $global$3
(global.set $g3
(i32.add
(global.get $global$3)
(global.get $g3)
(local.get $0)
)
)
(global.set $global$3
(global.set $g3
(i32.and
(i32.add
(global.get $global$3)
(global.get $g3)
(i32.const 15)
)
(i32.const -16)
Expand All @@ -76,35 +76,35 @@
)
(func $stackSave (result i32)
(return
(global.get $global$3)
(global.get $g3)
)
)
(func $stackRestore (param $0 i32)
(global.set $global$3
(global.set $g3
(local.get $0)
)
)
(func $establishStackSpace (param $0 i32) (param $1 i32)
(block $label$1
(global.set $global$3
(global.set $g3
(local.get $0)
)
(global.set $global$4
(global.set $g4
(local.get $1)
)
)
)
(func $setThrew (param $0 i32) (param $1 i32)
(if
(i32.eq
(global.get $global$7)
(global.get $g7)
(i32.const 0)
)
(then
(global.set $global$7
(global.set $g7
(local.get $0)
)
(global.set $global$8
(global.set $g8
(local.get $1)
)
)
Expand All @@ -124,7 +124,7 @@
(local $11 i32)
(block $label$1
(local.set $11
(global.get $global$3)
(global.get $g3)
)
;;@ fib.c:3:0
(local.set $6
Expand Down
2 changes: 1 addition & 1 deletion test/fn_prolog_epilog.debugInfo.wasm.fromBinary
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(type $0 (func))
;;@ src.cpp:1:1
(func $0
(func $f0
(nop)
;;@ src.cpp:2:1
(block $label$1
Expand Down
9 changes: 5 additions & 4 deletions test/lit/basic/atomics-unshared.wast
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
;; CHECK-BIN: (type $0 (func))

;; CHECK-BIN: (memory $0 1 1)
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (memory $0 1 1)
(memory $0 1 1)

;; CHECK-TEXT: (func $foo (type $0)
Expand Down Expand Up @@ -47,7 +44,11 @@
))
)
)
;; CHECK-BIN-NODEBUG: (func $0 (type $0)
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (memory $m0 1 1)

;; CHECK-BIN-NODEBUG: (func $f0 (type $0)
;; CHECK-BIN-NODEBUG-NEXT: (drop
;; CHECK-BIN-NODEBUG-NEXT: (i32.atomic.rmw.cmpxchg
;; CHECK-BIN-NODEBUG-NEXT: (i32.const 0)
Expand Down
Loading

0 comments on commit 52f4e29

Please sign in to comment.