Wat2Wasm converts the text format of WebAssembly to the binary format. Takes the text format in-memory as input, and returns either the binary encoding of the text format or an error if parsing fails.
(wat string)
| 12 | // Takes the text format in-memory as input, and returns either the binary |
| 13 | // encoding of the text format or an error if parsing fails. |
| 14 | func Wat2Wasm(wat string) ([]byte, error) { |
| 15 | retVec := C.wasm_byte_vec_t{} |
| 16 | err := C.wasmtime_wat2wasm( |
| 17 | C._GoStringPtr(wat), |
| 18 | C._GoStringLen(wat), |
| 19 | &retVec, |
| 20 | ) |
| 21 | runtime.KeepAlive(wat) |
| 22 | |
| 23 | if err == nil { |
| 24 | ret := C.GoBytes(unsafe.Pointer(retVec.data), C.int(retVec.size)) |
| 25 | C.wasm_byte_vec_delete(&retVec) |
| 26 | return ret, nil |
| 27 | } |
| 28 | |
| 29 | return nil, mkError(err) |
| 30 | } |
searching dependent graphs…