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

Function ReadFlagsFromFile

tools/opt/opt.cpp:615–652  ·  view source on GitHub ↗

Reads command-line flags the file specified in |oconfig_flag|. This string is assumed to have the form "-Oconfig=FILENAME". This function parses the string and extracts the file name after the '=' sign. Flags found in |FILENAME| are pushed at the end of the vector |file_flags|. This function returns true on success, false on failure.

Source from the content-addressed store, hash-verified

613//
614// This function returns true on success, false on failure.
615bool ReadFlagsFromFile(const char* oconfig_flag,
616 std::vector<std::string>* file_flags) {
617 const char* fname = strchr(oconfig_flag, '=');
618 if (fname == nullptr || fname[0] != '=') {
619 spvtools::Errorf(opt_diagnostic, nullptr, {}, "Invalid -Oconfig flag %s",
620 oconfig_flag);
621 return false;
622 }
623 fname++;
624
625 std::ifstream input_file;
626 input_file.open(fname);
627 if (input_file.fail()) {
628 spvtools::Errorf(opt_diagnostic, nullptr, {}, "Could not open file '%s'",
629 fname);
630 return false;
631 }
632
633 std::string line;
634 while (std::getline(input_file, line)) {
635 // Ignore empty lines and lines starting with the comment marker '#'.
636 if (line.length() == 0 || line[0] == '#') {
637 continue;
638 }
639
640 // Tokenize the line. Add all found tokens to the list of found flags. This
641 // mimics the way the shell will parse whitespace on the command line. NOTE:
642 // This does not support quoting and it is not intended to.
643 std::istringstream iss(line);
644 while (!iss.eof()) {
645 std::string flag;
646 iss >> flag;
647 file_flags->push_back(flag);
648 }
649 }
650
651 return true;
652}
653
654OptStatus ParseFlags(int argc, const char** argv,
655 spvtools::Optimizer* optimizer, const char** in_file,

Callers 1

ParseOconfigFlagFunction · 0.85

Calls 2

ErrorfFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected