github.com/tetratelabs/wazero@v1.2.1/internal/wasm/engine.go (about) 1 package wasm 2 3 import ( 4 "context" 5 6 "github.com/tetratelabs/wazero/api" 7 "github.com/tetratelabs/wazero/experimental" 8 ) 9 10 // Engine is a Store-scoped mechanism to compile functions declared or imported by a module. 11 // This is a top-level type implemented by an interpreter or compiler. 12 type Engine interface { 13 // Close closes this engine, and releases all the compiled cache. 14 Close() (err error) 15 16 // CompileModule implements the same method as documented on wasm.Engine. 17 CompileModule(ctx context.Context, module *Module, listeners []experimental.FunctionListener, ensureTermination bool) error 18 19 // CompiledModuleCount is exported for testing, to track the size of the compilation cache. 20 CompiledModuleCount() uint32 21 22 // DeleteCompiledModule releases compilation caches for the given module (source). 23 // Note: it is safe to call this function for a module from which module instances are instantiated even when these 24 // module instances have outstanding calls. 25 DeleteCompiledModule(module *Module) 26 27 // NewModuleEngine compiles down the function instances in a module, and returns ModuleEngine for the module. 28 // 29 // * module is the source module from which moduleFunctions are instantiated. This is used for caching. 30 // * instance is the *ModuleInstance which is created from `module`. 31 // 32 // Note: Input parameters must be pre-validated with wasm.Module Validate, to ensure no fields are invalid 33 // due to reasons such as out-of-bounds. 34 NewModuleEngine(module *Module, instance *ModuleInstance) (ModuleEngine, error) 35 } 36 37 // ModuleEngine implements function calls for a given module. 38 type ModuleEngine interface { 39 // NewFunction returns an api.Function for the given function pointed by the given Index. 40 NewFunction(index Index) api.Function 41 42 // ResolveImportedFunction is used to add imported functions needed to make this ModuleEngine fully functional. 43 // - `index` is the function Index of this imported function. 44 // - `indexInImportedModule` is the function Index of the imported function in the imported module. 45 // - `importedModuleEngine` is the ModuleEngine for the imported ModuleInstance. 46 ResolveImportedFunction(index, indexInImportedModule Index, importedModuleEngine ModuleEngine) 47 48 // LookupFunction returns the api.Function created from the function in the function table at the given offset. 49 LookupFunction(t *TableInstance, typeId FunctionTypeID, tableOffset Index) (api.Function, error) 50 51 // FunctionInstanceReference returns Reference for the given Index for a FunctionInstance. The returned values are used by 52 // the initialization via ElementSegment. 53 FunctionInstanceReference(funcIndex Index) Reference 54 }