Skip to content

Commit 506907b

Browse files
authored
[spec] Documentation of binary format (WebAssembly#17)
1 parent 863d963 commit 506907b

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

document/core/binary/instructions.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ Each variant of :ref:`memory instruction <syntax-instr-memory>` is encoded with
126126
.. _binary-storen:
127127
.. _binary-memory.size:
128128
.. _binary-memory.grow:
129+
.. _binary-memory.init:
130+
.. _binary-memory.drop:
131+
.. _binary-memory.copy:
132+
.. _binary-memory.fill:
129133

130134
.. math::
131135
\begin{array}{llclll}
@@ -156,11 +160,36 @@ Each variant of :ref:`memory instruction <syntax-instr-memory>` is encoded with
156160
\hex{3D}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{16}~m \\ &&|&
157161
\hex{3E}~~m{:}\Bmemarg &\Rightarrow& \I64.\STORE\K{32}~m \\ &&|&
158162
\hex{3F}~~\hex{00} &\Rightarrow& \MEMORYSIZE \\ &&|&
159-
\hex{40}~~\hex{00} &\Rightarrow& \MEMORYGROW \\
163+
\hex{40}~~\hex{00} &\Rightarrow& \MEMORYGROW \\ &&|&
164+
\hex{FC}~\hex{08}~~x{:}\Bdataidx &\Rightarrow& \MEMORYINIT~x \\ &&|&
165+
\hex{FC}~\hex{09}~~x{:}\Bdataidx &\Rightarrow& \MEMORYDROP~x \\ &&|&
166+
\hex{FC}~\hex{0A}~~\hex{00} &\Rightarrow& \MEMORYCOPY \\ &&|&
167+
\hex{FC}~\hex{0B}~~\hex{00} &\Rightarrow& \MEMORYFILL \\
160168
\end{array}
161169
162170
.. note::
163-
In future versions of WebAssembly, the additional zero bytes occurring in the encoding of the |MEMORYSIZE| and |MEMORYGROW| instructions may be used to index additional memories.
171+
In future versions of WebAssembly, the additional zero bytes occurring in the encoding of the |MEMORYSIZE|, |MEMORYGROW|, |MEMORYCOPY|, and |MEMORYFILL| instructions may be used to index additional memories.
172+
173+
174+
Table Instructions
175+
~~~~~~~~~~~~~~~~~~
176+
177+
Each variant of :ref:`table instruction <syntax-instr-table>` is encoded with a different byte code.
178+
179+
.. _binary-table.init:
180+
.. _binary-table.drop:
181+
.. _binary-table.copy:
182+
183+
.. math::
184+
\begin{array}{llclll}
185+
\production{instruction} & \Binstr &::=& \dots \\ &&|&
186+
\hex{FC}~\hex{0C}~~x{:}\Belemidx &\Rightarrow& \TABLEINIT~x \\ &&|&
187+
\hex{FC}~\hex{0D}~~x{:}\Belemidx &\Rightarrow& \TABLEDROP~x \\ &&|&
188+
\hex{FC}~\hex{0E}~~\hex{00} &\Rightarrow& \TABLECOPY \\
189+
\end{array}
190+
191+
.. note::
192+
In future versions of WebAssembly, the additional zero byte occurring in the encoding of the |TABLECOPY| instruction may be used to index an additional table.
164193

165194

166195
.. index:: numeric instruction

document/core/binary/modules.rst

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ except that :ref:`function definitions <syntax-func>` are split into two section
99
This separation enables *parallel* and *streaming* compilation of the functions in a module.
1010

1111

12-
.. index:: index, type index, function index, table index, memory index, global index, local index, label index
12+
.. index:: index, type index, function index, table index, memory index, global index, element index, data index, local index, label index
1313
pair: binary format; type index
1414
pair: binary format; function index
1515
pair: binary format; table index
1616
pair: binary format; memory index
1717
pair: binary format; global index
18+
pair: binary format; element index
19+
pair: binary format; data index
1820
pair: binary format; local index
1921
pair: binary format; label index
2022
.. _binary-typeidx:
2123
.. _binary-funcidx:
2224
.. _binary-tableidx:
2325
.. _binary-memidx:
2426
.. _binary-globalidx:
27+
.. _binary-elemidx:
28+
.. _binary-dataidx:
2529
.. _binary-localidx:
2630
.. _binary-labelidx:
2731
.. _binary-index:
@@ -38,6 +42,8 @@ All :ref:`indices <syntax-index>` are encoded with their respective value.
3842
\production{table index} & \Btableidx &::=& x{:}\Bu32 &\Rightarrow& x \\
3943
\production{memory index} & \Bmemidx &::=& x{:}\Bu32 &\Rightarrow& x \\
4044
\production{global index} & \Bglobalidx &::=& x{:}\Bu32 &\Rightarrow& x \\
45+
\production{element index} & \Belemidx &::=& x{:}\Bu32 &\Rightarrow& x \\
46+
\production{data index} & \Bdataidx &::=& x{:}\Bu32 &\Rightarrow& x \\
4147
\production{local index} & \Blocalidx &::=& x{:}\Bu32 &\Rightarrow& x \\
4248
\production{label index} & \Blabelidx &::=& l{:}\Bu32 &\Rightarrow& l \\
4349
\end{array}
@@ -319,10 +325,18 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
319325
\production{element section} & \Belemsec &::=&
320326
\X{seg}^\ast{:}\Bsection_9(\Bvec(\Belem)) &\Rightarrow& \X{seg} \\
321327
\production{element segment} & \Belem &::=&
322-
x{:}\Btableidx~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
323-
&\Rightarrow& \{ \ETABLE~x, \EOFFSET~e, \EINIT~y^\ast \} \\
328+
\hex{00}~~e{:}\Bexpr~~y^\ast{:}\Bvec(\Bfuncidx)
329+
&\Rightarrow& \{ \ETABLE~0, \EOFFSET~e, \EINIT~y^\ast \} \\
330+
\production{element segment} & \Belem &::=&
331+
\hex{01}~~y^\ast{:}\Bvec(\Bfuncidx)
332+
&\Rightarrow& \{ \EINIT~y^\ast \} \\
324333
\end{array}
325334
335+
.. note::
336+
In the current version of WebAssembly, at most one table may be defined or
337+
imported in a single module, so all valid :ref:`active <syntax-active>`
338+
element segments have a |ETABLE| value of :math:`0`.
339+
326340

327341
.. index:: ! code section, function, local, type index, function type
328342
pair: binary format; function
@@ -400,10 +414,18 @@ It decodes into a vector of :ref:`data segments <syntax-data>` that represent th
400414
\production{data section} & \Bdatasec &::=&
401415
\X{seg}^\ast{:}\Bsection_{11}(\Bvec(\Bdata)) &\Rightarrow& \X{seg} \\
402416
\production{data segment} & \Bdata &::=&
403-
x{:}\Bmemidx~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
404-
&\Rightarrow& \{ \DMEM~x, \DOFFSET~e, \DINIT~b^\ast \} \\
417+
\hex{00}~~e{:}\Bexpr~~b^\ast{:}\Bvec(\Bbyte)
418+
&\Rightarrow& \{ \DMEM~0, \DOFFSET~e, \DINIT~b^\ast \} \\
419+
\production{data segment} & \Bdata &::=&
420+
\hex{01}~~b^\ast{:}\Bvec(\Bbyte)
421+
&\Rightarrow& \{ \DINIT~b^\ast \} \\
405422
\end{array}
406423
424+
.. note::
425+
In the current version of WebAssembly, at most one memory may be defined or
426+
imported in a single module, so all valid :ref:`active <syntax-active>` data
427+
segments have a |DMEM| value of :math:`0`.
428+
407429

408430
.. index:: module, section, type definition, function type, function, table, memory, global, element, data, start function, import, export, context, version
409431
pair: binary format; module

document/core/util/macros.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@
478478
.. |Btableidx| mathdef:: \xref{binary/modules}{binary-tableidx}{\B{tableidx}}
479479
.. |Bmemidx| mathdef:: \xref{binary/modules}{binary-memidx}{\B{memidx}}
480480
.. |Bglobalidx| mathdef:: \xref{binary/modules}{binary-globalidx}{\B{globalidx}}
481+
.. |Belemidx| mathdef:: \xref{binary/modules}{binary-elemidx}{\B{elemidx}}
482+
.. |Bdataidx| mathdef:: \xref{binary/modules}{binary-dataidx}{\B{dataidx}}
481483
.. |Blocalidx| mathdef:: \xref{binary/modules}{binary-localidx}{\B{localidx}}
482484
.. |Blabelidx| mathdef:: \xref{binary/modules}{binary-labelidx}{\B{labelidx}}
483485

0 commit comments

Comments
 (0)