[Orc][Kaleidoscope] More tutorial cleanup, a little extra debugging output.
llvm-svn: 230705
diff --git a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
index 2e65756..9c93d12 100644
--- a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
@@ -1185,7 +1185,8 @@
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);
}
@@ -1201,7 +1202,7 @@
// 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; } );
@@ -1231,20 +1232,18 @@
// 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;
- // 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);
- // 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();
}
@@ -1310,7 +1309,7 @@
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();