* \brief Converts the WebAssembly text format into the WebAssembly binary * format. * * This will parse the text format and attempt to translate it to the binary * format. Note that the text parser assumes that all WebAssembly features are * enabled and will parse syntax of future proposals. The exact syntax here * parsed may be tweaked over time. * * Returns either an error if parsing fai
| 28 | * Returns either an error if parsing failed or the wasm binary. |
| 29 | */ |
| 30 | inline Result<std::vector<uint8_t>> wat2wasm(std::string_view wat) { |
| 31 | wasm_byte_vec_t ret; |
| 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()); |
| 40 | wasm_byte_vec_delete(&ret); |
| 41 | return vec; |
| 42 | } |
| 43 | |
| 44 | #endif // WASMTIME_FEATURE_WAT |
| 45 |