github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/testing/binaryencoding/global.go (about)

     1  package binaryencoding
     2  
     3  import (
     4  	"github.com/bananabytelabs/wazero/internal/wasm"
     5  )
     6  
     7  // encodeGlobal returns the wasm.Global encoded in WebAssembly 1.0 (20191205) Binary Format.
     8  //
     9  // See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#global-section%E2%91%A0
    10  func encodeGlobal(g wasm.Global) (data []byte) {
    11  	var mutable byte
    12  	if g.Type.Mutable {
    13  		mutable = 1
    14  	}
    15  	data = []byte{g.Type.ValType, mutable}
    16  	data = append(data, encodeConstantExpression(g.Init)...)
    17  	return
    18  }