Parses command-line flags. |argc| contains the number of command-line flags. |argv| points to an array of strings holding the flags. |optimizer| is the Optimizer instance used to optimize the program. On return, this function stores the name of the input program in |in_file|. The name of the output file in |out_file|. The return value indicates whether optimization should continue and a status co
| 747 | // optimization should continue and a status code indicating an error or |
| 748 | // success. |
| 749 | OptStatus ParseFlags(int argc, const char** argv, |
| 750 | spvtools::Optimizer* optimizer, const char** in_file, |
| 751 | const char** out_file, |
| 752 | spvtools::ValidatorOptions* validator_options, |
| 753 | spvtools::OptimizerOptions* optimizer_options) { |
| 754 | std::vector<std::string> pass_flags; |
| 755 | bool preserve_interface = false; |
| 756 | for (int argi = 1; argi < argc; ++argi) { |
| 757 | const char* cur_arg = argv[argi]; |
| 758 | if ('-' == cur_arg[0]) { |
| 759 | if (0 == strcmp(cur_arg, "--version")) { |
| 760 | spvtools::Logf(opt_diagnostic, SPV_MSG_INFO, nullptr, {}, "%s\n", |
| 761 | spvSoftwareVersionDetailsString()); |
| 762 | return {OPT_STOP, 0}; |
| 763 | } else if (0 == strcmp(cur_arg, "--help") || 0 == strcmp(cur_arg, "-h")) { |
| 764 | PrintUsage(argv[0]); |
| 765 | return {OPT_STOP, 0}; |
| 766 | } else if (0 == strcmp(cur_arg, "-o")) { |
| 767 | if (!*out_file && argi + 1 < argc) { |
| 768 | *out_file = argv[++argi]; |
| 769 | } else { |
| 770 | PrintUsage(argv[0]); |
| 771 | return {OPT_STOP, 1}; |
| 772 | } |
| 773 | } else if ('\0' == cur_arg[1]) { |
| 774 | // Setting a filename of "-" to indicate stdin. |
| 775 | if (!*in_file) { |
| 776 | *in_file = cur_arg; |
| 777 | } else { |
| 778 | spvtools::Error(opt_diagnostic, nullptr, {}, |
| 779 | "More than one input file specified"); |
| 780 | return {OPT_STOP, 1}; |
| 781 | } |
| 782 | } else if (0 == strncmp(cur_arg, "-Oconfig=", sizeof("-Oconfig=") - 1)) { |
| 783 | OptStatus status = |
| 784 | ParseOconfigFlag(argv[0], cur_arg, optimizer, in_file, out_file, |
| 785 | validator_options, optimizer_options); |
| 786 | if (status.action != OPT_CONTINUE) { |
| 787 | return status; |
| 788 | } |
| 789 | } else if (0 == strcmp(cur_arg, "--skip-validation")) { |
| 790 | optimizer_options->set_run_validator(false); |
| 791 | } else if (0 == strcmp(cur_arg, "--print-all")) { |
| 792 | optimizer->SetPrintAll(&std::cerr); |
| 793 | } else if (0 == strcmp(cur_arg, "--preserve-bindings")) { |
| 794 | optimizer_options->set_preserve_bindings(true); |
| 795 | } else if (0 == strcmp(cur_arg, "--preserve-spec-constants")) { |
| 796 | optimizer_options->set_preserve_spec_constants(true); |
| 797 | } else if (0 == strcmp(cur_arg, "--time-report")) { |
| 798 | optimizer->SetTimeReport(&std::cerr); |
| 799 | } else if (0 == strcmp(cur_arg, "--relax-struct-store")) { |
| 800 | validator_options->SetRelaxStructStore(true); |
| 801 | } else if (0 == strncmp(cur_arg, "--max-id-bound=", |
| 802 | sizeof("--max-id-bound=") - 1)) { |
| 803 | auto split_flag = spvtools::utils::SplitFlagArgs(cur_arg); |
| 804 | // Will not allow values in the range [2^31,2^32). |
| 805 | uint32_t max_id_bound = |
| 806 | static_cast<uint32_t>(atoi(split_flag.second.c_str())); |
no test coverage detected