[Orc][Kaleidoscope] More tutorial cleanup, a little extra debugging output.
authorLang Hames <lhames@gmail.com>
Thu, 26 Feb 2015 23:52:42 +0000 (23:52 +0000)
committerLang Hames <lhames@gmail.com>
Thu, 26 Feb 2015 23:52:42 +0000 (23:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230705 91177308-0d34-0410-b5e6-96231b3b80d8

examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp

index 2e65756049f23281caafe5333c79c8d9cf4d7dfd..9c93d128cc8e0f665d7061a6da3864911da68d0a 100644 (file)
@@ -1185,7 +1185,8 @@ public:
     return MangledName;
   }
 
     return MangledName;
   }
 
-  void addFunctionDefinition(std::unique_ptr<FunctionAST> FnAST) {
+  void addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
+    std::cerr << "Adding AST: " << FnAST->Proto->Name << "\n";
     FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST);
   }
 
     FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST);
   }
 
@@ -1201,7 +1202,7 @@ public:
 
                   // If we don't already have a definition of 'Name' then search
                   // the ASTs.
 
                   // If we don't already have a definition of 'Name' then search
                   // the ASTs.
-                  return searchUncompiledASTs(Name);
+                  return searchFunctionASTs(Name);
                 },
                 [](const std::string &S) { return 0; } );
 
                 },
                 [](const std::string &S) { return 0; } );
 
@@ -1231,20 +1232,18 @@ private:
 
   // This method searches the FunctionDefs map for a definition of 'Name'. If it
   // finds one it generates a stub for it and returns the address of the stub.
 
   // This method searches the FunctionDefs map for a definition of 'Name'. If it
   // finds one it generates a stub for it and returns the address of the stub.
-  TargetAddress searchUncompiledASTs(const std::string &Name) {
+  TargetAddress searchFunctionASTs(const std::string &Name) {
     auto DefI = FunctionDefs.find(Name);
     if (DefI == FunctionDefs.end())
       return 0;
 
     auto DefI = FunctionDefs.find(Name);
     if (DefI == FunctionDefs.end())
       return 0;
 
-    // We have AST for 'Name'. IRGen a stub for it and add it to the JIT.
-    // FIXME: What happens if IRGen fails?
-    auto H = irGenStub(std::move(DefI->second));
-
-    // Remove the function definition's AST now that we're
-    // finished with it.
+    // Return the address of the stub.
+    // Take the FunctionAST out of the map.
+    auto FnAST = std::move(DefI->second);
     FunctionDefs.erase(DefI);
 
     FunctionDefs.erase(DefI);
 
-    // Return the address of the stub.
+    // IRGen the AST, add it to the JIT, and return the address for it.
+    auto H = irGenStub(std::move(FnAST));
     return findSymbolIn(H, Name).getAddress();
   }
 
     return findSymbolIn(H, Name).getAddress();
   }
 
@@ -1310,7 +1309,7 @@ private:
 static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
   if (auto F = ParseDefinition()) {
     S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
 static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
   if (auto F = ParseDefinition()) {
     S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
-    J.addFunctionDefinition(std::move(F));
+    J.addFunctionAST(std::move(F));
   } else {
     // Skip token for error recovery.
     getNextToken();
   } else {
     // Skip token for error recovery.
     getNextToken();
index d7744ece6554d49a1db920a63e39717a684d6fbc..388c3f9b7bdb448e74da411787ec00815e31fcf7 100644 (file)
@@ -1174,7 +1174,8 @@ public:
     return MangledName;
   }
 
     return MangledName;
   }
 
-  void addFunctionDefinition(std::unique_ptr<FunctionAST> FnAST) {
+  void addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
+    std::cerr << "Adding AST: " << FnAST->Proto->Name << "\n";
     FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST);
   }
 
     FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST);
   }
 
@@ -1190,7 +1191,7 @@ public:
 
                   // If we don't already have a definition of 'Name' then search
                   // the ASTs.
 
                   // If we don't already have a definition of 'Name' then search
                   // the ASTs.
-                  return searchUncompiledASTs(Name);
+                  return searchFunctionASTs(Name);
                 },
                 [](const std::string &S) { return 0; } );
 
                 },
                 [](const std::string &S) { return 0; } );
 
@@ -1216,21 +1217,17 @@ private:
 
   // This method searches the FunctionDefs map for a definition of 'Name'. If it
   // finds one it generates a stub for it and returns the address of the stub.
 
   // This method searches the FunctionDefs map for a definition of 'Name'. If it
   // finds one it generates a stub for it and returns the address of the stub.
-  TargetAddress searchUncompiledASTs(const std::string &Name) {
+  TargetAddress searchFunctionASTs(const std::string &Name) {
     auto DefI = FunctionDefs.find(Name);
     if (DefI == FunctionDefs.end())
       return 0;
 
     auto DefI = FunctionDefs.find(Name);
     if (DefI == FunctionDefs.end())
       return 0;
 
-    // We have AST for 'Name'. IRGen it, add it to the JIT, and
-    // return the address for it.
-    // FIXME: What happens if IRGen fails?
-    auto H = addModule(IRGen(Session, *DefI->second));
-
-    // Remove the function definition's AST now that we're
-    // finished with it.
+    // Take the FunctionAST out of the map.
+    auto FnAST = std::move(DefI->second);
     FunctionDefs.erase(DefI);
 
     FunctionDefs.erase(DefI);
 
-    // Return the address of the function.
+    // IRGen the AST, add it to the JIT, and return the address for it.
+    auto H = addModule(IRGen(Session, *FnAST));
     return findSymbolIn(H, Name).getAddress();
   }
 
     return findSymbolIn(H, Name).getAddress();
   }
 
@@ -1246,7 +1243,7 @@ private:
 static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
   if (auto F = ParseDefinition()) {
     S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
 static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
   if (auto F = ParseDefinition()) {
     S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
-    J.addFunctionDefinition(std::move(F));
+    J.addFunctionAST(std::move(F));
   } else {
     // Skip token for error recovery.
     getNextToken();
   } else {
     // Skip token for error recovery.
     getNextToken();