|
25 | 25 | #if CLANG_VERSION_MAJOR >= 19 |
26 | 26 | #include "clang/Sema/Redeclaration.h" |
27 | 27 | #endif |
| 28 | +#include "clang/Serialization/ModuleFileExtension.h" |
28 | 29 |
|
29 | 30 | #include "llvm/ADT/DenseMap.h" |
30 | 31 | #include "llvm/ADT/SmallSet.h" |
|
34 | 35 | #include "llvm/Support/Compiler.h" |
35 | 36 | #include "llvm/Support/Error.h" |
36 | 37 | #include "llvm/Support/TargetSelect.h" |
| 38 | +#include "llvm/Support/raw_ostream.h" |
| 39 | + |
| 40 | +#include <utility> |
| 41 | +#include <vector> |
37 | 42 |
|
38 | 43 | namespace clang { |
39 | 44 | class CompilerInstance; |
@@ -136,19 +141,28 @@ class Interpreter { |
136 | 141 | private: |
137 | 142 | std::unique_ptr<clang::Interpreter> inner; |
138 | 143 |
|
| 144 | + Interpreter(std::unique_ptr<clang::Interpreter> CI) : inner(std::move(CI)) {} |
| 145 | + |
139 | 146 | public: |
140 | | - Interpreter(int argc, const char* const* argv, const char* llvmdir = 0, |
141 | | - const std::vector<std::shared_ptr<clang::ModuleFileExtension>>& |
142 | | - moduleExtensions = {}, |
143 | | - void* extraLibHandle = 0, bool noRuntime = true) { |
| 147 | + static std::unique_ptr<Interpreter> |
| 148 | + create(int argc, const char* const* argv, const char* llvmdir = nullptr, |
| 149 | + const std::vector<std::shared_ptr<clang::ModuleFileExtension>>& |
| 150 | + moduleExtensions = {}, |
| 151 | + void* extraLibHandle = nullptr, bool noRuntime = true) { |
144 | 152 | // Initialize all targets (required for device offloading) |
145 | 153 | llvm::InitializeAllTargetInfos(); |
146 | 154 | llvm::InitializeAllTargets(); |
147 | 155 | llvm::InitializeAllTargetMCs(); |
148 | 156 | llvm::InitializeAllAsmPrinters(); |
149 | 157 |
|
150 | 158 | std::vector<const char*> vargs(argv + 1, argv + argc); |
151 | | - inner = compat::createClangInterpreter(vargs); |
| 159 | + auto CI = compat::createClangInterpreter(vargs); |
| 160 | + if (!CI) { |
| 161 | + llvm::errs() << "Interpreter creation failed\n"; |
| 162 | + return nullptr; |
| 163 | + } |
| 164 | + |
| 165 | + return std::unique_ptr<Interpreter>(new Interpreter(std::move(CI))); |
152 | 166 | } |
153 | 167 |
|
154 | 168 | ~Interpreter() {} |
|
0 commit comments