github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/testing/binaryencoding/global.go (about)

     1  package binaryencoding
     2  
     3  import (
     4  	"github.com/wasilibs/wazerox/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  }