<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Ok, I've managed to get pointer to a function via ptr attribute of
Function object.<br>
<br>
now<br>
(defun foo (x) x)<br>
(defun bar (x) (funcall 'foo x))<br>
<br>
generates the following LLVM IR:<br>
<br>
define i8* @foo(i8* %x) {<br>
entry:<br>
ret i8* %x<br>
}<br>
<br>
define i8* @bar(i8* %x) {<br>
entry:<br>
%0 = alloca [4 x i8], align 1<br>
store [4 x i8] c"foo\00", [4 x i8]* %0, align 1<br>
%calltmp = call i8* @intern([4 x i8]* %0)<br>
%ptrfind = call i8* @find_llvm_function(i8* %calltmp)<br>
%cast = bitcast i8* %ptrfind to i8* (i8*)*<br>
%calltmp1 = call i8* %cast(i8* %x)<br>
ret i8* %calltmp1<br>
}<br>
<br>
except last two lines (with %calltmp1 and ret) do not actually get
generated, because generation of call instruction fails with<br>
error 'argument is neither a function nor a function pointer'<br>
<br>
I thought, that bitcast instruction before should do the trick of
transforming return value of @find_llvm_function<br>
(which is a wrapper around Python code, which searches in the Module
object) to a function pointer.<br>
Also, there is some possibility, that I got the guts of
@find_llvm_function wrong, however, in that case I'd expect,<br>
that code would still be generated, and problems would manifestate
only at runtime.<br>
<br>
Any ideas what am I doing wrong?<br>
<br>
<div class="moz-cite-prefix">On 05/04/2014 05:24 PM, Alexander
Potapenko wrote:<br>
</div>
<blockquote
cite="mid:CAG_fn=W9M0jB6NA3YVHebvhjA9ONG33aBjE8dc=EZbSFYMH28Q@mail.gmail.com"
type="cite">
<p dir="ltr">Don't you have the same problem with other atoms,
e.g. variable names?<br>
This sounds like something that should be implemented in the
language's runtime library.</p>
<div class="gmail_quote">On May 4, 2014 7:15 PM, "Alexander
Popolitov" <<a moz-do-not-send="true"
href="mailto:popolit@gmail.com">popolit@gmail.com</a>>
wrote:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi everyone!<br>
<br>
I'm trying to implement lisp's funcall function, which roughly
calls a function, name of which<br>
is known only at runtime.<br>
I know that LLVM IR 'call' directive can accept function
pointers, so the question is,<br>
is there a simple way to get a function pointer from a
function name (represented as e.g. i8*)?<br>
<br>
BTW, I'm using llvmpy to generate LLVM IR, so if there is a
way to do this using llvmpy tools, it would also do.<br>
<br>
Yours sincerely,<br>
Alexandr Popolitov<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a moz-do-not-send="true" href="mailto:LLVMdev@cs.uiuc.edu"
target="_blank">LLVMdev@cs.uiuc.edu</a> <a
moz-do-not-send="true" href="http://llvm.cs.uiuc.edu"
target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>