MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / NewModule

Function NewModule

module_feat_cranelift.go:13–33  ·  view source on GitHub ↗

NewModule compiles a new `Module` from the `wasm` provided with the given configuration in `engine`.

(engine *Engine, wasm []byte)

Source from the content-addressed store, hash-verified

11// NewModule compiles a new `Module` from the `wasm` provided with the given configuration
12// in `engine`.
13func NewModule(engine *Engine, wasm []byte) (*Module, error) {
14 // We can't create the `wasm_byte_vec_t` here and pass it in because
15 // that runs into the error of "passed a pointer to a pointer" because
16 // the vec itself is passed by pointer and it contains a pointer to
17 // `wasm`. To work around this we insert some C shims above and call
18 // them.
19 var wasmPtr *C.uint8_t
20 if len(wasm) > 0 {
21 wasmPtr = (*C.uint8_t)(unsafe.Pointer(&wasm[0]))
22 }
23 var ptr *C.wasmtime_module_t
24 err := C.wasmtime_module_new(engine.ptr(), wasmPtr, C.size_t(len(wasm)), &ptr)
25 runtime.KeepAlive(engine)
26 runtime.KeepAlive(wasm)
27
28 if err != nil {
29 return nil, mkError(err)
30 }
31
32 return mkModule(ptr), nil
33}
34
35// ModuleValidate validates whether `wasm` would be a valid wasm module according to the
36// configuration in `store`

Callers 15

TestInstanceFunction · 0.85
TestInstanceBadFunction · 0.85
TestInstanceGetFuncFunction · 0.85
NewModuleFromFileFunction · 0.85
refTypesInstanceFunction · 0.85
TestLinkerFunction · 0.85
TestLinkerTrapFunction · 0.85
TestLinkerModuleFunction · 0.85
TestLinkerFuncsFunction · 0.85

Calls 3

mkErrorFunction · 0.85
mkModuleFunction · 0.85
ptrMethod · 0.45

Tested by 15

TestInstanceFunction · 0.68
TestInstanceBadFunction · 0.68
TestInstanceGetFuncFunction · 0.68
refTypesInstanceFunction · 0.68
TestLinkerFunction · 0.68
TestLinkerTrapFunction · 0.68
TestLinkerModuleFunction · 0.68
TestLinkerFuncsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…