@@ -411,26 +411,6 @@ reexports(JITDylib &SourceJD, SymbolAliasMap Aliases,
411
411
Expected<SymbolAliasMap>
412
412
buildSimpleReexportsAliasMap (JITDylib &SourceJD, const SymbolNameSet &Symbols);
413
413
414
- // / ReexportsGenerator can be used with JITDylib::setGenerator to automatically
415
- // / re-export a subset of the source JITDylib's symbols in the target.
416
- class ReexportsGenerator {
417
- public:
418
- using SymbolPredicate = std::function<bool (SymbolStringPtr)>;
419
-
420
- // / Create a reexports generator. If an Allow predicate is passed, only
421
- // / symbols for which the predicate returns true will be reexported. If no
422
- // / Allow predicate is passed, all symbols will be exported.
423
- ReexportsGenerator (JITDylib &SourceJD, bool MatchNonExported = false ,
424
- SymbolPredicate Allow = SymbolPredicate());
425
-
426
- Expected<SymbolNameSet> operator ()(JITDylib &JD, const SymbolNameSet &Names);
427
-
428
- private:
429
- JITDylib &SourceJD;
430
- bool MatchNonExported = false ;
431
- SymbolPredicate Allow;
432
- };
433
-
434
414
// / Represents the state that a symbol has reached during materialization.
435
415
enum class SymbolState : uint8_t {
436
416
Invalid, // / No symbol should be in this state.
@@ -502,8 +482,12 @@ class JITDylib {
502
482
friend class ExecutionSession ;
503
483
friend class MaterializationResponsibility ;
504
484
public:
505
- using GeneratorFunction = std::function<Expected<SymbolNameSet>(
506
- JITDylib &Parent, const SymbolNameSet &Names)>;
485
+ class DefinitionGenerator {
486
+ public:
487
+ virtual ~DefinitionGenerator ();
488
+ virtual Expected<SymbolNameSet>
489
+ tryToGenerate (JITDylib &Parent, const SymbolNameSet &Names) = 0 ;
490
+ };
507
491
508
492
using AsynchronousSymbolQuerySet =
509
493
std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
@@ -519,13 +503,20 @@ class JITDylib {
519
503
// / Get a reference to the ExecutionSession for this JITDylib.
520
504
ExecutionSession &getExecutionSession () const { return ES; }
521
505
522
- // / Set a definition generator. If set, whenever a symbol fails to resolve
523
- // / within this JITDylib, lookup and lookupFlags will pass the unresolved
524
- // / symbols set to the definition generator. The generator can optionally
525
- // / add a definition for the unresolved symbols to the dylib.
526
- void setGenerator (GeneratorFunction DefGenerator) {
527
- this ->DefGenerator = std::move (DefGenerator);
528
- }
506
+ // / Adds a definition generator to this JITDylib and returns a referenece to
507
+ // / it.
508
+ // /
509
+ // / When JITDylibs are searched during lookup, if no existing definition of
510
+ // / a symbol is found, then any generators that have been added are run (in
511
+ // / the order that they were added) to potentially generate a definition.
512
+ template <typename GeneratorT>
513
+ GeneratorT &addGenerator (std::unique_ptr<GeneratorT> DefGenerator);
514
+
515
+ // / Remove a definition generator from this JITDylib.
516
+ // /
517
+ // / The given generator must exist in this JITDylib's generators list (i.e.
518
+ // / have been added and not yet removed).
519
+ void removeGenerator (DefinitionGenerator &G);
529
520
530
521
// / Set the search order to be used when fixing up definitions in JITDylib.
531
522
// / This will replace the previous search order, and apply to any symbol
@@ -744,7 +735,7 @@ class JITDylib {
744
735
SymbolTable Symbols;
745
736
UnmaterializedInfosMap UnmaterializedInfos;
746
737
MaterializingInfosMap MaterializingInfos;
747
- GeneratorFunction DefGenerator ;
738
+ std::vector<std::unique_ptr<DefinitionGenerator>> DefGenerators ;
748
739
JITDylibSearchList SearchOrder;
749
740
};
750
741
@@ -932,6 +923,14 @@ class ExecutionSession {
932
923
OutstandingMUs;
933
924
};
934
925
926
+ template <typename GeneratorT>
927
+ GeneratorT &JITDylib::addGenerator (std::unique_ptr<GeneratorT> DefGenerator) {
928
+ auto &G = *DefGenerator;
929
+ ES.runSessionLocked (
930
+ [&]() { DefGenerators.push_back (std::move (DefGenerator)); });
931
+ return G;
932
+ }
933
+
935
934
template <typename Func>
936
935
auto JITDylib::withSearchOrderDo (Func &&F)
937
936
-> decltype(F(std::declval<const JITDylibSearchList &>())) {
@@ -971,6 +970,27 @@ Error JITDylib::define(std::unique_ptr<MaterializationUnitType> &MU) {
971
970
});
972
971
}
973
972
973
+ // / ReexportsGenerator can be used with JITDylib::setGenerator to automatically
974
+ // / re-export a subset of the source JITDylib's symbols in the target.
975
+ class ReexportsGenerator : public JITDylib ::DefinitionGenerator {
976
+ public:
977
+ using SymbolPredicate = std::function<bool (SymbolStringPtr)>;
978
+
979
+ // / Create a reexports generator. If an Allow predicate is passed, only
980
+ // / symbols for which the predicate returns true will be reexported. If no
981
+ // / Allow predicate is passed, all symbols will be exported.
982
+ ReexportsGenerator (JITDylib &SourceJD, bool MatchNonExported = false ,
983
+ SymbolPredicate Allow = SymbolPredicate());
984
+
985
+ Expected<SymbolNameSet> tryToGenerate (JITDylib &JD,
986
+ const SymbolNameSet &Names) override ;
987
+
988
+ private:
989
+ JITDylib &SourceJD;
990
+ bool MatchNonExported = false ;
991
+ SymbolPredicate Allow;
992
+ };
993
+
974
994
// / Mangles symbol names then uniques them in the context of an
975
995
// / ExecutionSession.
976
996
class MangleAndInterner {
0 commit comments