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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
osgx
  • 90,338
  • 53
  • 357
  • 513
  • Why not use an ADA compiler directly? – Mat May 30 '12 at 13:33
  • 3
    Because there is no ADA for some hardware. – osgx May 30 '12 at 13:36
  • 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.) – Mat May 30 '12 at 13:38
  • 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. – osgx May 30 '12 at 13:41
  • @Marc C, think about it as in-house hardware; there are no chances to find existing ADA compiler for this platform. – osgx May 30 '12 at 13:44
  • 7
    @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. – Marc C May 30 '12 at 13:44
  • 2
    If its in-house hardware, where did you get a C compiler for it ? – NWS May 30 '12 at 14:13
  • @MarcC: +1 -- good point *and* you capitalized "Ada" correctly! – Jerry Coffin May 30 '12 at 14:44
  • 1
    @Marc C - Still, if you have gnu c99 + pthreads + POSIX, getting GNU Ada to work on it shouldn't be that huge a leap. – T.E.D. May 30 '12 at 16:28
  • 1
    @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. – osgx May 30 '12 at 16:38
  • 1
    @osgx - Ahhh. It was the backend I thought you had (which is why it seemed like not so much work left). – T.E.D. May 30 '12 at 17:04

2 Answers2

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 sales@adacore.com, if pursuing a commercial solution is a viable option for you. (At least get a price.)

Marc C
  • 8,664
  • 1
  • 24
  • 29
  • 2
    Thanks. What can you say about: http://adatoccpp.sourceforge.net (incomplete?) and http://mapusoft.com/products/ada-changer/? – osgx May 30 '12 at 13:45
  • 1
    FWIW: http://www.adacore.com/press/adacore-sofcheck-merge – Ira Baxter May 30 '12 at 13:45
  • Note that the author of that translator was also hired by AdaCore, so someone there ought to have an answer. – T.E.D. May 30 '12 at 16:25
  • I confirm that MapuSoft indeed has AdaMagic inside, and that works good. Also, S. Tucker Taft on Google+ told that AdaCore is developing SPARK2C – OCTAGRAM Feb 19 '17 at 00:46
  • There's also some interesting discussion here: http://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/440FBE21_ – Michael Shigorin Jun 25 '19 at 10:23
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.

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • 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. – T.E.D. May 30 '12 at 16:23
  • ...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. – T.E.D. May 30 '12 at 16:30
  • 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. – Ira Baxter May 31 '12 at 05:54