wasm.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_H_
  6. #define _WASM_H_
  7. #include "bh_platform.h"
  8. #include "bh_hashmap.h"
  9. #include "bh_assert.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /** Value Type */
  14. #define VALUE_TYPE_I32 0x7F
  15. #define VALUE_TYPE_I64 0X7E
  16. #define VALUE_TYPE_F32 0x7D
  17. #define VALUE_TYPE_F64 0x7C
  18. #define VALUE_TYPE_V128 0x7B
  19. #define VALUE_TYPE_FUNCREF 0x70
  20. #define VALUE_TYPE_EXTERNREF 0x6F
  21. #define VALUE_TYPE_VOID 0x40
  22. /* Used by AOT */
  23. #define VALUE_TYPE_I1 0x41
  24. /* Used by loader to represent any type of i32/i64/f32/f64 */
  25. #define VALUE_TYPE_ANY 0x42
  26. #define DEFAULT_NUM_BYTES_PER_PAGE 65536
  27. #define DEFAULT_MAX_PAGES 65536
  28. #define NULL_REF (0xFFFFFFFF)
  29. #define TABLE_MAX_SIZE (1024)
  30. #define INIT_EXPR_TYPE_I32_CONST 0x41
  31. #define INIT_EXPR_TYPE_I64_CONST 0x42
  32. #define INIT_EXPR_TYPE_F32_CONST 0x43
  33. #define INIT_EXPR_TYPE_F64_CONST 0x44
  34. #define INIT_EXPR_TYPE_V128_CONST 0xFD
  35. /* = WASM_OP_REF_FUNC */
  36. #define INIT_EXPR_TYPE_FUNCREF_CONST 0xD2
  37. /* = WASM_OP_REF_NULL */
  38. #define INIT_EXPR_TYPE_REFNULL_CONST 0xD0
  39. #define INIT_EXPR_TYPE_GET_GLOBAL 0x23
  40. #define INIT_EXPR_TYPE_ERROR 0xff
  41. #define WASM_MAGIC_NUMBER 0x6d736100
  42. #define WASM_CURRENT_VERSION 1
  43. #define SECTION_TYPE_USER 0
  44. #define SECTION_TYPE_TYPE 1
  45. #define SECTION_TYPE_IMPORT 2
  46. #define SECTION_TYPE_FUNC 3
  47. #define SECTION_TYPE_TABLE 4
  48. #define SECTION_TYPE_MEMORY 5
  49. #define SECTION_TYPE_GLOBAL 6
  50. #define SECTION_TYPE_EXPORT 7
  51. #define SECTION_TYPE_START 8
  52. #define SECTION_TYPE_ELEM 9
  53. #define SECTION_TYPE_CODE 10
  54. #define SECTION_TYPE_DATA 11
  55. #if WASM_ENABLE_BULK_MEMORY != 0
  56. #define SECTION_TYPE_DATACOUNT 12
  57. #endif
  58. #define SUB_SECTION_TYPE_MODULE 0
  59. #define SUB_SECTION_TYPE_FUNC 1
  60. #define SUB_SECTION_TYPE_LOCAL 2
  61. #define IMPORT_KIND_FUNC 0
  62. #define IMPORT_KIND_TABLE 1
  63. #define IMPORT_KIND_MEMORY 2
  64. #define IMPORT_KIND_GLOBAL 3
  65. #define EXPORT_KIND_FUNC 0
  66. #define EXPORT_KIND_TABLE 1
  67. #define EXPORT_KIND_MEMORY 2
  68. #define EXPORT_KIND_GLOBAL 3
  69. #define LABEL_TYPE_BLOCK 0
  70. #define LABEL_TYPE_LOOP 1
  71. #define LABEL_TYPE_IF 2
  72. #define LABEL_TYPE_FUNCTION 3
  73. typedef struct WASMModule WASMModule;
  74. typedef struct WASMFunction WASMFunction;
  75. typedef struct WASMGlobal WASMGlobal;
  76. typedef union V128 {
  77. int8 i8x16[16];
  78. int16 i16x8[8];
  79. int32 i32x8[4];
  80. int64 i64x2[2];
  81. float32 f32x4[4];
  82. float64 f64x2[2];
  83. } V128;
  84. typedef union WASMValue {
  85. int32 i32;
  86. uint32 u32;
  87. uint32 global_index;
  88. uint32 ref_index;
  89. int64 i64;
  90. uint64 u64;
  91. float32 f32;
  92. float64 f64;
  93. uintptr_t addr;
  94. V128 v128;
  95. } WASMValue;
  96. typedef struct InitializerExpression {
  97. /* type of INIT_EXPR_TYPE_XXX */
  98. /* it actually is instr, in some places, requires constant only */
  99. uint8 init_expr_type;
  100. WASMValue u;
  101. } InitializerExpression;
  102. typedef struct WASMType {
  103. uint16 param_count;
  104. uint16 result_count;
  105. uint16 param_cell_num;
  106. uint16 ret_cell_num;
  107. uint16 ref_count;
  108. /* types of params and results */
  109. uint8 types[1];
  110. } WASMType;
  111. typedef struct WASMTable {
  112. uint8 elem_type;
  113. uint32 flags;
  114. uint32 init_size;
  115. /* specified if (flags & 1), else it is 0x10000 */
  116. uint32 max_size;
  117. bool possible_grow;
  118. } WASMTable;
  119. typedef struct WASMMemory {
  120. uint32 flags;
  121. uint32 num_bytes_per_page;
  122. uint32 init_page_count;
  123. uint32 max_page_count;
  124. } WASMMemory;
  125. typedef struct WASMTableImport {
  126. char *module_name;
  127. char *field_name;
  128. uint8 elem_type;
  129. uint32 flags;
  130. uint32 init_size;
  131. /* specified if (flags & 1), else it is 0x10000 */
  132. uint32 max_size;
  133. bool possible_grow;
  134. #if WASM_ENABLE_MULTI_MODULE != 0
  135. WASMModule *import_module;
  136. WASMTable *import_table_linked;
  137. #endif
  138. } WASMTableImport;
  139. typedef struct WASMMemoryImport {
  140. char *module_name;
  141. char *field_name;
  142. uint32 flags;
  143. uint32 num_bytes_per_page;
  144. uint32 init_page_count;
  145. uint32 max_page_count;
  146. #if WASM_ENABLE_MULTI_MODULE != 0
  147. WASMModule *import_module;
  148. WASMMemory *import_memory_linked;
  149. #endif
  150. } WASMMemoryImport;
  151. typedef struct WASMFunctionImport {
  152. char *module_name;
  153. char *field_name;
  154. /* function type */
  155. WASMType *func_type;
  156. /* native function pointer after linked */
  157. void *func_ptr_linked;
  158. /* signature from registered native symbols */
  159. const char *signature;
  160. /* attachment */
  161. void *attachment;
  162. bool call_conv_raw;
  163. #if WASM_ENABLE_MULTI_MODULE != 0
  164. WASMModule *import_module;
  165. WASMFunction *import_func_linked;
  166. #endif
  167. bool call_conv_wasm_c_api;
  168. bool wasm_c_api_with_env;
  169. } WASMFunctionImport;
  170. typedef struct WASMGlobalImport {
  171. char *module_name;
  172. char *field_name;
  173. uint8 type;
  174. bool is_mutable;
  175. /* global data after linked */
  176. WASMValue global_data_linked;
  177. bool is_linked;
  178. #if WASM_ENABLE_MULTI_MODULE != 0
  179. /* imported function pointer after linked */
  180. /* TODO: remove if not needed */
  181. WASMModule *import_module;
  182. WASMGlobal *import_global_linked;
  183. #endif
  184. #if WASM_ENABLE_FAST_JIT != 0
  185. /* The data offset of current global in global data */
  186. uint32 data_offset;
  187. #endif
  188. } WASMGlobalImport;
  189. typedef struct WASMImport {
  190. uint8 kind;
  191. union {
  192. WASMFunctionImport function;
  193. WASMTableImport table;
  194. WASMMemoryImport memory;
  195. WASMGlobalImport global;
  196. struct {
  197. char *module_name;
  198. char *field_name;
  199. } names;
  200. } u;
  201. } WASMImport;
  202. struct WASMFunction {
  203. #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
  204. char *field_name;
  205. #endif
  206. /* the type of function */
  207. WASMType *func_type;
  208. uint32 local_count;
  209. uint8 *local_types;
  210. /* cell num of parameters */
  211. uint16 param_cell_num;
  212. /* cell num of return type */
  213. uint16 ret_cell_num;
  214. /* cell num of local variables */
  215. uint16 local_cell_num;
  216. /* offset of each local, including function parameters
  217. and local variables */
  218. uint16 *local_offsets;
  219. uint32 max_stack_cell_num;
  220. uint32 max_block_num;
  221. /* Whether function has opcode memory.grow */
  222. bool has_op_memory_grow;
  223. /* Whether function has opcode call or
  224. call_indirect */
  225. bool has_op_func_call;
  226. uint32 code_size;
  227. uint8 *code;
  228. #if WASM_ENABLE_FAST_INTERP != 0
  229. uint32 code_compiled_size;
  230. uint8 *code_compiled;
  231. uint8 *consts;
  232. uint32 const_cell_num;
  233. #endif
  234. #if WASM_ENABLE_FAST_JIT != 0
  235. void *fast_jit_jitted_code;
  236. #endif
  237. #if WASM_ENABLE_JIT != 0
  238. void *llvm_jit_func_ptr;
  239. #endif
  240. };
  241. struct WASMGlobal {
  242. uint8 type;
  243. bool is_mutable;
  244. InitializerExpression init_expr;
  245. #if WASM_ENABLE_FAST_JIT != 0
  246. /* The data offset of current global in global data */
  247. uint32 data_offset;
  248. #endif
  249. };
  250. typedef struct WASMExport {
  251. char *name;
  252. uint8 kind;
  253. uint32 index;
  254. } WASMExport;
  255. typedef struct WASMTableSeg {
  256. /* 0 to 7 */
  257. uint32 mode;
  258. /* funcref or externref, elemkind will be considered as funcref */
  259. uint32 elem_type;
  260. bool is_dropped;
  261. /* optional, only for active */
  262. uint32 table_index;
  263. InitializerExpression base_offset;
  264. uint32 function_count;
  265. uint32 *func_indexes;
  266. } WASMTableSeg;
  267. typedef struct WASMDataSeg {
  268. uint32 memory_index;
  269. InitializerExpression base_offset;
  270. uint32 data_length;
  271. #if WASM_ENABLE_BULK_MEMORY != 0
  272. bool is_passive;
  273. #endif
  274. uint8 *data;
  275. } WASMDataSeg;
  276. typedef struct BlockAddr {
  277. const uint8 *start_addr;
  278. uint8 *else_addr;
  279. uint8 *end_addr;
  280. } BlockAddr;
  281. #if WASM_ENABLE_LIBC_WASI != 0
  282. typedef struct WASIArguments {
  283. const char **dir_list;
  284. uint32 dir_count;
  285. const char **map_dir_list;
  286. uint32 map_dir_count;
  287. const char **env;
  288. uint32 env_count;
  289. /* in CIDR noation */
  290. const char **addr_pool;
  291. uint32 addr_count;
  292. const char **ns_lookup_pool;
  293. uint32 ns_lookup_count;
  294. char **argv;
  295. uint32 argc;
  296. int stdio[3];
  297. } WASIArguments;
  298. #endif
  299. typedef struct StringNode {
  300. struct StringNode *next;
  301. char *str;
  302. } StringNode, *StringList;
  303. typedef struct BrTableCache {
  304. struct BrTableCache *next;
  305. /* Address of br_table opcode */
  306. uint8 *br_table_op_addr;
  307. uint32 br_count;
  308. uint32 br_depths[1];
  309. } BrTableCache;
  310. #if WASM_ENABLE_DEBUG_INTERP != 0
  311. typedef struct WASMFastOPCodeNode {
  312. struct WASMFastOPCodeNode *next;
  313. uint64 offset;
  314. uint8 orig_op;
  315. } WASMFastOPCodeNode;
  316. #endif
  317. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  318. typedef struct WASMCustomSection {
  319. struct WASMCustomSection *next;
  320. /* Start address of the section name */
  321. char *name_addr;
  322. /* Length of the section name decoded from leb */
  323. uint32 name_len;
  324. /* Start address of the content (name len and name skipped) */
  325. uint8 *content_addr;
  326. uint32 content_len;
  327. } WASMCustomSection;
  328. #endif
  329. #if WASM_ENABLE_JIT != 0
  330. struct AOTCompData;
  331. struct AOTCompContext;
  332. /* Orc JIT thread arguments */
  333. typedef struct OrcJitThreadArg {
  334. struct AOTCompContext *comp_ctx;
  335. struct WASMModule *module;
  336. uint32 group_idx;
  337. } OrcJitThreadArg;
  338. #endif
  339. struct WASMModule {
  340. /* Module type, for module loaded from WASM bytecode binary,
  341. this field is Wasm_Module_Bytecode;
  342. for module loaded from AOT file, this field is
  343. Wasm_Module_AoT, and this structure should be treated as
  344. AOTModule structure. */
  345. uint32 module_type;
  346. uint32 type_count;
  347. uint32 import_count;
  348. uint32 function_count;
  349. uint32 table_count;
  350. uint32 memory_count;
  351. uint32 global_count;
  352. uint32 export_count;
  353. uint32 table_seg_count;
  354. /* data seg count read from data segment section */
  355. uint32 data_seg_count;
  356. #if WASM_ENABLE_BULK_MEMORY != 0
  357. /* data count read from datacount section */
  358. uint32 data_seg_count1;
  359. #endif
  360. uint32 import_function_count;
  361. uint32 import_table_count;
  362. uint32 import_memory_count;
  363. uint32 import_global_count;
  364. WASMImport *import_functions;
  365. WASMImport *import_tables;
  366. WASMImport *import_memories;
  367. WASMImport *import_globals;
  368. WASMType **types;
  369. WASMImport *imports;
  370. WASMFunction **functions;
  371. WASMTable *tables;
  372. WASMMemory *memories;
  373. WASMGlobal *globals;
  374. WASMExport *exports;
  375. WASMTableSeg *table_segments;
  376. WASMDataSeg **data_segments;
  377. uint32 start_function;
  378. /* total global variable size */
  379. uint32 global_data_size;
  380. /* the index of auxiliary __data_end global,
  381. -1 means unexported */
  382. uint32 aux_data_end_global_index;
  383. /* auxiliary __data_end exported by wasm app */
  384. uint32 aux_data_end;
  385. /* the index of auxiliary __heap_base global,
  386. -1 means unexported */
  387. uint32 aux_heap_base_global_index;
  388. /* auxiliary __heap_base exported by wasm app */
  389. uint32 aux_heap_base;
  390. /* the index of auxiliary stack top global,
  391. -1 means unexported */
  392. uint32 aux_stack_top_global_index;
  393. /* auxiliary stack bottom resolved */
  394. uint32 aux_stack_bottom;
  395. /* auxiliary stack size resolved */
  396. uint32 aux_stack_size;
  397. /* the index of malloc/free function,
  398. -1 means unexported */
  399. uint32 malloc_function;
  400. uint32 free_function;
  401. /* the index of __retain function,
  402. -1 means unexported */
  403. uint32 retain_function;
  404. /* Whether there is possible memory grow, e.g. memory.grow opcode */
  405. bool possible_memory_grow;
  406. StringList const_str_list;
  407. #if WASM_ENABLE_FAST_INTERP == 0
  408. bh_list br_table_cache_list_head;
  409. bh_list *br_table_cache_list;
  410. #endif
  411. #if WASM_ENABLE_LIBC_WASI != 0
  412. WASIArguments wasi_args;
  413. bool import_wasi_api;
  414. #endif
  415. #if WASM_ENABLE_MULTI_MODULE != 0
  416. /* TODO: add mutex for mutli-thread? */
  417. bh_list import_module_list_head;
  418. bh_list *import_module_list;
  419. #endif
  420. #if WASM_ENABLE_DEBUG_INTERP != 0 || WASM_ENABLE_DEBUG_AOT != 0
  421. bh_list fast_opcode_list;
  422. uint8 *buf_code;
  423. uint64 buf_code_size;
  424. #endif
  425. #if WASM_ENABLE_DEBUG_INTERP != 0 || WASM_ENABLE_DEBUG_AOT != 0 \
  426. || WASM_ENABLE_FAST_JIT != 0
  427. uint8 *load_addr;
  428. uint64 load_size;
  429. #endif
  430. #if WASM_ENABLE_DEBUG_INTERP != 0
  431. /**
  432. * Count how many instances reference this module. When source
  433. * debugging feature enabled, the debugger may modify the code
  434. * section of the module, so we need to report a warning if user
  435. * create several instances based on the same module
  436. *
  437. * Sub_instances created by lib-pthread or spawn API will not
  438. * influence or check the ref count
  439. */
  440. uint32 ref_count;
  441. korp_mutex ref_count_lock;
  442. #endif
  443. #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
  444. const uint8 *name_section_buf;
  445. const uint8 *name_section_buf_end;
  446. #endif
  447. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  448. WASMCustomSection *custom_section_list;
  449. #endif
  450. #if WASM_ENABLE_FAST_JIT != 0
  451. /* func pointers of Fast JITed (un-imported) functions */
  452. void **fast_jit_func_ptrs;
  453. #endif
  454. #if WASM_ENABLE_JIT != 0
  455. struct AOTCompData *comp_data;
  456. struct AOTCompContext *comp_ctx;
  457. /* func pointers of LLVM JITed (un-imported) functions */
  458. void **func_ptrs;
  459. /* whether the func pointers are compiled */
  460. bool *func_ptrs_compiled;
  461. bool orcjit_stop_compiling;
  462. korp_tid orcjit_threads[WASM_ORC_JIT_BACKEND_THREAD_NUM];
  463. OrcJitThreadArg orcjit_thread_args[WASM_ORC_JIT_BACKEND_THREAD_NUM];
  464. #endif
  465. };
  466. typedef struct BlockType {
  467. /* Block type may be expressed in one of two forms:
  468. * either by the type of the single return value or
  469. * by a type index of module.
  470. */
  471. union {
  472. uint8 value_type;
  473. WASMType *type;
  474. } u;
  475. bool is_value_type;
  476. } BlockType;
  477. typedef struct WASMBranchBlock {
  478. uint8 *begin_addr;
  479. uint8 *target_addr;
  480. uint32 *frame_sp;
  481. uint32 cell_num;
  482. } WASMBranchBlock;
  483. /* Execution environment, e.g. stack info */
  484. /**
  485. * Align an unsigned value on a alignment boundary.
  486. *
  487. * @param v the value to be aligned
  488. * @param b the alignment boundary (2, 4, 8, ...)
  489. *
  490. * @return the aligned value
  491. */
  492. inline static unsigned
  493. align_uint(unsigned v, unsigned b)
  494. {
  495. unsigned m = b - 1;
  496. return (v + m) & ~m;
  497. }
  498. /**
  499. * Return the hash value of c string.
  500. */
  501. inline static uint32
  502. wasm_string_hash(const char *str)
  503. {
  504. unsigned h = (unsigned)strlen(str);
  505. const uint8 *p = (uint8 *)str;
  506. const uint8 *end = p + h;
  507. while (p != end)
  508. h = ((h << 5) - h) + *p++;
  509. return h;
  510. }
  511. /**
  512. * Whether two c strings are equal.
  513. */
  514. inline static bool
  515. wasm_string_equal(const char *s1, const char *s2)
  516. {
  517. return strcmp(s1, s2) == 0 ? true : false;
  518. }
  519. /**
  520. * Return the byte size of value type.
  521. *
  522. */
  523. inline static uint32
  524. wasm_value_type_size(uint8 value_type)
  525. {
  526. switch (value_type) {
  527. case VALUE_TYPE_I32:
  528. case VALUE_TYPE_F32:
  529. #if WASM_ENABLE_REF_TYPES != 0
  530. case VALUE_TYPE_FUNCREF:
  531. case VALUE_TYPE_EXTERNREF:
  532. #endif
  533. return sizeof(int32);
  534. case VALUE_TYPE_I64:
  535. case VALUE_TYPE_F64:
  536. return sizeof(int64);
  537. #if WASM_ENABLE_SIMD != 0
  538. case VALUE_TYPE_V128:
  539. return sizeof(int64) * 2;
  540. #endif
  541. case VALUE_TYPE_VOID:
  542. return 0;
  543. default:
  544. bh_assert(0);
  545. }
  546. return 0;
  547. }
  548. inline static uint16
  549. wasm_value_type_cell_num(uint8 value_type)
  550. {
  551. return wasm_value_type_size(value_type) / 4;
  552. }
  553. inline static uint32
  554. wasm_get_cell_num(const uint8 *types, uint32 type_count)
  555. {
  556. uint32 cell_num = 0;
  557. uint32 i;
  558. for (i = 0; i < type_count; i++)
  559. cell_num += wasm_value_type_cell_num(types[i]);
  560. return cell_num;
  561. }
  562. #if WASM_ENABLE_REF_TYPES != 0
  563. inline static uint16
  564. wasm_value_type_cell_num_outside(uint8 value_type)
  565. {
  566. if (VALUE_TYPE_EXTERNREF == value_type) {
  567. return sizeof(uintptr_t) / sizeof(uint32);
  568. }
  569. else {
  570. return wasm_value_type_cell_num(value_type);
  571. }
  572. }
  573. #endif
  574. inline static bool
  575. wasm_type_equal(const WASMType *type1, const WASMType *type2)
  576. {
  577. if (type1 == type2) {
  578. return true;
  579. }
  580. return (type1->param_count == type2->param_count
  581. && type1->result_count == type2->result_count
  582. && memcmp(type1->types, type2->types,
  583. (uint32)(type1->param_count + type1->result_count))
  584. == 0)
  585. ? true
  586. : false;
  587. }
  588. inline static uint32
  589. wasm_get_smallest_type_idx(WASMType **types, uint32 type_count,
  590. uint32 cur_type_idx)
  591. {
  592. uint32 i;
  593. for (i = 0; i < cur_type_idx; i++) {
  594. if (wasm_type_equal(types[cur_type_idx], types[i]))
  595. return i;
  596. }
  597. (void)type_count;
  598. return cur_type_idx;
  599. }
  600. static inline uint32
  601. block_type_get_param_types(BlockType *block_type, uint8 **p_param_types)
  602. {
  603. uint32 param_count = 0;
  604. if (!block_type->is_value_type) {
  605. WASMType *wasm_type = block_type->u.type;
  606. *p_param_types = wasm_type->types;
  607. param_count = wasm_type->param_count;
  608. }
  609. else {
  610. *p_param_types = NULL;
  611. param_count = 0;
  612. }
  613. return param_count;
  614. }
  615. static inline uint32
  616. block_type_get_result_types(BlockType *block_type, uint8 **p_result_types)
  617. {
  618. uint32 result_count = 0;
  619. if (block_type->is_value_type) {
  620. if (block_type->u.value_type != VALUE_TYPE_VOID) {
  621. *p_result_types = &block_type->u.value_type;
  622. result_count = 1;
  623. }
  624. }
  625. else {
  626. WASMType *wasm_type = block_type->u.type;
  627. *p_result_types = wasm_type->types + wasm_type->param_count;
  628. result_count = wasm_type->result_count;
  629. }
  630. return result_count;
  631. }
  632. #ifdef __cplusplus
  633. } /* end of extern "C" */
  634. #endif
  635. #endif /* end of _WASM_H_ */