Skip to content

Commit

Permalink
Make source parser consistent with binary parser when naming things. NFC
Browse files Browse the repository at this point in the history
The `timport$` prefix is already used for tables, so the binary
parser currently uses `eimport$` to name tags (I guess because they
are normally exception tags?).

For defined globals the binary parser uses `global$` prefix.
  • Loading branch information
sbc100 committed Aug 6, 2024
1 parent e2e5b9c commit 2b1c1d8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/parser/context-decls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ ParseDeclsCtx::addGlobalDecl(Index pos, Name name, ImportNames* importNames) {
}
g->setExplicitName(name);
} else {
name = (importNames ? "gimport$" : "") + std::to_string(globalCounter++);
name = (importNames ? "gimport$" : "global$") + std::to_string(globalCounter++);
name = Names::getValidGlobalName(wasm, name);
g->name = name;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ ParseDeclsCtx::addTagDecl(Index pos, Name name, ImportNames* importNames) {
}
t->setExplicitName(name);
} else {
name = (importNames ? "timport$" : "") + std::to_string(tagCounter++);
name = (importNames ? "eimport$" : "tag$") + std::to_string(tagCounter++);
name = Names::getValidTagName(wasm, name);
t->name = name;
}
Expand Down
4 changes: 2 additions & 2 deletions test/lit/basic/tags.wast
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

;; CHECK-TEXT: (import "env" "im0" (tag $e-import (param i32)))

;; CHECK-TEXT: (import "env" "im1" (tag $timport$0 (param i32 f32)))
;; CHECK-TEXT: (import "env" "im1" (tag $eimport$0 (param i32 f32)))

;; CHECK-TEXT: (tag $1 (param i32))
;; CHECK-TEXT: (tag $tag$1 (param i32))

;; CHECK-TEXT: (tag $e (param i32 f32))
;; CHECK-BIN: (type $0 (func (param i32 f32)))
Expand Down
14 changes: 7 additions & 7 deletions test/lit/wat-kitchen-sink.wast
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@

;; CHECK: (import "mod" "t0" (tag $imported (param i32 i64)))

;; CHECK: (import "mod" "t1" (tag $timport$0))
;; CHECK: (import "mod" "t1" (tag $eimport$0))

;; CHECK: (import "mod" "imported-tag" (tag $timport$1))
;; CHECK: (import "mod" "imported-tag" (tag $eimport$1))

;; CHECK: (global $2 (mut i32) (i32.const 0))
;; CHECK: (global $global$2 (mut i32) (i32.const 0))

;; CHECK: (global $i32 i32 (i32.const 42))
(global $i32 i32 i32.const 42)
Expand Down Expand Up @@ -413,7 +413,7 @@
;; tags
(tag)

;; CHECK: (tag $2)
;; CHECK: (tag $tag$2)

;; CHECK: (tag $empty)
(tag $empty)
Expand Down Expand Up @@ -1919,7 +1919,7 @@
;; CHECK-NEXT: (catch $empty
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch $timport$0
;; CHECK-NEXT: (catch $eimport$0
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch_all
Expand Down Expand Up @@ -2228,7 +2228,7 @@
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch $timport$0
;; CHECK-NEXT: (catch $eimport$0
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
Expand Down Expand Up @@ -3710,7 +3710,7 @@
)

;; CHECK: (func $throw (type $0)
;; CHECK-NEXT: (throw $timport$1)
;; CHECK-NEXT: (throw $eimport$1)
;; CHECK-NEXT: (throw $tag-i32
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
Expand Down
4 changes: 2 additions & 2 deletions test/lld/em_asm_main_thread.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
(import "env" "emscripten_asm_const_int_sync_on_main_thread" (func $emscripten_asm_const_int_sync_on_main_thread (param i32 i32 i32) (result i32)))
(memory $0 2)
(data (i32.const 568) "{ Module.print(\"Hello world\"); }\00{ return $0 + $1; }\00{ Module.print(\"Got \" + $0); }\00")
(global (export "__start_em_asm") i32 (i32.const 568))
(global (export "__stop_em_asm") i32 (i32.const 652))
(table $0 1 1 funcref)
(global $global$0 (mut i32) (i32.const 66192))
(global $global$1 i32 (i32.const 66192))
(global $global$2 i32 (i32.const 652))
(global $global$3 (export "__start_em_asm") i32 (i32.const 568))
(global $global$4 (export "__stop_em_asm") i32 (i32.const 652))
(export "memory" (memory $0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "__heap_base" (global $global$1))
Expand Down
8 changes: 4 additions & 4 deletions test/lld/em_asm_main_thread.wat.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
(type $5 (func (param i32) (result i32)))
(type $6 (func (param i32 i32) (result i32)))
(import "env" "emscripten_asm_const_int_sync_on_main_thread" (func $emscripten_asm_const_int_sync_on_main_thread (param i32 i32 i32) (result i32)))
(global $0 i32 (i32.const 568))
(global $1 i32 (i32.const 652))
(global $global$0 (mut i32) (i32.const 66192))
(global $global$1 i32 (i32.const 66192))
(global $global$2 i32 (i32.const 652))
(global $global$3 i32 (i32.const 568))
(global $global$4 i32 (i32.const 652))
(memory $0 2)
(data $0 (i32.const 568) "{ Module.print(\"Hello world\"); }\00{ return $0 + $1; }\00{ Module.print(\"Got \" + $0); }\00")
(table $0 1 1 funcref)
(export "__start_em_asm" (global $0))
(export "__stop_em_asm" (global $1))
(export "__start_em_asm" (global $global$3))
(export "__stop_em_asm" (global $global$4))
(export "memory" (memory $0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "__heap_base" (global $global$1))
Expand Down

0 comments on commit 2b1c1d8

Please sign in to comment.