wasm_interp.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_JIT != 0
  22. uint8 *jitted_return_addr;
  23. #endif
  24. #if WASM_ENABLE_PERF_PROFILING != 0
  25. uint64 time_started;
  26. #endif
  27. #if WASM_ENABLE_EXCE_HANDLING != 0
  28. /* set to true if the callee returns an exception rather than
  29. * result values on the stack
  30. */
  31. bool exception_raised;
  32. uint32 tag_index;
  33. #endif
  34. #if WASM_ENABLE_FAST_INTERP != 0
  35. /* Return offset of the first return value of current frame,
  36. the callee will put return values here continuously */
  37. uint32 ret_offset;
  38. uint32 *lp;
  39. uint32 operand[1];
  40. #else
  41. /* Operand stack top pointer of the current frame. The bottom of
  42. the stack is the next cell after the last local variable. */
  43. uint32 *sp_bottom;
  44. uint32 *sp_boundary;
  45. uint32 *sp;
  46. WASMBranchBlock *csp_bottom;
  47. WASMBranchBlock *csp_boundary;
  48. WASMBranchBlock *csp;
  49. /**
  50. * Frame data, the layout is:
  51. * lp: parameters and local variables
  52. * sp_bottom to sp_boundary: wasm operand stack
  53. * csp_bottom to csp_boundary: wasm label stack
  54. * jit spill cache: only available for fast jit
  55. */
  56. uint32 lp[1];
  57. #endif
  58. } WASMInterpFrame;
  59. /**
  60. * Calculate the size of interpreter area of frame of a function.
  61. *
  62. * @param all_cell_num number of all cells including local variables
  63. * and the working stack slots
  64. *
  65. * @return the size of interpreter area of the frame
  66. */
  67. static inline unsigned
  68. wasm_interp_interp_frame_size(unsigned all_cell_num)
  69. {
  70. unsigned frame_size;
  71. #if WASM_ENABLE_FAST_INTERP == 0
  72. frame_size = (uint32)offsetof(WASMInterpFrame, lp) + all_cell_num * 4;
  73. #else
  74. frame_size = (uint32)offsetof(WASMInterpFrame, operand) + all_cell_num * 4;
  75. #endif
  76. return align_uint(frame_size, 4);
  77. }
  78. void
  79. wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
  80. struct WASMExecEnv *exec_env,
  81. struct WASMFunctionInstance *function, uint32 argc,
  82. uint32 argv[]);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* end of _WASM_INTERP_H */