aot.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /**
  18. * A segment of memory init data
  19. */
  20. typedef struct AOTMemInitData {
  21. /* Start address of init data */
  22. AOTInitExpr offset;
  23. /* Byte count */
  24. uint32 byte_count;
  25. /* Byte array */
  26. uint8 bytes[1];
  27. } AOTMemInitData;
  28. /**
  29. * A segment of table init data
  30. */
  31. typedef struct AOTTableInitData {
  32. /* Start address of init data */
  33. AOTInitExpr offset;
  34. /* Function index count */
  35. uint32 func_index_count;
  36. /* Function index array */
  37. uint32 func_indexes[1];
  38. } AOTTableInitData;
  39. /**
  40. * Import global variable
  41. */
  42. typedef struct AOTImportGlobal {
  43. char *module_name;
  44. char *global_name;
  45. /* VALUE_TYPE_I32/I64/F32/F64 */
  46. uint8 type;
  47. bool is_mutable;
  48. uint32 size;
  49. /* The data offset of current global in global data */
  50. uint32 data_offset;
  51. /* global data after linked */
  52. WASMValue global_data_linked;
  53. } AOTImportGlobal;
  54. /**
  55. * Global variable
  56. */
  57. typedef struct AOTGlobal {
  58. /* VALUE_TYPE_I32/I64/F32/F64 */
  59. uint8 type;
  60. bool is_mutable;
  61. uint32 size;
  62. /* The data offset of current global in global data */
  63. uint32 data_offset;
  64. AOTInitExpr init_expr;
  65. } AOTGlobal;
  66. /**
  67. * Import function
  68. */
  69. typedef struct AOTImportFunc {
  70. char *module_name;
  71. char *func_name;
  72. AOTFuncType *func_type;
  73. uint32 func_type_index;
  74. /* function pointer after linked */
  75. void *func_ptr_linked;
  76. } AOTImportFunc;
  77. /**
  78. * Function
  79. */
  80. typedef struct AOTFunc {
  81. AOTFuncType *func_type;
  82. uint32 func_type_index;
  83. uint32 local_count;
  84. uint8 *local_types;
  85. uint32 code_size;
  86. uint8 *code;
  87. } AOTFunc;
  88. /**
  89. * Export function
  90. */
  91. typedef struct AOTExportFunc {
  92. char *func_name;
  93. AOTFuncType *func_type;
  94. /* function pointer linked */
  95. void *func_ptr;
  96. uint32 func_index;
  97. } AOTExportFunc;
  98. typedef struct AOTCompData {
  99. /* Memory and memory init data info */
  100. uint32 num_bytes_per_page;
  101. uint32 mem_init_page_count;
  102. uint32 mem_max_page_count;
  103. uint32 mem_init_data_count;
  104. AOTMemInitData **mem_init_data_list;
  105. /* Table and table init data info */
  106. uint32 table_size;
  107. AOTTableInitData **table_init_data_list;
  108. uint32 table_init_data_count;
  109. AOTImportGlobal *import_globals;
  110. uint32 import_global_count;
  111. AOTGlobal *globals;
  112. uint32 global_count;
  113. AOTFuncType **func_types;
  114. uint32 func_type_count;
  115. AOTImportFunc *import_funcs;
  116. uint32 import_func_count;
  117. AOTFunc **funcs;
  118. uint32 func_count;
  119. AOTExportFunc *export_funcs;
  120. uint32 export_func_count;
  121. uint32 start_func_index;
  122. uint32 addr_data_size;
  123. uint32 global_data_size;
  124. uint32 llvm_aux_data_end;
  125. uint32 llvm_aux_stack_bottom;
  126. uint32 llvm_aux_stack_size;
  127. uint32 llvm_aux_stack_global_index;
  128. WASMModule *wasm_module;
  129. } AOTCompData;
  130. AOTCompData*
  131. aot_create_comp_data(WASMModule *module);
  132. void
  133. aot_destroy_comp_data(AOTCompData *comp_data);
  134. char*
  135. aot_get_last_error();
  136. void
  137. aot_set_last_error(const char *error);
  138. #ifdef __cplusplus
  139. } /* end of extern "C" */
  140. #endif
  141. #endif /* end of _AOT_H_ */