wasm_loader.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _WASM_LOADER_H
  17. #define _WASM_LOADER_H
  18. #include "wasm.h"
  19. #include "wasm_hashmap.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * Load a WASM module from a specified byte buffer.
  25. *
  26. * @param buf the byte buffer which contains the WASM binary data
  27. * @param size the size of the buffer
  28. * @param error_buf output of the exception info
  29. * @param error_buf_size the size of the exception string
  30. *
  31. * @return return module loaded, NULL if failed
  32. */
  33. WASMModule*
  34. wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size);
  35. /**
  36. * Load a WASM module from a specified WASM section list.
  37. *
  38. * @param section_list the section list which contains each section data
  39. * @param error_buf output of the exception info
  40. * @param error_buf_size the size of the exception string
  41. *
  42. * @return return WASM module loaded, NULL if failed
  43. */
  44. WASMModule*
  45. wasm_loader_load_from_sections(WASMSection *section_list,
  46. char *error_buf, uint32 error_buf_size);
  47. /**
  48. * Unload a WASM module.
  49. *
  50. * @param module the module to be unloaded
  51. */
  52. void
  53. wasm_loader_unload(WASMModule *module);
  54. /**
  55. * Find address of related else opcode and end opcode of opcode block/loop/if
  56. * according to the start address of opcode.
  57. *
  58. * @param module the module to find
  59. * @param start_addr the next address of opcode block/loop/if
  60. * @param code_end_addr the end address of function code block
  61. * @param block_type the type of block, 0/1/2 denotes block/loop/if
  62. * @param p_else_addr returns the else addr if found
  63. * @param p_end_addr returns the end addr if found
  64. * @param error_buf returns the error log for this function
  65. * @param error_buf_size returns the error log string length
  66. *
  67. * @return true if success, false otherwise
  68. */
  69. bool
  70. wasm_loader_find_block_addr(WASMModule *module,
  71. const uint8 *start_addr,
  72. const uint8 *code_end_addr,
  73. uint8 block_type,
  74. uint8 **p_else_addr,
  75. uint8 **p_end_addr,
  76. char *error_buf,
  77. uint32 error_buf_size);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* end of _WASM_LOADER_H */