Electronicdesign 24697 Ccg Adacore Promo

Ada Compiler Generates C Source

Nov. 17, 2018
AdaCore’s latest GNAT Pro Ada compiler can generate C source code, delivering portability to most platforms with a C compiler.

With AdaCore’s latest GNAT Pro Ada compiler, it’s now possible to generate C source code using its Common Code Generator (CCG). This is designed to provide portability to the vast majority of platforms that have a C compiler. It was originally done to support the popular 8-bit Microchip AVR that AdaCore doesn’t support with its native code support targeting platforms, such as the 32- and 64-bit x86, ARM, RISC-V, and Power architectures.

Using CCG is just a matter of a command-line option (see codelist below). It handles a subset of Ada, but this still includes features like fixed-point support and the minimal standard library. Features not supported are ones that would be hard to implement or those not supported by C compilers like overflow checks. This is one reason to use support for SPARK, a provable subset of Ada. CCG works with SPARK applications.

Compiling Ada/SPARK code into C like this is as easy as a command-line switch.

The ability to insert assembly code inline is also missing. However, it’s possible to edit generated C code to do this since the C compiler supports such a feature.

The Ada.Real_Time runtime package is supported if rts_monotonic_clock and rts_delay_until procedures are provided. The online documentation covers the details of everything that is and isn’t supported.

Support for 8-bit platforms is just one reason to use CCG. It can handle other platforms that don’t support Ada and SPARK compilers.

If you want a quick way to learn basic Ada and SPARK programming, then check out AdaCore’s online training tools. You can edit source code online and have it compiled and executed.

Sponsored Recommendations


To join the conversation, and become an exclusive member of Electronic Design, create an account today!