wasm_interp.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_INTERP_H
  6. #define _WASM_INTERP_H
  7. #include "wasm.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct WASMModuleInstance;
  12. struct WASMFunctionInstance;
  13. struct WASMExecEnv;
  14. typedef struct WASMInterpFrame {
  15. /* The frame of the caller that are calling the current function. */
  16. struct WASMInterpFrame *prev_frame;
  17. /* The current WASM function. */
  18. struct WASMFunctionInstance *function;
  19. /* Instruction pointer of the bytecode array. */
  20. uint8 *ip;
  21. /* Operand stack top pointer of the current frame. The bottom of
  22. the stack is the next cell after the last local variable. */
  23. uint32 *sp_bottom;
  24. uint32 *sp_boundary;
  25. uint32 *sp;
  26. WASMBranchBlock *csp_bottom;
  27. WASMBranchBlock *csp_boundary;
  28. WASMBranchBlock *csp;
  29. /* Frame data, the layout is:
  30. lp: param_cell_count + local_cell_count
  31. sp_bottom to sp_boundary: stack of data
  32. csp_bottom to csp_boundary: stack of block
  33. ref to frame end: data types of local vairables and stack data
  34. */
  35. uint32 lp[1];
  36. } WASMInterpFrame;
  37. /**
  38. * Calculate the size of interpreter area of frame of a function.
  39. *
  40. * @param all_cell_num number of all cells including local variables
  41. * and the working stack slots
  42. *
  43. * @return the size of interpreter area of the frame
  44. */
  45. static inline unsigned
  46. wasm_interp_interp_frame_size(unsigned all_cell_num)
  47. {
  48. return align_uint((uint32)offsetof(WASMInterpFrame, lp)
  49. + all_cell_num * 5, 4);
  50. }
  51. void
  52. wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
  53. struct WASMExecEnv *exec_env,
  54. struct WASMFunctionInstance *function,
  55. uint32 argc, uint32 argv[]);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* end of _WASM_INTERP_H */