C code generation
When compiling to C, SmartEiffel generates the following output:
- One or more C files
- A C header file, projectname.h.
- A type-to-id mapping file (see #Mapping types to IDs section below).
- A C compilation script (projectname.make or projectname.bat depending on the platform).
If you are using the
-no_split mode, all the C code will be put inside a projectname.c file. Otherwise, code will be split in chunks (of more or less the same size) called projectnameN.c, where N is a positive integer number. The number of chunks may vary depending on the size of the project. The policy for splitting files will probably change in SE 2.4.
The compilation script will contain a list of commands to invoke the system C compiler and compile the relevant files with the proper flags (extracted from the command line, ACE file and/or plugin options). It will only include compile commands for those C files which have no associated object file, or that have changed since the previous compilation. It will also contain a final linking command (to generate the executable) when any of the relevant C flags has changed.
The SmartEiffel runtime (i.e., auxiliar routines to handle some mechanisms like garbage collection, exceptions, etc) and plugins are not linked, but embedded instead. That means that the code for those components will be embedded inside the .c/.h files. The runtime files are located in the
sys/runtime/c directory of the compiler distribution. For example when compiling with the GC enabled, the file
sys/runtime/c/gc_lib.c is copied verbatim into one of the generated projectN.c and the file
sys/runtime/c/gc_lib.h is copied verbatim into the projectN.h.
Mapping types to IDs
When compiling to C, every type existing in the system is assigned an id, which is a unique positive integer number. This number is used in different parts of the C code instead of the actual type name. For example if the type STRING is assigned id 7, the feature is_equal of type STRING will be mapped to a C routine called r7is_equal (the 7 in the name comes from the type id).
Note that ids are assigned to types and not to classes. Most of the time there is one type per class, but there can be possibly more types per class. For example, even if ARRAY is a single class, ARRAY[INTEGER] and ARRAY[STRING] are distinct types, and as such will get different ids.
A few of the types based on library classes (all INTEGER*, REAL*, CHARACTER, BOOLEAN, POINTER, NATIVE_ARRAY[CHARACTER] and STRING) have a predefined, fixed id. For details on implementation of this fixed mapping, check the ID_PROVIDER class, specially feature make.
After compilation, the mapping of types to ids is stored in a text file called project.id. This file is a useful help to read the generated C code. It is also used by the compiler itself when recompiling; the compiler uses it to keep the mapping between different runs. Maintaining the mapping helps to get similar generated code between compiler runs, which means that fewer C files need to be recompiled.