Skip to content

Commit

Permalink
Final opcodes (#372)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Lively <[email protected]>
  • Loading branch information
rossberg and tlively authored Jul 31, 2023
1 parent a98c15c commit 9acb6e2
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 244 deletions.
85 changes: 54 additions & 31 deletions document/core/appendix/index-instructions.py

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions document/core/appendix/index-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ Category Constructor
:ref:`Vector type <syntax-vectype>` |V128| :math:`\hex{7B}` (-5 as |Bs7|)
:ref:`Packed type <syntax-packedtype>` |I8| :math:`\hex{7A}` (-6 as |Bs7|)
:ref:`Packed type <syntax-packedtype>` |I16| :math:`\hex{79}` (-7 as |Bs7|)
(reserved) :math:`\hex{78}` .. :math:`\hex{71}`
(reserved) :math:`\hex{78}` .. :math:`\hex{74}`
:ref:`Heap type <syntax-heaptype>` |NOFUNC| :math:`\hex{73}` (-13 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |NOEXTERN| :math:`\hex{72}` (-14 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |NONE| :math:`\hex{71}` (-15 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |FUNC| :math:`\hex{70}` (-16 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |EXTERN| :math:`\hex{6F}` (-17 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |ANY| :math:`\hex{6E}` (-18 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |EQT| :math:`\hex{6D}` (-19 as |Bs7|)
:ref:`Reference type <syntax-reftype>` |REF| |NULL| :math:`\hex{6C}` (-20 as |Bs7|)
:ref:`Reference type <syntax-reftype>` |REF| :math:`\hex{6B}` (-21 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |I31| :math:`\hex{6A}` (-22 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |NOFUNC| :math:`\hex{69}` (-23 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |NOEXTERN| :math:`\hex{68}` (-24 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |STRUCT| :math:`\hex{67}` (-25 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |ARRAY| :math:`\hex{66}` (-26 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |NONE| :math:`\hex{65}` (-27 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |I31| :math:`\hex{6C}` (-20 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |STRUCT| :math:`\hex{6B}` (-21 as |Bs7|)
:ref:`Heap type <syntax-heaptype>` |ARRAY| :math:`\hex{6A}` (-22 as |Bs7|)
:ref:`Reference type <syntax-reftype>` |REF| :math:`\hex{64}` (-28 as |Bs7|)
:ref:`Reference type <syntax-reftype>` |REF| |NULL| :math:`\hex{63}` (-29 as |Bs7|)
(reserved) :math:`\hex{64}` .. :math:`\hex{61}`
:ref:`Composite type <syntax-comptype>` :math:`\TFUNC~[\valtype^\ast] \toF[\valtype^\ast]` :math:`\hex{60}` (-32 as |Bs7|)
:ref:`Composite type <syntax-comptype>` :math:`\TSTRUCT~\fieldtype^\ast` :math:`\hex{5F}` (-33 as |Bs7|)
:ref:`Composite type <syntax-comptype>` :math:`\TARRAY~\fieldtype` :math:`\hex{5E}` (-34 as |Bs7|)
(reserved) :math:`\hex{5D}` .. :math:`\hex{51}`
:ref:`Sub type <syntax-subtype>` :math:`\TSUB~\typeidx^\ast~\comptype` :math:`\hex{50}` (-48 as |Bs7|)
:ref:`Recursive type <syntax-rectype>` :math:`\TREC~\subtype^\ast` :math:`\hex{4F}` (-49 as |Bs7|)
:ref:`Sub type <syntax-subtype>` :math:`\TSUB~\TFINAL~\typeidx^\ast~\comptype` :math:`\hex{4E}` (-50 as |Bs7|)
:ref:`Sub type <syntax-subtype>` :math:`\TSUB~\TFINAL~\typeidx^\ast~\comptype` :math:`\hex{4F}` (-49 as |Bs7|)
:ref:`Recursive type <syntax-rectype>` :math:`\TREC~\subtype^\ast` :math:`\hex{4E}` (-50 as |Bs7|)
(reserved) :math:`\hex{4D}` .. :math:`\hex{41}`
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)
:ref:`Table type <syntax-tabletype>` :math:`\limits~\reftype` (none)
Expand Down
60 changes: 30 additions & 30 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Control Instructions
\hex{15}~~x{:}\Btypeidx &\Rightarrow& \RETURNCALLREF~x \\ &&|&
\hex{D4}~~l{:}\Blabelidx &\Rightarrow& \BRONNULL~l \\ &&|&
\hex{D6}~~l{:}\Blabelidx &\Rightarrow& \BRONNONNULL~l \\ &&|&
\hex{FB}~~78{:}\Bu32~~(\NULL_1^?,\NULL_2^?){:}\Bcastflags\\&&&~~~~l{:}\Blabelidx~~\X{ht}_1{:}\Bheaptype~~\X{ht}_2{:}\Bheaptype &\Rightarrow& \BRONCAST~l~(\REF~\NULL_1^?~\X{ht}_1)~(\REF~\NULL_2^?~\X{ht}_2) \\ &&|&
\hex{FB}~~79{:}\Bu32~~(\NULL_1^?,\NULL_2^?){:}\Bcastflags\\&&&~~~~l{:}\Blabelidx~~\X{ht}_1{:}\Bheaptype~~\X{ht}_2{:}\Bheaptype &\Rightarrow& \BRONCASTFAIL~l~(\REF~\NULL_1^?~\X{ht}_1)~(\REF~\NULL_2^?~\X{ht}_2) \\
\hex{FB}~~24{:}\Bu32~~(\NULL_1^?,\NULL_2^?){:}\Bcastflags\\&&&~~~~l{:}\Blabelidx~~\X{ht}_1{:}\Bheaptype~~\X{ht}_2{:}\Bheaptype &\Rightarrow& \BRONCAST~l~(\REF~\NULL_1^?~\X{ht}_1)~(\REF~\NULL_2^?~\X{ht}_2) \\ &&|&
\hex{FB}~~25{:}\Bu32~~(\NULL_1^?,\NULL_2^?){:}\Bcastflags\\&&&~~~~l{:}\Blabelidx~~\X{ht}_1{:}\Bheaptype~~\X{ht}_2{:}\Bheaptype &\Rightarrow& \BRONCASTFAIL~l~(\REF~\NULL_1^?~\X{ht}_1)~(\REF~\NULL_2^?~\X{ht}_2) \\
\production{cast flags} & \Bcastflags &::=&
0{:}\Bu8 &\Rightarrow& (\epsilon, \epsilon) \\ &&|&
1{:}\Bu8 &\Rightarrow& (\NULL, \epsilon) \\ &&|&
Expand Down Expand Up @@ -142,35 +142,35 @@ Generic :ref:`reference instructions <syntax-instr-ref>` are represented by sing
\hex{D2}~~x{:}\Bfuncidx &\Rightarrow& \REFFUNC~x \\ &&|&
\hex{D3} &\Rightarrow& \REFASNONNULL \\ &&|&
\hex{D5} &\Rightarrow& \REFEQ \\ &&|&
\hex{FB}~~1{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \STRUCTNEW~x \\ &&|&
\hex{FB}~~2{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \STRUCTNEWDEFAULT~x \\ &&|&
\hex{FB}~~3{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGET~x~i \\ &&|&
\hex{FB}~~4{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGETS~x~i \\ &&|&
\hex{FB}~~5{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGETU~x~i \\ &&|&
\hex{FB}~~6{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTSET~x~i \\ &&|&
\hex{FB}~~0{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \STRUCTNEW~x \\ &&|&
\hex{FB}~~1{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \STRUCTNEWDEFAULT~x \\ &&|&
\hex{FB}~~2{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGET~x~i \\ &&|&
\hex{FB}~~3{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGETS~x~i \\ &&|&
\hex{FB}~~4{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGETU~x~i \\ &&|&
\hex{FB}~~5{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTSET~x~i \\ &&|&
\hex{FB}~~6{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYNEW~x \\ &&|&
\hex{FB}~~7{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYNEWDEFAULT~x \\ &&|&
\hex{FB}~~8{:}\Bu32~~x{:}\Btypeidx~~n{:}\Bu32 &\Rightarrow& \ARRAYNEWFIXED~x~n \\ &&|&
\hex{FB}~~9{:}\Bu32~~x{:}\Btypeidx~~y{:}\Bdataidx &\Rightarrow& \ARRAYNEWDATA~x~y \\ &&|&
\hex{FB}~~10{:}\Bu32~~x{:}\Btypeidx~~y{:}\Belemidx &\Rightarrow& \ARRAYNEWELEM~x~y \\ &&|&
\hex{FB}~~11{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGET~x \\ &&|&
\hex{FB}~~12{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGETS~x \\ &&|&
\hex{FB}~~13{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGETU~x \\ &&|&
\hex{FB}~~14{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYSET~x \\ &&|&
\hex{FB}~~15{:}\Bu32 &\Rightarrow& \ARRAYLEN \\ &&|&
\hex{FB}~~16{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYFILL~x \\ &&|&
\hex{FB}~~17{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYNEW~x \\ &&|&
\hex{FB}~~18{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYNEWDEFAULT~x \\ &&|&
\hex{FB}~~19{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGET~x \\ &&|&
\hex{FB}~~20{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGETS~x \\ &&|&
\hex{FB}~~21{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGETU~x \\ &&|&
\hex{FB}~~22{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYSET~x \\ &&|&
\hex{FB}~~23{:}\Bu32 &\Rightarrow& \ARRAYLEN \\ &&|&
\hex{FB}~~24{:}\Bu32~~x{:}\Btypeidx~~y{:}\Btypeidx &\Rightarrow& \ARRAYCOPY~x~y \\ &&|&
\hex{FB}~~25{:}\Bu32~~x{:}\Btypeidx~~n{:}\Bu32 &\Rightarrow& \ARRAYNEWFIXED~x~n \\ &&|&
\hex{FB}~~27{:}\Bu32~~x{:}\Btypeidx~~y{:}\Bdataidx &\Rightarrow& \ARRAYNEWDATA~x~y \\ &&|&
\hex{FB}~~28{:}\Bu32~~x{:}\Btypeidx~~y{:}\Belemidx &\Rightarrow& \ARRAYNEWELEM~x~y \\ &&|&
\hex{FB}~~32{:}\Bu32 &\Rightarrow& \I31NEW \\ &&|&
\hex{FB}~~33{:}\Bu32 &\Rightarrow& \I31GETS \\ &&|&
\hex{FB}~~34{:}\Bu32 &\Rightarrow& \I31GETU \\ &&|&
\hex{FB}~~64{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFTEST~(\REF~\X{ht}) \\ &&|&
\hex{FB}~~65{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFCAST~(\REF~\X{ht}) \\ &&|&
\hex{FB}~~72{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFTEST~(\REF~\NULL~\X{ht}) \\ &&|&
\hex{FB}~~73{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFCAST~(\REF~\NULL~\X{ht}) \\ &&|&
\hex{FB}~~84{:}\Bu32~~x{:}\Btypeidx~~y{:}\Bdataidx &\Rightarrow& \ARRAYINITDATA~x~y \\ &&|&
\hex{FB}~~85{:}\Bu32~~x{:}\Btypeidx~~y{:}\Belemidx &\Rightarrow& \ARRAYINITELEM~x~y \\ &&|&
\hex{FB}~~112{:}\Bu32 &\Rightarrow& \EXTERNINTERNALIZE \\ &&|&
\hex{FB}~~113{:}\Bu32 &\Rightarrow& \EXTERNEXTERNALIZE \\
\hex{FB}~~17{:}\Bu32~~x{:}\Btypeidx~~y{:}\Btypeidx &\Rightarrow& \ARRAYCOPY~x~y \\ &&|&
\hex{FB}~~18{:}\Bu32~~x{:}\Btypeidx~~y{:}\Bdataidx &\Rightarrow& \ARRAYINITDATA~x~y \\ &&|&
\hex{FB}~~19{:}\Bu32~~x{:}\Btypeidx~~y{:}\Belemidx &\Rightarrow& \ARRAYINITELEM~x~y \\ &&|&
\hex{FB}~~20{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFTEST~(\REF~\X{ht}) \\ &&|&
\hex{FB}~~21{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFTEST~(\REF~\NULL~\X{ht}) \\ &&|&
\hex{FB}~~22{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFCAST~(\REF~\X{ht}) \\ &&|&
\hex{FB}~~23{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFCAST~(\REF~\NULL~\X{ht}) \\ &&|&
\hex{FB}~~26{:}\Bu32 &\Rightarrow& \EXTERNINTERNALIZE \\ &&|&
\hex{FB}~~27{:}\Bu32 &\Rightarrow& \EXTERNEXTERNALIZE \\ &&|&
\hex{FB}~~28{:}\Bu32 &\Rightarrow& \I31NEW \\ &&|&
\hex{FB}~~29{:}\Bu32 &\Rightarrow& \I31GETS \\ &&|&
\hex{FB}~~30{:}\Bu32 &\Rightarrow& \I31GETU \\
\end{array}
Expand Down
22 changes: 11 additions & 11 deletions document/core/binary/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ Heap Types
.. math::
\begin{array}{llclll@{\qquad\qquad}l}
\production{abstract heap type} & \Babsheaptype &::=&
\hex{65} &\Rightarrow& \NONE \\ &&|&
\hex{66} &\Rightarrow& \ARRAY \\ &&|&
\hex{67} &\Rightarrow& \STRUCT \\ &&|&
\hex{68} &\Rightarrow& \NOEXTERN \\ &&|&
\hex{69} &\Rightarrow& \NOFUNC \\ &&|&
\hex{6A} &\Rightarrow& \I31 \\ &&|&
\hex{6D} &\Rightarrow& \EQT \\ &&|&
\hex{6E} &\Rightarrow& \ANY \\ &&|&
\hex{73} &\Rightarrow& \NOFUNC \\ &&|&
\hex{72} &\Rightarrow& \NOEXTERN \\ &&|&
\hex{71} &\Rightarrow& \NONE \\ &&|&
\hex{70} &\Rightarrow& \FUNC \\ &&|&
\hex{6F} &\Rightarrow& \EXTERN \\ &&|&
\hex{70} &\Rightarrow& \FUNC \\
\hex{6E} &\Rightarrow& \ANY \\ &&|&
\hex{6D} &\Rightarrow& \EQT \\ &&|&
\hex{6C} &\Rightarrow& \I31 \\ &&|&
\hex{6B} &\Rightarrow& \STRUCT \\ &&|&
\hex{6A} &\Rightarrow& \ARRAY \\
\production{heap type} & \Bheaptype &::=&
\X{ht}{:}\Babsheaptype &\Rightarrow& \X{ht} \\ &&|&
x{:}\Bs33 &\Rightarrow& x & (\iff x \geq 0) \\
Expand All @@ -86,8 +86,8 @@ Reference Types
.. math::
\begin{array}{llclll@{\qquad\qquad}l}
\production{reference type} & \Breftype &::=&
\hex{6B}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\X{ht} \\ &&|&
\hex{6C}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\NULL~\X{ht} \\ &&|&
\hex{64}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\X{ht} \\ &&|&
\hex{63}~~\X{ht}{:}\Bheaptype &\Rightarrow& \REF~\NULL~\X{ht} \\ &&|&
\X{ht}{:}\Babsheaptype &\Rightarrow& \REF~\NULL~\X{ht} \\
\end{array}
Expand Down
112 changes: 60 additions & 52 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,35 +177,35 @@ let heap_type s =
(fun s -> VarHT (var_type s33 s));
(fun s ->
match s7 s with
| -0x0d -> NoFuncHT
| -0x0e -> NoExternHT
| -0x0f -> NoneHT
| -0x10 -> FuncHT
| -0x11 -> ExternHT
| -0x12 -> AnyHT
| -0x13 -> EqHT
| -0x16 -> I31HT
| -0x17 -> NoFuncHT
| -0x18 -> NoExternHT
| -0x19 -> StructHT
| -0x1a -> ArrayHT
| -0x1b -> NoneHT
| -0x14 -> I31HT
| -0x15 -> StructHT
| -0x16 -> ArrayHT
| _ -> error s pos "malformed heap type"
)
] s

let ref_type s =
let pos = pos s in
match s7 s with
| -0x0d -> (Null, NoFuncHT)
| -0x0e -> (Null, NoExternHT)
| -0x0f -> (Null, NoneHT)
| -0x10 -> (Null, FuncHT)
| -0x11 -> (Null, ExternHT)
| -0x12 -> (Null, AnyHT)
| -0x13 -> (Null, EqHT)
| -0x14 -> (Null, heap_type s)
| -0x15 -> (NoNull, heap_type s)
| -0x16 -> (Null, I31HT)
| -0x17 -> (Null, NoFuncHT)
| -0x18 -> (Null, NoExternHT)
| -0x19 -> (Null, StructHT)
| -0x1a -> (Null, ArrayHT)
| -0x1b -> (Null, NoneHT)
| -0x14 -> (Null, I31HT)
| -0x15 -> (Null, StructHT)
| -0x16 -> (Null, ArrayHT)
| -0x1c -> (NoNull, heap_type s)
| -0x1d -> (Null, heap_type s)
| _ -> error s pos "malformed reference type"

let val_type s =
Expand Down Expand Up @@ -259,15 +259,15 @@ let sub_type s =
skip 1 s;
let xs = vec (var_type u32) s in
SubT (NoFinal, List.map (fun x -> VarHT x) xs, str_type s)
| Some i when i = -0x32 land 0x7f ->
| Some i when i = -0x31 land 0x7f ->
skip 1 s;
let xs = vec (var_type u32) s in
SubT (Final, List.map (fun x -> VarHT x) xs, str_type s)
| _ -> SubT (Final, [], str_type s)

let rec_type s =
match peek s with
| Some i when i = -0x31 land 0x7f -> skip 1 s; RecT (vec sub_type s)
| Some i when i = -0x32 land 0x7f -> skip 1 s; RecT (vec sub_type s)
| _ -> RecT [sub_type s]


Expand Down Expand Up @@ -588,48 +588,46 @@ let rec instr s =

| 0xfb as b ->
(match u32 s with
| 0x01l -> struct_new (at var s)
| 0x02l -> struct_new_default (at var s)
| 0x03l -> let x = at var s in let y = at var s in struct_get x y
| 0x04l -> let x = at var s in let y = at var s in struct_get_s x y
| 0x05l -> let x = at var s in let y = at var s in struct_get_u x y
| 0x06l -> let x = at var s in let y = at var s in struct_set x y

| 0x11l -> array_new (at var s)
| 0x12l -> array_new_default (at var s)
| 0x13l -> array_get (at var s)
| 0x14l -> array_get_s (at var s)
| 0x15l -> array_get_u (at var s)
| 0x16l -> array_set (at var s)
| 0x17l -> array_len

| 0x18l -> let x = at var s in let y = at var s in array_copy x y
| 0x0fl -> array_fill (at var s)
| 0x54l -> let x = at var s in let y = at var s in array_init_data x y
| 0x55l -> let x = at var s in let y = at var s in array_init_elem x y

| 0x19l -> let x = at var s in let n = u32 s in array_new_fixed x n
| 0x1bl -> let x = at var s in let y = at var s in array_new_data x y
| 0x1cl -> let x = at var s in let y = at var s in array_new_elem x y

| 0x20l -> i31_new
| 0x21l -> i31_get_s
| 0x22l -> i31_get_u

| 0x40l -> ref_test (NoNull, heap_type s)
| 0x41l -> ref_cast (NoNull, heap_type s)
| 0x48l -> ref_test (Null, heap_type s)
| 0x49l -> ref_cast (Null, heap_type s)
| 0x4el | 0x4fl as opcode ->
| 0x00l -> struct_new (at var s)
| 0x01l -> struct_new_default (at var s)
| 0x02l -> let x = at var s in let y = at var s in struct_get x y
| 0x03l -> let x = at var s in let y = at var s in struct_get_s x y
| 0x04l -> let x = at var s in let y = at var s in struct_get_u x y
| 0x05l -> let x = at var s in let y = at var s in struct_set x y

| 0x06l -> array_new (at var s)
| 0x07l -> array_new_default (at var s)
| 0x08l -> let x = at var s in let n = u32 s in array_new_fixed x n
| 0x09l -> let x = at var s in let y = at var s in array_new_data x y
| 0x0al -> let x = at var s in let y = at var s in array_new_elem x y
| 0x0bl -> array_get (at var s)
| 0x0cl -> array_get_s (at var s)
| 0x0dl -> array_get_u (at var s)
| 0x0el -> array_set (at var s)
| 0x0fl -> array_len
| 0x10l -> array_fill (at var s)
| 0x11l -> let x = at var s in let y = at var s in array_copy x y
| 0x12l -> let x = at var s in let y = at var s in array_init_data x y
| 0x13l -> let x = at var s in let y = at var s in array_init_elem x y

| 0x14l -> ref_test (NoNull, heap_type s)
| 0x15l -> ref_test (Null, heap_type s)
| 0x16l -> ref_cast (NoNull, heap_type s)
| 0x17l -> ref_cast (Null, heap_type s)
| 0x18l | 0x19l as opcode ->
let flags = byte s in
require (flags land 0xfc = 0) s (pos + 2) "malformed br_on_cast flags";
let x = at var s in
let rt1 = ((if bit 0 flags then Null else NoNull), heap_type s) in
let rt2 = ((if bit 1 flags then Null else NoNull), heap_type s) in
(if opcode = 0x4el then br_on_cast else br_on_cast_fail) x rt1 rt2
(if opcode = 0x18l then br_on_cast else br_on_cast_fail) x rt1 rt2

| 0x70l -> extern_internalize
| 0x71l -> extern_externalize
| 0x1al -> extern_internalize
| 0x1bl -> extern_externalize

| 0x1cl -> i31_new
| 0x1dl -> i31_get_s
| 0x1el -> i31_get_u

| n -> illegal2 s pos b n
)
Expand Down Expand Up @@ -848,15 +846,18 @@ let rec instr s =
| 0x97l -> i16x8_min_u
| 0x98l -> i16x8_max_s
| 0x99l -> i16x8_max_u
| 0x9al as n -> illegal s pos (I32.to_int_u n)
| 0x9bl -> i16x8_avgr_u
| 0x9cl -> i16x8_extmul_low_i8x16_s
| 0x9dl -> i16x8_extmul_high_i8x16_s
| 0x9el -> i16x8_extmul_low_i8x16_u
| 0x9fl -> i16x8_extmul_high_i8x16_u
| 0xa0l -> i32x4_abs
| 0xa1l -> i32x4_neg
| 0xa2l as n -> illegal s pos (I32.to_int_u n)
| 0xa3l -> i32x4_all_true
| 0xa4l -> i32x4_bitmask
| 0xa5l | 0xa6l as n -> illegal s pos (I32.to_int_u n)
| 0xa7l -> i32x4_extend_low_i16x8_s
| 0xa8l -> i32x4_extend_high_i16x8_s
| 0xa9l -> i32x4_extend_low_i16x8_u
Expand All @@ -865,7 +866,9 @@ let rec instr s =
| 0xacl -> i32x4_shr_s
| 0xadl -> i32x4_shr_u
| 0xael -> i32x4_add
| 0xafl | 0xb0l as n -> illegal s pos (I32.to_int_u n)
| 0xb1l -> i32x4_sub
| 0xb2l | 0xb3l | 0xb4l as n -> illegal s pos (I32.to_int_u n)
| 0xb5l -> i32x4_mul
| 0xb6l -> i32x4_min_s
| 0xb7l -> i32x4_min_u
Expand All @@ -878,8 +881,10 @@ let rec instr s =
| 0xbfl -> i32x4_extmul_high_i16x8_u
| 0xc0l -> i64x2_abs
| 0xc1l -> i64x2_neg
| 0xc2l as n -> illegal s pos (I32.to_int_u n)
| 0xc3l -> i64x2_all_true
| 0xc4l -> i64x2_bitmask
| 0xc5l | 0xc6l as n -> illegal s pos (I32.to_int_u n)
| 0xc7l -> i64x2_extend_low_i32x4_s
| 0xc8l -> i64x2_extend_high_i32x4_s
| 0xc9l -> i64x2_extend_low_i32x4_u
Expand All @@ -888,7 +893,9 @@ let rec instr s =
| 0xccl -> i64x2_shr_s
| 0xcdl -> i64x2_shr_u
| 0xcel -> i64x2_add
| 0xcfl | 0xd0l as n -> illegal s pos (I32.to_int_u n)
| 0xd1l -> i64x2_sub
| 0xd2l | 0xd3l | 0xd4l as n -> illegal s pos (I32.to_int_u n)
| 0xd5l -> i64x2_mul
| 0xd6l -> i64x2_eq
| 0xd7l -> i64x2_ne
Expand All @@ -902,6 +909,7 @@ let rec instr s =
| 0xdfl -> i64x2_extmul_high_i32x4_u
| 0xe0l -> f32x4_abs
| 0xe1l -> f32x4_neg
| 0xe2l as n -> illegal s pos (I32.to_int_u n)
| 0xe3l -> f32x4_sqrt
| 0xe4l -> f32x4_add
| 0xe5l -> f32x4_sub
Expand Down
Loading

0 comments on commit 9acb6e2

Please sign in to comment.