wasm_c_api_internal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_C_API_INTERNAL_H
  6. #define _WASM_C_API_INTERNAL_H
  7. #include "wasm_c_api.h"
  8. #include "wasm_runtime_common.h"
  9. #ifndef own
  10. #define own
  11. #endif
  12. /* Vectors */
  13. /* we will malloc resource for the vector's data field */
  14. /* we will release resource of data */
  15. /* caller needs to take care resource for the vector itself */
  16. #define DEFAULT_VECTOR_INIT_LENGTH (64)
  17. WASM_DECLARE_VEC(store, *)
  18. WASM_DECLARE_VEC(module, *)
  19. WASM_DECLARE_VEC(instance, *)
  20. /* Runtime Environment */
  21. typedef enum runtime_mode_e {
  22. INTERP_MODE = 0,
  23. JIT_MODE,
  24. AOT_MODE
  25. } runtime_mode_e;
  26. struct wasm_engine_t {
  27. /* support one store for now */
  28. wasm_store_vec_t *stores;
  29. /* Interpreter by deault */
  30. runtime_mode_e mode;
  31. };
  32. struct wasm_store_t {
  33. wasm_module_vec_t *modules;
  34. wasm_instance_vec_t *instances;
  35. };
  36. /* Type Representations */
  37. struct wasm_valtype_t {
  38. wasm_valkind_t kind;
  39. };
  40. struct wasm_functype_t {
  41. uint32 extern_kind;
  42. /* gona to new and delete own */
  43. wasm_valtype_vec_t *params;
  44. wasm_valtype_vec_t *results;
  45. };
  46. struct wasm_globaltype_t {
  47. uint32 extern_kind;
  48. /* gona to new and delete own */
  49. wasm_valtype_t *val_type;
  50. wasm_mutability_t mutability;
  51. };
  52. struct wasm_tabletype_t {
  53. uint32 extern_kind;
  54. /* always be WASM_FUNCREF */
  55. wasm_valtype_t *type;
  56. wasm_limits_t *limits;
  57. };
  58. struct wasm_memorytype_t {
  59. uint32 extern_kind;
  60. wasm_limits_t *limits;
  61. };
  62. struct wasm_externtype_t {
  63. uint32 extern_kind;
  64. uint8 data[1];
  65. };
  66. struct wasm_import_type_t {
  67. uint32 extern_kind;
  68. wasm_name_t *module_name;
  69. wasm_name_t *name;
  70. };
  71. struct wasm_export_type_t {
  72. uint32 extern_kind;
  73. wasm_name_t *module_name;
  74. wasm_name_t *name;
  75. };
  76. /* Runtime Objects */
  77. struct wasm_ref_t {
  78. uint32 obj;
  79. };
  80. struct wasm_trap_t {
  81. wasm_byte_vec_t *message;
  82. };
  83. struct wasm_func_t {
  84. wasm_name_t *module_name;
  85. wasm_name_t *name;
  86. uint16 kind;
  87. wasm_functype_t *func_type;
  88. bool with_env;
  89. union {
  90. wasm_func_callback_t cb;
  91. struct callback_ext {
  92. void *env;
  93. wasm_func_callback_with_env_t cb;
  94. void (*finalizer)(void *);
  95. } cb_env;
  96. } u;
  97. /*
  98. * an index in both functions runtime instance lists
  99. * of interpreter mode and aot mode
  100. */
  101. uint16 func_idx_rt;
  102. WASMModuleInstanceCommon *inst_comm_rt;
  103. };
  104. struct wasm_global_t {
  105. wasm_name_t *module_name;
  106. wasm_name_t *name;
  107. uint16 kind;
  108. wasm_globaltype_t *type;
  109. wasm_val_t *init;
  110. /*
  111. * an index in both global runtime instance lists
  112. * of interpreter mode and aot mode
  113. */
  114. uint16 global_idx_rt;
  115. WASMModuleInstanceCommon *inst_comm_rt;
  116. };
  117. struct wasm_memory_t {
  118. wasm_name_t *module_name;
  119. wasm_name_t *name;
  120. uint16 kind;
  121. wasm_memorytype_t *type;
  122. /*
  123. * an index in both memory runtime instance lists
  124. * of interpreter mode and aot mode
  125. */
  126. uint16 memory_idx_rt;
  127. WASMModuleInstanceCommon *inst_comm_rt;
  128. };
  129. struct wasm_table_t {
  130. wasm_name_t *module_name;
  131. wasm_name_t *name;
  132. uint16 kind;
  133. wasm_tabletype_t *type;
  134. /*
  135. * an index in both table runtime instance lists
  136. * of interpreter mode and aot mode
  137. */
  138. uint16 table_idx_rt;
  139. WASMModuleInstanceCommon *inst_comm_rt;
  140. };
  141. struct wasm_extern_t {
  142. wasm_name_t *module_name;
  143. wasm_name_t *name;
  144. uint16 kind;
  145. uint8 data[1];
  146. };
  147. struct wasm_instance_t {
  148. wasm_extern_vec_t *imports;
  149. wasm_extern_vec_t *exports;
  150. WASMModuleInstanceCommon *inst_comm_rt;
  151. };
  152. #endif /* _WASM_C_API_INTERNAL_H */