Skip to content

Commit a5f4a85

Browse files
committed
[spec] Group reference instructions more consistently
1 parent bbd632e commit a5f4a85

File tree

9 files changed

+2153
-2128
lines changed

9 files changed

+2153
-2128
lines changed

document/core/binary/instructions.rst

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Control Instructions
5454
.. _binary-br:
5555
.. _binary-br_if:
5656
.. _binary-br_table:
57+
.. _binary-br_on_null:
58+
.. _binary-br_on_non_null:
59+
.. _binary-br_on_cast:
60+
.. _binary-br_on_cast_fail:
5761
.. _binary-return:
5862
.. _binary-call:
5963
.. _binary-call_ref:
@@ -65,8 +69,10 @@ Control Instructions
6569
.. _binary-throw_ref:
6670
.. _binary-try_table:
6771
.. _binary-catch:
72+
.. _binary-castop:
6873

69-
$${grammar: Bblocktype {Binstr/block Binstr/control} Bcatch}
74+
$${grammar: Bblocktype {Binstr/block Binstr/control} Bcatch Bcastop}
75+
$${syntax-ignore: castop}
7076

7177
.. note::
7278
The ${:ELSE} opcode ${:0x05} in the encoding of an ${:IF} instruction can be omitted if the following instruction sequence is empty.
@@ -140,10 +146,6 @@ $${grammar: Bmemarg Binstr/memory}
140146
.. index:: reference instruction
141147
pair: binary format; instruction
142148
.. _binary-instr-ref:
143-
.. _binary-br_on_null:
144-
.. _binary-br_on_non_null:
145-
.. _binary-br_on_cast:
146-
.. _binary-br_on_cast_fail:
147149

148150
Reference Instructions
149151
~~~~~~~~~~~~~~~~~~~~~~
@@ -154,6 +156,24 @@ Generic :ref:`reference instructions <syntax-instr-ref>` are represented by sing
154156
.. _binary-ref.func:
155157
.. _binary-ref.is_null:
156158
.. _binary-ref.as_non_null:
159+
.. _binary-ref.test:
160+
.. _binary-ref.cast:
161+
162+
$${grammar: {Binstr/ref}}
163+
164+
165+
.. index:: aggregate instruction
166+
pair: binary format; instruction
167+
.. _binary-instr-aggr:
168+
169+
Aggregate Instructions
170+
~~~~~~~~~~~~~~~~~~~~~~
171+
172+
:ref:`Aggregate instructions <syntax-instr-aggr>` all use a prefix.
173+
174+
.. _binary-ref.i31:
175+
.. _binary-i31.get_s:
176+
.. _binary-i31.get_u:
157177
.. _binary-struct.new:
158178
.. _binary-struct.new_default:
159179
.. _binary-struct.get:
@@ -174,17 +194,10 @@ Generic :ref:`reference instructions <syntax-instr-ref>` are represented by sing
174194
.. _binary-array.copy:
175195
.. _binary-array.init_data:
176196
.. _binary-array.init_elem:
177-
.. _binary-ref.i31:
178-
.. _binary-i31.get_s:
179-
.. _binary-i31.get_u:
180-
.. _binary-ref.test:
181-
.. _binary-ref.cast:
182197
.. _binary-any.convert_extern:
183198
.. _binary-extern.convert_any:
184-
.. _binary-castop:
185199

186-
$${grammar: {Binstr/ref Binstr/struct Binstr/array Binstr/cast Binstr/extern Binstr/i31} Bcastop}
187-
$${syntax-ignore: castop}
200+
$${grammar: {Binstr/struct Binstr/array Binstr/extern Binstr/i31}}
188201

189202

190203
.. index:: numeric instruction

