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

Function compile_wat_module_from_file

examples/async.cc:90–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90handle<wasmtime_module_t, wasmtime_module_delete>
91compile_wat_module_from_file(wasm_engine_t *engine,
92 const std::string &filename) {
93 std::ifstream t(filename);
94 std::stringstream buffer;
95 buffer << t.rdbuf();
96 if (t.bad()) {
97 std::cerr << "error reading file: " << filename << std::endl;
98 std::exit(1);
99 }
100 const std::string &content = buffer.str();
101 wasm_byte_vec_t wasm_bytes;
102 handle<wasmtime_error_t, wasmtime_error_delete> error{
103 wasmtime_wat2wasm(content.data(), content.size(), &wasm_bytes)};
104 if (error) {
105 exit_with_error("failed to parse wat", error.get(), nullptr);
106 }
107 wasmtime_module_t *mod_ptr = nullptr;
108 error.reset(wasmtime_module_new(engine,
109 reinterpret_cast<uint8_t *>(wasm_bytes.data),
110 wasm_bytes.size, &mod_ptr));
111 wasm_byte_vec_delete(&wasm_bytes);
112 handle<wasmtime_module_t, wasmtime_module_delete> mod{mod_ptr};
113 if (!mod) {
114 exit_with_error("failed to compile module", error.get(), nullptr);
115 }
116 return mod;
117}
118
119class printer_thread_state {
120public:

Callers 1

mainFunction · 0.85

Calls 8

wasmtime_wat2wasmFunction · 0.85
wasmtime_module_newFunction · 0.85
strMethod · 0.80
exit_with_errorFunction · 0.70
dataMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected