wasm_interp.h 2.4 KB

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