[Haskell-cafe] Does this library already exist? template haskell + generate/compile C code + dlopen
newton at mit.edu
Wed Jun 8 18:58:17 CEST 2011
The Nikola GPU programming system has a very neat, flexible approach to how
you compile the EDSL-generated code. You can do it dynamically, calling
nvcc at runtime, OR it can play a trick where it calls nvcc at compile time
(via template haskell) and caches the result in a string literal within the
TH-generated Haskell code.
That is a pretty cool trick IMHO. Moreover, we can do that with any tool
that generates C code or native code, as follows:
At compile time, via Template Haskell:
1. call tool which creates C code
2. create temp files and call C compiler
3. load resulting object file as a bytestring and store it as a string
Then at runtime:
1. put bytestring back into a file
2. call dlopen
3. call dlsym, get FunPtr, voila!
Anyway, I was going to put together a simple library that encapsulates the
above steps. Such a library could be used, for example, in making this
stencil compiler project <http://people.csail.mit.edu/yuantang/> available
to Haskell users as well as C++ users. (The compiler is written in Haskell
But first I thought I'd ask if this already exists. Also, is there a
better way to do it? In particular, is there any way to get static linking
to work, rather than the silliness with strings, tempfiles, and dlopen.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe