wasm_interp.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #if WASM_ENABLE_FAST_INTERP != 0
  22. /* return offset of the first return value of current frame.
  23. the callee will put return values here continuously */
  24. uint32 ret_offset;
  25. uint32 *lp;
  26. uint32 operand[1];
  27. #else
  28. /* Operand stack top pointer of the current frame. The bottom of
  29. the stack is the next cell after the last local variable. */
  30. uint32 *sp_bottom;
  31. uint32 *sp_boundary;
  32. uint32 *sp;
  33. WASMBranchBlock *csp_bottom;
  34. WASMBranchBlock *csp_boundary;
  35. WASMBranchBlock *csp;
  36. /* Frame data, the layout is:
  37. lp: param_cell_count + local_cell_count
  38. sp_bottom to sp_boundary: stack of data
  39. csp_bottom to csp_boundary: stack of block
  40. ref to frame end: data types of local vairables and stack data
  41. */
  42. uint32 lp[1];
  43. #endif
  44. } WASMInterpFrame;
  45. /**
  46. * Calculate the size of interpreter area of frame of a function.
  47. *
  48. * @param all_cell_num number of all cells including local variables
  49. * and the working stack slots
  50. *
  51. * @return the size of interpreter area of the frame
  52. */
  53. static inline unsigned
  54. wasm_interp_interp_frame_size(unsigned all_cell_num)
  55. {
  56. return align_uint((uint32)offsetof(WASMInterpFrame, lp)
  57. + all_cell_num * 5, 4);
  58. }
  59. void
  60. wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
  61. struct WASMExecEnv *exec_env,
  62. struct WASMFunctionInstance *function,
  63. uint32 argc, uint32 argv[]);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* end of _WASM_INTERP_H */