| 18 | } |
| 19 | |
| 20 | void run_in_store(wasm_store_t* store) { |
| 21 | // Load binary. |
| 22 | printf("Loading binary...\n"); |
| 23 | FILE* file = fopen("finalize.wasm", "rb"); |
| 24 | if (!file) { |
| 25 | printf("> Error loading module!\n"); |
| 26 | exit(1); |
| 27 | } |
| 28 | fseek(file, 0L, SEEK_END); |
| 29 | size_t file_size = ftell(file); |
| 30 | fseek(file, 0L, SEEK_SET); |
| 31 | wasm_byte_vec_t binary; |
| 32 | wasm_byte_vec_new_uninitialized(&binary, file_size); |
| 33 | if (fread(binary.data, file_size, 1, file) != 1) { |
| 34 | printf("> Error loading module!\n"); |
| 35 | exit(1); |
| 36 | } |
| 37 | fclose(file); |
| 38 | |
| 39 | // Compile. |
| 40 | printf("Compiling module...\n"); |
| 41 | own wasm_module_t* module = wasm_module_new(store, &binary); |
| 42 | if (!module) { |
| 43 | printf("> Error compiling module!\n"); |
| 44 | exit(1); |
| 45 | } |
| 46 | |
| 47 | wasm_byte_vec_delete(&binary); |
| 48 | |
| 49 | // Instantiate. |
| 50 | printf("Instantiating modules...\n"); |
| 51 | for (int i = 0; i <= iterations; ++i) { |
| 52 | if (i % (iterations / 10) == 0) printf("%d\n", i); |
| 53 | wasm_extern_vec_t imports = WASM_EMPTY_VEC; |
| 54 | own wasm_instance_t* instance = |
| 55 | wasm_instance_new(store, module, &imports, NULL); |
| 56 | if (!instance) { |
| 57 | printf("> Error instantiating module %d!\n", i); |
| 58 | exit(1); |
| 59 | } |
| 60 | void* data = (void*)(intptr_t)i; |
| 61 | wasm_instance_set_host_info_with_finalizer(instance, data, &finalize); |
| 62 | wasm_instance_delete(instance); |
| 63 | ++live_count; |
| 64 | } |
| 65 | |
| 66 | wasm_module_delete(module); |
| 67 | } |
| 68 | |
| 69 | int main(int argc, const char* argv[]) { |
| 70 | // Initialize. |
no test coverage detected