wasm_interp.h 2.3 KB

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