wasm_c_api_internal.h 3.5 KB

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