Compiling to ANSI C

Simon Marlow marlowsd at
Mon Nov 9 03:57:46 EST 2009

On 07/11/2009 18:48, Daniel Peebles wrote:
> You can use -fvia-C and -keep-hc-files but the generated C code is
> pretty platform-dependent (at least in terms of word sizes and so
> on... it may be possible to port across platforms with the same word
> sizes?), and probably won't help you cross-compile. It also doesn't
> look much like any c code any human would have written, and I think
> there are plans to deprecate the via-C compilation pathway eventually.
> If you are looking to add cross-compilation to GHC, the first thing
> I'd look at is detaching the choice of native code generator from the
> preprocessor and hooking it up to a front-end command-line option
> instead :)

We already compile in all the NCG backends, so that should be quite 
straightforward.  What's much harder is arranging the rest of your 
cross-compilation environment - assembler, linker etc., and making sure 
you're using the right configuration parameters from the target machine 
for the build.  It's generally easier to get an unregisterised port 
working first, and then use that to bootstrap an NCG/registerised version.

> Someone on IRC (his username is dumael, not sure what his
> real name is) has already been working on an ARM native code generator
> for GHC recently.

Interesting, I didn't know that.  There's also the iPhone GHC port, 
which is unregisterised, I believe.

 >The recent LLVM back-end development should also
> make it pretty simple to generate code for other platforms (especially
> if we have a nice way to pass front-end options to the code
> generators)

Definitely, I think that will be a nice side-effect of the LLVM backend.


More information about the Glasgow-haskell-users mailing list