/build/source/src/core/reader/types/global.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::core::reader::span::Span; |
2 | | use crate::core::reader::types::ValType; |
3 | | use crate::core::reader::{WasmReadable, WasmReader}; |
4 | | use crate::execution::assert_validated::UnwrapValidatedExt; |
5 | | use crate::{unreachable_validated, Error, Result}; |
6 | | |
7 | | #[derive(Debug, Copy, Clone)] |
8 | | pub struct Global { |
9 | | pub ty: GlobalType, |
10 | | // TODO validate init_expr during validation and execute during instantiation |
11 | | pub init_expr: Span, |
12 | | } |
13 | | |
14 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
15 | | pub struct GlobalType { |
16 | | pub ty: ValType, |
17 | | pub is_mut: bool, |
18 | | } |
19 | | |
20 | | impl WasmReadable for GlobalType { |
21 | 2 | fn read(wasm: &mut WasmReader) -> Result<Self> { |
22 | 2 | let ty = ValType::read(wasm)?0 ; |
23 | 2 | let is_mut = match wasm.read_u8()?0 { |
24 | 0 | 0x00 => false, |
25 | 2 | 0x01 => true, |
26 | 0 | other => return Err(Error::InvalidMutType(other)), |
27 | | }; |
28 | 2 | Ok(Self { ty, is_mut }) |
29 | 2 | } |
30 | | |
31 | 0 | fn read_unvalidated(wasm: &mut WasmReader) -> Self { |
32 | 0 | let ty = ValType::read_unvalidated(wasm); |
33 | 0 | let is_mut = match wasm.read_u8().unwrap_validated() { |
34 | 0 | 0x00 => false, |
35 | 0 | 0x01 => true, |
36 | 0 | _ => unreachable_validated!(), |
37 | | }; |
38 | | |
39 | 0 | Self { ty, is_mut } |
40 | 0 | } |
41 | | } |