Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Assembly_Instance::Instantiate()
- {
- // Bind native callback functions to resolve expected external functions in input assembly.
- // Create types required by our binding functions
- wasm_valtype_t* val_i32 = wasm_valtype_new(WASM_I32);
- // Create binding function signatures
- // Function: Create ...
- wasm_functype_t *create_native_type = wasm_functype_new_1_1(val_i32, val_i32);
- wasm_func_t *create_native_func = wasm_func_new_with_env(m_store, create_native_type, create_native_callback, this, nullptr);
- wasm_functype_delete(create_native_type);
- // Function: Release ...
- wasm_functype_t *release_native_type = wasm_functype_new_2_1(val_i32, val_i32, val_i32);
- wasm_func_t *release_native_func = wasm_func_new_with_env(m_store, release_native_type, release_native_callback, this, nullptr);
- // Function: Native OP
- wasm_functype_t *native_op_type = wasm_functype_new_4_1(val_i32, val_i32, val_i32, val_i32, val_i32);
- wasm_func_t *native_op_func = wasm_func_new_with_env(m_store, native_op_type, native_op_callback, this, nullptr);
- // Clean up.
- wasm_functype_delete(release_native_type);
- // Instantiate.
- Logf("Instantiating module...\n");
- const wasm_extern_t* imports[INF_WASM_IMPORTS_REQUIRED];
- imports[m_create_native_import_location] = wasm_func_as_extern(create_native_func);
- imports[m_release_native_import_location] = wasm_func_as_extern(release_native_func);
- imports[m_native_op_import_location] = wasm_func_as_extern(native_op_func);
- wasm_valtype_delete(val_i32);
- wasm_trap_t *err = nullptr;
- m_instance = wasm_instance_new(m_store, m_module, imports, &err);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement