Hi Reid,<br>It's just an example.<br>All the tested function are in bitcode.<br>The arguments might be complex and might not be converted back to GenericValue.<br><br><br><div class="gmail_quote">On Fri, Feb 11, 2011 at 10:45 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid.kleckner@gmail.com">reid.kleckner@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">If you know the prototype of f, you can just use getPointerToFunction<br>
and cast the result:<br>
<br>
// Let F be an llvm::Function* referring to 'f'.<br>
void (*f)(int*) = (void (*)(int*))JIT->getPointerToFunction(F);<br>
int a;<br>
f(&a);<br>
// read a<br>
<br>
I haven't compiled this, it's a guess at the usage from memory.<br>
<font color="#888888"><br>
Reid<br>
</font><div><div></div><div class="h5"><br>
On Fri, Feb 11, 2011 at 12:55 PM, Vu Le <<a href="mailto:vmle@ucdavis.edu">vmle@ucdavis.edu</a>> wrote:<br>
> Suppose I want to test the function f with zero.<br>
> f(int *t){<br>
>   *t = 2<br>
> }<br>
> What I did was that I create a wrapper<br>
> void Wrapper(){<br>
>   int a = 1;<br>
>   int *b = &a;<br>
>   f(b);<br>
>   // now I want to print the value of b<br>
>   // but I don't know how<br>
> }<br>
><br>
> Thanks.<br>
> Vu<br>
> On Thu, Feb 10, 2011 at 6:56 PM, Reid Kleckner <<a href="mailto:reid.kleckner@gmail.com">reid.kleckner@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Not sure what you mean here.  If you have a copy of that pointer in<br>
>> the caller of the wrapper function, you should be able to follow it to<br>
>> recover the modified value as normal.<br>
>><br>
>> Reid<br>
>><br>
>> On Thu, Feb 10, 2011 at 9:20 PM, Vu Le <<a href="mailto:vmle@ucdavis.edu">vmle@ucdavis.edu</a>> wrote:<br>
>> > Hi Reid,<br>
>> > If an argument is a pointer and the function changes the value it<br>
>> > pointed<br>
>> > to,<br>
>> > do you know how to get that updated value after executing the wrapper<br>
>> > function?<br>
>> ><br>
>> > Thanks.<br>
>> > Vu<br>
>> ><br>
>> > On Tue, Jan 11, 2011 at 2:40 PM, Reid Kleckner <<a href="mailto:reid.kleckner@gmail.com">reid.kleckner@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Tue, Jan 11, 2011 at 1:41 PM, Vu Le <<a href="mailto:vmle@ucdavis.edu">vmle@ucdavis.edu</a>> wrote:<br>
>> >> > Hi,<br>
>> >> > I want to implement a tool that probes a function with several input<br>
>> >> > and<br>
>> >> > records all the return output.<br>
>> >> > The function might have more than 1 return value (by reference<br>
>> >> > parameters).<br>
>> >> ><br>
>> >> > Does ExecutionEngine::runFunction() support function call with<br>
>> >> > complex<br>
>> >> > argument type?<br>
>> >> > If not, I guess that I have to create a wrapper function, prepare all<br>
>> >> > the<br>
>> >> > data, and call the original function.<br>
>> >> > Am I on the right track?<br>
>> >><br>
>> >> For functions with complicated parameters and return values,<br>
>> >> runFunction will generate a wrapper function that calls the function<br>
>> >> with the right arguments.  This is fairly expensive and leaks memory<br>
>> >> if called more than once for the same function.  If the type of the<br>
>> >> function is known, you can just use getPointerToFunction, cast that,<br>
>> >> and call it from C.<br>
>> >><br>
>> >> If it's not known but you want to call it many times with different<br>
>> >> arguments, you could generate a wrapper function responsible for<br>
>> >> unpacking your own datastructure describing the arguments and calling<br>
>> >> the function you are testing with those arguments.  Seems like you are<br>
>> >> on the right track there.<br>
>> >><br>
>> >> Reid<br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>