github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/wasm/runtime/wasmtime/module.go (about) 1 package wasmtime 2 3 import ( 4 "github.com/bytecodealliance/wasmtime-go/v17" 5 6 "github.com/machinefi/w3bstream/pkg/modules/wasm/abi/types" 7 ) 8 9 // NewWasmtimeModule 10 func NewWasmtimeModule(vm *VM, mod *wasmtime.Module, code []byte) (*Module, error) { 11 m := &Module{ 12 vm: vm, 13 mod: mod, 14 code: code, 15 } 16 m.Init() 17 return m, nil 18 } 19 20 type Module struct { 21 vm *VM 22 mod *wasmtime.Module 23 abiNames []string 24 code []byte 25 // debug *DwarfInfo 26 } 27 28 func (m *Module) Init() { 29 m.abiNames = m.GetABINameList() 30 31 // if debug := ParseDwarf(m.code); debug != nil { 32 // m.debug = debug 33 // } 34 m.code = nil 35 } 36 37 func (m *Module) NewInstance() types.Instance { 38 return NewWasmtimeInstance(m.vm, m) 39 } 40 41 func (m *Module) GetABINameList() []string { 42 exps := m.mod.Exports() 43 names := make([]string, 0, len(exps)) 44 45 for _, e := range exps { 46 if t := e.Type().FuncType(); t != nil { 47 // if strings.HasPrefix(e.Name(), "ws_") { 48 names = append(names, e.Name()) 49 // } 50 } 51 } 52 return names 53 }