www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Will it be possible to write a GCC frontend in D?

reply rempas <rempas tutanota.com> writes:
I'm using a book called "modern compiler design (version 2)" to 
learn how to create compiler and I thought about learning and 
applying this knowledge on writing a GCC frontend just for fun to 
see where this gets me. However, I've seen some tutorials and 
I've seen people doing it in C++. Now, I want to do it in D (of 
course!). My problem is that I don't if the headers are using C++ 
features because If this is possible then I won't be able to use 
ImportC to "automatically" get bindings to use in D. Any ideas?
Feb 23 2022
next sibling parent reply bachmeier <no spam.net> writes:
On Wednesday, 23 February 2022 at 19:58:45 UTC, rempas wrote:
 I'm using a book called "modern compiler design (version 2)" to 
 learn how to create compiler and I thought about learning and 
 applying this knowledge on writing a GCC frontend just for fun 
 to see where this gets me. However, I've seen some tutorials 
 and I've seen people doing it in C++. Now, I want to do it in D 
 (of course!). My problem is that I don't if the headers are 
 using C++ features because If this is possible then I won't be 
 able to use ImportC to "automatically" get bindings to use in 
 D. Any ideas?
Not sure if this is the same thing (a link would have helped) but [this is done in C](https://www.cs.usfca.edu/~galles/compilerdesign/C/csupport.html)
Feb 23 2022
parent rempas <rempas tutanota.com> writes:
On Wednesday, 23 February 2022 at 20:06:58 UTC, bachmeier wrote:
 Not sure if this is the same thing (a link would have helped) 
 but [this is done in 
 C](https://www.cs.usfca.edu/~galles/compilerdesign/C/csupport.html)
Thank you! However, one things that I didn't mentioned is that GCC was once written in C but now it is written in C++ so the date this was created matters.
Feb 23 2022
prev sibling parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 23 February 2022 at 19:58:45 UTC, rempas wrote:
 Will it be possible to write a GCC frontend in D?
I should hope so, otherwise gdc wouldn't exist, yet it does.
Feb 23 2022
parent reply rempas <rempas tutanota.com> writes:
On Wednesday, 23 February 2022 at 20:19:04 UTC, Adam D Ruppe 
wrote:
 I should hope so, otherwise gdc wouldn't exist, yet it does.
[extern (C++)](https://github.com/D-Programming-GDC/gdc/tree/master/gcc/d/dmd) and manually creating the decorations. At least that's my understanding of browsing the source and that was until 2018. Do you know where is the updated GDC branch btw?
Feb 23 2022
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Wednesday, 23 February 2022 at 20:42:10 UTC, rempas wrote:
 Do you know where is the updated GDC branch btw?
There is no branch, it is just part of the upstream mainline. see: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=gcc/d/dmd;h=454baa71a0d270fb891acdda6fd0215a3d6cb588;hb=HEAD and yeah it is extern(C++). importC isn't going to be helpful, but still, gdc proves you can make a gcc frontend in d.
Feb 23 2022
parent rempas <rempas tutanota.com> writes:
On Wednesday, 23 February 2022 at 21:33:00 UTC, Adam D Ruppe 
wrote:
 There is no branch, it is just part of the upstream mainline. 
 see:

 https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=gcc/d/dmd;h=454baa71a0d270fb891acdda6fd0215a3d6cb588;hb=HEAD
Oh, this is what I mean by saying "branch" so my mistake. Thanks for the info!
 and yeah it is extern(C++). importC isn't going to be helpful, 
 but still, gdc proves you can make a gcc frontend in d.
Yeah, If you put it that way. Tbh, I already knew it was possible to do is this way because I know GDC's frontend was written in D. However, I was wondering if we can have C bindings but it seems that's not the case.
Feb 23 2022