MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / CanonicalizeFlag

Function CanonicalizeFlag

tools/opt/opt.cpp:716–739  ·  view source on GitHub ↗

Canonicalize the flag in |argv[argi]| of the form '--pass arg' into '--pass=arg'. The optimizer only accepts arguments to pass names that use the form '--pass_name=arg'. Since spirv-opt also accepts the other form, this function makes the necessary conversion. Pass flags that require additional arguments should be handled here. Note that additional arguments should be given as a single string.

Source from the content-addressed store, hash-verified

714// "argv[argi]=argv[argi + 1]" is returned. Otherwise, |argi| is unmodified and
715// the string "|argv[argi]|" is returned.
716std::string CanonicalizeFlag(const char** argv, int argc, int* argi) {
717 const char* cur_arg = argv[*argi];
718 const char* next_arg = (*argi + 1 < argc) ? argv[*argi + 1] : nullptr;
719 std::ostringstream canonical_arg;
720 canonical_arg << cur_arg;
721
722 // NOTE: DO NOT ADD NEW FLAGS HERE.
723 //
724 // These flags are supported for backwards compatibility. When adding new
725 // passes that need extra arguments in its command-line flag, please make them
726 // use the syntax "--pass_name[=pass_arg].
727 if (0 == strcmp(cur_arg, "--set-spec-const-default-value") ||
728 0 == strcmp(cur_arg, "--loop-fission") ||
729 0 == strcmp(cur_arg, "--loop-fusion") ||
730 0 == strcmp(cur_arg, "--loop-unroll-partial") ||
731 0 == strcmp(cur_arg, "--loop-peeling-threshold")) {
732 if (next_arg) {
733 canonical_arg << "=" << next_arg;
734 ++(*argi);
735 }
736 }
737
738 return canonical_arg.str();
739}
740
741// Parses command-line flags. |argc| contains the number of command-line flags.
742// |argv| points to an array of strings holding the flags. |optimizer| is the

Callers 1

ParseFlagsFunction · 0.85

Calls 1

strMethod · 0.45

Tested by

no test coverage detected