wasm_loader.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(uint8 *buf, uint32 size,
  25. #if WASM_ENABLE_MULTI_MODULE != 0
  26. bool main_module,
  27. #endif
  28. const LoadArgs *args, char *error_buf, uint32 error_buf_size);
  29. /**
  30. * Load a WASM module from a specified WASM section list.
  31. *
  32. * @param section_list the section list which contains each section data
  33. * @param error_buf output of the exception info
  34. * @param error_buf_size the size of the exception string
  35. *
  36. * @return return WASM module loaded, NULL if failed
  37. */
  38. WASMModule *
  39. wasm_loader_load_from_sections(WASMSection *section_list, char *error_buf,
  40. uint32 error_buf_size);
  41. /**
  42. * Unload a WASM module.
  43. *
  44. * @param module the module to be unloaded
  45. */
  46. void
  47. wasm_loader_unload(WASMModule *module);
  48. /**
  49. * Find address of related else opcode and end opcode of opcode block/loop/if
  50. * according to the start address of opcode.
  51. *
  52. * @param module the module to find
  53. * @param start_addr the next address of opcode block/loop/if
  54. * @param code_end_addr the end address of function code block
  55. * @param block_type the type of block, 0/1/2 denotes block/loop/if
  56. * @param p_else_addr returns the else addr if found
  57. * @param p_end_addr returns the end addr if found
  58. * @param error_buf returns the error log for this function
  59. * @param error_buf_size returns the error log string length
  60. *
  61. * @return true if success, false otherwise
  62. */
  63. bool
  64. wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
  65. const uint8 *start_addr, const uint8 *code_end_addr,
  66. uint8 block_type, uint8 **p_else_addr,
  67. uint8 **p_end_addr);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif /* end of _WASM_LOADER_H */