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

Function read_wat_file

examples/linking.c:110–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110static 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
135static void exit_with_error(const char *message, wasmtime_error_t *error,
136 wasm_trap_t *trap) {

Callers 1

mainFunction · 0.85

Calls 2

wasmtime_wat2wasmFunction · 0.85
exit_with_errorFunction · 0.70

Tested by

no test coverage detected