| 74 | |
| 75 | |
| 76 | int main(int argc, const char* argv[]) { |
| 77 | // Initialize. |
| 78 | printf("Initializing...\n"); |
| 79 | wasm_engine_t* engine = wasm_engine_new(); |
| 80 | wasm_store_t* store = wasm_store_new(engine); |
| 81 | |
| 82 | // Load binary. |
| 83 | printf("Loading binary...\n"); |
| 84 | FILE* file = fopen("table.wasm", "rb"); |
| 85 | if (!file) { |
| 86 | printf("> Error loading module!\n"); |
| 87 | return 1; |
| 88 | } |
| 89 | fseek(file, 0L, SEEK_END); |
| 90 | size_t file_size = ftell(file); |
| 91 | fseek(file, 0L, SEEK_SET); |
| 92 | wasm_byte_vec_t binary; |
| 93 | wasm_byte_vec_new_uninitialized(&binary, file_size); |
| 94 | if (fread(binary.data, file_size, 1, file) != 1) { |
| 95 | printf("> Error loading module!\n"); |
| 96 | return 1; |
| 97 | } |
| 98 | fclose(file); |
| 99 | |
| 100 | // Compile. |
| 101 | printf("Compiling module...\n"); |
| 102 | own wasm_module_t* module = wasm_module_new(store, &binary); |
| 103 | if (!module) { |
| 104 | printf("> Error compiling module!\n"); |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | wasm_byte_vec_delete(&binary); |
| 109 | |
| 110 | // Instantiate. |
| 111 | printf("Instantiating module...\n"); |
| 112 | wasm_extern_vec_t imports = WASM_EMPTY_VEC; |
| 113 | own wasm_instance_t* instance = |
| 114 | wasm_instance_new(store, module, &imports, NULL); |
| 115 | if (!instance) { |
| 116 | printf("> Error instantiating module!\n"); |
| 117 | return 1; |
| 118 | } |
| 119 | |
| 120 | // Extract export. |
| 121 | printf("Extracting exports...\n"); |
| 122 | own wasm_extern_vec_t exports; |
| 123 | wasm_instance_exports(instance, &exports); |
| 124 | size_t i = 0; |
| 125 | wasm_table_t* table = get_export_table(&exports, i++); |
| 126 | wasm_func_t* call_indirect = get_export_func(&exports, i++); |
| 127 | wasm_func_t* f = get_export_func(&exports, i++); |
| 128 | wasm_func_t* g = get_export_func(&exports, i++); |
| 129 | |
| 130 | wasm_module_delete(module); |
| 131 | |
| 132 | // Create external function. |
| 133 | printf("Creating callback...\n"); |
nothing calls this directly
no test coverage detected