| 222 | } |
| 223 | |
| 224 | CompileHelper::IRData::IRData(const std::vector<SourceFileData> &SourceFiles) |
| 225 | : Path(getUniqueFilePath(getTmpDirPath(), "link", "bc")) { |
| 226 | |
| 227 | std::vector<std::string> IRPaths; |
| 228 | for (auto &SourceFile : SourceFiles) { |
| 229 | auto IRPath = compile(SourceFile); |
| 230 | if (IRPath.empty()) { |
| 231 | IRPaths.clear(); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | IRPaths.emplace_back(IRPath); |
| 236 | } |
| 237 | if (IRPaths.empty()) |
| 238 | return; |
| 239 | |
| 240 | auto CMD = "llvm-link -o " + Path; |
| 241 | for (auto &IRPath : IRPaths) |
| 242 | CMD += " " + IRPath; |
| 243 | if (system(CMD.c_str()) || !fs::exists(Path)) |
| 244 | return; |
| 245 | |
| 246 | for (auto &IRPath : IRPaths) { |
| 247 | if (!fs::exists(IRPath)) |
| 248 | continue; |
| 249 | fs::remove(IRPath); |
| 250 | } |
| 251 | |
| 252 | Ctx = std::make_unique<llvm::LLVMContext>(); |
| 253 | if (!Ctx) |
| 254 | return; |
| 255 | |
| 256 | llvm::SMDiagnostic SMDiag; |
| 257 | Ptr = llvm::parseIRFile(Path, SMDiag, *Ctx); |
| 258 | if (!Ptr && fs::exists(Path)) |
| 259 | fs::remove(Path); |
| 260 | } |
| 261 | |
| 262 | CompileHelper::IRData::~IRData() { |
| 263 |
nothing calls this directly
no test coverage detected