Wasmtime
wat.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_WAT_HH
6#define WASMTIME_WAT_HH
7
8#include <string_view>
9#include <vector>
10#include <wasmtime/conf.h>
11#include <wasmtime/error.hh>
12#include <wasmtime/span.hh>
13#include <wasmtime/wat.h>
14
15namespace wasmtime {
16
17#ifdef WASMTIME_FEATURE_WAT
18
30inline Result<std::vector<uint8_t>> wat2wasm(std::string_view wat) {
32 auto *error = wasmtime_wat2wasm(wat.data(), wat.size(), &ret);
33 if (error != nullptr) {
34 return Error(error);
35 }
36 std::vector<uint8_t> vec;
37 // NOLINTNEXTLINE TODO can this be done without triggering lints?
38 Span<uint8_t> raw(reinterpret_cast<uint8_t *>(ret.data), ret.size);
39 vec.assign(raw.begin(), raw.end());
41 return vec;
42}
43
44#endif // WASMTIME_FEATURE_WAT
45
46} // namespace wasmtime
47
48#endif // WASMTIME_WAT_HH
Errors coming from Wasmtime.
Definition: error.hh:24
Fallible result type used for Wasmtime.
Definition: error.hh:83
Span class used when c++20 is not available.
Definition: span.hh:45
iterator end() const
Returns end iterator.
Definition: span.hh:85
iterator begin() const
Returns begin iterator.
Definition: span.hh:82
Build-time defines for how the C API was built.
A list of bytes.
Definition: wasm.h:102
size_t size
Length of this vector.
Definition: wasm.h:102
wasm_byte_t * data
Pointer to the base of this vector.
Definition: wasm.h:102
void wasm_byte_vec_delete(wasm_byte_vec_t *)
Deletes a byte vector.
wasmtime_error_t * wasmtime_wat2wasm(const char *wat, size_t wat_len, wasm_byte_vec_t *ret)
Converts from the text format of WebAssembly to the binary format.
Result< std::vector< uint8_t > > wat2wasm(std::string_view wat)
Converts the WebAssembly text format into the WebAssembly binary format.
Definition: wat.hh:30