Wasmex.Engine (wasmex v0.9.2)
An Engine
which is a global context for compilation and management of Wasm
modules.
Engines store global configuration preferences such as compilation settings, enabled features, etc. You'll likely only need at most one of these for a program.
You can create an engine with default configuration settings using
EngineConfig::default()
. Be sure to consult the documentation of
Wasmex.EngineConfig
for default settings.
Example
iex> {:ok, _engine} = Wasmex.Engine.new(%Wasmex.EngineConfig{})
Summary
Functions
Creates a new Wasmex.Engine
with default settings.
Creates a new Wasmex.Engine
with the specified options.
Ahead-of-time (AOT) compiles a WebAssembly module.
Types
Functions
default()
@spec default() :: t()
Creates a new Wasmex.Engine
with default settings.
Example
iex> _engine = Wasmex.Engine.default()
new(config)
@spec new(Wasmex.EngineConfig.t()) :: {:ok, t()} | {:error, binary()}
Creates a new Wasmex.Engine
with the specified options.
Example
iex> {:ok, _engine} = Wasmex.Engine.new(%Wasmex.EngineConfig{})
precompile_module(engine, bytes)
Ahead-of-time (AOT) compiles a WebAssembly module.
The bytes
provided must be in one of two formats:
- A binary-encoded WebAssembly module
- A text-encoded instance of the WebAssembly text format
This method may be used to compile a module for use with a
different target host. The output of this method may be used with
Wasmex.Module.unsafe_deserialize/2
on hosts compatible with the
Wasmex.EngineConfig
associated with this Wasmex.Engine
.
The output of this method is safe to send to another host machine
for later execution. As the output is already a compiled module,
translation and code generation will be skipped and this will
improve the performance of constructing a Wasmex.Module
from
the output of this method.
Example
iex> {:ok, engine} = Wasmex.Engine.new(%Wasmex.EngineConfig{})
iex> bytes = File.read!(TestHelper.wasm_test_file_path())
iex> {:ok, _serialized_module} = Wasmex.Engine.precompile_module(engine, bytes)