[C2hs] a new C parser

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Feb 19 07:51:58 EST 2007

On Mon, 2007-02-19 at 03:23 +0100, Jelmer Vernooij wrote:
> On Mon, 2007-02-19 at 01:43 +0000, Duncan Coutts wrote:
> > I posted some time ago about a plan to make a new C parser that would
> > correctly deal with the typedef problem and then to try some automated
> > testing by making a gcc wrapper. I've now mostly done that.
> > 
> > Currently I can parse almost all of the Linux kernel, glibc, GNU
> > binutils, and the C code produced by ghc when it compiles itself.
> [...]
> > Then I need to start merging the new parser into the darcs version of
> > c2hs. I'll try and do this as a series of small understandable patches.
> > 
> > If anyone wants to play with the code I've got right now rather than
> > wait for things to get merged then do say. I could put up a tarball.

> That's very nice! Problems with the current C parser are blocking me
> from actually using c2hs at the moment (and I failed at my attempts to
> fix it). If there's anything I could test, please let me know.

So I've been compiling various packages with this cc-wrapper. I could do
with some help on that. Mind you, Gentoo makes this fairly easy to do.
If you've got other sources you want it to work with then now's a good
time to try. Here's the tarball of my current tree:


(Tarball unpacks to just c2hs/)

to test:

$ cd c2hs/c2hs/c/tests
$ make cc-wrapper
$ mkdir /tmp/c2hs
$ export C2HS_CC_LOGDIR=/tmp/c2hs

then invoke cc-wrapper as if it were gcc.

look in $C2HS_CC_LOGDIR for a .log file and error .report files.
The .report files are self contained, that is they should have all the
info necessary for someone else to reproduce the failure (since it
contains the full pre-processed source).

An improved cc-wrapper script would be helpful though. I wrote it in
Haskell however there's a problem there. GHC's I/O libs always put all
file descriptors into non-blocking mode and since the
blocking/non-blocking status on open file descriptors is shared between
processes (silly design imho) this can cause problems. For some
compilations (especially when compiling glibc for some reason) I get
this error from cc1 about stdout being "temporarily unavailable".

I think the solution is to use a bash (or whatever) script to capture
the gcc args, parse them and pass them onto the Haskell C parser prog.

Patches welcome :-)


More information about the C2hs mailing list