From 3c1817cfdf610099210fc1dfef58dbeea87c5710 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 5 Aug 2024 16:12:48 -0700 Subject: [PATCH] Make source parser consistent with binary parser when naming things. NFC 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. --- src/parser/context-decls.cpp | 5 +++-- test/lit/basic/tags.wast | 4 ++-- test/lit/wat-kitchen-sink.wast | 14 +++++++------- test/lld/em_asm_main_thread.wat | 4 ++-- test/lld/em_asm_main_thread.wat.out | 8 ++++---- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/parser/context-decls.cpp b/src/parser/context-decls.cpp index c5b21203859..8e9638ae7b3 100644 --- a/src/parser/context-decls.cpp +++ b/src/parser/context-decls.cpp @@ -196,7 +196,8 @@ 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; } @@ -276,7 +277,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; } diff --git a/test/lit/basic/tags.wast b/test/lit/basic/tags.wast index cd0615eab01..7d99816c1d8 100644 --- a/test/lit/basic/tags.wast +++ b/test/lit/basic/tags.wast @@ -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))) diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index 10f581d21ad..ac8a00cc288 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -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) @@ -413,7 +413,7 @@ ;; tags (tag) - ;; CHECK: (tag $2) + ;; CHECK: (tag $tag$2) ;; CHECK: (tag $empty) (tag $empty) @@ -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 @@ -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: ) @@ -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: ) diff --git a/test/lld/em_asm_main_thread.wat b/test/lld/em_asm_main_thread.wat index 65f530d699c..90f6e811161 100644 --- a/test/lld/em_asm_main_thread.wat +++ b/test/lld/em_asm_main_thread.wat @@ -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)) diff --git a/test/lld/em_asm_main_thread.wat.out b/test/lld/em_asm_main_thread.wat.out index 5eaa3a826b2..5d817ca8677 100644 --- a/test/lld/em_asm_main_thread.wat.out +++ b/test/lld/em_asm_main_thread.wat.out @@ -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))