Thread overview
Will it be possible to write a GCC frontend in D?
Feb 23, 2022
rempas
Feb 23, 2022
bachmeier
Feb 23, 2022
rempas
Feb 23, 2022
Adam D Ruppe
Feb 23, 2022
rempas
Feb 23, 2022
Adam D Ruppe
Feb 24, 2022
rempas
February 23, 2022

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?

February 23, 2022

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

February 23, 2022
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.
February 23, 2022

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

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.

February 23, 2022

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++) 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?

February 23, 2022
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.
February 24, 2022
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.