Sample Front-End

The Sample Front-End (SFE) is an exemplary front-end for GCC. Up to version 4.3.3, TreeLang was part of the main GCC tree and considered as a kind of reference front-end to serve as base for future frond-end development. But, it has been removed since gcc-4.4.0 to reduce the effort to keep TreeLang in sync and working with the development and extensions of the middle-end API. However, to provide examples for the upcoming GCC versions (4.4 and higher), Sample Front-End is created as a new reference front-end for GCC to simplify the entry into GCC front-end development. Opposed to TreeLang, SFE will be not be integrated into the GCC main tree to avoid increasing the general maintainability effort.

As an entry to GCC front-ends, I created a front-end skeleton (download, for further versions see below) which only contains the fundamental parts of a front-end to be runnable (maybe you’ll be able to further reduce this skeleton :-)). Based on this skeleton, the single parts of a GCC front-end (e.g. language specs, options file, language hooks, etc.) are explained in greater detail. As a next step the Sample Front-End is filled with contents to show the use of GENERIC as intermediate (tree) representation of the frond-end and the interactions with GCC’s given infrastructure (middle-end (GIMPLE, optimization), garbage collection, identifier pool, etc.). Thereby, the first version will be a very static front-end producing assembly output for the following simplified C code:

[code lang=”c”]
static unsigned int global_var = 0;
char *str = "Glob Value: %u\n";

typedef unsigned int (*fptr_t) (char *in_val, signed char change_val);

struct callback
{
fptr_t cb_fnc;
char val;
} arr[10];

unsigned int fptr_do1 (char *in_val, signed char change_val)
{
return (*in_val += change_val);
}

/* simplified declaration of main – omitting argc and argv */
int main ()
{
for ( global_var = 0; global_var < 10; global_var++ )
{
if ( (global_var & 1) == 0 ) /* even number */
arr[global_var].val = global_var;
else
arr[global_var].val = global_var+1;

arr[global_var].cb_fnc = fptr_do1;
}

return arr[0].cb_fnc(&arr[0].val, 0); /* return 0 */
}
[/code]

Compile the SFE skeleton

As gcc-4.5.0 has not yet been officially released by today (September 10th 2009) and is currently in stage1 development, you need to download gcc-4.4.0 or gcc-4.4.1 from one of the gcc mirrors. Extract the archive – this will create the gcc toplevel directory named gcc-x.y.z. Then change into the gcc directory of the toplevel directory and extract the SFE.skeleton.tar.gz file – this will create the directory toplev/gcc/sample_fe. As the next step, configure gcc the common way by just adding sample_fe to the –enable-languages parameter. Finally, call make and make install to compile the new front-end:

[code lang=”bash”]
configure […] –enable-languages=sample_fe
make
make check (optionally)
make install
[/code]

SFE skeleton versions

Please find below different version of the SFE skeleton. Although the skeleton uses an explicit version number, like e.g. 4.4.4, it should then work with any version of the same GCC release line, meaning a skeleton versioned with 4.4.4 should work with any 4.4.x based GCC version, because the front-end API doesn’t change in a patch release.

  • SFE skeleton for GCC 4.4.x: download
  • SFE skeleton for GCC 4.5.x: TBD

One thought on “Sample Front-End”

  1. Hi

    I have tried to compile the sample front end provided in this page with gcc-2.95. When i make, i am getting the following error:

    make[1]: *** No rule to make target sample_fe/Makefile.in', needed by Makefile’. Stop.

    Could you please help me get out of this situation?

    Thanks
    Pavan

Leave a Reply

Your email address will not be published. Required fields are marked *