wasm.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/MemoryStream.h>
  8. #include <LibCore/ArgsParser.h>
  9. #include <LibCore/DeprecatedFile.h>
  10. #include <LibCore/File.h>
  11. #include <LibCore/MappedFile.h>
  12. #include <LibLine/Editor.h>
  13. #include <LibMain/Main.h>
  14. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  15. #include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
  16. #include <LibWasm/Printer/Printer.h>
  17. #include <LibWasm/Types.h>
  18. #include <LibWasm/Wasi.h>
  19. #include <signal.h>
  20. #include <unistd.h>
  21. RefPtr<Line::Editor> g_line_editor;
  22. static OwnPtr<Stream> g_stdout {};
  23. static OwnPtr<Wasm::Printer> g_printer {};
  24. static bool g_continue { false };
  25. static void (*old_signal)(int);
  26. static Wasm::DebuggerBytecodeInterpreter g_interpreter;
  27. static void sigint_handler(int)
  28. {
  29. if (!g_continue) {
  30. signal(SIGINT, old_signal);
  31. kill(getpid(), SIGINT);
  32. }
  33. g_continue = false;
  34. }
  35. static bool post_interpret_hook(Wasm::Configuration&, Wasm::InstructionPointer& ip, Wasm::Instruction const& instr, Wasm::Interpreter const& interpreter)
  36. {
  37. if (interpreter.did_trap()) {
  38. g_continue = false;
  39. warnln("Trapped when executing ip={}", ip);
  40. g_printer->print(instr);
  41. warnln("Trap reason: {}", interpreter.trap_reason());
  42. const_cast<Wasm::Interpreter&>(interpreter).clear_trap();
  43. }
  44. return true;
  45. }
  46. static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPointer& ip, Wasm::Instruction const& instr)
  47. {
  48. static bool always_print_stack = false;
  49. static bool always_print_instruction = false;
  50. if (always_print_stack)
  51. config.dump_stack();
  52. if (always_print_instruction) {
  53. g_stdout->write_until_depleted(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
  54. g_printer->print(instr);
  55. }
  56. if (g_continue)
  57. return true;
  58. g_stdout->write_until_depleted(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
  59. g_printer->print(instr);
  60. DeprecatedString last_command = "";
  61. for (;;) {
  62. auto result = g_line_editor->get_line("> ");
  63. if (result.is_error()) {
  64. return false;
  65. }
  66. auto str = result.release_value();
  67. g_line_editor->add_to_history(str);
  68. if (str.is_empty())
  69. str = last_command;
  70. else
  71. last_command = str;
  72. auto args = str.split_view(' ');
  73. if (args.is_empty())
  74. continue;
  75. auto& cmd = args[0];
  76. if (cmd.is_one_of("h", "help")) {
  77. warnln("Wasm shell commands");
  78. warnln("Toplevel:");
  79. warnln("- [s]tep Run one instruction");
  80. warnln("- next Alias for step");
  81. warnln("- [c]ontinue Execute until a trap or the program exit point");
  82. warnln("- [p]rint <args...> Print various things (see section on print)");
  83. warnln("- call <fn> <args...> Call the function <fn> with the given arguments");
  84. warnln("- set <args...> Set shell option (see section on settings)");
  85. warnln("- unset <args...> Unset shell option (see section on settings)");
  86. warnln("- [h]elp Print this help");
  87. warnln();
  88. warnln("Print:");
  89. warnln("- print [s]tack Print the contents of the stack, including frames and labels");
  90. warnln("- print [[m]em]ory <index> Print the contents of the memory identified by <index>");
  91. warnln("- print [[i]nstr]uction Print the current instruction");
  92. warnln("- print [[f]unc]tion <index> Print the function identified by <index>");
  93. warnln();
  94. warnln("Settings:");
  95. warnln("- set print stack Make the shell print the stack on every instruction executed");
  96. warnln("- set print [instr]uction Make the shell print the instruction that will be executed next");
  97. warnln();
  98. continue;
  99. }
  100. if (cmd.is_one_of("s", "step", "next")) {
  101. return true;
  102. }
  103. if (cmd.is_one_of("p", "print")) {
  104. if (args.size() < 2) {
  105. warnln("Print what?");
  106. continue;
  107. }
  108. auto& what = args[1];
  109. if (what.is_one_of("s", "stack")) {
  110. config.dump_stack();
  111. continue;
  112. }
  113. if (what.is_one_of("m", "mem", "memory")) {
  114. if (args.size() < 3) {
  115. warnln("print what memory?");
  116. continue;
  117. }
  118. auto value = args[2].to_uint<u64>();
  119. if (!value.has_value()) {
  120. warnln("invalid memory index {}", args[2]);
  121. continue;
  122. }
  123. auto mem = config.store().get(Wasm::MemoryAddress(value.value()));
  124. if (!mem) {
  125. warnln("invalid memory index {} (not found)", args[2]);
  126. continue;
  127. }
  128. warnln("{:>32hex-dump}", mem->data().bytes());
  129. continue;
  130. }
  131. if (what.is_one_of("i", "instr", "instruction")) {
  132. g_printer->print(instr);
  133. continue;
  134. }
  135. if (what.is_one_of("f", "func", "function")) {
  136. if (args.size() < 3) {
  137. warnln("print what function?");
  138. continue;
  139. }
  140. auto value = args[2].to_uint<u64>();
  141. if (!value.has_value()) {
  142. warnln("invalid function index {}", args[2]);
  143. continue;
  144. }
  145. auto fn = config.store().get(Wasm::FunctionAddress(value.value()));
  146. if (!fn) {
  147. warnln("invalid function index {} (not found)", args[2]);
  148. continue;
  149. }
  150. if (auto* fn_value = fn->get_pointer<Wasm::HostFunction>()) {
  151. warnln("Host function at {:p}", &fn_value->function());
  152. continue;
  153. }
  154. if (auto* fn_value = fn->get_pointer<Wasm::WasmFunction>()) {
  155. g_printer->print(fn_value->code());
  156. continue;
  157. }
  158. }
  159. }
  160. if (cmd == "call"sv) {
  161. if (args.size() < 2) {
  162. warnln("call what?");
  163. continue;
  164. }
  165. Optional<Wasm::FunctionAddress> address;
  166. auto index = args[1].to_uint<u64>();
  167. if (index.has_value()) {
  168. address = config.frame().module().functions()[index.value()];
  169. } else {
  170. auto& name = args[1];
  171. for (auto& export_ : config.frame().module().exports()) {
  172. if (export_.name() == name) {
  173. if (auto addr = export_.value().get_pointer<Wasm::FunctionAddress>()) {
  174. address = *addr;
  175. break;
  176. }
  177. }
  178. }
  179. }
  180. if (!address.has_value()) {
  181. failed_to_find:;
  182. warnln("Could not find a function {}", args[1]);
  183. continue;
  184. }
  185. auto fn = config.store().get(*address);
  186. if (!fn)
  187. goto failed_to_find;
  188. auto type = fn->visit([&](auto& value) { return value.type(); });
  189. if (type.parameters().size() + 2 != args.size()) {
  190. warnln("Expected {} arguments for call, but found only {}", type.parameters().size(), args.size() - 2);
  191. continue;
  192. }
  193. Vector<u64> values_to_push;
  194. Vector<Wasm::Value> values;
  195. for (size_t index = 2; index < args.size(); ++index)
  196. values_to_push.append(args[index].to_uint().value_or(0));
  197. for (auto& param : type.parameters())
  198. values.append(Wasm::Value { param, values_to_push.take_last() });
  199. Wasm::Result result { Wasm::Trap {} };
  200. {
  201. Wasm::BytecodeInterpreter::CallFrameHandle handle { g_interpreter, config };
  202. result = config.call(g_interpreter, *address, move(values)).assert_wasm_result();
  203. }
  204. if (result.is_trap()) {
  205. warnln("Execution trapped: {}", result.trap().reason);
  206. } else {
  207. if (!result.values().is_empty())
  208. warnln("Returned:");
  209. for (auto& value : result.values()) {
  210. g_stdout->write_until_depleted(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
  211. g_printer->print(value);
  212. }
  213. }
  214. continue;
  215. }
  216. if (cmd.is_one_of("set", "unset")) {
  217. auto value = !cmd.starts_with('u');
  218. if (args.size() < 3) {
  219. warnln("(un)set what (to what)?");
  220. continue;
  221. }
  222. if (args[1] == "print"sv) {
  223. if (args[2] == "stack"sv)
  224. always_print_stack = value;
  225. else if (args[2].is_one_of("instr", "instruction"))
  226. always_print_instruction = value;
  227. else
  228. warnln("Unknown print category '{}'", args[2]);
  229. continue;
  230. }
  231. warnln("Unknown set category '{}'", args[1]);
  232. continue;
  233. }
  234. if (cmd.is_one_of("c", "continue")) {
  235. g_continue = true;
  236. return true;
  237. }
  238. warnln("Command not understood: {}", cmd);
  239. }
  240. }
  241. static Optional<Wasm::Module> parse(StringView filename)
  242. {
  243. auto result = Core::MappedFile::map(filename);
  244. if (result.is_error()) {
  245. warnln("Failed to open {}: {}", filename, result.error());
  246. return {};
  247. }
  248. FixedMemoryStream stream { ReadonlyBytes { result.value()->data(), result.value()->size() } };
  249. auto parse_result = Wasm::Module::parse(stream);
  250. if (parse_result.is_error()) {
  251. warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!");
  252. warnln("The parse error was {}", Wasm::parse_error_to_deprecated_string(parse_result.error()));
  253. return {};
  254. }
  255. return parse_result.release_value();
  256. }
  257. static void print_link_error(Wasm::LinkError const& error)
  258. {
  259. for (auto const& missing : error.missing_imports)
  260. warnln("Missing import '{}'", missing);
  261. }
  262. ErrorOr<int> serenity_main(Main::Arguments arguments)
  263. {
  264. StringView filename;
  265. bool print = false;
  266. bool attempt_instantiate = false;
  267. bool debug = false;
  268. bool export_all_imports = false;
  269. bool shell_mode = false;
  270. bool wasi = false;
  271. DeprecatedString exported_function_to_execute;
  272. Vector<u64> values_to_push;
  273. Vector<DeprecatedString> modules_to_link_in;
  274. Vector<StringView> args_if_wasi;
  275. Vector<StringView> wasi_preopened_mappings;
  276. Core::ArgsParser parser;
  277. parser.add_positional_argument(filename, "File name to parse", "file");
  278. parser.add_option(debug, "Open a debugger", "debug", 'd');
  279. parser.add_option(print, "Print the parsed module", "print", 'p');
  280. parser.add_option(attempt_instantiate, "Attempt to instantiate the module", "instantiate", 'i');
  281. parser.add_option(exported_function_to_execute, "Attempt to execute the named exported function from the module (implies -i)", "execute", 'e', "name");
  282. parser.add_option(export_all_imports, "Export noop functions corresponding to imports", "export-noop", 0);
  283. parser.add_option(shell_mode, "Launch a REPL in the module's context (implies -i)", "shell", 's');
  284. parser.add_option(wasi, "Enable WASI", "wasi", 'w');
  285. parser.add_option(Core::ArgsParser::Option {
  286. .argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
  287. .help_string = "Directory mappings to expose via WASI",
  288. .long_name = "wasi-map-dir",
  289. .short_name = 0,
  290. .value_name = "path[:path]",
  291. .accept_value = [&](StringView str) {
  292. if (!str.is_empty()) {
  293. wasi_preopened_mappings.append(str);
  294. return true;
  295. }
  296. return false;
  297. },
  298. });
  299. parser.add_option(Core::ArgsParser::Option {
  300. .argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
  301. .help_string = "Extra modules to link with, use to resolve imports",
  302. .long_name = "link",
  303. .short_name = 'l',
  304. .value_name = "file",
  305. .accept_value = [&](StringView str) {
  306. if (!str.is_empty()) {
  307. modules_to_link_in.append(str);
  308. return true;
  309. }
  310. return false;
  311. },
  312. });
  313. parser.add_option(Core::ArgsParser::Option {
  314. .argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
  315. .help_string = "Supply arguments to the function (default=0) (expects u64, casts to required type)",
  316. .long_name = "arg",
  317. .short_name = 0,
  318. .value_name = "u64",
  319. .accept_value = [&](StringView str) -> bool {
  320. if (auto v = str.to_uint<u64>(); v.has_value()) {
  321. values_to_push.append(v.value());
  322. return true;
  323. }
  324. return false;
  325. },
  326. });
  327. parser.add_positional_argument(args_if_wasi, "Arguments to pass to the WASI module", "args", Core::ArgsParser::Required::No);
  328. parser.parse(arguments);
  329. if (shell_mode) {
  330. debug = true;
  331. attempt_instantiate = true;
  332. }
  333. if (!shell_mode && debug && exported_function_to_execute.is_empty()) {
  334. warnln("Debug what? (pass -e fn)");
  335. return 1;
  336. }
  337. if (debug || shell_mode) {
  338. old_signal = signal(SIGINT, sigint_handler);
  339. }
  340. if (!exported_function_to_execute.is_empty())
  341. attempt_instantiate = true;
  342. auto parse_result = parse(filename);
  343. if (!parse_result.has_value())
  344. return 1;
  345. g_stdout = TRY(Core::File::standard_output());
  346. g_printer = TRY(try_make<Wasm::Printer>(*g_stdout));
  347. if (print && !attempt_instantiate) {
  348. Wasm::Printer printer(*g_stdout);
  349. printer.print(parse_result.value());
  350. }
  351. if (attempt_instantiate) {
  352. Wasm::AbstractMachine machine;
  353. Optional<Wasm::Wasi::Implementation> wasi_impl;
  354. if (wasi) {
  355. wasi_impl.emplace(Wasm::Wasi::Implementation::Details {
  356. .provide_arguments = [&] {
  357. Vector<String> strings;
  358. for (auto& string : args_if_wasi)
  359. strings.append(String::from_utf8(string).release_value_but_fixme_should_propagate_errors());
  360. return strings; },
  361. .provide_environment = {},
  362. .provide_preopened_directories = [&] {
  363. Vector<Wasm::Wasi::Implementation::MappedPath> paths;
  364. for (auto& string : wasi_preopened_mappings) {
  365. auto split_index = string.find(':');
  366. if (split_index.has_value()) {
  367. LexicalPath host_path { Core::DeprecatedFile::real_path_for(string.substring_view(0, *split_index)) };
  368. LexicalPath mapped_path { string.substring_view(*split_index + 1) };
  369. paths.append({move(host_path), move(mapped_path)});
  370. } else {
  371. LexicalPath host_path { Core::DeprecatedFile::real_path_for(string) };
  372. LexicalPath mapped_path { string };
  373. paths.append({move(host_path), move(mapped_path)});
  374. }
  375. }
  376. return paths; },
  377. });
  378. }
  379. Core::EventLoop main_loop;
  380. if (debug) {
  381. g_line_editor = Line::Editor::construct();
  382. g_interpreter.pre_interpret_hook = pre_interpret_hook;
  383. g_interpreter.post_interpret_hook = post_interpret_hook;
  384. }
  385. // First, resolve the linked modules
  386. Vector<NonnullOwnPtr<Wasm::ModuleInstance>> linked_instances;
  387. Vector<Wasm::Module> linked_modules;
  388. for (auto& name : modules_to_link_in) {
  389. auto parse_result = parse(name);
  390. if (!parse_result.has_value()) {
  391. warnln("Failed to parse linked module '{}'", name);
  392. return 1;
  393. }
  394. linked_modules.append(parse_result.release_value());
  395. Wasm::Linker linker { linked_modules.last() };
  396. for (auto& instance : linked_instances)
  397. linker.link(*instance);
  398. auto link_result = linker.finish();
  399. if (link_result.is_error()) {
  400. warnln("Linking imported module '{}' failed", name);
  401. print_link_error(link_result.error());
  402. return 1;
  403. }
  404. auto instantiation_result = machine.instantiate(linked_modules.last(), link_result.release_value());
  405. if (instantiation_result.is_error()) {
  406. warnln("Instantiation of imported module '{}' failed: {}", name, instantiation_result.error().error);
  407. return 1;
  408. }
  409. linked_instances.append(instantiation_result.release_value());
  410. }
  411. Wasm::Linker linker { parse_result.value() };
  412. for (auto& instance : linked_instances)
  413. linker.link(*instance);
  414. if (wasi) {
  415. HashMap<Wasm::Linker::Name, Wasm::ExternValue> wasi_exports;
  416. for (auto& entry : linker.unresolved_imports()) {
  417. if (entry.module != "wasi_snapshot_preview1"sv)
  418. continue;
  419. auto function = wasi_impl->function_by_name(entry.name);
  420. if (function.is_error()) {
  421. dbgln("wasi function {} not implemented :(", entry.name);
  422. continue;
  423. }
  424. auto address = machine.store().allocate(function.release_value());
  425. wasi_exports.set(entry, *address);
  426. }
  427. linker.link(wasi_exports);
  428. }
  429. if (export_all_imports) {
  430. HashMap<Wasm::Linker::Name, Wasm::ExternValue> exports;
  431. for (auto& entry : linker.unresolved_imports()) {
  432. if (!entry.type.has<Wasm::TypeIndex>())
  433. continue;
  434. auto type = parse_result.value().type(entry.type.get<Wasm::TypeIndex>());
  435. auto address = machine.store().allocate(Wasm::HostFunction(
  436. [name = entry.name, type = type](auto&, auto& arguments) -> Wasm::Result {
  437. StringBuilder argument_builder;
  438. bool first = true;
  439. for (auto& argument : arguments) {
  440. AllocatingMemoryStream stream;
  441. Wasm::Printer { stream }.print(argument);
  442. if (first)
  443. first = false;
  444. else
  445. argument_builder.append(", "sv);
  446. auto buffer = ByteBuffer::create_uninitialized(stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
  447. stream.read_until_filled(buffer).release_value_but_fixme_should_propagate_errors();
  448. argument_builder.append(StringView(buffer).trim_whitespace());
  449. }
  450. dbgln("[wasm runtime] Stub function {} was called with the following arguments: {}", name, argument_builder.to_deprecated_string());
  451. Vector<Wasm::Value> result;
  452. result.ensure_capacity(type.results().size());
  453. for (auto& result_type : type.results())
  454. result.append(Wasm::Value { result_type, 0ull });
  455. return Wasm::Result { move(result) };
  456. },
  457. type));
  458. exports.set(entry, *address);
  459. }
  460. linker.link(exports);
  461. }
  462. auto link_result = linker.finish();
  463. if (link_result.is_error()) {
  464. warnln("Linking main module failed");
  465. print_link_error(link_result.error());
  466. return 1;
  467. }
  468. auto result = machine.instantiate(parse_result.value(), link_result.release_value());
  469. if (result.is_error()) {
  470. warnln("Module instantiation failed: {}", result.error().error);
  471. return 1;
  472. }
  473. auto module_instance = result.release_value();
  474. auto launch_repl = [&] {
  475. Wasm::Configuration config { machine.store() };
  476. Wasm::Expression expression { {} };
  477. config.set_frame(Wasm::Frame {
  478. *module_instance,
  479. Vector<Wasm::Value> {},
  480. expression,
  481. 0,
  482. });
  483. Wasm::Instruction instr { Wasm::Instructions::nop };
  484. Wasm::InstructionPointer ip { 0 };
  485. g_continue = false;
  486. pre_interpret_hook(config, ip, instr);
  487. };
  488. auto print_func = [&](auto const& address) {
  489. Wasm::FunctionInstance* fn = machine.store().get(address);
  490. g_stdout->write_until_depleted(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()).release_value_but_fixme_should_propagate_errors();
  491. if (fn) {
  492. g_stdout->write_until_depleted(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes()).release_value_but_fixme_should_propagate_errors();
  493. fn->visit(
  494. [&](Wasm::WasmFunction const& func) {
  495. Wasm::Printer printer { *g_stdout, 3 };
  496. g_stdout->write_until_depleted(" type:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
  497. printer.print(func.type());
  498. g_stdout->write_until_depleted(" code:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
  499. printer.print(func.code());
  500. },
  501. [](Wasm::HostFunction const&) {});
  502. }
  503. };
  504. if (print) {
  505. // Now, let's dump the functions!
  506. for (auto& address : module_instance->functions()) {
  507. print_func(address);
  508. }
  509. }
  510. if (shell_mode) {
  511. launch_repl();
  512. return 0;
  513. }
  514. if (!exported_function_to_execute.is_empty()) {
  515. Optional<Wasm::FunctionAddress> run_address;
  516. Vector<Wasm::Value> values;
  517. for (auto& entry : module_instance->exports()) {
  518. if (entry.name() == exported_function_to_execute) {
  519. if (auto addr = entry.value().get_pointer<Wasm::FunctionAddress>())
  520. run_address = *addr;
  521. }
  522. }
  523. if (!run_address.has_value()) {
  524. warnln("No such exported function, sorry :(");
  525. return 1;
  526. }
  527. auto instance = machine.store().get(*run_address);
  528. VERIFY(instance);
  529. if (instance->has<Wasm::HostFunction>()) {
  530. warnln("Exported function is a host function, cannot run that yet");
  531. return 1;
  532. }
  533. for (auto& param : instance->get<Wasm::WasmFunction>().type().parameters()) {
  534. if (values_to_push.is_empty())
  535. values.append(Wasm::Value { param, 0ull });
  536. else
  537. values.append(Wasm::Value { param, values_to_push.take_last() });
  538. }
  539. if (print) {
  540. outln("Executing ");
  541. print_func(*run_address);
  542. outln();
  543. }
  544. auto result = machine.invoke(g_interpreter, run_address.value(), move(values)).assert_wasm_result();
  545. if (debug)
  546. launch_repl();
  547. if (result.is_trap()) {
  548. warnln("Execution trapped: {}", result.trap().reason);
  549. } else {
  550. if (!result.values().is_empty())
  551. warnln("Returned:");
  552. for (auto& value : result.values()) {
  553. g_stdout->write_until_depleted(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
  554. g_printer->print(value);
  555. }
  556. }
  557. }
  558. }
  559. return 0;
  560. }