Native code compiler

The Mercury compiler can now generate assembler directly, rather than compiling to assembler via C. This is implemented by linking the Mercury compiler front-end with the GNU Compiler Collection back-end. The GNU Compiler Collection back-end is a fairly portable, relatively language-independent, and mostly target-independent optimizing compiler that has been ported to a very wide variety of platforms, and which has front-ends for a variety of languages, including C, C++, Ada, Fortran, Java, and now Mercury.


2009-09-25: This back-end has not been tested in a while and may not work.

The version of the native code compiler in our CVS repository and our release-of-the-day distributions (after 2002-09-11) is based on GCC 3.2.

It bootstraps, and passes all of the appropriate tests in our test suite. It is essentially ready for an official release.

However, currently it has only been tested on i686-pc-linux-gnu (Intel x86 PCs running GNU/Linux). We have don't know if it works on other systems.

The version of the Mercury native code compiler that was included in Mercury 0.10.1 and 0.10.2-beta-* should be considered a beta release. It does not support nested modules or tabled evaluation. It was based on an unreleased snapshot version of the GCC back-end, and it does not work with any officially released version of GCC.

The version of the GCC back-end interface included in Mercury 0.10 was also a beta release. As well as the issues with 0.10.1, it also had a bug that often caused the compiler to abort. The work-around for that is to compile with `--no-optimize-initializations'. This was fixed in Mercury 0.10.1.

For more information, see the file mercury-gcc/README in the mercury-gcc distribution (see below).


The sources for the Mercury native code compiler come in three parts:

Unfortunately the interface to the GCC back-end changes quite frequently, so you need to be very careful that you get matching versions of all of the above.

For directions on how to build from these sources, see the file mercury-gcc/README in the mercury-gcc distribution.


The native-code compiler is included in some of our binary distributions for 0.10, 0.10.1, 0.10.2-beta, and the release-of-the-day releases. The distributions that include the native-code compiler are the ones named "*i686-pc-linux-gnu-O4*" (but NOT the ones named "*i686-pc-linux-gnu-O4-hlc").