Proof of concept: Groveller tool(aka jextract)
Henry Jen
henry.jen at oracle.com
Thu Sep 25 05:48:48 UTC 2014
Hi,
Attached please find a proof of concept of the jextract tool,
implemented on top of jnr-clang(with local modification to add couple
more function binding to libclang).
With FindSymbol, one can give a header file and specified symbols to be
extracted into a interface, and the tool will generate jnr code to
describe the interface and all struct involved, it's not perfect but
demonstrate what can be done.
Test.java is the code manualy written to load the native library, in it
is some code to show we can call to some native functions, in this POC,
__xstat, gettimeofday and puts.
The work flow to get Test.java working is like this,
1. Create a headers.h to include needed header files, in this example
following three are needed for above functions,
#include <stdio.h>
#include <sys/stat.h>
#include <sys/time.h>
2. `java -cp $CP -Xint FindSymbol headers.h __xstat gettimeofday puts`
This will generate a couple java files, MiniLibC.java is the interface
and other java files describe struct used in those functions, in this
case, Stat.java, Timespec.java, Timeval.java and Timezone.java.
$CP will have jnr-clang and all its dependencies.
3. Build generated code and Test.java with javac, will need jnr-ffi in
classpath.
4. Run the Test with java -cp $CP Test <file to get stat>. $CP will have
jnr-ffi and its dependencies.
The POC is tested on Linux with libclang installed.
Like I said, this is a proof of concept, but I would expect simple C
functions can be quickly generated in the same manner and called
properly. Certainly there are many places can be improved, this is just
a start.
Now questions is when will we be able to see jnr code get into panama
repo? Assuming that's required for this POC to continue evolving within
panama repo.
Cheers,
Henry
More information about the panama-dev
mailing list