wasm_loader.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_LOADER_H
  6. #define _WASM_LOADER_H
  7. #include "wasm.h"
  8. #include "bh_hashmap.h"
  9. #include "../common/wasm_runtime_common.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * Load a WASM module from a specified byte buffer.
  15. *
  16. * @param buf the byte buffer which contains the WASM binary data
  17. * @param size the size of the buffer
  18. * @param error_buf output of the exception info
  19. * @param error_buf_size the size of the exception string
  20. *
  21. * @return return module loaded, NULL if failed
  22. */
  23. WASMModule *
  24. wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf,
  25. uint32 error_buf_size);
  26. /**
  27. * Load a WASM module from a specified WASM section list.
  28. *
  29. * @param section_list the section list which contains each section data
  30. * @param error_buf output of the exception info
  31. * @param error_buf_size the size of the exception string
  32. *
  33. * @return return WASM module loaded, NULL if failed
  34. */
  35. WASMModule *
  36. wasm_loader_load_from_sections(WASMSection *section_list, char *error_buf,
  37. uint32 error_buf_size);
  38. /**
  39. * Unload a WASM module.
  40. *
  41. * @param module the module to be unloaded
  42. */
  43. void
  44. wasm_loader_unload(WASMModule *module);
  45. /**
  46. * Find address of related else opcode and end opcode of opcode block/loop/if
  47. * according to the start address of opcode.
  48. *
  49. * @param module the module to find
  50. * @param start_addr the next address of opcode block/loop/if
  51. * @param code_end_addr the end address of function code block
  52. * @param block_type the type of block, 0/1/2 denotes block/loop/if
  53. * @param p_else_addr returns the else addr if found
  54. * @param p_end_addr returns the end addr if found
  55. * @param error_buf returns the error log for this function
  56. * @param error_buf_size returns the error log string length
  57. *
  58. * @return true if success, false otherwise
  59. */
  60. bool
  61. wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
  62. const uint8 *start_addr, const uint8 *code_end_addr,
  63. uint8 block_type, uint8 **p_else_addr,
  64. uint8 **p_end_addr);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif /* end of _WASM_LOADER_H */