@@ -654,11 +654,9 @@ impl fmt::Display for BinOp {
654654/// Definition of a Wasm global variable.
655655#[ derive( Debug , Clone ) ]
656656pub struct GlobalDef {
657- /// The Wasm value type of the global.
658- pub wasm_type : WasmType ,
659657 /// Whether the global is mutable.
660658 pub mutable : bool ,
661- /// The constant initializer value.
659+ /// The constant initializer value (also encodes the type) .
662660 pub init_value : GlobalInit ,
663661}
664662
@@ -671,6 +669,18 @@ pub enum GlobalInit {
671669 F64 ( f64 ) ,
672670}
673671
672+ impl GlobalInit {
673+ /// Get the WasmType of this global init value.
674+ pub fn ty ( & self ) -> WasmType {
675+ match self {
676+ GlobalInit :: I32 ( _) => WasmType :: I32 ,
677+ GlobalInit :: I64 ( _) => WasmType :: I64 ,
678+ GlobalInit :: F32 ( _) => WasmType :: F32 ,
679+ GlobalInit :: F64 ( _) => WasmType :: F64 ,
680+ }
681+ }
682+ }
683+
674684/// A data segment to initialize memory.
675685#[ derive( Debug , Clone ) ]
676686pub struct DataSegmentDef {
@@ -1138,14 +1148,12 @@ mod tests {
11381148 assert ! ( !info. has_mutable_globals( ) ) ;
11391149
11401150 info. globals . push ( GlobalDef {
1141- wasm_type : WasmType :: I32 ,
11421151 mutable : false ,
11431152 init_value : GlobalInit :: I32 ( 0 ) ,
11441153 } ) ;
11451154 assert ! ( !info. has_mutable_globals( ) ) ;
11461155
11471156 info. globals . push ( GlobalDef {
1148- wasm_type : WasmType :: I32 ,
11491157 mutable : true ,
11501158 init_value : GlobalInit :: I32 ( 0 ) ,
11511159 } ) ;
0 commit comments