Modern Ada to C/C++ translator [closed]
Asked Answered
B

2

8

Is there any source-to-source converter (translator) from Ada (95, 2005) to C? How full they are (can they convert every feature of Ada into gnu c99 + pthreads + POSIX)?

Is it possible to use such ada-to-c translator in critical applications?

PS: Translators to C++ (up to 2003 with gnu extensions) are welcome too.

PPS: when said "gnu c99", it means only that C99 + most gnu extensions are supported, but don't mean the GCC.

Bergeron answered 30/5, 2012 at 13:30 Comment(11)
Why not use an ADA compiler directly?Scrape
Because there is no ADA for some hardware.Bergeron
Your mention of GNU C99 made me think you were compiling with GCC. Doesn't GCC's ADA frontend(s) work on all targets GCC supports? (I have no idea.)Scrape
I mentioned GNU C99 (and pthread) because I think that some features of ADA can't be converted to plain C. Also, GNU C99 is just set of extensions over C99 and they are supported not only be GCC, but also by Intel, LLVM/clang any other compiler which wants to compile linux software and kernel.Bergeron
@Marc C, think about it as in-house hardware; there are no chances to find existing ADA compiler for this platform.Bergeron
@Mat, it seems to be a common misconception (I've heard it twice in the last month :-) that if GCC targets a platform you get Ada for free. Nope, doesn't work like that.Szeged
If its in-house hardware, where did you get a C compiler for it ?Sandwich
@MarcC: +1 -- good point and you capitalized "Ada" correctly!Regrate
@Marc C - Still, if you have gnu c99 + pthreads + POSIX, getting GNU Ada to work on it shouldn't be that huge a leap.Corrasion
@T.E.D., I have compiler for 'c99 with gnu extensions' but have no GCC (it is really different things). In theory I can compile GNU Ada, but it will not emit machine code for this hardware. It'll require porting of GCC backend.Bergeron
@Bergeron - Ahhh. It was the backend I thought you had (which is why it seemed like not so much work left).Corrasion
S
9

I don't know of any open source Ada-to-C translator. The only one I knew of at all was SofCheck's, which was reportedly pretty good.

SofCheck has since been bought by AdaCore, and I did a very brief search of the AdaCore website for the translator, and nothing jumped out. You could ask them at [email protected], if pursuing a commercial solution is a viable option for you. (At least get a price.)

Szeged answered 30/5, 2012 at 13:42 Comment(5)
Thanks. What can you say about: adatoccpp.sourceforge.net (incomplete?) and mapusoft.com/products/ada-changer?Bergeron
FWIW: adacore.com/press/adacore-sofcheck-mergeMaggio
Note that the author of that translator was also hired by AdaCore, so someone there ought to have an answer.Corrasion
I confirm that MapuSoft indeed has AdaMagic inside, and that works good. Also, S. Tucker Taft on Google+ told that AdaCore is developing SPARK2CLedda
There's also some interesting discussion here: computer-programming-forum.com/44-ada/a0b2113cf98dc015.htm -- citing: It would be possible to write a translator to portable C for a subset of Ada. It would also be possible to write a translator from a (larger) subset of Ada to C specific to a given platform/OS/C-compiler combination. In general, however, it is impossible to write a translator from Ada to portable C. It is difficult to translate generics and exceptions, and impossible to translate tasks and protected units to portable C. Jeff Carter PGP:1024/440FBE21Mendoza
M
2

Unless there is an incredibly strong reason to use Ada for this application (e.g., customer demands it, or you already have a big application coded in Ada that you want to use), it will likely be a lot less painful if you just bite the bullet and code your solution in well-crafted C99 or C++ as you see fit.

If you insist, Sofcheck's translator might be best; they've been working on it a long time.

Failing that, you might(?) build a translator starting with the ASIS output of an Ada compiler. That's likely rather a lot of persnickety work since Ada has pretty precise semantics that you'd better preserve if you want to just carelessly code in Ada, translate and run. It will be even more work if you want the output to be "pretty" for the final customer. (Long term maintenance should be a consideration). I suspect implementing code to simulate Ada's rendezvous might be rather tricky, being both semantically complicated and asynchronous at the same time. The real flaw with this approach is that it is a lot of work; maybe just getting on with your life and coding the application itself in something non-Ada would be less effort.

See my caveats on language translation done poorly and alternative methods.

Maggio answered 30/5, 2012 at 13:51 Comment(3)
This is half of a right answer, but rewriting perfectly working code when you don't have to is really stupid. I don't care what language it was written in, and what the supposed benefits are of the new language are. If you flat out can't get a compiler, that's another matter, but that hasn't been asserted here.Corrasion
...the + half is that rewriting is generally better than trying to hand-translate. You'll still end up with something that has to be debugged and tested every bit as much as the original product did when it was brand new though.Corrasion
I didn't intend to imply he should rewrite the application. In fact, OP didn't say if he had an Ada program, only that he wanted to use an Ada compiler; I have (mistakenly?) assumed he was going to write a new application. If he has an Ada program, then an automated translation of whatever quality is likely to be better (less costly, faster, less risk) than a hand rewrite, agreed. I revised the answer to make this clearer.Maggio

© 2022 - 2024 — McMap. All rights reserved.