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