@@ -38,6 +38,7 @@ class ThreadSafeContext;
3838namespace clang {
3939
4040class CompilerInstance ;
41+ class CodeGenerator ;
4142
4243class IncrementalExecutor ;
4344class IncrementalParser ;
@@ -78,30 +79,25 @@ class IncrementalCompilerBuilder {
7879 llvm::StringRef CudaSDKPath;
7980};
8081
81- class Interpreter ;
82- // / Provides a callback class allowing to listen to interpreter events and to
83- // / specialize some operations.
84- class InterpreterCallbacks {
85- Interpreter &Interp;
86-
87- public:
88- InterpreterCallbacks (Interpreter &I) : Interp(I) {}
89- virtual ~InterpreterCallbacks ();
90- virtual void ProcessingTopLevelStmtDecl (TopLevelStmtDecl *D);
91- };
82+ class IncrementalAction ;
83+ class InProcessPrintingASTConsumer ;
9284
9385// / Provides top-level interfaces for incremental compilation and execution.
9486class Interpreter {
95- friend Value;
87+ friend class Value ;
88+ friend InProcessPrintingASTConsumer;
9689
9790 std::unique_ptr<llvm::orc::ThreadSafeContext> TSCtx;
98- std::unique_ptr<InterpreterCallbacks> InterpreterCB;
91+ // / Long-lived, incremental parsing action.
92+ std::unique_ptr<IncrementalAction> Act;
9993 std::unique_ptr<IncrementalParser> IncrParser;
10094 std::unique_ptr<IncrementalExecutor> IncrExecutor;
10195
10296 // An optional parser for CUDA offloading
10397 std::unique_ptr<IncrementalParser> DeviceParser;
10498
99+ std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder;
100+
105101 unsigned InitPTUSize = 0 ;
106102
107103 // This member holds the last result of the value printing. It's a class
@@ -120,10 +116,15 @@ class Interpreter {
120116
121117 std::array<Expr *, 4 > ValuePrintingInfo = {0 };
122118
119+ // / When CodeGen is created the first llvm::Module gets cached in many places
120+ // / and we must keep it alive.
121+ std::unique_ptr<llvm::Module> CachedInCodeGenModule;
122+
123123protected:
124124 // Derived classes can use an extended interface of the Interpreter.
125125 Interpreter (std::unique_ptr<CompilerInstance> CI, llvm::Error &Err,
126- std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr );
126+ std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr ,
127+ std::unique_ptr<clang::ASTConsumer> Consumer = nullptr );
127128
128129 // Create the internal IncrementalExecutor, or re-create it after calling
129130 // ResetExecutor().
@@ -170,32 +171,29 @@ class Interpreter {
170171 llvm::Expected<llvm::orc::ExecutorAddr>
171172 getSymbolAddressFromLinkerName (llvm::StringRef LinkerName) const ;
172173
173- InterpreterCallbacks *getInterpreterCallbacks () {
174- return InterpreterCB.get ();
175- }
176- const InterpreterCallbacks *getInterpreterCallbacks () const {
177- return const_cast <Interpreter *>(this )->getInterpreterCallbacks ();
178- }
179- void setInterpreterCallbacks (std::unique_ptr<InterpreterCallbacks> CB) {
180- InterpreterCB = std::move (CB);
181- }
182-
183- llvm::Expected<Expr *> SynthesizeExpr (Expr *E);
184-
185174 std::unique_ptr<llvm::Module> GenModule ();
186175
187176private:
188177 size_t getEffectivePTUSize () const ;
189178 void markUserCodeStart ();
190179
191- std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder;
180+ // / @}
181+ // / @name Value and pretty printing support
182+ // / @{
192183
193184 std::string ValueDataToString (const Value &V);
194185 std::string ValueTypeToString (const Value &V) const ;
195186
187+ llvm::Expected<Expr *> AttachValuePrinting (Expr *E);
188+
196189 // When we deallocate clang::Value we need to run the destructor of the type.
197190 // This function forces emission of the needed dtor.
198191 llvm::Expected<llvm::orc::ExecutorAddr> CompileDtorCall (CXXRecordDecl *CXXRD);
192+
193+ // / @}
194+ // / @name Code generation
195+ // / @{
196+ CodeGenerator *getCodeGen () const ;
199197};
200198} // namespace clang
201199
0 commit comments