summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2015-02-08 21:03:30 +0000
committerDavid Blaikie <dblaikie@gmail.com>2015-02-08 21:03:30 +0000
commit9c4c23b32e21df81de54e1f51df93ec77a55acfb (patch)
tree48a314e6009798095fc8eda70eeca90d5dc1f22c /llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
parentbae16b3f5355e50bb4a0d5265f5304142a6afc0b (diff)
downloadbcm5719-llvm-9c4c23b32e21df81de54e1f51df93ec77a55acfb.tar.gz
bcm5719-llvm-9c4c23b32e21df81de54e1f51df93ec77a55acfb.zip
Kaleidoscope-Orc: Reuse the IRGen utility function in later chapters, and remove an unused parameter.
llvm-svn: 228543
Diffstat (limited to 'llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp')
-rw-r--r--llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp b/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
index e1e259da76c..2963f30e2ed 100644
--- a/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
@@ -1124,6 +1124,19 @@ Function *FunctionAST::IRGen(IRGenContext &C) const {
// Top-Level parsing and JIT Driver
//===----------------------------------------------------------------------===//
+static std::unique_ptr<llvm::Module> IRGen(SessionContext &S,
+ const FunctionAST &F) {
+ IRGenContext C(S);
+ auto LF = F.IRGen(C);
+ if (!LF)
+ return nullptr;
+#ifndef MINIMAL_STDERR_OUTPUT
+ fprintf(stderr, "Read function definition:");
+ LF->dump();
+#endif
+ return C.takeM();
+}
+
class KaleidoscopeJIT {
public:
typedef ObjectLinkingLayer<> ObjLayerT;
@@ -1166,20 +1179,19 @@ public:
// If we don't find 'Name' in the JIT, see if we have some AST
// for it.
- if (!Session.FunctionDefs.count(Name))
+ auto DefI = Session.FunctionDefs.find(Name);
+ if (DefI == Session.FunctionDefs.end())
return 0;
// We have AST for 'Name'. IRGen it, add it to the JIT, and
// return the address for it.
- IRGenContext C(Session);
- {
- // Take ownership of the AST: We can release the memory as
- // soon as we've IRGen'd it.
- auto FuncAST = std::move(Session.FunctionDefs[Name]);
- FuncAST->IRGen(C);
- }
-
- addModule(C.takeM());
+ // FIXME: What happens if IRGen fails?
+ addModule(IRGen(Session, *DefI->second));
+
+ // Remove the function definition's AST now that we've
+ // finished with it.
+ Session.FunctionDefs.erase(DefI);
+
return getMangledSymbolAddress(Name);
},
[](const std::string &S) { return 0; } );
OpenPOWER on IntegriCloud