| 46 | wasm_trap_t *trap); |
| 47 | |
| 48 | int main() { |
| 49 | // Configuring engine to support generating of DWARF info. |
| 50 | // lldb can be used to attach to the program and observe |
| 51 | // original fib-wasm.c source code and variables. |
| 52 | wasm_config_t *config = wasm_config_new(); |
| 53 | wasmtime_config_debug_info_set(config, true); |
| 54 | wasmtime_config_cranelift_opt_level_set(config, WASMTIME_OPT_LEVEL_NONE); |
| 55 | |
| 56 | // Initialize. |
| 57 | printf("Initializing...\n"); |
| 58 | wasm_engine_t *engine = wasm_engine_new_with_config(config); |
| 59 | wasmtime_store_t *store = wasmtime_store_new(engine, NULL, NULL); |
| 60 | wasmtime_context_t *context = wasmtime_store_context(store); |
| 61 | |
| 62 | #ifdef WASMTIME_TEST_ONLY |
| 63 | // NOTE: This validation is for wasmtime testing and should not be included in |
| 64 | // your code. |
| 65 | if (__jit_debug_descriptor.first_entry != NULL) { |
| 66 | fprintf(stderr, "FAIL: JIT descriptor is already initialized\n"); |
| 67 | return 1; |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | // Load binary. |
| 72 | printf("Loading binary...\n"); |
| 73 | FILE *file = fopen("target/wasm32-unknown-unknown/debug/fib.wasm", "rb"); |
| 74 | if (!file) { |
| 75 | printf("> Error opening module!\n"); |
| 76 | return 1; |
| 77 | } |
| 78 | fseek(file, 0L, SEEK_END); |
| 79 | size_t file_size = ftell(file); |
| 80 | fseek(file, 0L, SEEK_SET); |
| 81 | wasm_byte_vec_t binary; |
| 82 | wasm_byte_vec_new_uninitialized(&binary, file_size); |
| 83 | if (fread(binary.data, file_size, 1, file) != 1) { |
| 84 | printf("> Error reading module!\n"); |
| 85 | return 1; |
| 86 | } |
| 87 | fclose(file); |
| 88 | |
| 89 | // Compile. |
| 90 | printf("Compiling module...\n"); |
| 91 | wasmtime_module_t *module = NULL; |
| 92 | wasmtime_error_t *error = |
| 93 | wasmtime_module_new(engine, (uint8_t *)binary.data, binary.size, &module); |
| 94 | if (!module) |
| 95 | exit_with_error("failed to compile module", error, NULL); |
| 96 | wasm_byte_vec_delete(&binary); |
| 97 | |
| 98 | // Instantiate. |
| 99 | printf("Instantiating module...\n"); |
| 100 | wasmtime_instance_t instance; |
| 101 | wasm_trap_t *trap = NULL; |
| 102 | error = wasmtime_instance_new(context, module, NULL, 0, &instance, &trap); |
| 103 | if (error != NULL || trap != NULL) |
| 104 | exit_with_error("failed to instantiate", error, trap); |
| 105 | wasmtime_module_delete(module); |
nothing calls this directly
no test coverage detected