Thanks!
Problem is though, that the Ruby compiler is integrated in the compilation of the program being executed, to be able to parse & compile dynamic code at run-time. Therefore the calls to ExecutionEngine::getPointerToGlobal(F) need to be made in LLVM code. Here is a detailed simplistic example in pseudocode of what we want to do:
First Ruby code is entered at run-time, received as a string, parsed and compiled into the following code:
%-----------------------------------------------------
; External function
declare int %printf(sbyte*, ...)
; Custom function
int %puts_kernel( sbyte* %string )
{
%tmp.0 = call int (sbyte*, ...)* %printf( sbyte* %string )
ret int 0
}
%-----------------------------------------------------
This code is represented in the string variable
%dynamically_compiled_function_code below:
%-----------------------------------------------------
%dynamically_compiled_function_code = internal constant [LENGTH x sbyte] c"--String with the function code--\0A\00"
; Table of function pointer(s)
%kernel = type { int ( sbyte* )* }
int %main() {
; Create the kernel in memory, and get pointer to first function pointer
%theKernel = malloc %kernel
%FirstFunctionPTR = getelementptr %kernel* %theKernel, long 0, ubyte 0
;Load code
%myNewFunction = %getPointerToGlobal(%dynamically_compiled_function_code)
; Write memory address of myNewFunction() into kernel struct
store RETURNTYPE (PARAMTYPE*)* %myNewFunction, RETURNTYPE (PARAMTYPE*)** %FirstFunctionPTR
;Any code using first function element in %kernel is now_
;using dynamically updated function!?
ret int 0
}
%-----------------------------------------------------
The questionmark is at this pseudocode row:
%myNewFunction = %getPointerToGlobal(%dynamically_compiled_function_code)
Is there an llvm version of the getPointerToGlobal() function as outlined, and can the %myNewFunction pointer be used as described?
Also, does the getPointerToGlobal() take human readable code (.ll) or only binary byte code (.bc)? Is there a specification of how to write binary byte code directly, so we do not have to externally call the llvm-as utility?
Best regards
Anders