| 108 | } |
| 109 | |
| 110 | static void read_wat_file(wasm_byte_vec_t *bytes, const char *filename) { |
| 111 | wasm_byte_vec_t wat; |
| 112 | // Load our input file to parse it next |
| 113 | FILE *file = fopen(filename, "r"); |
| 114 | if (!file) { |
| 115 | printf("> Error loading file!\n"); |
| 116 | exit(1); |
| 117 | } |
| 118 | fseek(file, 0L, SEEK_END); |
| 119 | size_t file_size = ftell(file); |
| 120 | wasm_byte_vec_new_uninitialized(&wat, file_size); |
| 121 | fseek(file, 0L, SEEK_SET); |
| 122 | if (fread(wat.data, file_size, 1, file) != 1) { |
| 123 | printf("> Error loading module!\n"); |
| 124 | exit(1); |
| 125 | } |
| 126 | fclose(file); |
| 127 | |
| 128 | // Parse the wat into the binary wasm format |
| 129 | wasmtime_error_t *error = wasmtime_wat2wasm(wat.data, wat.size, bytes); |
| 130 | if (error != NULL) |
| 131 | exit_with_error("failed to parse wat", error, NULL); |
| 132 | wasm_byte_vec_delete(&wat); |
| 133 | } |
| 134 | |
| 135 | static void exit_with_error(const char *message, wasmtime_error_t *error, |
| 136 | wasm_trap_t *trap) { |
no test coverage detected