wasm_application.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "bh_platform.h"
  6. #if WASM_ENABLE_INTERP != 0
  7. #include "../interpreter/wasm_runtime.h"
  8. #endif
  9. #if WASM_ENABLE_AOT != 0
  10. #include "../aot/aot_runtime.h"
  11. #endif
  12. static void
  13. set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
  14. {
  15. if (error_buf != NULL)
  16. snprintf(error_buf, error_buf_size, "%s", string);
  17. }
  18. static void *
  19. runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst,
  20. char *error_buf, uint32 error_buf_size)
  21. {
  22. void *mem;
  23. if (size >= UINT32_MAX || !(mem = wasm_runtime_malloc((uint32)size))) {
  24. if (module_inst != NULL) {
  25. wasm_runtime_set_exception(module_inst, "allocate memory failed");
  26. }
  27. else if (error_buf != NULL) {
  28. set_error_buf(error_buf, error_buf_size, "allocate memory failed");
  29. }
  30. return NULL;
  31. }
  32. memset(mem, 0, (uint32)size);
  33. return mem;
  34. }
  35. static union {
  36. int a;
  37. char b;
  38. } __ue = { .a = 1 };
  39. #define is_little_endian() (__ue.b == 1)
  40. /**
  41. * Implementation of wasm_application_execute_main()
  42. */
  43. static bool
  44. check_main_func_type(const WASMType *type)
  45. {
  46. if (!(type->param_count == 0 || type->param_count == 2)
  47. || type->result_count > 1) {
  48. LOG_ERROR(
  49. "WASM execute application failed: invalid main function type.\n");
  50. return false;
  51. }
  52. if (type->param_count == 2
  53. && !(type->types[0] == VALUE_TYPE_I32
  54. && type->types[1] == VALUE_TYPE_I32)) {
  55. LOG_ERROR(
  56. "WASM execute application failed: invalid main function type.\n");
  57. return false;
  58. }
  59. if (type->result_count
  60. && type->types[type->param_count] != VALUE_TYPE_I32) {
  61. LOG_ERROR(
  62. "WASM execute application failed: invalid main function type.\n");
  63. return false;
  64. }
  65. return true;
  66. }
  67. bool
  68. wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
  69. char *argv[])
  70. {
  71. WASMFunctionInstanceCommon *func;
  72. WASMType *func_type = NULL;
  73. WASMExecEnv *exec_env = NULL;
  74. uint32 argc1 = 0, argv1[2] = { 0 };
  75. uint32 total_argv_size = 0;
  76. uint64 total_size;
  77. uint32 argv_buf_offset = 0;
  78. int32 i;
  79. char *argv_buf, *p, *p_end;
  80. uint32 *argv_offsets, module_type;
  81. bool ret, is_import_func = true;
  82. exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
  83. if (!exec_env) {
  84. wasm_runtime_set_exception(module_inst,
  85. "create singleton exec_env failed");
  86. return false;
  87. }
  88. #if WASM_ENABLE_LIBC_WASI != 0
  89. /* In wasi mode, we should call the function named "_start"
  90. which initializes the wasi envrionment and then calls
  91. the actual main function. Directly calling main function
  92. may cause exception thrown. */
  93. if ((func = wasm_runtime_lookup_wasi_start_function(module_inst))) {
  94. #if WASM_ENABLE_DEBUG_INTERP != 0
  95. wasm_runtime_start_debug_instance(exec_env);
  96. #endif
  97. return wasm_runtime_call_wasm(exec_env, func, 0, NULL);
  98. }
  99. #endif /* end of WASM_ENABLE_LIBC_WASI */
  100. if (!(func = wasm_runtime_lookup_function(module_inst, "main", NULL))
  101. && !(func = wasm_runtime_lookup_function(module_inst,
  102. "__main_argc_argv", NULL))
  103. && !(func = wasm_runtime_lookup_function(module_inst, "_main", NULL))) {
  104. #if WASM_ENABLE_LIBC_WASI != 0
  105. wasm_runtime_set_exception(
  106. module_inst, "lookup the entry point symbol (like _start, main, "
  107. "_main, __main_argc_argv) failed");
  108. #else
  109. wasm_runtime_set_exception(module_inst,
  110. "lookup the entry point symbol (like main, "
  111. "_main, __main_argc_argv) failed");
  112. #endif
  113. return false;
  114. }
  115. #if WASM_ENABLE_INTERP != 0
  116. if (module_inst->module_type == Wasm_Module_Bytecode) {
  117. is_import_func = ((WASMFunctionInstance *)func)->is_import_func;
  118. }
  119. #endif
  120. #if WASM_ENABLE_AOT != 0
  121. if (module_inst->module_type == Wasm_Module_AoT) {
  122. is_import_func = ((AOTFunctionInstance *)func)->is_import_func;
  123. }
  124. #endif
  125. if (is_import_func) {
  126. wasm_runtime_set_exception(module_inst, "lookup main function failed");
  127. return false;
  128. }
  129. module_type = module_inst->module_type;
  130. func_type = wasm_runtime_get_function_type(func, module_type);
  131. if (!func_type) {
  132. LOG_ERROR("invalid module instance type");
  133. return false;
  134. }
  135. if (!check_main_func_type(func_type)) {
  136. wasm_runtime_set_exception(module_inst,
  137. "invalid function type of main function");
  138. return false;
  139. }
  140. if (func_type->param_count) {
  141. for (i = 0; i < argc; i++)
  142. total_argv_size += (uint32)(strlen(argv[i]) + 1);
  143. total_argv_size = align_uint(total_argv_size, 4);
  144. total_size = (uint64)total_argv_size + sizeof(int32) * (uint64)argc;
  145. if (total_size >= UINT32_MAX
  146. || !(argv_buf_offset = wasm_runtime_module_malloc(
  147. module_inst, (uint32)total_size, (void **)&argv_buf))) {
  148. wasm_runtime_set_exception(module_inst, "allocate memory failed");
  149. return false;
  150. }
  151. p = argv_buf;
  152. argv_offsets = (uint32 *)(p + total_argv_size);
  153. p_end = p + total_size;
  154. for (i = 0; i < argc; i++) {
  155. bh_memcpy_s(p, (uint32)(p_end - p), argv[i],
  156. (uint32)(strlen(argv[i]) + 1));
  157. argv_offsets[i] = argv_buf_offset + (uint32)(p - argv_buf);
  158. p += strlen(argv[i]) + 1;
  159. }
  160. argc1 = 2;
  161. argv1[0] = (uint32)argc;
  162. argv1[1] =
  163. (uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
  164. }
  165. #if WASM_ENABLE_DEBUG_INTERP != 0
  166. wasm_runtime_start_debug_instance(exec_env);
  167. #endif
  168. ret = wasm_runtime_call_wasm(exec_env, func, argc1, argv1);
  169. if (ret && func_type->result_count > 0 && argc > 0 && argv)
  170. /* copy the return value */
  171. *(int *)argv = (int)argv1[0];
  172. if (argv_buf_offset)
  173. wasm_runtime_module_free(module_inst, argv_buf_offset);
  174. return ret;
  175. }
  176. #if WASM_ENABLE_MULTI_MODULE != 0
  177. static WASMModuleInstance *
  178. get_sub_module_inst(const WASMModuleInstance *parent_module_inst,
  179. const char *sub_module_name)
  180. {
  181. WASMSubModInstNode *node =
  182. bh_list_first_elem(parent_module_inst->sub_module_inst_list);
  183. while (node && strcmp(node->module_name, sub_module_name)) {
  184. node = bh_list_elem_next(node);
  185. }
  186. return node ? node->module_inst : NULL;
  187. }
  188. static bool
  189. parse_function_name(char *orig_function_name, char **p_module_name,
  190. char **p_function_name)
  191. {
  192. if (orig_function_name[0] != '$') {
  193. *p_module_name = NULL;
  194. *p_function_name = orig_function_name;
  195. return true;
  196. }
  197. /**
  198. * $module_name$function_name\0
  199. * ===>
  200. * module_name\0function_name\0
  201. * ===>
  202. * module_name
  203. * function_name
  204. */
  205. char *p1 = orig_function_name;
  206. char *p2 = strchr(p1 + 1, '$');
  207. if (!p2) {
  208. LOG_DEBUG("can not parse the incoming function name");
  209. return false;
  210. }
  211. *p_module_name = p1 + 1;
  212. *p2 = '\0';
  213. *p_function_name = p2 + 1;
  214. return strlen(*p_module_name) && strlen(*p_function_name);
  215. }
  216. #endif
  217. /**
  218. * Implementation of wasm_application_execute_func()
  219. */
  220. static bool
  221. resolve_function(WASMModuleInstanceCommon *module_inst, const char *name,
  222. WASMFunctionInstanceCommon **out_func,
  223. WASMModuleInstanceCommon **out_module_inst)
  224. {
  225. WASMFunctionInstanceCommon *target_func = NULL;
  226. WASMModuleInstanceCommon *target_inst = NULL;
  227. #if WASM_ENABLE_MULTI_MODULE != 0
  228. char *function_name = NULL;
  229. char *orig_name = NULL;
  230. char *sub_module_name = NULL;
  231. uint32 length = (uint32)(strlen(name) + 1);
  232. orig_name = runtime_malloc(sizeof(char) * length, NULL, NULL, 0);
  233. if (!orig_name) {
  234. goto LEAVE;
  235. }
  236. strncpy(orig_name, name, length);
  237. if (!parse_function_name(orig_name, &sub_module_name, &function_name)) {
  238. goto LEAVE;
  239. }
  240. LOG_DEBUG("%s -> %s and %s", name, sub_module_name, function_name);
  241. if (sub_module_name) {
  242. target_inst = (WASMModuleInstanceCommon *)get_sub_module_inst(
  243. (WASMModuleInstance *)module_inst, sub_module_name);
  244. if (!target_inst) {
  245. LOG_DEBUG("can not find a sub module named %s", sub_module_name);
  246. goto LEAVE;
  247. }
  248. }
  249. else {
  250. target_inst = module_inst;
  251. }
  252. #else
  253. const char *function_name = name;
  254. target_inst = module_inst;
  255. #endif
  256. target_func =
  257. wasm_runtime_lookup_function(target_inst, function_name, NULL);
  258. #if WASM_ENABLE_MULTI_MODULE != 0
  259. LEAVE:
  260. if (orig_name)
  261. wasm_runtime_free(orig_name);
  262. #endif
  263. *out_func = target_func;
  264. *out_module_inst = target_inst;
  265. return target_func;
  266. }
  267. union ieee754_float {
  268. float f;
  269. /* This is the IEEE 754 single-precision format. */
  270. union {
  271. struct {
  272. unsigned int negative : 1;
  273. unsigned int exponent : 8;
  274. unsigned int mantissa : 23;
  275. } ieee_big_endian;
  276. struct {
  277. unsigned int mantissa : 23;
  278. unsigned int exponent : 8;
  279. unsigned int negative : 1;
  280. } ieee_little_endian;
  281. } ieee;
  282. };
  283. union ieee754_double {
  284. double d;
  285. /* This is the IEEE 754 double-precision format. */
  286. union {
  287. struct {
  288. unsigned int negative : 1;
  289. unsigned int exponent : 11;
  290. /* Together these comprise the mantissa. */
  291. unsigned int mantissa0 : 20;
  292. unsigned int mantissa1 : 32;
  293. } ieee_big_endian;
  294. struct {
  295. /* Together these comprise the mantissa. */
  296. unsigned int mantissa1 : 32;
  297. unsigned int mantissa0 : 20;
  298. unsigned int exponent : 11;
  299. unsigned int negative : 1;
  300. } ieee_little_endian;
  301. } ieee;
  302. };
  303. bool
  304. wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
  305. const char *name, int32 argc, char *argv[])
  306. {
  307. WASMFunctionInstanceCommon *target_func;
  308. WASMModuleInstanceCommon *target_inst;
  309. WASMType *type = NULL;
  310. WASMExecEnv *exec_env = NULL;
  311. uint32 argc1, *argv1 = NULL, cell_num = 0, j, k = 0;
  312. #if WASM_ENABLE_REF_TYPES != 0
  313. uint32 param_size_in_double_world = 0, result_size_in_double_world = 0;
  314. #endif
  315. int32 i, p, module_type;
  316. uint64 total_size;
  317. const char *exception;
  318. char buf[128];
  319. bh_assert(argc >= 0);
  320. LOG_DEBUG("call a function \"%s\" with %d arguments", name, argc);
  321. if (!resolve_function(module_inst, name, &target_func, &target_inst)) {
  322. snprintf(buf, sizeof(buf), "lookup function %s failed", name);
  323. wasm_runtime_set_exception(module_inst, buf);
  324. goto fail;
  325. }
  326. module_type = target_inst->module_type;
  327. type = wasm_runtime_get_function_type(target_func, module_type);
  328. if (!type) {
  329. LOG_ERROR("invalid module instance type");
  330. return false;
  331. }
  332. if (type->param_count != (uint32)argc) {
  333. wasm_runtime_set_exception(module_inst, "invalid input argument count");
  334. goto fail;
  335. }
  336. #if WASM_ENABLE_REF_TYPES != 0
  337. for (i = 0; i < type->param_count; i++) {
  338. param_size_in_double_world +=
  339. wasm_value_type_cell_num_outside(type->types[i]);
  340. }
  341. for (i = 0; i < type->result_count; i++) {
  342. result_size_in_double_world += wasm_value_type_cell_num_outside(
  343. type->types[type->param_count + i]);
  344. }
  345. argc1 = param_size_in_double_world;
  346. cell_num = (param_size_in_double_world >= result_size_in_double_world)
  347. ? param_size_in_double_world
  348. : result_size_in_double_world;
  349. #else
  350. argc1 = type->param_cell_num;
  351. cell_num = (argc1 > type->ret_cell_num) ? argc1 : type->ret_cell_num;
  352. #endif
  353. total_size = sizeof(uint32) * (uint64)(cell_num > 2 ? cell_num : 2);
  354. if ((!(argv1 = runtime_malloc((uint32)total_size, target_inst, NULL, 0)))) {
  355. goto fail;
  356. }
  357. /* Parse arguments */
  358. for (i = 0, p = 0; i < argc; i++) {
  359. char *endptr = NULL;
  360. bh_assert(argv[i] != NULL);
  361. if (argv[i][0] == '\0') {
  362. snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
  363. wasm_runtime_set_exception(module_inst, buf);
  364. goto fail;
  365. }
  366. switch (type->types[i]) {
  367. case VALUE_TYPE_I32:
  368. argv1[p++] = (uint32)strtoul(argv[i], &endptr, 0);
  369. break;
  370. case VALUE_TYPE_I64:
  371. {
  372. union {
  373. uint64 val;
  374. uint32 parts[2];
  375. } u;
  376. u.val = strtoull(argv[i], &endptr, 0);
  377. argv1[p++] = u.parts[0];
  378. argv1[p++] = u.parts[1];
  379. break;
  380. }
  381. case VALUE_TYPE_F32:
  382. {
  383. float32 f32 = strtof(argv[i], &endptr);
  384. if (isnan(f32)) {
  385. if (argv[i][0] == '-') {
  386. union ieee754_float u;
  387. u.f = f32;
  388. if (is_little_endian())
  389. u.ieee.ieee_little_endian.negative = 1;
  390. else
  391. u.ieee.ieee_big_endian.negative = 1;
  392. memcpy(&f32, &u.f, sizeof(float));
  393. }
  394. if (endptr[0] == ':') {
  395. uint32 sig;
  396. union ieee754_float u;
  397. sig = (uint32)strtoul(endptr + 1, &endptr, 0);
  398. u.f = f32;
  399. if (is_little_endian())
  400. u.ieee.ieee_little_endian.mantissa = sig;
  401. else
  402. u.ieee.ieee_big_endian.mantissa = sig;
  403. memcpy(&f32, &u.f, sizeof(float));
  404. }
  405. }
  406. memcpy(&argv1[p++], &f32, sizeof(float));
  407. break;
  408. }
  409. case VALUE_TYPE_F64:
  410. {
  411. union {
  412. float64 val;
  413. uint32 parts[2];
  414. } u;
  415. u.val = strtod(argv[i], &endptr);
  416. if (isnan(u.val)) {
  417. if (argv[i][0] == '-') {
  418. union ieee754_double ud;
  419. ud.d = u.val;
  420. if (is_little_endian())
  421. ud.ieee.ieee_little_endian.negative = 1;
  422. else
  423. ud.ieee.ieee_big_endian.negative = 1;
  424. memcpy(&u.val, &ud.d, sizeof(double));
  425. }
  426. if (endptr[0] == ':') {
  427. uint64 sig;
  428. union ieee754_double ud;
  429. sig = strtoull(endptr + 1, &endptr, 0);
  430. ud.d = u.val;
  431. if (is_little_endian()) {
  432. ud.ieee.ieee_little_endian.mantissa0 = sig >> 32;
  433. ud.ieee.ieee_little_endian.mantissa1 = (uint32)sig;
  434. }
  435. else {
  436. ud.ieee.ieee_big_endian.mantissa0 = sig >> 32;
  437. ud.ieee.ieee_big_endian.mantissa1 = (uint32)sig;
  438. }
  439. memcpy(&u.val, &ud.d, sizeof(double));
  440. }
  441. }
  442. argv1[p++] = u.parts[0];
  443. argv1[p++] = u.parts[1];
  444. break;
  445. }
  446. #if WASM_ENABLE_SIMD != 0
  447. case VALUE_TYPE_V128:
  448. {
  449. /* it likes 0x123\0x234 or 123\234 */
  450. /* retrive first i64 */
  451. *(uint64 *)(argv1 + p) = strtoull(argv[i], &endptr, 0);
  452. /* skip \ */
  453. endptr++;
  454. /* retrive second i64 */
  455. *(uint64 *)(argv1 + p + 2) = strtoull(endptr, &endptr, 0);
  456. p += 4;
  457. break;
  458. }
  459. #endif /* WASM_ENABLE_SIMD != 0 */
  460. #if WASM_ENABLE_REF_TYPES != 0
  461. case VALUE_TYPE_FUNCREF:
  462. {
  463. if (strncasecmp(argv[i], "null", 4) == 0) {
  464. argv1[p++] = (uint32)-1;
  465. }
  466. else {
  467. argv1[p++] = (uint32)strtoul(argv[i], &endptr, 0);
  468. }
  469. break;
  470. }
  471. case VALUE_TYPE_EXTERNREF:
  472. {
  473. #if UINTPTR_MAX == UINT32_MAX
  474. if (strncasecmp(argv[i], "null", 4) == 0) {
  475. argv1[p++] = (uint32)-1;
  476. }
  477. else {
  478. argv1[p++] = strtoul(argv[i], &endptr, 0);
  479. }
  480. #else
  481. union {
  482. uintptr_t val;
  483. uint32 parts[2];
  484. } u;
  485. if (strncasecmp(argv[i], "null", 4) == 0) {
  486. u.val = (uintptr_t)-1LL;
  487. }
  488. else {
  489. u.val = strtoull(argv[i], &endptr, 0);
  490. }
  491. argv1[p++] = u.parts[0];
  492. argv1[p++] = u.parts[1];
  493. #endif
  494. break;
  495. }
  496. #endif /* WASM_ENABLE_REF_TYPES */
  497. default:
  498. bh_assert(0);
  499. break;
  500. }
  501. if (endptr && *endptr != '\0' && *endptr != '_') {
  502. snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
  503. i, argv[i]);
  504. wasm_runtime_set_exception(module_inst, buf);
  505. goto fail;
  506. }
  507. }
  508. wasm_runtime_set_exception(module_inst, NULL);
  509. #if WASM_ENABLE_REF_TYPES == 0
  510. bh_assert(p == (int32)argc1);
  511. #endif
  512. exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
  513. if (!exec_env) {
  514. wasm_runtime_set_exception(module_inst,
  515. "create singleton exec_env failed");
  516. goto fail;
  517. }
  518. #if WASM_ENABLE_DEBUG_INTERP != 0
  519. wasm_runtime_start_debug_instance(exec_env);
  520. #endif
  521. if (!wasm_runtime_call_wasm(exec_env, target_func, argc1, argv1)) {
  522. goto fail;
  523. }
  524. /* print return value */
  525. for (j = 0; j < type->result_count; j++) {
  526. switch (type->types[type->param_count + j]) {
  527. case VALUE_TYPE_I32:
  528. {
  529. os_printf("0x%" PRIx32 ":i32", argv1[k]);
  530. k++;
  531. break;
  532. }
  533. case VALUE_TYPE_I64:
  534. {
  535. union {
  536. uint64 val;
  537. uint32 parts[2];
  538. } u;
  539. u.parts[0] = argv1[k];
  540. u.parts[1] = argv1[k + 1];
  541. k += 2;
  542. os_printf("0x%" PRIx64 ":i64", u.val);
  543. break;
  544. }
  545. case VALUE_TYPE_F32:
  546. {
  547. os_printf("%.7g:f32", *(float32 *)(argv1 + k));
  548. k++;
  549. break;
  550. }
  551. case VALUE_TYPE_F64:
  552. {
  553. union {
  554. float64 val;
  555. uint32 parts[2];
  556. } u;
  557. u.parts[0] = argv1[k];
  558. u.parts[1] = argv1[k + 1];
  559. k += 2;
  560. os_printf("%.7g:f64", u.val);
  561. break;
  562. }
  563. #if WASM_ENABLE_REF_TYPES != 0
  564. case VALUE_TYPE_FUNCREF:
  565. {
  566. if (argv1[k] != NULL_REF)
  567. os_printf("%u:ref.func", argv1[k]);
  568. else
  569. os_printf("func:ref.null");
  570. k++;
  571. break;
  572. }
  573. case VALUE_TYPE_EXTERNREF:
  574. {
  575. #if UINTPTR_MAX == UINT32_MAX
  576. if (argv1[k] != 0 && argv1[k] != (uint32)-1)
  577. os_printf("%p:ref.extern", (void *)argv1[k]);
  578. else
  579. os_printf("extern:ref.null");
  580. k++;
  581. #else
  582. union {
  583. uintptr_t val;
  584. uint32 parts[2];
  585. } u;
  586. u.parts[0] = argv1[k];
  587. u.parts[1] = argv1[k + 1];
  588. k += 2;
  589. if (u.val && u.val != (uintptr_t)-1LL)
  590. os_printf("%p:ref.extern", (void *)u.val);
  591. else
  592. os_printf("extern:ref.null");
  593. #endif
  594. break;
  595. }
  596. #endif
  597. #if WASM_ENABLE_SIMD != 0
  598. case VALUE_TYPE_V128:
  599. {
  600. uint64 *v = (uint64 *)(argv1 + k);
  601. os_printf("<0x%016" PRIx64 " 0x%016" PRIx64 ">:v128", *v,
  602. *(v + 1));
  603. k += 4;
  604. break;
  605. }
  606. #endif /* WASM_ENABLE_SIMD != 0 */
  607. default:
  608. bh_assert(0);
  609. break;
  610. }
  611. if (j < (uint32)(type->result_count - 1))
  612. os_printf(",");
  613. }
  614. os_printf("\n");
  615. wasm_runtime_free(argv1);
  616. return true;
  617. fail:
  618. if (argv1)
  619. wasm_runtime_free(argv1);
  620. exception = wasm_runtime_get_exception(module_inst);
  621. bh_assert(exception);
  622. os_printf("%s\n", exception);
  623. return false;
  624. }