MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / Module

Class Module

crates/c-api/include/wasmtime/module.hh:28–166  ·  view source on GitHub ↗

* \brief Representation of a compiled WebAssembly module. * * This type contains JIT code of a compiled WebAssembly module. A `Module` is * connected to an `Engine` and can only be instantiated within that `Engine`. * You can inspect a `Module` for its type information. This is passed as an * argument to other APIs to instantiate it. */

Source from the content-addressed store, hash-verified

26 * argument to other APIs to instantiate it.
27 */
28class Module {
29 WASMTIME_CLONE_WRAPPER(Module, wasmtime_module);
30
31#ifdef WASMTIME_FEATURE_COMPILER
32
33#ifdef WASMTIME_FEATURE_WAT
34 /**
35 * \brief Compiles a module from the WebAssembly text format.
36 *
37 * This function will automatically use `wat2wasm` on the input and then
38 * delegate to the #compile function.
39 */
40 static Result<Module> compile(Engine &engine, std::string_view wat) {
41 auto wasm = wat2wasm(wat);
42 if (!wasm) {
43 return wasm.err();
44 }
45 auto bytes = wasm.ok();
46 return compile(engine, bytes);
47 }
48#endif // WASMTIME_FEATURE_WAT
49
50 /**
51 * \brief Compiles a module from the WebAssembly binary format.
52 *
53 * This function compiles the provided WebAssembly binary specified by `wasm`
54 * within the compilation settings configured by `engine`. This method is
55 * synchronous and will not return until the module has finished compiling.
56 *
57 * This function can fail if the WebAssembly binary is invalid or doesn't
58 * validate (or similar).
59 */
60 static Result<Module> compile(Engine &engine, Span<uint8_t> wasm) {
61 wasmtime_module_t *ret = nullptr;
62 auto *error =
63 wasmtime_module_new(engine.capi(), wasm.data(), wasm.size(), &ret);
64 if (error != nullptr) {
65 return Error(error);
66 }
67 return Module(ret);
68 }
69
70 /**
71 * \brief Validates the provided WebAssembly binary without compiling it.
72 *
73 * This function will validate whether the provided binary is indeed valid
74 * within the compilation settings of the `engine` provided.
75 */
76 static Result<std::monostate> validate(Engine &engine, Span<uint8_t> wasm) {
77 auto *error =
78 wasmtime_module_validate(engine.capi(), wasm.data(), wasm.size());
79 if (error != nullptr) {
80 return Error(error);
81 }
82 return std::monostate();
83 }
84#endif // WASMTIME_FEATURE_COMPILER
85

Callers 5

compileMethod · 0.70
deserializeMethod · 0.70
deserialize_fileMethod · 0.70
fromMethod · 0.50
wasm.hhFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected