Displaying 10 results from an estimated 10 matches for "puts_kernelptr".
2004 Apr 02
2
[LLVMdev] Function pointers
OK, I solved it all ( so far :) ), mixing in some load-instructions and called on the result of that, which worked.
Here is the skeleton-code:
%kernel = type { int ()* }
int puts_kernel(){...}
; main()
%theKernel = malloc %kernel
%puts_kernelPTR = getelementptr %kernel* %theKernel, long 1, ubyte 0
store int ()* %puts_kernel, int ()** %puts_kernelPTR
%tmp.11 = load int ()** %puts_kernelPTR
%tmp.2 = call int %tmp.11()
free %kernel* %theKernel
:-)
Anders
-----Original Message-----
From: Anders Alexandersson <an...
2004 Apr 02
0
[LLVMdev] Function pointers
...> OK, I solved it all ( so far :) ), mixing in some load-instructions and
> called on the result of that, which worked.
>
> Here is the skeleton-code:
>
> %kernel = type { int ()* }
>
> int puts_kernel(){...}
>
> ; main()
>
> %theKernel = malloc %kernel
> %puts_kernelPTR = getelementptr %kernel* %theKernel, long 1, ubyte 0
>
> store int ()* %puts_kernel, int ()** %puts_kernelPTR
> %tmp.11 = load int ()** %puts_kernelPTR
>
> %tmp.2 = call int %tmp.11()
>
> free %kernel* %theKernel
Yup, that's close. You should be able to use an alloca inst...
2004 May 03
2
[LLVMdev] Problems with getelementptr
...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)
----------------------...
2004 May 11
2
[LLVMdev] Problems accessing structs
...oc "myKernelMap"
"myKernel" = malloc "Kernel"
"myKernelMapPTR" = getelementptr "Kernel"* "myKernel", long 0, ubyte 0
store "myKernelMap"* "myKernelMapInstance", "myKernelMap"** "myKernelMapPTR"
"puts_kernelPTRPTRMAP" = getelementptr "Kernel"* "myKernel", long 0, ubyte 0
"puts_kernelPTRMAP" = load "myKernelMap"** "puts_kernelPTRPTRMAP"
"puts_kernelPTR" = getelementptr "myKernelMap"* "puts_kernelPTRMAP", long 0, ubyte 0
st...
2004 May 05
2
[LLVMdev] Not allowed to reuse variables?
Hello!
I am having trouble with identifiers:
%tmpFunction = load int ()** %puts_kernelPTR
...
%tmpFunction = load int ()** %puts_kernelPTR
generates
Redefinition of value named 'tmpFunction' in the 'int () *' type plane!
Is it not allowed to reuse variables? Is there some way to do it?
Anders
----------------------------------------------------------------
Anders A...
2004 May 11
0
[LLVMdev] Problems accessing structs
..."
> "myKernel" = malloc "Kernel"
> "myKernelMapPTR" = getelementptr "Kernel"* "myKernel", long 0, ubyte 0
> store "myKernelMap"* "myKernelMapInstance", "myKernelMap"** "myKernelMapPTR"
> "puts_kernelPTRPTRMAP" = getelementptr "Kernel"* "myKernel", long 0, ubyte 0
> "puts_kernelPTRMAP" = load "myKernelMap"** "puts_kernelPTRPTRMAP"
> "puts_kernelPTR" = getelementptr "myKernelMap"* "puts_kernelPTRMAP", long 0,...
2004 May 03
0
[LLVMdev] Problems with getelementptr
...he '%myKernelMap*' in the Kernel type.
> store "myKernelMap"* "myKernelMapInstance", "myKernelMap"** "myKernelMapPTR"
And this stores the pointer as you would expect.
> ; 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
Okay, here you're getting into trouble. myKernel is of type Kernel, which
doesn't contain a pointer to a function. In your case, you need to
actually emit a load to get to the structure in question, something...
2004 May 05
0
[LLVMdev] Not allowed to reuse variables?
On Wed, May 05, 2004 at 03:35:46PM +0200, Anders Alexandersson wrote:
> %tmpFunction = load int ()** %puts_kernelPTR
> ...
> %tmpFunction = load int ()** %puts_kernelPTR
>
> generates
>
> Redefinition of value named 'tmpFunction' in the 'int () *' type plane!
>
> Is it not allowed to reuse variables? Is there some way to do it?
LLVM uses the Static Single Assignment (S...
2004 Apr 02
0
[LLVMdev] Function pointers
I solved that one by substituting alloca into malloc, and forwarded the problem to actually calling the %puts_kernel function via my newly created function pointer.
This works:
%tmp.1 = call int %puts_kernel()
This:
%tmp.2 = call int %puts_kernelPTR()
issues error:
"Reference to an invalid definition: 'puts_kernelPTR' of type 'int () *'"
How do I call the function using the function pointer?
Anders
-----Original Message-----
From: Anders Alexandersson <anders.alexandersson at student.htu.se>
To: llvmdev at...
2004 Apr 02
0
[LLVMdev] Function pointers
So, here comes the next question:)
Now the program compiles, but crashes when run, "Segmentation fault".
%kernel = type { int ()* }
int %puts_kernel()
{
ret int 0
}
int %main() {
%theKernel = alloca %kernel
%puts_kernelPTR = getelementptr %kernel* %theKernel, long 1, ubyte 0
store int ()* %puts_kernel, int ()** %puts_kernelPTR
ret int 0
}
I want to learn how to achieve the mechanisms in this C code:
#include <stdio.h>
int DoIt(void);
int DoIt(void){
return 0;
}
int main()
{
int (*pt2Functio...