From 2b42a5c3bdd4316a6caf6aab887598086ca22c75 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 18 Feb 2015 23:16:09 +0000 Subject: [PATCH] [Orc][Kaleidoscope] Fix a fixme - no reason we can't use C++14 in the tutorials. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229765 91177308-0d34-0410-b5e6-96231b3b80d8 --- examples/Kaleidoscope/Orc/fully_lazy/toy.cpp | 25 +++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp b/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp index 3ef97998a2d..9210dd1f3bb 100644 --- a/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp +++ b/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp @@ -1253,18 +1253,21 @@ public: // Step 4) Add the module containing the stub to the JIT. auto H = addModule(C.takeM()); - // Step 5) Set the compile and update actions for the callback. The compile - // action will IRGen and Codegen the function. The update action - // will update FunctionBodyPointer to point at the newly compiled - // function pointer. + // Step 5) Set the compile and update actions for the callback. // - // FIXME: Use generalized capture for FnAST when we get C++14 support. - FunctionAST *FnASTPtr = FnAST.release(); - CallbackInfo.setCompileAction([this,FnASTPtr](){ - std::unique_ptr Fn(FnASTPtr); - auto H = addModule(IRGen(Session, *Fn)); - return findSymbolIn(H, Fn->Proto->Name).getAddress(); - }); + // The compile action will IRGen the function and add it to the JIT, then + // request its address, which will trigger codegen. Since we don't need the + // AST after this, we pass ownership of the AST into the compile action: + // compile actions (and update actions) are deleted after they're run, so + // this will free the AST for us. + // + // The update action will update FunctionBodyPointer to point at the newly + // compiled function. + CallbackInfo.setCompileAction( + [this,Fn = std::shared_ptr(std::move(FnAST))](){ + auto H = addModule(IRGen(Session, *Fn)); + return findSymbolIn(H, Fn->Proto->Name).getAddress(); + }); CallbackInfo.setUpdateAction( CompileCallbacks.getLocalFPUpdater(H, Mangle(BodyPtrName))); } -- 2.34.1