|
19 | 19 | #include "llvm/ADT/StringRef.h"
|
20 | 20 | #include "llvm/Support/CommandLine.h"
|
21 | 21 | #include "llvm/Support/FormatVariadic.h"
|
| 22 | +#include "llvm/Support/MemoryBuffer.h" |
22 | 23 | #include "llvm/Support/Regex.h"
|
23 | 24 | #include "llvm/Support/Signals.h"
|
24 | 25 | #include "llvm/Support/raw_ostream.h"
|
@@ -270,12 +271,24 @@ int main(int argc, const char **argv) {
|
270 | 271 | }
|
271 | 272 | }
|
272 | 273 | }
|
| 274 | + |
| 275 | + clang::tooling::ClangTool Tool(OptionsParser->getCompilations(), |
| 276 | + OptionsParser->getSourcePathList()); |
| 277 | + std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers; |
| 278 | + for (const auto &File : OptionsParser->getSourcePathList()) { |
| 279 | + auto Content = llvm::MemoryBuffer::getFile(File); |
| 280 | + if (!Content) { |
| 281 | + llvm::errs() << "Error: can't read file '" << File |
| 282 | + << "': " << Content.getError().message() << "\n"; |
| 283 | + return 1; |
| 284 | + } |
| 285 | + Buffers.push_back(std::move(Content.get())); |
| 286 | + Tool.mapVirtualFile(File, Buffers.back()->getBuffer()); |
| 287 | + } |
| 288 | + |
273 | 289 | auto HeaderFilter = headerFilter();
|
274 | 290 | if (!HeaderFilter)
|
275 | 291 | return 1; // error already reported.
|
276 | 292 | ActionFactory Factory(HeaderFilter);
|
277 |
| - return clang::tooling::ClangTool(OptionsParser->getCompilations(), |
278 |
| - OptionsParser->getSourcePathList()) |
279 |
| - .run(&Factory) || |
280 |
| - Errors != 0; |
| 293 | + return Tool.run(&Factory) || Errors != 0; |
281 | 294 | }
|
0 commit comments