www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - About the front-end & dogfood

reply Bill Baxter <dnewsgroup billbaxter.com> writes:
About this: http://www.digitalmars.com/d/2.0/faq.html#dogfood
"""
The front end is in C++ in order to interface to the existing gcc and 
dmd back ends. It's also meant to be easily interfaced to other existing 
back ends, which are likely written in C++.
"""

Aren't most compiler back-ends written in C, or at least come with a C 
interface?  Given that basically nothing can call C++, not even C++ code 
from another compiler, why would you seal your back end up in C++?

It's pretty obvious that front end writers are eventually going to want 
to write their front ends in their target language, since everyone knows 
the "eat your own dogfood" mantra.   So C is really the only logical 
language choice for a general-purpose back-end interface.

Assuming I'm right and there is a C interface on any back end that 
matters, there shouldn't be any problem writing the front end in D, just 
extern(C) where necessary.

Right?

--bb
Mar 07 2008
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Bill Baxter wrote:

 Assuming I'm right and there is a C interface on any back end that 
 matters, there shouldn't be any problem writing the front end in D, just 
 extern(C) where necessary.
 
 Right?

Hmm, perhaps I'm missing something obvious here, but what would you use to bootstrap the front end with ? Some kind of D-to-C transmogrifier ? --anders
Mar 07 2008
next sibling parent Jascha Wetzel <firstname mainia.de> writes:
Anders F Björklund wrote:
 Hmm, perhaps I'm missing something obvious here, but what would you use
 to bootstrap the front end with ? Some kind of D-to-C transmogrifier ?

i don't think one would really want to port an existing backend to D just to have the whole compiler be written in D. therefore one could eventually just compile the D portion of the compiler using itself.
Mar 07 2008
prev sibling parent reply Russell Lewis <webmaster villagersonline.com> writes:
Anders F Björklund wrote:
 Bill Baxter wrote:
 
 Assuming I'm right and there is a C interface on any back end that 
 matters, there shouldn't be any problem writing the front end in D, 
 just extern(C) where necessary.

 Right?

Hmm, perhaps I'm missing something obvious here, but what would you use to bootstrap the front end with ? Some kind of D-to-C transmogrifier ?

The inelegant, but practical, answer is "the previous version of the D compiler." It's how gcc works, basically. When you download gcc to a box, it has a bootstrap mode which is designed to be compilable on just about any old C compiler. Once that is built, then that bootstrap compiler is used to actually compile the gcc code (the full gcc sources use some features which might or might not work with other compilers). At least, that's how I remember it. This obviously doesn't work if you are the first guy to write a compiler on a given platform, but on an existing platform with existing historic compilers, it works. <plug> This is another good reason for "dsimpl," which I suggested (in a previous post) that we write. You could write the front-end in complex, advanced D, translate it to "simple D" using "dsimpl" and then build the compiler using a simplistic D compiler. </plug>
Mar 07 2008
next sibling parent Jascha Wetzel <firstname mainia.de> writes:
Russell Lewis wrote:
 The inelegant, but practical, answer is "the previous version of the D 
 compiler."  It's how gcc works, basically.  When you download gcc to a 
 box, it has a bootstrap mode which is designed to be compilable on just 
 about any old C compiler.  Once that is built, then that bootstrap 
 compiler is used to actually compile the gcc code (the full gcc sources 
 use some features which might or might not work with other compilers). 
 At least, that's how I remember it.
 
 This obviously doesn't work if you are the first guy to write a compiler 
 on a given platform, but on an existing platform with existing historic 
 compilers, it works.
 
 <plug>
 
 This is another good reason for "dsimpl," which I suggested (in a 
 previous post) that we write.  You could write the front-end in complex, 
 advanced D, translate it to "simple D" using "dsimpl" and then build the 
 compiler using a simplistic D compiler.
 
 </plug>

or you could just cross-compile, which sounds like it should be easier.
Mar 07 2008
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Russell Lewis wrote:

 Hmm, perhaps I'm missing something obvious here, but what would you use
 to bootstrap the front end with ? Some kind of D-to-C transmogrifier ?

The inelegant, but practical, answer is "the previous version of the D compiler."

That is what I suspected, which makes the whole thing kinda impractical. I suppose D2 could be bootstrapped with D1, if one really really wanted. Personally I prefer having the frontend written in a portable language. There isn't that much difference between Walter's D and C++ anyway. :-) --anders
Mar 07 2008
prev sibling parent Jascha Wetzel <firstname mainia.de> writes:
Bill Baxter wrote:
 About this: http://www.digitalmars.com/d/2.0/faq.html#dogfood
 """
 The front end is in C++ in order to interface to the existing gcc and 
 dmd back ends. It's also meant to be easily interfaced to other existing 
 back ends, which are likely written in C++.
 """
 
 Aren't most compiler back-ends written in C, or at least come with a C 
 interface?  Given that basically nothing can call C++, not even C++ code 
 from another compiler, why would you seal your back end up in C++?
 
 It's pretty obvious that front end writers are eventually going to want 
 to write their front ends in their target language, since everyone knows 
 the "eat your own dogfood" mantra.   So C is really the only logical 
 language choice for a general-purpose back-end interface.
 
 Assuming I'm right and there is a C interface on any back end that 
 matters, there shouldn't be any problem writing the front end in D, just 
 extern(C) where necessary.
 
 Right?

i'm not sure whether i understand the question, since of course it's possible to write D frontends in D - there are frontend projects in D. there is also a C binding for LLVM and LLVM matters ;)
Mar 07 2008