From 7177c2d930ecc21c95d73042ed86a5a844c288ae Mon Sep 17 00:00:00 2001 From: Tom Stuart Date: Fri, 17 Feb 2023 21:26:08 +0000 Subject: [PATCH] Support parsing `v128.const i64x2 0 0` in #parse_numeric_instruction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the only vector instruction which appears in test/core/*.wast (and was only added yesterday [0]) so it’s not yet worth properly implementing the instruction in general. The one occurrence in linking.wast uses `i64x2` as its shape descriptor [1] so here we read two numbers (actually zeros) after reading the instruction and shape. [0] https://github.com/WebAssembly/spec/pull/1597 [1] https://webassembly.github.io/spec/core/syntax/instructions.html#syntax-vec-shape --- lib/wasminna/ast_parser.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/wasminna/ast_parser.rb b/lib/wasminna/ast_parser.rb index 9ae202a..e9baecc 100644 --- a/lib/wasminna/ast_parser.rb +++ b/lib/wasminna/ast_parser.rb @@ -719,7 +719,7 @@ def parse_numeric_instruction opcode.match(NUMERIC_OPCODE_REGEXP) => { type:, bits:, operation: } - type = { 'f' => :float, 'i' => :integer }.fetch(type) + type = { 'f' => :float, 'i' => :integer, 'v' => :vector }.fetch(type) bits = bits.to_i(10) case operation @@ -730,6 +730,8 @@ def parse_numeric_instruction parse_integer(bits:) in :float parse_float(bits:) + in :vector + parse_vector(bits:) end Const.new(type:, bits:, number:) @@ -1054,6 +1056,14 @@ def parse_float(bits:) Float.parse(read).encode(format:) end + def parse_vector(bits:) + raise unless bits == 128 + read => 'i64x2' + read => '0' + read => '0' + 0 + end + def parse_string read => string encoding = string.encoding