This is an Ada compiler based on LLVM, connecting the GNAT front-end to the LLVM code generator to generate LLVM bitcode for Ada and to open the LLVM ecosystem to Ada.
Note that we are not planning on replacing any existing GNAT port that's based on GCC: this project is meant to provide additional, not replacement, GNAT ports.
You are welcome to experiment with this technology and provide feedback on successes, usages, limitations, pull requests, etc.
- For more information on LLVM, see llvm.org.
- For more information on GNAT, see adacore.com.
GNAT LLVM has been built successfully on GNU/Linux and Mac OS Mojave x86_64 native targets, using LLVM 9.0.1. Do not hesitate to report success on other configurations.
This fork aims to provide Ada support for the ESP8266 and ESP32 chips by using the LLVM Xtensa backend.
To build GNAT LLVM from sources, follow these steps:
-
Obtain a check out of the GNAT sources from gcc.gnu.org and the Xtensa LLVM backend
$ git submodule update --init --recursive
-
Install (and put in your PATH) a recent GNAT, e.g GNAT Community 2021 or GCC 11.
-
Install LLVM and Clang 13.0.x
The recommended way to build GNAT LLVM is to use an existing LLVM and clang package installed via e.g. "brew install llvm" on Mac OS or "sudo apt-get install llvm-dev" on Ubuntu. You can also build llvm yourself with the options that suit your needs. After installing/building, make sure the llvm bin directory containing llvm-config and clang is in your PATH.
An alternative only suitable for core GNAT LLVM development on x86 native configurations is to use the following command, assuming you have cmake version >= 3.13.4 in your path:
-
Build the Xtensa LLVM backend
$ make llvm
Note that there's currently a bug in LLVM's aliasing handling. We check for it and generate slightly pessimized code in that case, but a patch to be applied to LLVM's lib/Analyze directory is in the file llvm/patches/LLVMStructTBAAPatch.diff.
-
Finally build GNAT LLVM:
$ make build
This only builds the compiler but no Ada runtime. Currently there is no working runtime for Xtensa.
This creates a "ready to use" set of directories "bin" and "lib" under llvm-interface which you can put in your PATH:
PATH=$PWD/llvm-interface/bin:$PATH
To be able to generate Xtensa binaries the locally built clang also has to be added to the PATH:
PATH=$PWD/llvm/llvm-obj/bin:$PATH
-
If you want in addition to generate bitcode for the GNAT runtime, you can do:
$ make gnatlib-bc
This will generate libgnat.bc and libgnarl.bc in the adalib directory, along with libgnat.a and libgnarl.a.
-
To run the compiler and produce a native object file:
$ llvm-gcc -c file.adb
-
To debug the compiler:
$ gdb -args llvm-gnat1 -c file.adb
-
To build a complete native executable:
$ llvm-gnatmake main.adb
-
To build a whole project:
$ gprbuild --target=llvm -Pprj ...
-
To generate LLVM bitcode (will generate a .bc file):
$ llvm-gcc -c -emit-llvm file.adb
-
To generate LLVM assembly (will generate a .ll file):
$ llvm-gcc -c -S -emit-llvm file.adb
-
To generate native assembly file (will generate a .s file):
$ llvm-gcc -S file.adb
-
To build for Xtensa:
$ llvm-gnatmake -c unit.adb -cargs --target=xtensa -mcpu=esp8266
The GNAT LLVM tool is licensed under the GNU General Public License version 3
or later; see file COPYING3
for details.