| Previous Section | Next Section | Table of Contents | Glossary | Index |
CCL uses an interface translation system based on the FFIGEN
system, which is described at
http://www.ccs.neu.edu/home/lth/ffigen/.
The interface translator makes
the constant, type, structure, and function definitions in a set of
C-language header files available to lisp code.
The basic idea of the FFIGEN scheme is to use the C compiler's frontend and parser to translate .h files into semantically equivalent .ffi files, which represent the definitions from the headers using a syntax based on S-expressions. Lisp code can then concentrate on the .ffi representation, without having to concern itself with the semantics of header file inclusion or the arcana of C parsing.
The original FFIGEN system used a modified version of
the LCC C compiler to produce .ffi files. Since many LinuxPPC
header files contain GCC-specific constructs, CCL's
translation system uses a modified version of GCC (called,
somewhat confusingly, ffigen.)
A version of ffigen based on GCC-4.0 was developed during the spring and summer of 2005. Sources (diffs relative to the GCC-4.0 release) are available here, and binaries are available for DarwinPPC and for LinuxPPC. These versions should be insensitive to to the version of GCC (and its preprocessor) installed on the system.
An older version was developed in 2001-2002; it depended on the installed version of GCC being 2.95. It may still be of interest for people unable to run the GCC-4.0-based version for whatever reason.
A LinuxPPC binary of this older version is available at ftp://clozure.com/pub/ffigen-0.1.tar.gz, and LinuxPPC source differences are at ftp://clozure.com/pub/ffigen-src.tar.gz.
For Darwin, the binary of the older FFIGEN is available at ftp://clozure.com/pub/ffigen-darwin.tar.gz, and the source differences are at ftp://clozure.com/pub/ffigen-darwin-src.tar.gz.
A shell script (distributed with the source and binary packages) called h-to-ffi.sh reads a specified .h file (and optional preprocessor arguments) and writes a (hopefully) equivalent .ffi file to standard output, calling the installed C preprocessor and the ffigen program with appropriate arguments.
For each interface directory (see FIXTHIS)
subdir distributed with CCL, a shell
script (distributed with CCL as
"ccl:headers;subdir;C;populate.sh"
("ccl:darwin-headers;subdir;C;populate.sh"
for Darwin)) calls h-to-ffi.sh on a large number of the header
files in /usr/include (or some other system header
path) and creates a parallel directory tree in
"ccl:headers;subdir;C;system;header;path;"
(or
"ccl:darwin-headers;subdir;C;system;header;path;"),
populating that directory with .ffi files.
A lisp function defined in "ccl:library;parse-ffi.lisp" reads the .ffi files in a specified interface directory subdir and generates new versions of the databases (files with the extension .cdb).
The CDB databases are used by the #$ and #_ reader macros and are used in the expansion of RREF, RLET, and related macros.
Ensure that the FFIGEN program is installed. See the"README" file in the source or binary archive for specific installation instructions.This example assumes LinuxPPC; for 32-bit DarwinPPC, substitute"ccl:darwin-headers;" for "ccl:headers;". For 64-bit DarwinPPC,substitute "ccl:darwin-headers64;".
Edit the "ccl:headers;subdir;C;populate.sh"shell script. When you're confident that the files and preprocessor options match your environment, cd to the"ccl:headers;subdir;C;" directory and invoke ./populate.sh. Repeat this step until you're able to cleanly translate all files referenced in the shell script.
Run CCL:
? (require "PARSE-FFI")
PARSE-FFI
? (parse-standard-ffi-files :SUBDIR)
;;; lots of output ... after a while, shiny new .cdb files should
;;; appear in "ccl:headers;subdir;"
;;; (or "ccl:darwin-headers;subdir;" under Darwin)
| Previous Section | Next Section | Table of Contents | Glossary | Index |