- // new module. Create one that resolves symbols by looking back into the JIT.
- auto MM = createLookasideRTDyldMM<SectionMemoryManager>(
- [&](const std::string &Name) -> uint64_t {
- // First try to find 'Name' within the JIT.
- if (auto Symbol = findMangledSymbol(Name))
- return Symbol.getAddress();
-
- // If we don't find 'Name' in the JIT, see if we have some AST
- // for it.
- auto DefI = Session.FunctionDefs.find(Name);
- if (DefI == Session.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?
- addModule(IRGen(Session, *DefI->second));
-
- // Remove the function definition's AST now that we've
- // finished with it.
- Session.FunctionDefs.erase(DefI);
-
- return findMangledSymbol(Name).getAddress();
- },
- [](const std::string &S) { return 0; } );
-
- return LazyEmitLayer.addModuleSet(std::move(S), std::move(MM));
+ // new module. Create one that resolves symbols by looking back into the
+ // JIT.
+ auto Resolver = createLambdaResolver(
+ [&](const std::string &Name) {
+ // First try to find 'Name' within the JIT.
+ if (auto Symbol = findSymbol(Name))
+ return RuntimeDyld::SymbolInfo(Symbol.getAddress(),
+ Symbol.getFlags());
+
+ // If we don't already have a definition of 'Name' then search
+ // the ASTs.
+ return searchFunctionASTs(Name);
+ },
+ [](const std::string &S) { return nullptr; } );
+
+ return LazyEmitLayer.addModuleSet(singletonSet(std::move(M)),
+ make_unique<SectionMemoryManager>(),
+ std::move(Resolver));