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