aot.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _AOT_H_
  6. #define _AOT_H_
  7. #include "bh_platform.h"
  8. #include "bh_assert.h"
  9. #include "../common/wasm_runtime_common.h"
  10. #include "../interpreter/wasm.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define AOT_FUNC_PREFIX "aot_func#"
  15. typedef InitializerExpression AOTInitExpr;
  16. typedef WASMType AOTFuncType;
  17. typedef WASMExport AOTExport;
  18. /**
  19. * Import memory
  20. */
  21. typedef struct AOTImportMemory {
  22. char *module_name;
  23. char *memory_name;
  24. uint32 memory_flags;
  25. uint32 num_bytes_per_page;
  26. uint32 mem_init_page_count;
  27. uint32 mem_max_page_count;
  28. } AOTImportMemory;
  29. /**
  30. * Memory information
  31. */
  32. typedef struct AOTMemory {
  33. /* memory info */
  34. uint32 memory_flags;
  35. uint32 num_bytes_per_page;
  36. uint32 mem_init_page_count;
  37. uint32 mem_max_page_count;
  38. } AOTMemory;
  39. /**
  40. * A segment of memory init data
  41. */
  42. typedef struct AOTMemInitData {
  43. #if WASM_ENABLE_BULK_MEMORY != 0
  44. /* Passive flag */
  45. bool is_passive;
  46. /* memory index */
  47. uint32 memory_index;
  48. #endif
  49. /* Start address of init data */
  50. AOTInitExpr offset;
  51. /* Byte count */
  52. uint32 byte_count;
  53. /* Byte array */
  54. uint8 bytes[1];
  55. } AOTMemInitData;
  56. /**
  57. * Import table
  58. */
  59. typedef struct AOTImportTable {
  60. char *module_name;
  61. char *table_name;
  62. uint32 table_flags;
  63. uint32 table_init_size;
  64. uint32 table_max_size;
  65. } AOTImportTable;
  66. /**
  67. * Table
  68. */
  69. typedef struct AOTTable {
  70. uint32 elem_type;
  71. uint32 table_flags;
  72. uint32 table_init_size;
  73. uint32 table_max_size;
  74. } AOTTable;
  75. /**
  76. * A segment of table init data
  77. */
  78. typedef struct AOTTableInitData {
  79. uint32 table_index;
  80. /* Start address of init data */
  81. AOTInitExpr offset;
  82. /* Function index count */
  83. uint32 func_index_count;
  84. /* Function index array */
  85. uint32 func_indexes[1];
  86. } AOTTableInitData;
  87. /**
  88. * Import global variable
  89. */
  90. typedef struct AOTImportGlobal {
  91. char *module_name;
  92. char *global_name;
  93. /* VALUE_TYPE_I32/I64/F32/F64 */
  94. uint8 type;
  95. bool is_mutable;
  96. uint32 size;
  97. /* The data offset of current global in global data */
  98. uint32 data_offset;
  99. /* global data after linked */
  100. WASMValue global_data_linked;
  101. } AOTImportGlobal;
  102. /**
  103. * Global variable
  104. */
  105. typedef struct AOTGlobal {
  106. /* VALUE_TYPE_I32/I64/F32/F64 */
  107. uint8 type;
  108. bool is_mutable;
  109. uint32 size;
  110. /* The data offset of current global in global data */
  111. uint32 data_offset;
  112. AOTInitExpr init_expr;
  113. } AOTGlobal;
  114. /**
  115. * Import function
  116. */
  117. typedef struct AOTImportFunc {
  118. char *module_name;
  119. char *func_name;
  120. AOTFuncType *func_type;
  121. uint32 func_type_index;
  122. /* function pointer after linked */
  123. void *func_ptr_linked;
  124. /* signature from registered native symbols */
  125. const char *signature;
  126. /* attachment */
  127. void *attachment;
  128. bool call_conv_raw;
  129. } AOTImportFunc;
  130. /**
  131. * Function
  132. */
  133. typedef struct AOTFunc {
  134. AOTFuncType *func_type;
  135. uint32 func_type_index;
  136. uint32 local_count;
  137. uint8 *local_types;
  138. uint16 param_cell_num;
  139. uint16 local_cell_num;
  140. uint32 code_size;
  141. uint8 *code;
  142. } AOTFunc;
  143. typedef struct AOTCompData {
  144. /* Import memories */
  145. uint32 import_memory_count;
  146. AOTImportMemory *import_memories;
  147. /* Memories */
  148. uint32 memory_count;
  149. AOTMemory *memories;
  150. /* Memory init data info */
  151. uint32 mem_init_data_count;
  152. AOTMemInitData **mem_init_data_list;
  153. /* Import tables */
  154. uint32 import_table_count;
  155. AOTImportTable *import_tables;
  156. /* Tables */
  157. uint32 table_count;
  158. AOTTable *tables;
  159. /* Table init data info */
  160. uint32 table_init_data_count;
  161. AOTTableInitData **table_init_data_list;
  162. /* Import globals */
  163. uint32 import_global_count;
  164. AOTImportGlobal *import_globals;
  165. /* Globals */
  166. uint32 global_count;
  167. AOTGlobal *globals;
  168. /* Function types */
  169. uint32 func_type_count;
  170. AOTFuncType **func_types;
  171. /* Import functions */
  172. uint32 import_func_count;
  173. AOTImportFunc *import_funcs;
  174. /* Functions */
  175. uint32 func_count;
  176. AOTFunc **funcs;
  177. uint32 start_func_index;
  178. uint32 addr_data_size;
  179. uint32 global_data_size;
  180. uint32 llvm_aux_data_end;
  181. uint32 llvm_aux_stack_bottom;
  182. uint32 llvm_aux_stack_size;
  183. uint32 llvm_aux_stack_global_index;
  184. WASMModule *wasm_module;
  185. } AOTCompData;
  186. AOTCompData*
  187. aot_create_comp_data(WASMModule *module);
  188. void
  189. aot_destroy_comp_data(AOTCompData *comp_data);
  190. char*
  191. aot_get_last_error();
  192. void
  193. aot_set_last_error(const char *error);
  194. #ifdef __cplusplus
  195. } /* end of extern "C" */
  196. #endif
  197. #endif /* end of _AOT_H_ */