FFIGEN (Foreign Function Interface GENerator) is a program suite that facilitates the writing of translators from C header files to foreign function interfaces for particular language implementations.
FFIGEN Manifesto and Overview
(HTML) (ps.gz, 26 KB)
FFIGEN User's Manual
(HTML) (ps.gz, 30 KB)
FFIGEN Back-end for Chez Scheme Version 5
(ps.gz, 52 KB)
There are three motivating observations behind FFIGEN. The first is that C header files are hard to parse because of the preprocessor, general syntactic grunge, and the problem of getting the data layouts right. The second is that foreign function interfaces differ widely and that translations to different FFIs can't be the same, yet should share work as much as possible. The third is that not all translations are suitable for all purposes; there may be multiple valid translations - each of which serves a different need - for any given language's FFI.
For these reasons, a translator from C header syntax to an FFI should have two parts: one target-independent front-end that translates from the header file into a rational intermediate form and which can be used with all translators, and a target-dependent back-end that translates from the intermediate form to an FFI for the target system, using a translation policy to guide the translation. This design nicely facilitates writing back-ends for multiple languages, multiple FFIs per language, and multiple policies per FFI.
FFIGEN is a system that implements the split-translation philosophy.
The current version of FFIGEN is available as a set of modifications to lcc version 3.4b; you also need to get the lcc sources. The FFIGEN distribution includes documentation on how to write back-ends and a documented example back-end for the FFI of Chez Scheme version 5.
This is a preliminary release of FFIGEN. It works, but is neither complete nor polished.
Click here to download the
full FFIGEN distribution. (148 KB)
This archive has not been updated with the fixes in the bug fix file (below).
Click here to download bug fixes up to February 13, 1996. (29 KB)
Fixes to chez.sch to handle structs/unions that are declared but not
defined; function pointers; and unsigned shorts (a typo). Also a minor fix
to policy.sch to remove gratuitous non-standard-ness (use of reverse! rather
than reverse). Also included generated standard libraries for Chez Scheme
back-end (unknowingly left out of distribution). Unpack in lcc main
directory.
Click here to download an example of a Chez Scheme policy file, left out of distribution.
Click here to download the lcc 3.4b distribution. (965 KB)
Related systems:
The FFIGEN to-do list.
lth@acm.org
24 May 2000