Kaleidoscope-Orc: Reuse the IRGen utility function in later chapters, and remove an unused parameter.
llvm-svn: 228543
diff --git a/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp b/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp
index 41abd27..1a2043f 100644
--- a/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp
@@ -1182,16 +1182,24 @@
LazyEmitLayerT LazyEmitLayer;
};
+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();
+}
+
static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
if (auto F = ParseDefinition()) {
- IRGenContext C(S);
- if (auto LF = F->IRGen(C)) {
-#ifndef MINIMAL_STDERR_OUTPUT
- std::cerr << "Read function definition:\n";
- LF->dump();
-#endif
- J.addModule(C.takeM());
+ if (auto M = IRGen(S, *F)) {
S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
+ J.addModule(std::move(M));
}
} else {
// Skip token for error recovery.