Ada Compiler Generates C Source

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.

About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

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