Previous Section Next Section Table of Contents Glossary Index

Chapter 12. The Foreign-Function Interface

12.7. The Interface Translator

12.7.1. Overview

CCL uses an interface translation system based on the FFIGEN system, which is described at this page 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 OS header files contain GCC-specific constructs, CCL's translation system uses a modified version of GCC (called, somewhat confusingly, ffigen.)

See here for information on building and installing ffigen.

A component shell script 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 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" (or some other platform-specific headers directory) 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;", etc.), 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.

12.7.2. Details: rebuilding the CDB databases, step by step

  1. Ensure that the FFIGEN program is installed. See the"README" file generated during the FFIGEN build process for specific installation instructions.This example assumes LinuxPPC; for other platforms, substitute the appropriate headers directory.

  2. 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.

  3. Run CCL:

                  ? (require "PARSE-FFI")
                  PARSE-FFI
    
                  ? (ccl::parse-standard-ffi-files :SUBDIR)
                  ;;; lots of output ... after a while, shiny new .cdb files should
                  ;;; appear in "ccl:headers;subdir;"
              

    It may be necessary to call CCL::PARSE-STANDARD-FFI-FILES twice, to ensure that forward-references are resolved


Previous Section Next Section Table of Contents Glossary Index