aot_emit_function.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "aot_emit_function.h"
  6. #include "aot_emit_exception.h"
  7. #include "aot_emit_control.h"
  8. #include "../aot/aot_runtime.h"
  9. static bool
  10. create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
  11. {
  12. LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder);
  13. AOTFuncType *aot_func_type = func_ctx->aot_func->func_type;
  14. /* Create function return block if it isn't created */
  15. if (!func_ctx->func_return_block) {
  16. if (!(func_ctx->func_return_block =
  17. LLVMAppendBasicBlockInContext(comp_ctx->context,
  18. func_ctx->func, "func_ret"))) {
  19. aot_set_last_error("llvm add basic block failed.");
  20. return false;
  21. }
  22. /* Create return IR */
  23. LLVMPositionBuilderAtEnd(comp_ctx->builder, func_ctx->func_return_block);
  24. if (aot_func_type->result_count) {
  25. switch (aot_func_type->types[aot_func_type->param_count]) {
  26. case VALUE_TYPE_I32:
  27. LLVMBuildRet(comp_ctx->builder, I32_ZERO);
  28. break;
  29. case VALUE_TYPE_I64:
  30. LLVMBuildRet(comp_ctx->builder, I64_ZERO);
  31. break;
  32. case VALUE_TYPE_F32:
  33. LLVMBuildRet(comp_ctx->builder, F32_ZERO);
  34. break;
  35. case VALUE_TYPE_F64:
  36. LLVMBuildRet(comp_ctx->builder, F64_ZERO);
  37. break;
  38. }
  39. }
  40. else {
  41. LLVMBuildRetVoid(comp_ctx->builder);
  42. }
  43. }
  44. LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
  45. return true;
  46. }
  47. /* Check whether there was exception thrown, if yes, return directly */
  48. static bool
  49. check_exception_thrown(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
  50. {
  51. LLVMBasicBlockRef block_curr, check_exce_succ;
  52. LLVMValueRef value, cmp;
  53. /* Create function return block if it isn't created */
  54. if (!create_func_return_block(comp_ctx, func_ctx))
  55. return false;
  56. /* Load the first byte of aot_module_inst->cur_exception, and check
  57. whether it is '\0'. If yes, no exception was thrown. */
  58. if (!(value = LLVMBuildLoad(comp_ctx->builder, func_ctx->cur_exception,
  59. "exce_value"))
  60. || !(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ,
  61. value, I8_ZERO, "cmp"))) {
  62. aot_set_last_error("llvm build icmp failed.");
  63. return false;
  64. }
  65. /* Add check exection success block */
  66. if (!(check_exce_succ = LLVMAppendBasicBlockInContext(comp_ctx->context,
  67. func_ctx->func,
  68. "check_exce_succ"))) {
  69. aot_set_last_error("llvm add basic block failed.");
  70. return false;
  71. }
  72. block_curr = LLVMGetInsertBlock(comp_ctx->builder);
  73. LLVMMoveBasicBlockAfter(check_exce_succ, block_curr);
  74. LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
  75. /* Create condition br */
  76. if (!LLVMBuildCondBr(comp_ctx->builder, cmp,
  77. check_exce_succ, func_ctx->func_return_block)) {
  78. aot_set_last_error("llvm build cond br failed.");
  79. return false;
  80. }
  81. LLVMPositionBuilderAtEnd(comp_ctx->builder, check_exce_succ);
  82. return true;
  83. }
  84. /* Check whether there was exception thrown, if yes, return directly */
  85. static bool
  86. check_call_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
  87. LLVMValueRef res)
  88. {
  89. LLVMBasicBlockRef block_curr, check_call_succ;
  90. LLVMValueRef cmp;
  91. /* Create function return block if it isn't created */
  92. if (!create_func_return_block(comp_ctx, func_ctx))
  93. return false;
  94. if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntNE,
  95. res, I8_ZERO, "cmp"))) {
  96. aot_set_last_error("llvm build icmp failed.");
  97. return false;
  98. }
  99. /* Add check exection success block */
  100. if (!(check_call_succ = LLVMAppendBasicBlockInContext(comp_ctx->context,
  101. func_ctx->func,
  102. "check_exce_succ"))) {
  103. aot_set_last_error("llvm add basic block failed.");
  104. return false;
  105. }
  106. block_curr = LLVMGetInsertBlock(comp_ctx->builder);
  107. LLVMMoveBasicBlockAfter(check_call_succ, block_curr);
  108. LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
  109. /* Create condition br */
  110. if (!LLVMBuildCondBr(comp_ctx->builder, cmp,
  111. check_call_succ, func_ctx->func_return_block)) {
  112. aot_set_last_error("llvm build cond br failed.");
  113. return false;
  114. }
  115. LLVMPositionBuilderAtEnd(comp_ctx->builder, check_call_succ);
  116. return true;
  117. }
  118. static bool
  119. call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
  120. LLVMValueRef func_idx, AOTFuncType *aot_func_type,
  121. LLVMTypeRef *param_types, LLVMValueRef *param_values,
  122. uint32 param_count, uint32 param_cell_num,
  123. LLVMTypeRef ret_type, uint8 wasm_ret_type,
  124. LLVMValueRef *p_value_ret, LLVMValueRef *p_res)
  125. {
  126. LLVMTypeRef func_type, func_ptr_type, func_param_types[4];
  127. LLVMTypeRef ret_ptr_type, elem_ptr_type;
  128. LLVMValueRef func, elem_idx, elem_ptr;
  129. LLVMValueRef func_param_values[4], value_ret = NULL, res;
  130. char buf[32], *func_name = "aot_invoke_native";
  131. uint32 i, cell_num = 0;
  132. /* prepare function type of aot_invoke_native */
  133. func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
  134. func_param_types[1] = I32_TYPE; /* func_idx */
  135. func_param_types[2] = I32_TYPE; /* argc */
  136. func_param_types[3] = INT32_PTR_TYPE; /* argv */
  137. if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 4, false))) {
  138. aot_set_last_error("llvm add function type failed.");
  139. return false;
  140. }
  141. /* prepare function pointer */
  142. if (comp_ctx->is_jit_mode) {
  143. if (!(func_ptr_type = LLVMPointerType(func_type, 0))) {
  144. aot_set_last_error("create LLVM function type failed.");
  145. return false;
  146. }
  147. /* JIT mode, call the function directly */
  148. if (!(func = I64_CONST((uint64)(uintptr_t)aot_invoke_native))
  149. || !(func = LLVMConstIntToPtr(func, func_ptr_type))) {
  150. aot_set_last_error("create LLVM value failed.");
  151. return false;
  152. }
  153. }
  154. else {
  155. if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
  156. && !(func = LLVMAddFunction(comp_ctx->module,
  157. func_name, func_type))) {
  158. aot_set_last_error("add LLVM function failed.");
  159. return false;
  160. }
  161. }
  162. if (param_count > 64) {
  163. aot_set_last_error("prepare native arguments failed: "
  164. "maximum 64 parameter cell number supported.");
  165. return false;
  166. }
  167. /* prepare frame_lp */
  168. for (i = 0; i < param_count; i++) {
  169. if (!(elem_idx = I32_CONST(cell_num))
  170. || !(elem_ptr_type = LLVMPointerType(param_types[i], 0))) {
  171. aot_set_last_error("llvm add const or pointer type failed.");
  172. return false;
  173. }
  174. snprintf(buf, sizeof(buf), "%s%d", "elem", i);
  175. if (!(elem_ptr = LLVMBuildInBoundsGEP(comp_ctx->builder,
  176. func_ctx->argv_buf, &elem_idx, 1, buf))
  177. || !(elem_ptr = LLVMBuildBitCast(comp_ctx->builder, elem_ptr,
  178. elem_ptr_type, buf))) {
  179. aot_set_last_error("llvm build bit cast failed.");
  180. return false;
  181. }
  182. if (!(res = LLVMBuildStore(comp_ctx->builder, param_values[i], elem_ptr))) {
  183. aot_set_last_error("llvm build store failed.");
  184. return false;
  185. }
  186. LLVMSetAlignment(res, 1);
  187. cell_num += wasm_value_type_cell_num(aot_func_type->types[i]);
  188. }
  189. func_param_values[0] = func_ctx->exec_env;
  190. func_param_values[1] = func_idx;
  191. func_param_values[2] = I32_CONST(param_cell_num);
  192. func_param_values[3] = func_ctx->argv_buf;
  193. if (!func_param_values[2]) {
  194. aot_set_last_error("llvm create const failed.");
  195. return false;
  196. }
  197. /* call aot_invoke_native() function */
  198. if (!(res = LLVMBuildCall(comp_ctx->builder, func,
  199. func_param_values, 4, "res"))) {
  200. aot_set_last_error("llvm build call failed.");
  201. return false;
  202. }
  203. /* get function return value */
  204. if (wasm_ret_type != VALUE_TYPE_VOID) {
  205. if (!(ret_ptr_type = LLVMPointerType(ret_type, 0))) {
  206. aot_set_last_error("llvm add pointer type failed.");
  207. return false;
  208. }
  209. if (!(value_ret = LLVMBuildBitCast(comp_ctx->builder, func_ctx->argv_buf,
  210. ret_ptr_type, "argv_ret"))) {
  211. aot_set_last_error("llvm build bit cast failed.");
  212. return false;
  213. }
  214. if (!(*p_value_ret = LLVMBuildLoad(comp_ctx->builder, value_ret,
  215. "value_ret"))) {
  216. aot_set_last_error("llvm build load failed.");
  217. return false;
  218. }
  219. }
  220. *p_res = res;
  221. return true;
  222. }
  223. bool
  224. aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
  225. uint32 func_idx, uint8 **p_frame_ip)
  226. {
  227. uint32 import_func_count = comp_ctx->comp_data->import_func_count;
  228. AOTImportFunc *import_funcs = comp_ctx->comp_data->import_funcs;
  229. uint32 func_count = comp_ctx->func_ctx_count, param_cell_num = 0;
  230. AOTFuncContext **func_ctxes = comp_ctx->func_ctxes;
  231. AOTFuncType *func_type;
  232. LLVMTypeRef *param_types = NULL, ret_type;
  233. LLVMValueRef *param_values = NULL, value_ret = NULL, func;
  234. LLVMValueRef import_func_idx, res;
  235. int32 i, j = 0, param_count;
  236. uint64 total_size;
  237. uint8 wasm_ret_type;
  238. bool ret = false;
  239. /* Check function index */
  240. if (func_idx >= import_func_count + func_count) {
  241. aot_set_last_error("Function index out of range.");
  242. return false;
  243. }
  244. /* Get function type */
  245. if (func_idx < import_func_count)
  246. func_type = import_funcs[func_idx].func_type;
  247. else
  248. func_type = func_ctxes[func_idx - import_func_count]->
  249. aot_func->func_type;
  250. /* Get param cell number */
  251. param_cell_num = wasm_type_param_cell_num(func_type);
  252. /* Allocate memory for parameters */
  253. param_count = (int32)func_type->param_count;
  254. total_size = sizeof(LLVMValueRef) * (uint64)(param_count + 1);
  255. if (total_size >= UINT32_MAX
  256. || !(param_values = wasm_runtime_malloc((uint32)total_size))) {
  257. aot_set_last_error("Allocate memory failed.");
  258. return false;
  259. }
  260. /* First parameter is exec env */
  261. param_values[j++] = func_ctx->exec_env;
  262. /* Pop parameters from stack */
  263. for (i = param_count - 1; i >= 0; i--)
  264. POP(param_values[i + j], func_type->types[i]);
  265. if (func_idx < import_func_count) {
  266. if (!(import_func_idx = I32_CONST(func_idx))) {
  267. aot_set_last_error("llvm build inbounds gep failed.");
  268. goto fail;
  269. }
  270. /* Initialize parameter types of the LLVM function */
  271. total_size = sizeof(LLVMTypeRef) * (uint64)(param_count + 1);
  272. if (total_size >= UINT32_MAX
  273. || !(param_types = wasm_runtime_malloc((uint32)total_size))) {
  274. aot_set_last_error("Allocate memory failed.");
  275. goto fail;
  276. }
  277. j = 0;
  278. param_types[j++] = comp_ctx->exec_env_type;
  279. for (i = 0; i < param_count; i++)
  280. param_types[j++] = TO_LLVM_TYPE(func_type->types[i]);
  281. if (func_type->result_count) {
  282. wasm_ret_type = func_type->types[func_type->param_count];
  283. ret_type = TO_LLVM_TYPE(wasm_ret_type);
  284. }
  285. else {
  286. wasm_ret_type = VALUE_TYPE_VOID;
  287. ret_type = VOID_TYPE;
  288. }
  289. /* call aot_invoke_native() */
  290. if (!call_aot_invoke_native_func(comp_ctx, func_ctx, import_func_idx, func_type,
  291. param_types + 1, param_values + 1,
  292. param_count, param_cell_num,
  293. ret_type, wasm_ret_type, &value_ret, &res))
  294. goto fail;
  295. /* Check whether there was exception thrown when executing the function */
  296. if (!check_call_return(comp_ctx, func_ctx, res))
  297. goto fail;
  298. }
  299. else {
  300. func = func_ctxes[func_idx - import_func_count]->func;
  301. /* Call the function */
  302. if (!(value_ret = LLVMBuildCall(comp_ctx->builder, func,
  303. param_values, (uint32)param_count + 1,
  304. (func_type->result_count > 0
  305. ? "call" : "")))) {
  306. aot_set_last_error("LLVM build call failed.");
  307. goto fail;
  308. }
  309. /* Set calling convention for the call with the func's calling convention */
  310. LLVMSetInstructionCallConv(value_ret, LLVMGetFunctionCallConv(func));
  311. /* Check whether there was exception thrown when executing the function */
  312. if (!check_exception_thrown(comp_ctx, func_ctx))
  313. goto fail;
  314. }
  315. if (func_type->result_count > 0)
  316. PUSH(value_ret, func_type->types[func_type->param_count]);
  317. ret = true;
  318. fail:
  319. if (param_types)
  320. wasm_runtime_free(param_types);
  321. if (param_values)
  322. wasm_runtime_free(param_values);
  323. return ret;
  324. }
  325. static bool
  326. call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
  327. AOTFuncType *aot_func_type,
  328. LLVMValueRef func_type_idx, LLVMValueRef table_elem_idx,
  329. LLVMTypeRef *param_types, LLVMValueRef *param_values,
  330. uint32 param_count, uint32 param_cell_num,
  331. LLVMTypeRef ret_type, uint8 wasm_ret_type,
  332. LLVMValueRef *p_value_ret, LLVMValueRef *p_res)
  333. {
  334. LLVMTypeRef func_type, func_ptr_type, func_param_types[6];
  335. LLVMTypeRef ret_ptr_type, elem_ptr_type;
  336. LLVMValueRef func, elem_idx, elem_ptr;
  337. LLVMValueRef func_param_values[6], value_ret = NULL, res = NULL;
  338. char buf[32], *func_name = "aot_call_indirect";
  339. uint32 i, cell_num = 0;
  340. /* prepare function type of aot_call_indirect */
  341. func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
  342. func_param_types[1] = INT8_TYPE; /* check_func_type */
  343. func_param_types[2] = I32_TYPE; /* func_type_idx */
  344. func_param_types[3] = I32_TYPE; /* table_elem_idx */
  345. func_param_types[4] = I32_TYPE; /* argc */
  346. func_param_types[5] = INT32_PTR_TYPE; /* argv */
  347. if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 6, false))) {
  348. aot_set_last_error("llvm add function type failed.");
  349. return false;
  350. }
  351. /* prepare function pointer */
  352. if (comp_ctx->is_jit_mode) {
  353. if (!(func_ptr_type = LLVMPointerType(func_type, 0))) {
  354. aot_set_last_error("create LLVM function type failed.");
  355. return false;
  356. }
  357. /* JIT mode, call the function directly */
  358. if (!(func = I64_CONST((uint64)(uintptr_t)aot_call_indirect))
  359. || !(func = LLVMConstIntToPtr(func, func_ptr_type))) {
  360. aot_set_last_error("create LLVM value failed.");
  361. return false;
  362. }
  363. }
  364. else {
  365. if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
  366. && !(func = LLVMAddFunction(comp_ctx->module,
  367. func_name, func_type))) {
  368. aot_set_last_error("add LLVM function failed.");
  369. return false;
  370. }
  371. }
  372. if (param_count > 64) {
  373. aot_set_last_error("prepare native arguments failed: "
  374. "maximum 64 parameter cell number supported.");
  375. return false;
  376. }
  377. /* prepare frame_lp */
  378. for (i = 0; i < param_count; i++) {
  379. if (!(elem_idx = I32_CONST(cell_num))
  380. || !(elem_ptr_type = LLVMPointerType(param_types[i], 0))) {
  381. aot_set_last_error("llvm add const or pointer type failed.");
  382. return false;
  383. }
  384. snprintf(buf, sizeof(buf), "%s%d", "elem", i);
  385. if (!(elem_ptr = LLVMBuildInBoundsGEP(comp_ctx->builder,
  386. func_ctx->argv_buf, &elem_idx, 1, buf))
  387. || !(elem_ptr = LLVMBuildBitCast(comp_ctx->builder, elem_ptr,
  388. elem_ptr_type, buf))) {
  389. aot_set_last_error("llvm build bit cast failed.");
  390. return false;
  391. }
  392. if (!(res = LLVMBuildStore(comp_ctx->builder, param_values[i], elem_ptr))) {
  393. aot_set_last_error("llvm build store failed.");
  394. return false;
  395. }
  396. LLVMSetAlignment(res, 1);
  397. cell_num += wasm_value_type_cell_num(aot_func_type->types[i]);
  398. }
  399. func_param_values[0] = func_ctx->exec_env;
  400. func_param_values[1] = I8_CONST(true);
  401. func_param_values[2] = func_type_idx;
  402. func_param_values[3] = table_elem_idx;
  403. func_param_values[4] = I32_CONST(param_cell_num);
  404. func_param_values[5] = func_ctx->argv_buf;
  405. if (!func_param_values[1] || !func_param_values[4]) {
  406. aot_set_last_error("llvm create const failed.");
  407. return false;
  408. }
  409. /* call aot_call_indirect() function */
  410. if (!(res = LLVMBuildCall(comp_ctx->builder, func,
  411. func_param_values, 6, "res"))) {
  412. aot_set_last_error("llvm build call failed.");
  413. return false;
  414. }
  415. /* get function return value */
  416. if (wasm_ret_type != VALUE_TYPE_VOID) {
  417. if (!(ret_ptr_type = LLVMPointerType(ret_type, 0))) {
  418. aot_set_last_error("llvm add pointer type failed.");
  419. return false;
  420. }
  421. if (!(value_ret = LLVMBuildBitCast(comp_ctx->builder, func_ctx->argv_buf,
  422. ret_ptr_type, "argv_ret"))) {
  423. aot_set_last_error("llvm build bit cast failed.");
  424. return false;
  425. }
  426. if (!(*p_value_ret = LLVMBuildLoad(comp_ctx->builder, value_ret,
  427. "value_ret"))) {
  428. aot_set_last_error("llvm build load failed.");
  429. return false;
  430. }
  431. }
  432. *p_res = res;
  433. return true;
  434. }
  435. bool
  436. aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
  437. uint32 type_idx)
  438. {
  439. AOTFuncType *func_type;
  440. LLVMValueRef elem_idx, ftype_idx;
  441. LLVMValueRef *param_values = NULL, value_ret = NULL, res = NULL;
  442. LLVMTypeRef *param_types = NULL, ret_type;
  443. int32 i, param_count;
  444. uint32 param_cell_num;
  445. uint64 total_size;
  446. uint8 wasm_ret_type;
  447. bool ret;
  448. /* Check function type index */
  449. if (type_idx >= comp_ctx->comp_data->func_type_count) {
  450. aot_set_last_error("type index is overflow");
  451. return false;
  452. }
  453. ftype_idx = I32_CONST(type_idx);
  454. CHECK_LLVM_CONST(ftype_idx);
  455. func_type = comp_ctx->comp_data->func_types[type_idx];
  456. param_cell_num = wasm_type_param_cell_num(func_type);
  457. POP_I32(elem_idx);
  458. /* Initialize parameter types of the LLVM function */
  459. param_count = (int32)func_type->param_count;
  460. total_size = sizeof(LLVMTypeRef) * (uint64)param_count;
  461. if (total_size >= UINT32_MAX
  462. || !(param_types = wasm_runtime_malloc((uint32)total_size))) {
  463. aot_set_last_error("Allocate memory failed.");
  464. goto fail;
  465. }
  466. for (i = 0; i < param_count; i++)
  467. param_types[i] = TO_LLVM_TYPE(func_type->types[i]);
  468. /* Resolve return type of the LLVM function */
  469. if (func_type->result_count) {
  470. wasm_ret_type = func_type->types[func_type->param_count];
  471. ret_type = TO_LLVM_TYPE(wasm_ret_type);
  472. }
  473. else {
  474. wasm_ret_type = VALUE_TYPE_VOID;
  475. ret_type = VOID_TYPE;
  476. }
  477. /* Allocate memory for parameters */
  478. total_size = sizeof(LLVMValueRef) * (uint64)param_count;
  479. if (total_size >= UINT32_MAX
  480. || !(param_values = wasm_runtime_malloc((uint32)total_size))) {
  481. aot_set_last_error("Allocate memory failed.");
  482. goto fail;
  483. }
  484. /* Pop parameters from stack */
  485. for (i = param_count - 1; i >= 0; i--)
  486. POP(param_values[i], func_type->types[i]);
  487. if (!call_aot_call_indirect_func(comp_ctx, func_ctx,
  488. func_type, ftype_idx, elem_idx,
  489. param_types, param_values,
  490. param_count, param_cell_num,
  491. ret_type, wasm_ret_type,
  492. &value_ret, &res))
  493. goto fail;
  494. if (func_type->result_count > 0)
  495. PUSH(value_ret, func_type->types[func_type->param_count]);
  496. /* Check whether there was exception thrown when executing the function */
  497. if (!check_call_return(comp_ctx, func_ctx, res))
  498. goto fail;
  499. ret = true;
  500. fail:
  501. if (param_values)
  502. wasm_runtime_free(param_values);
  503. if (param_types)
  504. wasm_runtime_free(param_types);
  505. return ret;
  506. }