use super::InitExpr;
use crate::{errors::ModuleError, GlobalType};
#[derive(Debug, Copy, Clone)]
pub struct GlobalIdx(pub(crate) u32);
impl GlobalIdx {
pub fn into_u32(self) -> u32 {
self.0
}
pub fn into_usize(self) -> usize {
self.0 as usize
}
}
#[derive(Debug)]
pub struct Global {
global_type: GlobalType,
init_expr: InitExpr,
}
impl TryFrom<wasmparser::Global<'_>> for Global {
type Error = ModuleError;
fn try_from(global: wasmparser::Global<'_>) -> Result<Self, Self::Error> {
let global_type = global.ty.try_into()?;
let init_expr = InitExpr::new(global.init_expr);
Ok(Global {
global_type,
init_expr,
})
}
}
impl Global {
pub fn into_type_and_init(self) -> (GlobalType, InitExpr) {
(self.global_type, self.init_expr)
}
}