Skip to content

Commit 8a51908

Browse files
committed
Store state
1 parent a1639ef commit 8a51908

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
10711071
Module *getCurrentNamedModule() const { return CurrentCXXNamedModule; }
10721072

10731073
TranslationUnitDecl *getTranslationUnitDecl() const {
1074+
assert(TUDecl->getMostRecentDecl() == TUDecl &&
1075+
"The active TU is not current one!");
10741076
return TUDecl->getMostRecentDecl();
10751077
}
10761078
void addTranslationUnitDecl() {

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ class Interpreter {
140140
public:
141141
virtual ~Interpreter();
142142

143+
class SynthesizingCodeRAII {
144+
145+
};
146+
147+
SynthesizingCodeRAII EnterCodeSynthesisScope() {
148+
149+
}
150+
143151
static llvm::Expected<std::unique_ptr<Interpreter>>
144152
create(std::unique_ptr<CompilerInstance> CI);
145153
static llvm::Expected<std::unique_ptr<Interpreter>>
@@ -187,6 +195,8 @@ class Interpreter {
187195

188196
std::unique_ptr<llvm::Module> GenModule();
189197

198+
199+
190200
private:
191201
size_t getEffectivePTUSize() const;
192202
void markUserCodeStart();

clang/lib/Interpreter/IncrementalExecutor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
6868

6969
IncrementalExecutor::~IncrementalExecutor() {}
7070

71-
llvm::Error IncrementalExecutor::addModule(std::unique_ptr<llvm::Module> &M) {
72-
return Jit->addIRModule({std::move(M), TSCtx});
73-
}
74-
7571
llvm::Error IncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
7672
llvm::orc::ResourceTrackerSP RT =
7773
Jit->getMainJITDylib().createResourceTracker();

clang/lib/Interpreter/IncrementalExecutor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class IncrementalExecutor {
5252
llvm::orc::LLJITBuilder &JITBuilder, llvm::Error &Err);
5353
~IncrementalExecutor();
5454

55-
llvm::Error addModule(std::unique_ptr<llvm::Module> &M);
5655
llvm::Error addModule(PartialTranslationUnit &PTU);
5756
llvm::Error removeModule(PartialTranslationUnit &PTU);
5857
llvm::Error runCtors() const;

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ llvm::Error Interpreter::CreateExecutor() {
410410

411411
void Interpreter::ResetExecutor() { IncrExecutor.reset(); }
412412

413-
414413
llvm::Error Interpreter::ExecuteModule(std::unique_ptr<llvm::Module> &M) {
415414
if (!IncrExecutor) {
416415
auto Err = CreateExecutor();

clang/lib/Interpreter/ValuePrinter.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ static std::string PrintEnum(const Value &V) {
115115
IsFirst = false;
116116
}
117117
}
118-
119-
llvm::SmallString<24> ApStr;
120-
AP.toString(ApStr, /*Radix=*/10);
121-
122-
SS << " : " << PrintQualType(Ctx, ED->getIntegerType()) << " " << ApStr;
118+
llvm::SmallString<64> APStr;
119+
AP.toString(APStr, /*Radix=*/10);
120+
SS << " : " << PrintQualType(Ctx, ED->getIntegerType()) << " " << APStr;
123121
return Str;
124122
}
125123

@@ -279,10 +277,15 @@ static llvm::Expected<llvm::orc::ExecutorAddr> CompileDecl(Interpreter &Interp,
279277
ASTConsumer &Consumer = Interp.getCompilerInstance()->getASTConsumer();
280278
Consumer.HandleTopLevelDecl(DeclGroupRef(D));
281279
Interp.getCompilerInstance()->getSema().PerformPendingInstantiations();
282-
Consumer.HandleTranslationUnit(Interp.getASTContext());
280+
ASTContext &C = Interp.getASTContext();
281+
TranslationUnitDecl *TUPart = C.getTranslationUnitDecl();
282+
assert(!TUPart->containsDecl(D) && "Decl already added!");
283+
TUPart->addDecl(D);
284+
Consumer.HandleTranslationUnit(C);
283285

284286
if (std::unique_ptr<llvm::Module> M = Interp.GenModule()) {
285-
if (llvm::Error Err = Interp.ExecuteModule(M))
287+
PartialTranslationUnit PTU = {TUPart, std::move(M)};
288+
if (llvm::Error Err = Interp.Execute(PTU))
286289
return Err;
287290
ASTNameGenerator ASTNameGen(Interp.getASTContext());
288291
llvm::Expected<llvm::orc::ExecutorAddr> AddrOrErr =

0 commit comments

Comments
 (0)