| 20 | } |
| 21 | |
| 22 | void run_in_store(wasm::Store* store) { |
| 23 | // Load binary. |
| 24 | std::cout << "Loading binary..." << std::endl; |
| 25 | std::ifstream file("finalize.wasm"); |
| 26 | file.seekg(0, std::ios_base::end); |
| 27 | auto file_size = file.tellg(); |
| 28 | file.seekg(0); |
| 29 | auto binary = wasm::vec<byte_t>::make_uninitialized(file_size); |
| 30 | file.read(binary.get(), file_size); |
| 31 | file.close(); |
| 32 | if (file.fail()) { |
| 33 | std::cout << "> Error loading module!" << std::endl; |
| 34 | exit(1); |
| 35 | } |
| 36 | |
| 37 | // Compile. |
| 38 | std::cout << "Compiling module..." << std::endl; |
| 39 | auto module = wasm::Module::make(store, binary); |
| 40 | if (!module) { |
| 41 | std::cout << "> Error compiling module!" << std::endl; |
| 42 | exit(1); |
| 43 | } |
| 44 | |
| 45 | // Instantiate. |
| 46 | std::cout << "Instantiating modules..." << std::endl; |
| 47 | for (int i = 0; i <= iterations; ++i) { |
| 48 | if (i % (iterations / 10) == 0) std::cout << i << std::endl; |
| 49 | auto imports = wasm::vec<wasm::Extern*>::make(); |
| 50 | auto instance = wasm::Instance::make(store, module.get(), imports); |
| 51 | if (!instance) { |
| 52 | std::cout << "> Error instantiating module " << i << "!" << std::endl; |
| 53 | exit(1); |
| 54 | } |
| 55 | instance->set_host_info(reinterpret_cast<void*>(i), &finalize); |
| 56 | ++live_count; |
| 57 | } |
| 58 | |
| 59 | // Shut down. |
| 60 | std::cout << "Shutting down..." << std::endl; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | void run() { |
no test coverage detected