GNAT - Ada compiler, part of GCC

The Ada front end for GCC started out life outside of the FSF GCC tree as a projected funded by the (now defunct) Ada Joint Program Office (AJPO). In the 90's the AJPO funded NYU to develop an Ada 95 compiler. GNAT was merged into the FSF tree and became stable within that tree sometime in the late GCC 3.X series.

General information about Ada and to a large extent GNAT can be found at the wikibooks Ada page. GNAT now supports Ada 95, Ada 2005 and Ada 2012 versions of the Ada standard.

How do I download/install GNAT on my system?

In many cases, it is either pre-installed on most GNU/Linux distributions or can be installed with the appropriate package management commands.

For other platforms and more details, see Installing Ada in the wikibook.

Running a single test

For example, to build (and run) just the test array21.adb invoke make like so:

$ make -C $BUILDDIR/gcc check-gnat RUNTESTFLAGS="dg.exp=array21.adb"

See also the thread on how to Run a single ada test.

Running GNAT on single tests

An easy way to run on a single test from the test suite is to set LD_LIBRARY_PATH to the same value as in gnat.log and invoke gnatmake as shown in the log. The is necessary so that the GNAT runtime library, system.ads, and any other libraries needed by the test, can be found. For example, with GCC sources in $SRCDIR and build directory $BUILDDIR:

$ LD_LIBRARY_PATH=$BUILDDIR/gcc:$BUILDDIR/gcc/32::$BUILDDIR/gcc:$BUILDDIR/gcc/32:$BUILDDIR/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libsanitizer/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libvtv/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libssp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libphobos/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libgomp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libitm/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libatomic/.libs:$BUILDDIR/./gcc:$BUILDDIR/./prev-gcc:$BUILDDIR/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libsanitizer/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libvtv/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libssp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libphobos/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libgomp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libitm/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libatomic/.libs:$BUILDDIR/./gcc:$BUILDDIR/./prev-gcc $BUILDDIR/gcc/xgcc -B$BUILDDIR/gcc --RTS=$BUILDDIR/x86_64-pc-linux-gnu/./libada -c $SRCDIR/gcc/testsuite/gnat.dg/array21.adb 

gnatmake passes command-line options it doesn't recognize to GCC so invoking it with -### has the effect of printing the command-line options it invokes GCC behind the scenes.

Debugging GNAT

To debug the Ada front end in GDB, set LD_LIBRARY_PATH to the same value as in gnat.log and invoke GCC with the -wrapper gdb,--arg option as usual. For example, you might invoke GDB like so:

$ LD_LIBRARY_PATH=$BUILDDIR/gcc:$BUILDDIR/gcc/32::$BUILDDIR/gcc:$BUILDDIR/gcc/32:$BUILDDIR/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libsanitizer/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libvtv/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libssp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libphobos/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libgomp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libitm/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libatomic/.libs:$BUILDDIR/./gcc:$BUILDDIR/./prev-gcc:$BUILDDIR/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libsanitizer/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libvtv/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libssp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libphobos/src/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libgomp/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libitm/.libs:$BUILDDIR/x86_64-pc-linux-gnu/libatomic/.libs:$BUILDDIR/./gcc:$BUILDDIR/./prev-gcc $BUILDDIR/gcc/xgcc -B$BUILDDIR/gcc --RTS=$BUILDDIR/x86_64-pc-linux-gnu/./libada -c $SRCDIR/gcc/testsuite/gnat.dg/array21.adb -wrapper gdb,--arg

Common Questions about GNAT

No. GNAT does not and never did translate Ada code to C code. It translates Ada in the same way that the C front end translates C. Further adding to this confusion is the fact that earlier versions of GNAT did create a single .c file to call the elaboration code of each of the Ada packages but at no time was any of the user code translated into C.

None: GNAT (last edited 2020-08-19 00:14:20 by MartinSebor)