Advertisement
Guest User

Untitled

a guest
May 7th, 2020
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1.  
  2. bool Assembly_Instance::Instantiate()
  3. {
  4. // Bind native callback functions to resolve expected external functions in input assembly.
  5.  
  6.  
  7. // Create types required by our binding functions
  8. wasm_valtype_t* val_i32 = wasm_valtype_new(WASM_I32);
  9.  
  10. // Create binding function signatures
  11.  
  12. // Function: Create ...
  13. wasm_functype_t *create_native_type = wasm_functype_new_1_1(val_i32, val_i32);
  14.  
  15.  
  16. wasm_func_t *create_native_func = wasm_func_new_with_env(m_store, create_native_type, create_native_callback, this, nullptr);
  17. wasm_functype_delete(create_native_type);
  18.  
  19. // Function: Release ...
  20. wasm_functype_t *release_native_type = wasm_functype_new_2_1(val_i32, val_i32, val_i32);
  21. wasm_func_t *release_native_func = wasm_func_new_with_env(m_store, release_native_type, release_native_callback, this, nullptr);
  22.  
  23. // Function: Native OP
  24. wasm_functype_t *native_op_type = wasm_functype_new_4_1(val_i32, val_i32, val_i32, val_i32, val_i32);
  25. wasm_func_t *native_op_func = wasm_func_new_with_env(m_store, native_op_type, native_op_callback, this, nullptr);
  26.  
  27. // Clean up.
  28. wasm_functype_delete(release_native_type);
  29.  
  30.  
  31. // Instantiate.
  32. Logf("Instantiating module...\n");
  33. const wasm_extern_t* imports[INF_WASM_IMPORTS_REQUIRED];
  34.  
  35. imports[m_create_native_import_location] = wasm_func_as_extern(create_native_func);
  36. imports[m_release_native_import_location] = wasm_func_as_extern(release_native_func);
  37. imports[m_native_op_import_location] = wasm_func_as_extern(native_op_func);
  38.  
  39.  
  40. wasm_valtype_delete(val_i32);
  41.  
  42.  
  43.  
  44. wasm_trap_t *err = nullptr;
  45. m_instance = wasm_instance_new(m_store, m_module, imports, &err);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement