[LLVMdev] Problems with getelementptr

Anders Alexandersson anders.alexandersson at student.htu.se
Mon May 3 07:13:02 PDT 2004


Hello!

I'm having trouble with pointer traversing. I have a design as follows:  class -> map -> classFunctions

Starting with a pointer to the class, I want to get a pointer to a classFunction via a pointer to the map.

I can't get that function pointer!

How shall I think to get the traversing right (see code below)? Is it something with the fact that I am using only pointers in my structs?

Best regards
Anders

; My user defined function
int %puts_kernel(sbyte* %string)
{
        %tmp.0 = call int (sbyte*, ...)* %printf( sbyte* %string )
        ret int 0

}

;the map and the class. The class is called "Kernel".
"myKernelMap" = type {int (sbyte*)*}
"Kernel" = type {"myKernelMap"*}

;Allocating...OK
"myKernelMapInstance" = malloc "myKernelMap"
%myKernel = malloc "Kernel"

;Assigning the map to the class...OK
"myKernelMapPTR" = getelementptr "Kernel"* %myKernel, long 0, ubyte 0
store "myKernelMap"* "myKernelMapInstance", "myKernelMap"** "myKernelMapPTR"

; Try to get pointer to the functionPointer in the map, NOT OK! :-(
%puts_kernelPTR = getelementptr "Kernel"* %myKernel, long 0, ubyte 0, long 0, ubyte 0
store int (sbyte*)* %puts_kernel, int (sbyte*)** %puts_kernelPTR

;Want to call the function with a string
%tmp.11 = load int (sbyte*)** %puts_kernelPTR
%result = call int %tmp.11(sbyte* %string)

----------------------------------------------------------------
Anders Alexandersson
Masters student at the special year of Software Engineering, HTU Trollhättan
E-mail: anders.alexandersson at student.htu.se




More information about the llvm-dev mailing list