diff options
author | Jérôme Vouillon <jerome.vouillon@gmail.com> | 2023-05-12 23:43:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-12 14:43:09 -0700 |
commit | 71a151240241fd50c42d88fe0ba9800c03527387 (patch) | |
tree | de98957b6f5341c3b14147c0cf6e1753d38940fe /test | |
parent | d7b14a67ca4e9b111d5733239af88328cb779030 (diff) | |
download | binaryen-71a151240241fd50c42d88fe0ba9800c03527387.tar.gz binaryen-71a151240241fd50c42d88fe0ba9800c03527387.tar.bz2 binaryen-71a151240241fd50c42d88fe0ba9800c03527387.zip |
[Strings] Adopt new instruction binary encoding (#5714)
See WebAssembly/stringref#46.
This format is already adopted by V8: https://chromium-review.googlesource.com/c/v8/v8/+/3892695.
The text format is left unchanged (see #5607 for a discussion on the subject).
I have also added support for string.encode_lossy_utf8 and
string.encode_lossy_utf8 array (by allowing the replace policy for
Binaryen's string.encode_wtf8 instruction).
Diffstat (limited to 'test')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 16 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 13 | ||||
-rw-r--r-- | test/lit/passes/simplify-locals-strings.wast | 68 | ||||
-rw-r--r-- | test/lit/strings.wast | 34 |
4 files changed, 125 insertions, 6 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 2c6ec2d6c..cb26c372d 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -1174,7 +1174,7 @@ void test_core() { 0, false), BinaryenStringNew(module, - BinaryenStringNewReplace(), + BinaryenStringNewLossyUTF8(), makeInt32(module, 0), makeInt32(module, 0), 0, @@ -1209,7 +1209,7 @@ void test_core() { makeInt32(module, 0), false), BinaryenStringNew(module, - BinaryenStringNewReplaceArray(), + BinaryenStringNewLossyUTF8Array(), BinaryenGlobalGet(module, "i8Array-global", i8Array), 0, makeInt32(module, 0), @@ -1261,6 +1261,12 @@ void test_core() { 0), BinaryenStringEncode( module, + BinaryenStringEncodeLossyUTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + makeInt32(module, 0), + 0), + BinaryenStringEncode( + module, BinaryenStringEncodeWTF8(), BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), makeInt32(module, 0), @@ -1279,6 +1285,12 @@ void test_core() { makeInt32(module, 0)), BinaryenStringEncode( module, + BinaryenStringEncodeLossyUTF8Array(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0)), + BinaryenStringEncode( + module, BinaryenStringEncodeWTF8Array(), BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), BinaryenGlobalGet(module, "i8Array-global", i8Array), diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index f9b688eaf..946245631 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -2434,6 +2434,12 @@ BinaryenFeatureAll: 126975 ) ) (drop + (string.encode_wtf8 replace + (global.get $string-global) + (i32.const 0) + ) + ) + (drop (string.encode_wtf8 wtf8 (global.get $string-global) (i32.const 0) @@ -2453,6 +2459,13 @@ BinaryenFeatureAll: 126975 ) ) (drop + (string.encode_wtf8_array replace + (global.get $string-global) + (global.get $i8Array-global) + (i32.const 0) + ) + ) + (drop (string.encode_wtf8_array wtf8 (global.get $string-global) (global.get $i8Array-global) diff --git a/test/lit/passes/simplify-locals-strings.wast b/test/lit/passes/simplify-locals-strings.wast index 176d6fbb8..646eee6bd 100644 --- a/test/lit/passes/simplify-locals-strings.wast +++ b/test/lit/passes/simplify-locals-strings.wast @@ -320,7 +320,7 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (string.encode_wtf16 + ;; CHECK-NEXT: (string.encode_wtf8 replace ;; CHECK-NEXT: (local.get $ref) ;; CHECK-NEXT: (i32.const 30) ;; CHECK-NEXT: ) @@ -328,6 +328,20 @@ ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (local.get $temp) ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $temp + ;; CHECK-NEXT: (i32.load + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (string.encode_wtf16 + ;; CHECK-NEXT: (local.get $ref) + ;; CHECK-NEXT: (i32.const 40) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (local.get $temp) + ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $no-load-past-encode (param $ref stringref) (local $temp i32) @@ -366,7 +380,7 @@ ) ) (drop - (string.encode_wtf16 + (string.encode_wtf8 replace (local.get $ref) (i32.const 30) ) @@ -374,6 +388,20 @@ (drop (local.get $temp) ) + (local.set $temp + (i32.load + (i32.const 1) + ) + ) + (drop + (string.encode_wtf16 + (local.get $ref) + (i32.const 40) + ) + ) + (drop + (local.get $temp) + ) ) ;; CHECK: (func $no-load-past-encode-gc (type $stringref_ref|$array|_ref|$array16|_=>_none) (param $ref stringref) (param $array (ref $array)) (param $array16 (ref $array16)) @@ -417,10 +445,26 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (string.encode_wtf8_array replace + ;; CHECK-NEXT: (local.get $ref) + ;; CHECK-NEXT: (local.get $array) + ;; CHECK-NEXT: (i32.const 30) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (local.get $temp) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $temp + ;; CHECK-NEXT: (array.get_u $array + ;; CHECK-NEXT: (local.get $array) + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (string.encode_wtf16_array ;; CHECK-NEXT: (local.get $ref) ;; CHECK-NEXT: (local.get $array16) - ;; CHECK-NEXT: (i32.const 30) + ;; CHECK-NEXT: (i32.const 40) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop @@ -470,10 +514,26 @@ ) ) (drop + (string.encode_wtf8_array replace + (local.get $ref) + (local.get $array) + (i32.const 30) + ) + ) + (drop + (local.get $temp) + ) + (local.set $temp + (array.get $array + (local.get $array) + (i32.const 0) + ) + ) + (drop (string.encode_wtf16_array (local.get $ref) (local.get $array16) - (i32.const 30) + (i32.const 40) ) ) (drop diff --git a/test/lit/strings.wast b/test/lit/strings.wast index 1e38ff894..dcb1bffd2 100644 --- a/test/lit/strings.wast +++ b/test/lit/strings.wast @@ -184,6 +184,14 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (string.encode_wtf8 replace + ;; CHECK-NEXT: (local.get $ref) + ;; CHECK-NEXT: (i32.const 10) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (string.encode_wtf8 utf8 ;; CHECK-NEXT: (local.get $ref) ;; CHECK-NEXT: (i32.const 20) @@ -206,6 +214,14 @@ ) ) (drop + (i32.eqz ;; validate the output is i32 + (string.encode_wtf8 replace + (local.get $ref) + (i32.const 10) + ) + ) + ) + (drop (string.encode_wtf8 utf8 (local.get $ref) (i32.const 20) @@ -546,6 +562,15 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (string.encode_wtf8_array replace + ;; CHECK-NEXT: (local.get $ref) + ;; CHECK-NEXT: (local.get $array) + ;; CHECK-NEXT: (i32.const 10) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (string.encode_wtf8_array utf8 ;; CHECK-NEXT: (local.get $ref) ;; CHECK-NEXT: (local.get $array) @@ -571,6 +596,15 @@ ) ) (drop + (i32.eqz ;; validate the output is i32 + (string.encode_wtf8_array replace + (local.get $ref) + (local.get $array) + (i32.const 10) + ) + ) + ) + (drop (string.encode_wtf8_array utf8 (local.get $ref) (local.get $array) |