Kaleidoscope-Orc: Extract IRGen work into a utility function.
authorDavid Blaikie <dblaikie@gmail.com>
Sun, 8 Feb 2015 20:29:28 +0000 (20:29 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Sun, 8 Feb 2015 20:29:28 +0000 (20:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228539 91177308-0d34-0410-b5e6-96231b3b80d8

examples/Kaleidoscope/Orc/initial/toy.cpp

index 6daa8d5e92400dc7290c62b946edc3c31a1a5847..1b772259a19ef8f384e644e0fa81f6d761b68d4c 100644 (file)
@@ -1180,16 +1180,24 @@ private:
   CompileLayerT CompileLayer;
 };
 
-static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
-  if (auto F = ParseDefinition()) {
-    IRGenContext C(S);
-    if (auto LF = F->IRGen(C)) {
+static std::unique_ptr<llvm::Module>
+IRGen(KaleidoscopeJIT &J, SessionContext &S, const FunctionAST &F) {
+  IRGenContext C(S);
+  auto LF = F.IRGen(C);
+  if (!LF)
+    return nullptr;
 #ifndef MINIMAL_STDERR_OUTPUT
-      std::cerr << "Read function definition:\n";
-      LF->dump();
+  fprintf(stderr, "Read function definition:");
+  LF->dump();
 #endif
-      J.addModule(C.takeM());
+  return C.takeM();
+}
+
+static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
+  if (auto F = ParseDefinition()) {
+    if (auto M = IRGen(J, S, *F)) {
       S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
+      J.addModule(std::move(M));
     }
   } else {
     // Skip token for error recovery.