use super::{utils::FromWasmparser as _, ConstExpr};
use crate::GlobalType;
#[derive(Debug, Copy, Clone)]
pub struct GlobalIdx(u32);
impl From<u32> for GlobalIdx {
fn from(index: u32) -> Self {
Self(index)
}
}
impl GlobalIdx {
pub fn into_u32(self) -> u32 {
self.0
}
}
#[derive(Debug)]
pub struct Global {
global_type: GlobalType,
init_expr: ConstExpr,
}
impl From<wasmparser::Global<'_>> for Global {
fn from(global: wasmparser::Global<'_>) -> Self {
let global_type = GlobalType::from_wasmparser(global.ty);
let init_expr = ConstExpr::new(global.init_expr);
Self {
global_type,
init_expr,
}
}
}
impl Global {
pub fn into_type_and_init(self) -> (GlobalType, ConstExpr) {
(self.global_type, self.init_expr)
}
}