MCPcopy Create free account
hub / github.com/clice-io/clice / save_compilation_info

Method save_compilation_info

src/command/command.cpp:82–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 ranges::copy(args, buf);
81 return {buf, args.size()};
82}
83
84object_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:

Callers

nothing calls this directly

Calls 12

default_visibilityFunction · 0.85
is_discarded_optionFunction · 0.85
is_codegen_optionFunction · 0.85
is_xclang_optionFunction · 0.85
is_user_content_optionFunction · 0.85
is_include_path_optionFunction · 0.85
joinFunction · 0.85
renderMethod · 0.80
emptyMethod · 0.45
saveMethod · 0.45
parseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected