@@ -311,6 +311,8 @@ class LLJITBuilderState {
311
311
312
312
using PlatformSetupFunction = unique_function<Expected<JITDylibSP>(LLJIT &J)>;
313
313
314
+ using NotifyCreatedFunction = std::function<Error(LLJIT &)>;
315
+
314
316
std::unique_ptr<ExecutorProcessControl> EPC;
315
317
std::unique_ptr<ExecutionSession> ES;
316
318
std::optional<JITTargetMachineBuilder> JTMB;
@@ -321,6 +323,7 @@ class LLJITBuilderState {
321
323
CompileFunctionCreator CreateCompileFunction;
322
324
unique_function<Error(LLJIT &)> PrePlatformSetup;
323
325
PlatformSetupFunction SetUpPlatform;
326
+ NotifyCreatedFunction NotifyCreated;
324
327
unsigned NumCompileThreads = 0 ;
325
328
326
329
// / Called prior to JIT class construcion to fix up defaults.
@@ -441,6 +444,16 @@ class LLJITBuilderSetters {
441
444
return impl ();
442
445
}
443
446
447
+ // / Set up a callback after successful construction of the JIT.
448
+ // /
449
+ // / This is useful to attach generators to JITDylibs or inject initial symbol
450
+ // / definitions.
451
+ SetterImpl &
452
+ setNotifyCreatedCallback (LLJITBuilderState::NotifyCreatedFunction Callback) {
453
+ impl ().NotifyCreated = std::move (Callback);
454
+ return impl ();
455
+ }
456
+
444
457
// / Set the number of compile threads to use.
445
458
// /
446
459
// / If set to zero, compilation will be performed on the execution thread when
@@ -474,6 +487,11 @@ class LLJITBuilderSetters {
474
487
std::unique_ptr<JITType> J (new JITType (impl (), Err));
475
488
if (Err)
476
489
return std::move (Err);
490
+
491
+ if (impl ().NotifyCreated )
492
+ if (Error Err = impl ().NotifyCreated (*J))
493
+ return Err;
494
+
477
495
return std::move (J);
478
496
}
479
497
0 commit comments