Skip to content

Commit 1ffb924

Browse files
authored
[spec] Fix binary format of data/elem tags to allow LEB (#1461)
1 parent 082ae4d commit 1ffb924

File tree

2 files changed

+62
-17
lines changed

2 files changed

+62
-17
lines changed

document/core/binary/modules.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -327,36 +327,36 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
327327
\production{element section} & \Belemsec &::=&
328328
\X{seg}^\ast{:}\Bsection_9(\Bvec(\Belem)) &\Rightarrow& \X{seg} \\
329329
\production{element segment} & \Belem &::=&
330-
\hex{00}~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
330+
0{:}\Bu32~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
331331
&\Rightarrow& \\&&&\quad
332332
\{ \ETYPE~\FUNCREF, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
333-
\hex{01}~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
333+
1{:}\Bu32~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
334334
&\Rightarrow& \\&&&\quad
335335
\{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EPASSIVE \} \\ &&|&
336-
\hex{02}~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
336+
2{:}\Bu32~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
337337
&\Rightarrow& \\&&&\quad
338338
\{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\ &&|&
339-
\hex{03}~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
339+
3{:}\Bu32~~\X{et}:\Belemkind~~y^\ast{:}\Bvec(\Bfuncidx)
340340
&\Rightarrow& \\&&&\quad
341341
\{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EDECLARATIVE \} \\ &&|&
342-
\hex{04}~~e{:}\Bexpr~~\X{el}^\ast{:}\Bvec(\Bexpr)
342+
4{:}\Bu32~~e{:}\Bexpr~~\X{el}^\ast{:}\Bvec(\Bexpr)
343343
&\Rightarrow& \\&&&\quad
344344
\{ \ETYPE~\FUNCREF, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
345-
\hex{05}~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
345+
5{:}\Bu32~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
346346
&\Rightarrow& \\&&&\quad
347347
\{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EPASSIVE \} \\ &&|&
348-
\hex{06}~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
348+
6{:}\Bu32~~x{:}\Btableidx~~e{:}\Bexpr~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
349349
&\Rightarrow& \\&&&\quad
350350
\{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\ &&|&
351-
\hex{07}~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
351+
7{:}\Bu32~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
352352
&\Rightarrow& \\&&&\quad
353353
\{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EDECLARATIVE \} \\
354354
\production{element kind} & \Belemkind &::=&
355355
\hex{00} &\Rightarrow& \FUNCREF \\
356356
\end{array}
357357
358358
.. note::
359-
The initial byte can be interpreted as a bitfield.
359+
The initial integer can be interpreted as a bitfield.
360360
Bit 0 indicates a passive or declarative segment,
361361
bit 1 indicates the presence of an explicit table index for an active segment and otherwise distinguishes passive from declarative segments,
362362
bit 2 indicates the use of element type and element :ref:`expressions <binary-expr>` instead of element kind and element indices.
@@ -440,16 +440,16 @@ It decodes into a vector of :ref:`data segments <syntax-data>` that represent th
440440
\production{data section} & \Bdatasec &::=&
441441
\X{seg}^\ast{:}\Bsection_{11}(\Bvec(\Bdata)) &\Rightarrow& \X{seg} \\
442442
\production{data segment} & \Bdata &::=&
443-
\hex{00}~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
443+
0{:}\Bu32~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
444444
&\Rightarrow& \{ \DINIT~b^\ast, \DMODE~\DACTIVE~\{ \DMEM~0, \DOFFSET~e \} \} \\ &&|&
445-
\hex{01}~~b^\ast{:}\Bvec(\Bbyte)
445+
1{:}\Bu32~~b^\ast{:}\Bvec(\Bbyte)
446446
&\Rightarrow& \{ \DINIT~b^\ast, \DMODE~\DPASSIVE \} \\ &&|&
447-
\hex{02}~~x{:}\Bmemidx~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
447+
2{:}\Bu32~~x{:}\Bmemidx~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
448448
&\Rightarrow& \{ \DINIT~b^\ast, \DMODE~\DACTIVE~\{ \DMEM~x, \DOFFSET~e \} \} \\
449449
\end{array}
450450
451451
.. note::
452-
The initial byte can be interpreted as a bitfield.
452+
The initial integer can be interpreted as a bitfield.
453453
Bit 0 indicates a passive segment,
454454
bit 1 indicates the presence of an explicit memory index for an active segment.
455455

test/core/binary.wast

+49-4
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,68 @@
140140
"\41\00\0b\00" ;; (i32.const 0) with no elements
141141
)
142142

143-
;; Data segment memory index can have non-minimal length
143+
;; Data segment tags and memory index can have non-minimal length
144144
(module binary
145145
"\00asm" "\01\00\00\00"
146146
"\05\03\01" ;; Memory section with 1 entry
147147
"\00\00" ;; no max, minimum 0
148148
"\0b\07\01" ;; Data section with 1 entry
149-
"\80\00" ;; Memory index 0, encoded with 2 bytes
149+
"\80\00" ;; Active segment, encoded with 2 bytes
150+
"\41\00\0b\00" ;; (i32.const 0) with contents ""
151+
)
152+
(module binary
153+
"\00asm" "\01\00\00\00"
154+
"\05\03\01" ;; Memory section with 1 entry
155+
"\00\00" ;; no max, minimum 0
156+
"\0b\08\01" ;; Data section with 1 entry
157+
"\82\00" ;; Active segment, encoded with 2 bytes
158+
"\00" ;; explicit memory index
159+
"\41\00\0b\00" ;; (i32.const 0) with contents ""
160+
)
161+
(module binary
162+
"\00asm" "\01\00\00\00"
163+
"\05\03\01" ;; Memory section with 1 entry
164+
"\00\00" ;; no max, minimum 0
165+
"\0b\09\01" ;; Data section with 1 entry
166+
"\82\00" ;; Active segment, encoded with 2 bytes
167+
"\80\00" ;; explicit memory index, encoded with 2 bytes
150168
"\41\00\0b\00" ;; (i32.const 0) with contents ""
151169
)
152170

153-
;; Element segment table index can have non-minimal length
171+
;; Element segment tags and table index can have non-minimal length
172+
(module binary
173+
"\00asm" "\01\00\00\00"
174+
"\04\04\01" ;; Table section with 1 entry
175+
"\70\00\00" ;; no max, minimum 0, funcref
176+
"\09\07\01" ;; Element section with 1 entry
177+
"\80\00" ;; Active segment
178+
"\41\00\0b\00" ;; (i32.const 0) with no elements
179+
)
154180
(module binary
155181
"\00asm" "\01\00\00\00"
156182
"\04\04\01" ;; Table section with 1 entry
157183
"\70\00\00" ;; no max, minimum 0, funcref
158184
"\09\09\01" ;; Element section with 1 entry
159-
"\02\80\00" ;; Table index 0, encoded with 2 bytes
185+
"\02" ;; Active segment
186+
"\80\00" ;; explicit table index, encoded with 2 bytes
187+
"\41\00\0b\00\00" ;; (i32.const 0) with no elements
188+
)
189+
(module binary
190+
"\00asm" "\01\00\00\00"
191+
"\04\04\01" ;; Table section with 1 entry
192+
"\70\00\00" ;; no max, minimum 0, funcref
193+
"\09\09\01" ;; Element section with 1 entry
194+
"\82\00" ;; Active segment, encoded with 2 bytes
195+
"\00" ;; explicit table index
196+
"\41\00\0b\00\00" ;; (i32.const 0) with no elements
197+
)
198+
(module binary
199+
"\00asm" "\01\00\00\00"
200+
"\04\04\01" ;; Table section with 1 entry
201+
"\70\00\00" ;; no max, minimum 0, funcref
202+
"\09\0a\01" ;; Element section with 1 entry
203+
"\82\00" ;; Active segment, encoded with 2 bytes
204+
"\80\00" ;; explicit table index, encoded with 2 bytes
160205
"\41\00\0b\00\00" ;; (i32.const 0) with no elements
161206
)
162207

0 commit comments

Comments
 (0)