wasm_c_api_internal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_trap_t {
  73. wasm_byte_vec_t *message;
  74. Vector *frames;
  75. };
  76. struct wasm_func_t {
  77. wasm_name_t *module_name;
  78. wasm_name_t *name;
  79. uint16 kind;
  80. wasm_functype_t *type;
  81. bool with_env;
  82. union {
  83. wasm_func_callback_t cb;
  84. struct callback_ext {
  85. void *env;
  86. wasm_func_callback_with_env_t cb;
  87. void (*finalizer)(void *);
  88. } cb_env;
  89. } u;
  90. /*
  91. * an index in both functions runtime instance lists
  92. * of interpreter mode and aot mode
  93. */
  94. uint16 func_idx_rt;
  95. WASMModuleInstanceCommon *inst_comm_rt;
  96. WASMFunctionInstanceCommon *func_comm_rt;
  97. };
  98. struct wasm_global_t {
  99. wasm_name_t *module_name;
  100. wasm_name_t *name;
  101. uint16 kind;
  102. wasm_globaltype_t *type;
  103. wasm_val_t *init;
  104. /*
  105. * an index in both global runtime instance lists
  106. * of interpreter mode and aot mode
  107. */
  108. uint16 global_idx_rt;
  109. WASMModuleInstanceCommon *inst_comm_rt;
  110. };
  111. struct wasm_memory_t {
  112. wasm_name_t *module_name;
  113. wasm_name_t *name;
  114. uint16 kind;
  115. wasm_memorytype_t *type;
  116. /*
  117. * an index in both memory runtime instance lists
  118. * of interpreter mode and aot mode
  119. */
  120. uint16 memory_idx_rt;
  121. WASMModuleInstanceCommon *inst_comm_rt;
  122. };
  123. struct wasm_table_t {
  124. wasm_name_t *module_name;
  125. wasm_name_t *name;
  126. uint16 kind;
  127. wasm_tabletype_t *type;
  128. /*
  129. * an index in both table runtime instance lists
  130. * of interpreter mode and aot mode
  131. */
  132. uint16 table_idx_rt;
  133. WASMModuleInstanceCommon *inst_comm_rt;
  134. };
  135. struct wasm_extern_t {
  136. wasm_name_t *module_name;
  137. wasm_name_t *name;
  138. wasm_externkind_t kind;
  139. uint8 data[1];
  140. };
  141. struct wasm_instance_t {
  142. wasm_extern_vec_t *imports;
  143. wasm_extern_vec_t *exports;
  144. WASMModuleInstanceCommon *inst_comm_rt;
  145. };
  146. #endif /* _WASM_C_API_INTERNAL_H */