document/core/syntax/instructions.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ If missing, the operands must be of :ref:`numeric <syntax-numtype>` or :ref:`vec
6161
.. _syntax-br_on_non_null:
6262
.. _syntax-br_on_cast:
6363
.. _syntax-br_on_cast_fail:
64-
.. _syntax-return:
6564
.. _syntax-call:
65+
.. _syntax-call_ref:
6666
.. _syntax-call_indirect:
67-
.. _syntax-instrs:
68-
.. _syntax-instr-control:
67+
.. _syntax-return:
68+
.. _syntax-return_call:
69+
.. _syntax-return_call_ref:
70+
.. _syntax-return_call_indirect:
6971
.. _syntax-throw:
7072
.. _syntax-throw_ref:
7173
.. _syntax-try_table:
7274
.. _syntax-catch:
75+
.. _syntax-instrs:
76+
.. _syntax-instr-control:
7377
.. _exception:
7478

7579
Control Instructions
@@ -284,6 +288,7 @@ while the latter performs a downcast and :ref:`traps <trap>` if the operand's ty
284288
.. _syntax-i31.get_u:
285289
.. _syntax-any.convert_extern:
286290
.. _syntax-extern.convert_any:
291+
.. _syntax-instr-aggr:
287292
.. _syntax-instr-struct:
288293
.. _syntax-instr-array:
289294
.. _syntax-instr-i31:

document/core/text/instructions.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ Reference Instructions
201201
.. _text-ref.func:
202202
.. _text-ref.is_null:
203203
.. _text-ref.as_non_null:
204+
.. _text-ref.test:
205+
.. _text-ref.cast:
206+
207+
$${grammar: {Tplaininstr_/ref}}
208+
209+
210+
.. index:: aggregate instruction
211+
pair: text format; instruction
212+
.. _text-instr-aggr:
213+
214+
Aggregate Instructions
215+
~~~~~~~~~~~~~~~~~~~~~~
216+
217+
.. _text-ref.i31:
218+
.. _text-i31.get_s:
219+
.. _text-i31.get_u:
204220
.. _text-struct.new:
205221
.. _text-struct.new_default:
206222
.. _text-struct.get:
@@ -221,15 +237,10 @@ Reference Instructions
221237
.. _text-array.copy:
222238
.. _text-array.init_data:
223239
.. _text-array.init_elem:
224-
.. _text-ref.i31:
225-
.. _text-i31.get_s:
226-
.. _text-i31.get_u:
227-
.. _text-ref.test:
228-
.. _text-ref.cast:
229240
.. _text-any.convert_extern:
230241
.. _text-extern.convert_any:
231242

232-
$${grammar: {Tplaininstr_/ref Tplaininstr_/i31 Tplaininstr_/struct Tplaininstr_/array Tplaininstr_/extern}}
243+
$${grammar: {Tplaininstr_/i31 Tplaininstr_/struct Tplaininstr_/array Tplaininstr_/extern}}
233244

234245

235246
.. index:: numeric instruction

specification/wasm-3.0/5.3-binary.instructions.spectec

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ grammar Binstr/parametric : instr =
1515

1616
;; Control instructions
1717

18+
syntax castop = (null?, null?)
19+
20+
grammar Bcastop : castop =
21+
| 0x00 => (eps, eps)
22+
| 0x01 => (NULL, eps)
23+
| 0x02 => (eps, NULL)
24+
| 0x03 => (NULL, NULL)
25+
1826
grammar Bblocktype : blocktype =
1927
| 0x40 => _RESULT eps
2028
| t:Bvaltype => _RESULT t
@@ -42,6 +50,12 @@ grammar Binstr/control : instr = ...
4250
| 0x14 x:Btypeidx => CALL_REF (_IDX x)
4351
| 0x15 x:Btypeidx => RETURN_CALL_REF (_IDX x)
4452
| 0x1F bt:Bblocktype c*:Blist(Bcatch) (in:Binstr)* 0x0B => TRY_TABLE bt c* in*
53+
| 0xD5 l:Blabelidx => BR_ON_NULL l
54+
| 0xD6 l:Blabelidx => BR_ON_NON_NULL l
55+
| 0xFB 24:Bu32 (null_1?, null_2?):Bcastop
56+
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST l (REF null_1? ht_1) (REF null_2? ht_2)
57+
| 0xFB 25:Bu32 (null_1?, null_2?):Bcastop
58+
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_FAIL l (REF null_1? ht_1) (REF null_2? ht_2)
4559
| ...
4660

4761
grammar Bcatch : catch =
@@ -122,22 +136,16 @@ grammar Binstr/memory : instr = ...
122136

123137
;; Reference instructions
124138

125-
syntax castop = (null?, null?)
126-
127-
grammar Bcastop : castop =
128-
| 0x00 => (eps, eps)
129-
| 0x01 => (NULL, eps)
130-
| 0x02 => (eps, NULL)
131-
| 0x03 => (NULL, NULL)
132-
133139
grammar Binstr/ref : instr = ...
134140
| 0xD0 ht:Bheaptype => REF.NULL ht
135141
| 0xD1 => REF.IS_NULL
136142
| 0xD2 x:Bfuncidx => REF.FUNC x
137143
| 0xD3 => REF.EQ
138144
| 0xD4 => REF.AS_NON_NULL
139-
| 0xD5 l:Blabelidx => BR_ON_NULL l
140-
| 0xD6 l:Blabelidx => BR_ON_NON_NULL l
145+
| 0xFB 20:Bu32 ht:Bheaptype => REF.TEST (REF ht)
146+
| 0xFB 21:Bu32 ht:Bheaptype => REF.TEST (REF NULL ht)
147+
| 0xFB 22:Bu32 ht:Bheaptype => REF.CAST (REF ht)
148+
| 0xFB 23:Bu32 ht:Bheaptype => REF.CAST (REF NULL ht)
141149
| ...
142150

143151
grammar Binstr/struct : instr = ...
@@ -166,17 +174,6 @@ grammar Binstr/array : instr = ...
166174
| 0xFB 19:Bu32 x:Btypeidx y:Belemidx => ARRAY.INIT_ELEM x y
167175
| ...
168176

169-
grammar Binstr/cast : instr = ...
170-
| 0xFB 20:Bu32 ht:Bheaptype => REF.TEST (REF ht)
171-
| 0xFB 21:Bu32 ht:Bheaptype => REF.TEST (REF NULL ht)
172-
| 0xFB 22:Bu32 ht:Bheaptype => REF.CAST (REF ht)
173-
| 0xFB 23:Bu32 ht:Bheaptype => REF.CAST (REF NULL ht)
174-
| 0xFB 24:Bu32 (null_1?, null_2?):Bcastop
175-
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST l (REF null_1? ht_1) (REF null_2? ht_2)
176-
| 0xFB 25:Bu32 (null_1?, null_2?):Bcastop
177-
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_FAIL l (REF null_1? ht_1) (REF null_2? ht_2)
178-
| ...
179-
180177
grammar Binstr/extern : instr = ...
181178
| 0xFB 26:Bu32 => ANY.CONVERT_EXTERN
182179
| 0xFB 27:Bu32 => EXTERN.CONVERT_ANY
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)