Skip to content

Commit

Permalink
Support parsing v128.const i64x2 0 0 in #parse_numeric_instruction
Browse files Browse the repository at this point in the history
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] WebAssembly/spec#1597
[1] https://webassembly.github.io/spec/core/syntax/instructions.html#syntax-vec-shape
  • Loading branch information
tomstuart committed Feb 17, 2023
1 parent a37fbd8 commit 7177c2d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/wasminna/ast_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7177c2d

Please sign in to comment.