wasm_c_api_internal.h 3.7 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. struct wasm_engine_t {
  22. /* support one store for now */
  23. wasm_store_vec_t *stores;
  24. };
  25. struct wasm_store_t {
  26. wasm_module_vec_t *modules;
  27. wasm_instance_vec_t *instances;
  28. };
  29. /* Type Representations */
  30. struct wasm_valtype_t {
  31. wasm_valkind_t kind;
  32. };
  33. struct wasm_functype_t {
  34. uint32 extern_kind;
  35. /* gona to new and delete own */
  36. wasm_valtype_vec_t *params;
  37. wasm_valtype_vec_t *results;
  38. };
  39. struct wasm_globaltype_t {
  40. uint32 extern_kind;
  41. /* gona to new and delete own */
  42. wasm_valtype_t *val_type;
  43. wasm_mutability_t mutability;
  44. };
  45. struct wasm_tabletype_t {
  46. uint32 extern_kind;
  47. /* always be WASM_FUNCREF */
  48. wasm_valtype_t *val_type;
  49. wasm_limits_t limits;
  50. };
  51. struct wasm_memorytype_t {
  52. uint32 extern_kind;
  53. wasm_limits_t limits;
  54. };
  55. struct wasm_externtype_t {
  56. uint32 extern_kind;
  57. uint8 data[1];
  58. };
  59. struct wasm_importtype_t {
  60. wasm_name_t *module_name;
  61. wasm_name_t *name;
  62. wasm_externtype_t *extern_type;
  63. };
  64. struct wasm_exporttype_t {
  65. wasm_name_t *name;
  66. wasm_externtype_t *extern_type;
  67. };
  68. /* Runtime Objects */
  69. struct wasm_ref_t {
  70. uint32 obj;
  71. };
  72. struct wasm_frame_t {
  73. wasm_instance_t *instance;
  74. uint32 module_offset;
  75. uint32 func_index;
  76. uint32 func_offset;
  77. };
  78. struct wasm_trap_t {
  79. wasm_byte_vec_t *message;
  80. Vector *frames;
  81. };
  82. struct wasm_func_t {
  83. wasm_name_t *module_name;
  84. wasm_name_t *name;
  85. uint16 kind;
  86. wasm_functype_t *type;
  87. bool with_env;
  88. union {
  89. wasm_func_callback_t cb;
  90. struct callback_ext {
  91. void *env;
  92. wasm_func_callback_with_env_t cb;
  93. void (*finalizer)(void *);
  94. } cb_env;
  95. } u;
  96. /*
  97. * an index in both functions runtime instance lists
  98. * of interpreter mode and aot mode
  99. */
  100. uint16 func_idx_rt;
  101. WASMModuleInstanceCommon *inst_comm_rt;
  102. WASMFunctionInstanceCommon *func_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. wasm_externkind_t 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 */