| 80 | ranges::copy(args, buf); |
| 81 | return {buf, args.size()}; |
| 82 | } |
| 83 | |
| 84 | object_ptr<CompilationInfo> |
| 85 | CompilationDatabase::save_compilation_info(llvm::StringRef file, |
| 86 | llvm::StringRef directory, |
| 87 | llvm::ArrayRef<const char*> arguments) { |
| 88 | assert(!arguments.empty() && "arguments must contain at least the driver"); |
| 89 | |
| 90 | /// clang's option table cannot parse nvcc's own spellings, and the loop |
| 91 | /// below discards what it cannot parse — rewrite them first so the |
| 92 | /// regular classification applies. |
| 93 | std::vector<std::string> nvcc_translated; |
| 94 | llvm::SmallVector<const char*, 32> nvcc_arguments; |
| 95 | if(Toolchain::driver_family(arguments[0]) == CompilerFamily::NVCC) { |
| 96 | nvcc_translated = translate_nvcc_command(arguments, directory); |
| 97 | for(auto& arg: nvcc_translated) |
| 98 | nvcc_arguments.push_back(arg.c_str()); |
| 99 | arguments = nvcc_arguments; |
| 100 | } |
| 101 | |
| 102 | auto render_arg = [&](auto& out, const kota::option::ParsedArg& arg) { |
| 103 | auto cb = [&](std::string_view s) { |
| 104 | out.push_back(strings.save(s).data()); |
| 105 | }; |
| 106 | option::table().render(arg, cb); |
| 107 | }; |
| 108 | |
| 109 | llvm::SmallVector<const char*, 32> canonical_args; |
| 110 | llvm::SmallVector<const char*, 16> patch_args; |
| 111 | |
| 112 | /// Driver goes into canonical. |
| 113 | canonical_args.push_back(strings.save(arguments[0]).data()); |
| 114 | |
| 115 | bool remove_pch = false; |
| 116 | |
| 117 | std::vector<std::string> parse_args(arguments.begin() + 1, arguments.end()); |
| 118 | auto options = kota::option::ParseOptions{.dash_dash_parsing = true, |
| 119 | .visibility = default_visibility(arguments[0])}; |
| 120 | for(auto& result: option::table().parse(parse_args, options)) { |
| 121 | if(!result.has_value()) { |
| 122 | auto& err = result.error(); |
| 123 | LOG_WARN("parse error at index {}: {} when parse: {}", err.index, err.message, file); |
| 124 | continue; |
| 125 | } |
| 126 | auto& arg = *result; |
| 127 | auto id = arg.id; |
| 128 | |
| 129 | /// Discard options irrelevant to frontend. |
| 130 | if(is_discarded_option(id)) { |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | /// Discard codegen-only options. |
| 135 | if(is_codegen_option(id)) { |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | /// Handle CMake's Xclang PCH workaround: |
nothing calls this directly
no test coverage detected