llvm.org GIT mirror llvm / e508109
[Orc][Kaleidoscope] More tutorial cleanup, a little extra debugging output. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230705 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 4 years ago
2 changed file(s) with 19 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
11841184 return MangledName;
11851185 }
11861186
1187 void addFunctionDefinition(std::unique_ptr FnAST) {
1187 void addFunctionAST(std::unique_ptr FnAST) {
1188 std::cerr << "Adding AST: " << FnAST->Proto->Name << "\n";
11881189 FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST);
11891190 }
11901191
12001201
12011202 // If we don't already have a definition of 'Name' then search
12021203 // the ASTs.
1203 return searchUncompiledASTs(Name);
1204 return searchFunctionASTs(Name);
12041205 },
12051206 [](const std::string &S) { return 0; } );
12061207
12301231
12311232 // This method searches the FunctionDefs map for a definition of 'Name'. If it
12321233 // finds one it generates a stub for it and returns the address of the stub.
1233 TargetAddress searchUncompiledASTs(const std::string &Name) {
1234 TargetAddress searchFunctionASTs(const std::string &Name) {
12341235 auto DefI = FunctionDefs.find(Name);
12351236 if (DefI == FunctionDefs.end())
12361237 return 0;
12371238
1238 // We have AST for 'Name'. IRGen a stub for it and add it to the JIT.
1239 // FIXME: What happens if IRGen fails?
1240 auto H = irGenStub(std::move(DefI->second));
1241
1242 // Remove the function definition's AST now that we're
1243 // finished with it.
1239 // Return the address of the stub.
1240 // Take the FunctionAST out of the map.
1241 auto FnAST = std::move(DefI->second);
12441242 FunctionDefs.erase(DefI);
12451243
1246 // Return the address of the stub.
1244 // IRGen the AST, add it to the JIT, and return the address for it.
1245 auto H = irGenStub(std::move(FnAST));
12471246 return findSymbolIn(H, Name).getAddress();
12481247 }
12491248
13091308 static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
13101309 if (auto F = ParseDefinition()) {
13111310 S.addPrototypeAST(llvm::make_unique(*F->Proto));
1312 J.addFunctionDefinition(std::move(F));
1311 J.addFunctionAST(std::move(F));
13131312 } else {
13141313 // Skip token for error recovery.
13151314 getNextToken();
11731173 return MangledName;
11741174 }
11751175
1176 void addFunctionDefinition(std::unique_ptr FnAST) {
1176 void addFunctionAST(std::unique_ptr FnAST) {
1177 std::cerr << "Adding AST: " << FnAST->Proto->Name << "\n";
11771178 FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST);
11781179 }
11791180
11891190
11901191 // If we don't already have a definition of 'Name' then search
11911192 // the ASTs.
1192 return searchUncompiledASTs(Name);
1193 return searchFunctionASTs(Name);
11931194 },
11941195 [](const std::string &S) { return 0; } );
11951196
12151216
12161217 // This method searches the FunctionDefs map for a definition of 'Name'. If it
12171218 // finds one it generates a stub for it and returns the address of the stub.
1218 TargetAddress searchUncompiledASTs(const std::string &Name) {
1219 TargetAddress searchFunctionASTs(const std::string &Name) {
12191220 auto DefI = FunctionDefs.find(Name);
12201221 if (DefI == FunctionDefs.end())
12211222 return 0;
12221223
1223 // We have AST for 'Name'. IRGen it, add it to the JIT, and
1224 // return the address for it.
1225 // FIXME: What happens if IRGen fails?
1226 auto H = addModule(IRGen(Session, *DefI->second));
1227
1228 // Remove the function definition's AST now that we're
1229 // finished with it.
1224 // Take the FunctionAST out of the map.
1225 auto FnAST = std::move(DefI->second);
12301226 FunctionDefs.erase(DefI);
12311227
1232 // Return the address of the function.
1228 // IRGen the AST, add it to the JIT, and return the address for it.
1229 auto H = addModule(IRGen(Session, *FnAST));
12331230 return findSymbolIn(H, Name).getAddress();
12341231 }
12351232
12451242 static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
12461243 if (auto F = ParseDefinition()) {
12471244 S.addPrototypeAST(llvm::make_unique(*F->Proto));
1248 J.addFunctionDefinition(std::move(F));
1245 J.addFunctionAST(std::move(F));
12491246 } else {
12501247 // Skip token for error recovery.
12511248 getNextToken();