- // 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 (uint64_t Addr = getMangledSymbolAddress(Name))
- return Addr;
-
- // If we don't find 'Name' in the JIT, see if we have some AST
- // for it.
- if (!Session.FunctionDefs.count(Name))
- return 0;
-
- // We have AST for 'Name'. IRGen it, add it to the JIT, and
- // return the address for it.
- IRGenContext C(Session);
- {
- // Take ownership of the AST: We can release the memory as
- // soon as we've IRGen'd it.
- auto FuncAST = std::move(Session.FunctionDefs[Name]);
- FuncAST->IRGen(C);
- }
-
- addModule(C.takeM());
- return getMangledSymbolAddress(Name);
- },
- [](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));