www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Automated translation from C++ to D

reply Georg Wrede <georg.wrede nospam.org> writes:
On Feb 3, in this newsgroup, Walter wrote:

 1) It's written in Java, which is the easiest code to translate to D
 besides C, perhaps even easier (no macros <g>). Furthermore, Kris has
 written a tool to automate some of the translation. Automated
 translation from C++ is essentially impossible.
Hardly anybody would disagree there! But, (hey, it's me talking, what can you expect? ;-) ) since you have both a C++ compiler and a D compiler, would the following tack cut it: Compile the C++ "half-way" (your choice of which passes), and then translate that to D source code? Mind you, I'm not suggesting you'd do this for real, heck you've got other things to do. This is mostly academic. Would there be any very different issues if this is done using Digital Mars compilers versus GCC?
Feb 21 2006
next sibling parent Sean Kelly <sean f4.ca> writes:
Georg Wrede wrote:
 On Feb 3, in this newsgroup, Walter wrote:
 
 1) It's written in Java, which is the easiest code to translate to D
 besides C, perhaps even easier (no macros <g>). Furthermore, Kris has
 written a tool to automate some of the translation. Automated
 translation from C++ is essentially impossible.
Hardly anybody would disagree there! But, (hey, it's me talking, what can you expect? ;-) ) since you have both a C++ compiler and a D compiler, would the following tack cut it: Compile the C++ "half-way" (your choice of which passes), and then translate that to D source code?
I think templates would likely cause some problems. And the preprocessor code shouldn't be processed completely. And then there's copy semantics and all the operator overloads D doesn't support. I can't claim to have nearly as much experience as Walter, but this sounds like a nightmare. C to D sounds much more achievable, but even that required a modified C preprocessor to accomplish.
 Would there be any very different issues if this is done using Digital 
 Mars compilers versus GCC?
Probably not. The language spec doesn't vary from platform to platform, only the compiler implementation. Sean
Feb 21 2006
prev sibling parent reply "Walter Bright" <newshound digitalmars.com> writes:
"Georg Wrede" <georg.wrede nospam.org> wrote in message 
news:43FB4E35.5080606 nospam.org...
 Compile the C++ "half-way" (your choice of which passes), and then 
 translate that to D source code?
It would be nearly useless, because one has to adopt different algorithms.
Feb 21 2006
next sibling parent reply Aarti <aarti interia.pl> writes:
Walter Bright napisał(a):
 "Georg Wrede" <georg.wrede nospam.org> wrote in message 
 news:43FB4E35.5080606 nospam.org...
 
Compile the C++ "half-way" (your choice of which passes), and then 
translate that to D source code?
It would be nearly useless, because one has to adopt different algorithms.
...but what about GCC intermediate languages? Documentation on: http://gcc.gnu.org/onlinedocs/gccint/Tree-SSA.html#Tree-SSA says: "GCC uses three main intermediate languages to represent the program during compilation: GENERIC, GIMPLE and RTL. GENERIC is a language-independent representation generated by each front end. It is used to serve as an interface between the parser and optimizer. GENERIC is a common representation that is able to represent programs written in all the languages supported by GCC." Is GENERIC too low-level language to make it possible to convert it in a sensible way to D? Regards Marcin Kuszczak
Feb 21 2006
parent "Walter Bright" <newshound digitalmars.com> writes:
"Aarti" <aarti interia.pl> wrote in message 
news:dtfs08$2iqg$1 digitaldaemon.com...
 ...but what about GCC intermediate languages? Documentation on:
 http://gcc.gnu.org/onlinedocs/gccint/Tree-SSA.html#Tree-SSA
 says:
 "GCC uses three main intermediate languages to represent the program 
 during compilation: GENERIC, GIMPLE and RTL. GENERIC is a 
 language-independent representation generated by each front end. It is 
 used to serve as an interface between the parser and optimizer. GENERIC is 
 a common representation that is able to represent programs written in all 
 the languages supported by GCC."

 Is GENERIC too low-level language to make it possible to convert it in a 
 sensible way to D?
Let me illustrate by example. I could write an assembler to D translator, but the D code emitted would look like: add(&flags, &EAX, 6); cmp(&flags, EAX, EBX); if (jne(&flags)) goto L1A0; etc. It would bear no reasonable relation to whatever source code produced it. I haven't looked at the gcc intermediate code, but it's more than likely too low level.
Feb 23 2006
prev sibling parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Walter Bright wrote:
 "Georg Wrede" <georg.wrede nospam.org> wrote in message 
 news:43FB4E35.5080606 nospam.org...
 
Compile the C++ "half-way" (your choice of which passes), and then 
translate that to D source code?
It would be nearly useless, because one has to adopt different algorithms.
Why? Aren't the constructs pretty much the same? C++ classes maybe a hell to parse, but it's possible (obviously has been done), and they must be translatable to D classes! Templates can be translated to templates (I assume ..) variables to variables .. functions to functions .. One thing that comes to mind is passing objects *by-value* but I think it can be simulated with D structs? (D structs can be passed by value, am I not correct?)
Feb 25 2006
parent reply bobef <bobef lessequal.com> writes:
Hasan Aljudy wrote:
 Walter Bright wrote:
 "Georg Wrede" <georg.wrede nospam.org> wrote in message 
 news:43FB4E35.5080606 nospam.org...

 Compile the C++ "half-way" (your choice of which passes), and then 
 translate that to D source code?
It would be nearly useless, because one has to adopt different algorithms.
Why? Aren't the constructs pretty much the same?
Everything is the same. It is just bits in the memory, which is electricity, which is energy, which is everything...
 
 C++ classes maybe a hell to parse, but it's possible (obviously has been 
 done), and they must be translatable to D classes!
 
 Templates can be translated to templates (I assume ..)
 
 variables to variables ..
 functions to functions ..
 
 One thing that comes to mind is passing objects *by-value* but I think 
 it can be simulated with D structs? (D structs can be passed by value, 
 am I not correct?)
 
I think the question is not is it possible. Of course it is, if your brain can do you, the computer can do it too. The question is does it worth the effort, and I believe the answer has been already given...
Feb 26 2006
parent James Dunne <james.jdunne gmail.com> writes:
bobef wrote:
 Hasan Aljudy wrote:
 
 Walter Bright wrote:

 "Georg Wrede" <georg.wrede nospam.org> wrote in message 
 news:43FB4E35.5080606 nospam.org...

 Compile the C++ "half-way" (your choice of which passes), and then 
 translate that to D source code?
It would be nearly useless, because one has to adopt different algorithms.
Why? Aren't the constructs pretty much the same?
Everything is the same. It is just bits in the memory, which is electricity, which is energy, which is everything...
 C++ classes maybe a hell to parse, but it's possible (obviously has 
 been done), and they must be translatable to D classes!

 Templates can be translated to templates (I assume ..)

 variables to variables ..
 functions to functions ..

 One thing that comes to mind is passing objects *by-value* but I think 
 it can be simulated with D structs? (D structs can be passed by value, 
 am I not correct?)
I think the question is not is it possible. Of course it is, if your brain can do you, the computer can do it too. The question is does it worth the effort, and I believe the answer has been already given...
My thinking exactly. If your brain can do it, a computer can too. The effort involved out of the brain in order to coax the computer into doing it is the question. =) -- Regards, James Dunne
Feb 26 2006