wasm_interp.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #if WASM_ENABLE_GC != 0
  40. uint8 *frame_ref;
  41. #endif
  42. uint32 operand[1];
  43. #else /* else of WASM_ENABLE_FAST_INTERP != 0 */
  44. /* Operand stack top pointer of the current frame. The bottom of
  45. the stack is the next cell after the last local variable. */
  46. uint32 *sp_bottom;
  47. uint32 *sp_boundary;
  48. uint32 *sp;
  49. WASMBranchBlock *csp_bottom;
  50. WASMBranchBlock *csp_boundary;
  51. WASMBranchBlock *csp;
  52. /**
  53. * Frame data, the layout is:
  54. * lp: parameters and local variables
  55. * sp_bottom to sp_boundary: wasm operand stack
  56. * csp_bottom to csp_boundary: wasm label stack
  57. * frame ref flags: only available for GC
  58. * whether each cell in local and stack area is a GC obj
  59. * jit spill cache: only available for fast jit
  60. */
  61. uint32 lp[1];
  62. #endif /* end of WASM_ENABLE_FAST_INTERP != 0 */
  63. } WASMInterpFrame;
  64. /**
  65. * Calculate the size of interpreter area of frame of a function.
  66. *
  67. * @param all_cell_num number of all cells including local variables
  68. * and the working stack slots
  69. *
  70. * @return the size of interpreter area of the frame
  71. */
  72. static inline unsigned
  73. wasm_interp_interp_frame_size(unsigned all_cell_num)
  74. {
  75. unsigned frame_size;
  76. #if WASM_ENABLE_FAST_INTERP == 0
  77. #if WASM_ENABLE_GC == 0
  78. frame_size = (uint32)offsetof(WASMInterpFrame, lp) + all_cell_num * 4;
  79. #else
  80. frame_size =
  81. (uint32)offsetof(WASMInterpFrame, lp) + align_uint(all_cell_num * 5, 4);
  82. #endif
  83. #else
  84. frame_size = (uint32)offsetof(WASMInterpFrame, operand) + all_cell_num * 4;
  85. #endif
  86. return align_uint(frame_size, 4);
  87. }
  88. void
  89. wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
  90. struct WASMExecEnv *exec_env,
  91. struct WASMFunctionInstance *function, uint32 argc,
  92. uint32 argv[]);
  93. #if WASM_ENABLE_GC != 0
  94. bool
  95. wasm_interp_traverse_gc_rootset(struct WASMExecEnv *exec_env, void *heap);
  96. uint8 *
  97. wasm_interp_get_frame_ref(WASMInterpFrame *frame);
  98. #endif
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif /* end of _WASM_INTERP_H */