C2Eif - A C to Eiffel translator


Can we reuse some of the huge code-base developed in C to take advantage of modern programming language features such as type safety, object-orientation, and contracts?
The research is about a source-to-source translation of C code into Eiffel, a modern object-oriented programming language, and the supporting tool C2Eif. The translation is completely automatic and supports the entire C language (ANSI, as well as many GNU C Compiler extensions, through CIL) as used in practice, including its usage of native system libraries and inlined assembly code.
Our experiments show that C2Eif can handle C applications and libraries of significant size (such as vim and libgsl), as well as challenging benchmarks such as the GCC torture tests. The produced Eiffel code is functionally equivalent to the original C code, and takes advantage of some of Eiffel's object-oriented features to produce readable, maintainable, and easy-to-debug translations.


AutoOO - our technique for object-oriented reengineering - has been introduced in C2Eif version 0.3. It uses implicit design elements from C programs to build reengineered object-oriented programs. It builds on top of C2Eif (but has been added to its user interface):


Version 0.5, 2012-12-10

C2Eif binaries for Windows and Linux
C2Eif EiffelStudio plugin for Windows and Linux (extract into Eiffel71\studio\wizards\new_projects)
C2Eif source code

Version 0.4, 2012-10-12

C2Eif binaries for Windows and Linux
C2Eif source code

Version 0.3 - Codename AutoOO, 2012-08-22

C2Eif binary for Linux
C2Eif source code
Example translations containing C, Eiffel and binaries

Version 0.2, 2012-05-14

C2Eif binary for Linux
C2Eif source code
Example translations containing C, Eiffel and binaries

Version 0.1, 2011-10-17

C2Eif binary for Linux
Example translations containing C, Eiffel and binaries

Translated Libraries

The libraries come with little demo programs that show how to use the library. There are also binaries of the demo programs; you can directly try yourself.

MongoDB Driver

A library for interacting with the MongoDB database.
Download | MongoDB Website, MongoDB C Driver Website, C API

MPZ (part of GMP)

A library for arbitrary-precision integers.
Download | GMP Website, C API

PCRE - Perl Compatible Regular Expressions

A library for regular expression pattern matching using the same syntax and semantics as Perl 5.
Download | PCRE Website, PCRE Documentation


A library for playing music files (mp3 and wav).
Download | SDL_mixer Website, C API

* To compile the sources you need x86 EiffelStudio with the gcc C compiler.



General Overview

C source code can be compiled to Eiffel source code in three easy steps:

  1. Preprocess your C project with CIL.
    This is usually as simple as configure; make CC="cilly --merge --save-temps" but sometimes you have to help CIL a little. Running make on a project foo should give you a foo binary (or foo.a library) and the merged C file foo.cil.c.
  2. Open the merged C file in C2Eif and hit Compile.
    This will create Eiffel classes in the directory you specified.
  3. Open the Eiffel classes with EiffelStudio.
    Have fun continuing development of your C project in Eiffel :-)



Wrapping C Libraries

It is also possible to create C library wrappers with C2Eif instead of translating C code. To do so, only preprocess the header files of the C library (instead of the actual C library) with CIL in the first step above. You can find an example here.