mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-27 13:40:33 +03:00
1.8 KiB
1.8 KiB
Dynamic compile bind
D part
- bind function returns
BindPtr
object which is reference counted internally BindPtr
haveopCall
andtoDelegate
methods to call directly or create D delegate- On creation
BindPtr
callvoid registerBindPayload(void* handle, void* originalFunc, void* exampleFunc, const ParamSlice* params, size_t paramsSize)
functionhandle
- pointer to pointer to function, which uniquely identifies bind object, actual function pointer to generated code will be written here duringcompileDynamicCode
call.originalFunc
- pointer tooriginal
function, this is special function, generated insidebind
, which just forwards parameter to user function or delegate, this function always have@dynamicCompileEmit
attribute, so jit runtime will fins it even if user function wasn't marked@dynamicCompile
exampleFunc
- special function with parameters matched to original user function, runtime will extracts parameters types from it, never calledparams
- list of slices to bind parameters, will be null for placeholdersparamsSize
- items count inparams
- On destruction
BindPtr
callvoid unregisterBindPayload(void* handle);
handle
- same handle as passed inregisterBindPayload
previously
Runtime part
registerBindPayload
add handle to internal list- During
compileDynamicCode
generateBind
- Generate new function for each bind handle- Parse each bind parameter into llvm constant using existing
parseInitializer
(previously used for@dynamicCompileConst
) - If parameter is function pointer from another bind handle, replace with direct reference to that function
- Generate call to original function (this call will be inlined)
- Parse each bind parameter into llvm constant using existing
- Generate and optimize module as usual
applyBind
- update handles to generated code