rmansfield created this revision.
rmansfield added a reviewer: lhames.
rmansfield requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106889

Files:
  clang/examples/clang-interpreter/main.cpp

Index: clang/examples/clang-interpreter/main.cpp
===================================================================
--- clang/examples/clang-interpreter/main.cpp
+++ clang/examples/clang-interpreter/main.cpp
@@ -50,31 +50,37 @@
 
 class SimpleJIT {
 private:
-  ExecutionSession ES;
+  std::unique_ptr<ExecutionSession> ES;
   std::unique_ptr<TargetMachine> TM;
   const DataLayout DL;
-  MangleAndInterner Mangle{ES, DL};
-  JITDylib &MainJD{ES.createBareJITDylib("<main>")};
-  RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr};
-  IRCompileLayer CompileLayer{ES, ObjectLayer,
-                              std::make_unique<SimpleCompiler>(*TM)};
+  MangleAndInterner Mangle;
+  JITDylib &MainJD;
+  RTDyldObjectLinkingLayer ObjectLayer;
+  IRCompileLayer CompileLayer;
 
   static std::unique_ptr<SectionMemoryManager> createMemMgr() {
     return std::make_unique<SectionMemoryManager>();
   }
 
   SimpleJIT(
-      std::unique_ptr<TargetMachine> TM, DataLayout DL,
+      std::unique_ptr<ExecutionSession> ES, std::unique_ptr<TargetMachine> TM,
+      DataLayout DL,
       std::unique_ptr<DynamicLibrarySearchGenerator> ProcessSymbolsGenerator)
-      : TM(std::move(TM)), DL(std::move(DL)) {
+      : ES(std::move(ES)), TM(std::move(TM)), DL(std::move(DL)),
+        Mangle(*this->ES, this->DL),
+        MainJD(this->ES->createBareJITDylib("<main>")),
+        ObjectLayer(*this->ES, createMemMgr),
+        CompileLayer(*this->ES, ObjectLayer,
+                     std::make_unique<SimpleCompiler>(*this->TM)) {
+
     llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
     MainJD.addGenerator(std::move(ProcessSymbolsGenerator));
   }
 
 public:
   ~SimpleJIT() {
-    if (auto Err = ES.endSession())
-      ES.reportError(std::move(Err));
+    if (auto Err = ES->endSession())
+      ES->reportError(std::move(Err));
   }
 
   static Expected<std::unique_ptr<SimpleJIT>> Create() {
@@ -86,6 +92,12 @@
     if (!TM)
       return TM.takeError();
 
+    auto EPC = SelfExecutorProcessControl::Create();
+    if (!EPC)
+      return EPC.takeError();
+
+    auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
+
     auto DL = (*TM)->createDataLayout();
 
     auto ProcessSymbolsGenerator =
@@ -95,8 +107,9 @@
     if (!ProcessSymbolsGenerator)
       return ProcessSymbolsGenerator.takeError();
 
-    return std::unique_ptr<SimpleJIT>(new SimpleJIT(
-        std::move(*TM), std::move(DL), std::move(*ProcessSymbolsGenerator)));
+    return std::unique_ptr<SimpleJIT>(
+        new SimpleJIT(std::move(ES), std::move(*TM), std::move(DL),
+                      std::move(*ProcessSymbolsGenerator)));
   }
 
   const TargetMachine &getTargetMachine() const { return *TM; }
@@ -106,7 +119,7 @@
   }
 
   Expected<JITEvaluatedSymbol> findSymbol(const StringRef &Name) {
-    return ES.lookup({&MainJD}, Mangle(Name));
+    return ES->lookup({&MainJD}, Mangle(Name));
   }
 
   Expected<JITTargetAddress> getSymbolAddress(const StringRef &Name) {
@@ -125,11 +138,11 @@
 int main(int argc, const char **argv) {
   // This just needs to be some symbol in the binary; C++ doesn't
   // allow taking the address of ::main however.
-  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
   std::string Path = GetExecutablePath(argv[0], MainAddr);
   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
   TextDiagnosticPrinter *DiagClient =
-    new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+      new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
 
   IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
@@ -204,7 +217,7 @@
   if (Clang.getHeaderSearchOpts().UseBuiltinIncludes &&
       Clang.getHeaderSearchOpts().ResourceDir.empty())
     Clang.getHeaderSearchOpts().ResourceDir =
-      CompilerInvocation::GetResourcesPath(argv[0], MainAddr);
+        CompilerInvocation::GetResourcesPath(argv[0], MainAddr);
 
   // Create and execute the frontend to generate an LLVM bitcode module.
   std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D106889: [examples]... Ryan Mansfield via Phabricator via cfe-commits

Reply via email to