parse C header files and transformation
Hello list, How to do some C header files parsing and automatic code transformation. like: parse this <sys/time.h> header file, and generate code for this API: int gettimeofday(struct timeval *tv, struct timezone *tz); generated code(automatically call the API, and dump the structure appropriately): void dump_time(void) { struct timeval tv = {0}; struct timezone tz = {0}; gettimeofday(&tv, &tz); printf("tv_sec: %d, tv_usec: %d\n", tv.tv_sec, tv.tv_usec); printf("tz_minuteswest: %d, tz_dsttime: %d\n", tz.tz_minuteswest, tz.tz_dsttime); } because I'm working on a SDK which has hundreds of API to set and get headware states. It'll will be very nice to write some haskell code to parse the header files and generate C code that can dump hardware state automatically. BR Ted
I have been looking at module Language.C(http://trac.sivity.net/language_c), a complete C99 parser and pretty printer. It has some similar examples in darcs repo (darcs get http://code.haskell.org/language-c), like ComputeSize.hs, but haven't figured out a way. On Mon, Mar 4, 2013 at 8:33 PM, Ted Feng <artisdom@gmail.com> wrote:
Hello list,
How to do some C header files parsing and automatic code transformation.
like:
parse this <sys/time.h> header file, and generate code for this API:
int gettimeofday(struct timeval *tv, struct timezone *tz);
generated code(automatically call the API, and dump the structure appropriately):
void dump_time(void) { struct timeval tv = {0}; struct timezone tz = {0};
gettimeofday(&tv, &tz); printf("tv_sec: %d, tv_usec: %d\n", tv.tv_sec, tv.tv_usec); printf("tz_minuteswest: %d, tz_dsttime: %d\n", tz.tz_minuteswest, tz.tz_dsttime); }
because I'm working on a SDK which has hundreds of API to set and get headware states. It'll will be very nice to write some haskell code to parse the header files and generate C code that can dump hardware state automatically.
BR Ted
participants (1)
-
Ted Feng