| 112 | // clang-format on |
| 113 | |
| 114 | int main(int, const char** argv) { |
| 115 | if (!flags::Parse(argv)) { |
| 116 | return 1; |
| 117 | } |
| 118 | if (flags::h.value() || flags::help.value()) { |
| 119 | printf(kHelpTextFmt, argv[0], argv[0]); |
| 120 | return 0; |
| 121 | } |
| 122 | if (flags::version.value()) { |
| 123 | printf("%s\n", spvSoftwareVersionDetailsString()); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | if (flags::positional_arguments.size() != 1) { |
| 128 | std::cerr << "Expected exactly one input file." << std::endl; |
| 129 | return 1; |
| 130 | } |
| 131 | if (flags::entrypoint.value() || flags::compiler_cmd.value()) { |
| 132 | std::cerr << "Unimplemented flags." << std::endl; |
| 133 | return 1; |
| 134 | } |
| 135 | |
| 136 | std::vector<uint32_t> binary; |
| 137 | if (!ReadBinaryFile(flags::positional_arguments[0].c_str(), &binary)) { |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | if (flags::source.value()) { |
| 142 | std::unordered_map<std::string, std::string> sourceCode; |
| 143 | if (!ExtractSourceFromModule(binary, &sourceCode)) { |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | if (flags::list.value()) { |
| 148 | for (const auto & [ filename, source ] : sourceCode) { |
| 149 | printf("%s\n", filename.c_str()); |
| 150 | } |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | const bool outputToConsole = flags::outdir.value() == "-"; |
| 155 | |
| 156 | if (outputToConsole) { |
| 157 | for (const auto & [ filename, source ] : sourceCode) { |
| 158 | std::cout << filename << ":" << std::endl |
| 159 | << source << std::endl |
| 160 | << std::endl; |
| 161 | } |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | const std::filesystem::path outdirPath(flags::outdir.value()); |
| 166 | if (!OutputSourceFiles(sourceCode, outdirPath.string(), |
| 167 | flags::force.value())) { |
| 168 | return 1; |
| 169 | } |
| 170 | } |
| 171 |
nothing calls this directly
no test coverage detected