| 431 | } |
| 432 | |
| 433 | void save(const program& p) const |
| 434 | { |
| 435 | auto* os = &std::cout; |
| 436 | std::ofstream fs; |
| 437 | if(not output.empty()) |
| 438 | { |
| 439 | fs.open(output, std::ios::binary); |
| 440 | os = &fs; |
| 441 | } |
| 442 | |
| 443 | std::string type = output_type; |
| 444 | if(type.empty()) |
| 445 | { |
| 446 | if(output.empty()) |
| 447 | type = "text"; |
| 448 | else |
| 449 | type = "binary"; |
| 450 | } |
| 451 | |
| 452 | if(type == "py") |
| 453 | p.print_py(*os); |
| 454 | else if(type == "cpp") |
| 455 | p.print_cpp(*os); |
| 456 | else if(type == "graphviz") |
| 457 | p.print_graph(*os, brief); |
| 458 | else if(type == "text") |
| 459 | *os << p << std::endl; |
| 460 | else if(type == "json") |
| 461 | *os << to_json_string(p.to_value()) << std::endl; |
| 462 | else if(type == "binary") |
| 463 | write(*os, save_buffer(p)); |
| 464 | else if(type == "netron") |
| 465 | *os << make_netron_output(p) << std::endl; |
| 466 | } |
| 467 | }; |
| 468 | |
| 469 | struct program_params |