| Thread overview | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 25, 2009 D to C compiler? | ||||
|---|---|---|---|---|
| ||||
I remember reading something about a D to C compiler on this group a few years ago. (I'm not really a regular here anymore, so there might have been more recent mentions that I've missed.) Does anyone know if there's any such project still around that's alive or could be revived? Or if there's any other viable solutions for converting D to C (or C++)? The reason I would want to do this is to port D code to currently non-supported platforms. This is especially important for game projects (like my own monsterscript project) - most game console SDKs take C/C++ and nothing else. The C/C++ output wouldn't have to be nice or even human readable - just compilable. It would only be used as a middle step in the compilation process for these platforms. Any ideas or suggestions? Nico | ||||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nicolay Korslund | On Sun, 25 Jan 2009 17:56:30 +0300, Nicolay Korslund <korslund@gmail.com> wrote:
> I remember reading something about a D to C compiler on this group a few years ago. (I'm not really a regular here anymore, so there might have been more recent mentions that I've missed.) Does anyone know if there's any such project still around that's alive or could be revived? Or if there's any other viable solutions for converting D to C (or C++)?
>
> The reason I would want to do this is to port D code to currently non-supported platforms. This is especially important for game projects (like my own monsterscript project) - most game console SDKs take C/C++ and nothing else. The C/C++ output wouldn't have to be nice or even human readable - just compilable. It would only be used as a middle step in the compilation process for these platforms.
>
> Any ideas or suggestions?
>
> Nico
There were two projects I've heard of, but none of them are functional AFAIK.
Perhaps, LDC could translate D code into C?
BTW, what are the platforms you are talking about?
| |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nicolay Korslund | "Nicolay Korslund" <korslund@gmail.com> wrote in message news:glhuiu$11ck$1@digitalmars.com... >I remember reading something about a D to C compiler on this group a few years ago. (I'm not really a regular here anymore, so there might have been more recent mentions that I've missed.) Does anyone know if there's any such project still around that's alive or could be revived? Or if there's any other viable solutions for converting D to C (or C++)? > > The reason I would want to do this is to port D code to currently non-supported platforms. This is especially important for game projects (like my own monsterscript project) - most game console SDKs take C/C++ and nothing else. The C/C++ output wouldn't have to be nice or even human readable - just compilable. It would only be used as a middle step in the compilation process for these platforms. > > Any ideas or suggestions? > > Nico I don't think there's anything like that in a fully-usable form just yet, but there are at least a few leads: - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, but I don't know how far along that is or if it's working with LDC (and from what I hear, even LDC itself isn't quite production-ready just yet, but it is movng along quickly). - It might be possible to create something with ANTLR to do this, but you'd have to define a full D grammar in ANTLR along with instructions on how to convert it to C. A lot of work, but might be easier than a full from-scratch D-to-C converter. - Also, I'm in the early stages of a pet project that, if successful, may eventually be able to do that. But it's nowhere near such a level yet. But regardless, the ability to convert D to plain C is something that IMO really does need to happen at some point. | |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | == Quote from Nick Sabalausky (a@a.a)'s article
> - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, but I don't know how far along that is or if it's working with LDC (and from what I hear, even LDC itself isn't quite production-ready just yet, but it is movng along quickly).
This is true. I've played around w/ this C back end w/ some toy programs and and it works reasonably well, but I forgot about it. At any rate, could this be used as a temporary kludge to get LDC "working" on unsupported platforms like Windows until it works natively? Basically, LDC for Windows and other unsupported platforms would compile the D code to C, and then compile the C code w/ the native C compiler for the platform.
| |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dsimcha | On Sun, Jan 25, 2009 at 2:11 PM, dsimcha <dsimcha@yahoo.com> wrote:
> == Quote from Nick Sabalausky (a@a.a)'s article
>> - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, but I don't know how far along that is or if it's working with LDC (and from what I hear, even LDC itself isn't quite production-ready just yet, but it is movng along quickly).
>
> This is true. I've played around w/ this C back end w/ some toy programs and and it works reasonably well, but I forgot about it. At any rate, could this be used as a temporary kludge to get LDC "working" on unsupported platforms like Windows until it works natively? Basically, LDC for Windows and other unsupported platforms would compile the D code to C, and then compile the C code w/ the native C compiler for the platform.
The problem with LDC on Windows is not that LLVM doesn't have a backend for Windows; it does. It's just that LLVM doesn't yet support Windows exception handling. Using the C backend wouldn't help there.
| |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | == Quote from Jarrett Billingsley (jarrett.billingsley@gmail.com)'s article > On Sun, Jan 25, 2009 at 2:11 PM, dsimcha <dsimcha@yahoo.com> wrote: > > == Quote from Nick Sabalausky (a@a.a)'s article > >> - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, but I don't know how far along that is or if it's working with LDC (and from what I hear, even LDC itself isn't quite production-ready just yet, but it is movng along quickly). > > > > This is true. I've played around w/ this C back end w/ some toy programs and and it works reasonably well, but I forgot about it. At any rate, could this be used as a temporary kludge to get LDC "working" on unsupported platforms like Windows until it works natively? Basically, LDC for Windows and other unsupported platforms would compile the D code to C, and then compile the C code w/ the native C compiler for the platform. > The problem with LDC on Windows is not that LLVM doesn't have a backend for Windows; it does. It's just that LLVM doesn't yet support Windows exception handling. Using the C backend wouldn't help there. Is there any decent reading material out there about how exception handling is works under the hood and why it can't be done in a cross-platform way at the C level? From reading and participating in discussions about LDC, I've come to realize that implementing exception handling is a *much* harder problem than I would have anticipated, and I've become very curious as to why. Wikipedia would be the obvious place, but it doesn't seem to provide much detail. | |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | On Sun, 25 Jan 2009 23:01:49 +0300, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote: > On Sun, Jan 25, 2009 at 2:11 PM, dsimcha <dsimcha@yahoo.com> wrote: >> == Quote from Nick Sabalausky (a@a.a)'s article >>> - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, >>> but I don't know how far along that is or if it's working with LDC (and from >>> what I hear, even LDC itself isn't quite production-ready just yet, but it >>> is movng along quickly). >> >> This is true. I've played around w/ this C back end w/ some toy programs and and >> it works reasonably well, but I forgot about it. At any rate, could this be used >> as a temporary kludge to get LDC "working" on unsupported platforms like Windows >> until it works natively? Basically, LDC for Windows and other unsupported >> platforms would compile the D code to C, and then compile the C code w/ the native >> C compiler for the platform. > > The problem with LDC on Windows is not that LLVM doesn't have a > backend for Windows; it does. It's just that LLVM doesn't yet support > Windows exception handling. Using the C backend wouldn't help there. Err... Isn't generated C code cross-platform? Code generated for Linux could be used to compile code for Windows, no? | |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
On Mon, Jan 26, 2009 at 5:01 AM, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote: > On Sun, Jan 25, 2009 at 2:11 PM, dsimcha <dsimcha@yahoo.com> wrote: >> == Quote from Nick Sabalausky (a@a.a)'s article >>> - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, but I don't know how far along that is or if it's working with LDC (and from what I hear, even LDC itself isn't quite production-ready just yet, but it is movng along quickly). >> >> This is true. I've played around w/ this C back end w/ some toy programs and and it works reasonably well, but I forgot about it. At any rate, could this be used as a temporary kludge to get LDC "working" on unsupported platforms like Windows until it works natively? Basically, LDC for Windows and other unsupported platforms would compile the D code to C, and then compile the C code w/ the native C compiler for the platform. > > The problem with LDC on Windows is not that LLVM doesn't have a backend for Windows; it does. It's just that LLVM doesn't yet support Windows exception handling. Using the C backend wouldn't help there. I would think a C backend would be converting exceptions into portable setjmp/longjmp. That's the only way to emulate exceptions in C as far as I know. Not so? --bb | ||||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin wrote:
> On Sun, 25 Jan 2009 23:01:49 +0300, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:
>
>> On Sun, Jan 25, 2009 at 2:11 PM, dsimcha <dsimcha@yahoo.com> wrote:
>>> == Quote from Nick Sabalausky (a@a.a)'s article
>>>> - Like Denis said, I've heard LLVM is supposed to have a plain-C
>>>> backend,
>>>> but I don't know how far along that is or if it's working with LDC
>>>> (and from
>>>> what I hear, even LDC itself isn't quite production-ready just yet,
>>>> but it
>>>> is movng along quickly).
>>>
>>> This is true. I've played around w/ this C back end w/ some toy
>>> programs and and
>>> it works reasonably well, but I forgot about it. At any rate, could
>>> this be used
>>> as a temporary kludge to get LDC "working" on unsupported platforms
>>> like Windows
>>> until it works natively? Basically, LDC for Windows and other
>>> unsupported
>>> platforms would compile the D code to C, and then compile the C code
>>> w/ the native
>>> C compiler for the platform.
>>
>> The problem with LDC on Windows is not that LLVM doesn't have a backend for Windows; it does. It's just that LLVM doesn't yet support Windows exception handling. Using the C backend wouldn't help there.
>
> Err... Isn't generated C code cross-platform? Code generated for Linux could be used to compile code for Windows, no?
That presumes that the interfaces are cross-platform, but they're not. The win32 api's are win32 specific. Exception handling specifications are different between windows and unix (nearly all unix os' use the exact same eh specs for the last 10 years or so). Within the unix world, the lowest level syscalls aren't the same across the various flavors. That's why specifications like posix were created. Those interfaces are specifically designed to insulate applications from the lowest level details of cross-system differences.
Anyway, if only it was that simple.. :)
Later,
Brad
| |||
January 25, 2009 Re: D to C compiler? | ||||
|---|---|---|---|---|
| ||||
Bill Baxter wrote:
> On Mon, Jan 26, 2009 at 5:01 AM, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:
>> On Sun, Jan 25, 2009 at 2:11 PM, dsimcha <dsimcha@yahoo.com> wrote:
>>> == Quote from Nick Sabalausky (a@a.a)'s article
>>>> - Like Denis said, I've heard LLVM is supposed to have a plain-C backend, but I don't know how far along that is or if it's working with LDC (and from what I hear, even LDC itself isn't quite production-ready just yet, but it is movng along quickly).
>>> This is true. I've played around w/ this C back end w/ some toy programs and and it works reasonably well, but I forgot about it. At any rate, could this be used as a temporary kludge to get LDC "working" on unsupported platforms like Windows until it works natively? Basically, LDC for Windows and other unsupported platforms would compile the D code to C, and then compile the C code w/ the native C compiler for the platform.
>> The problem with LDC on Windows is not that LLVM doesn't have a backend for Windows; it does. It's just that LLVM doesn't yet support Windows exception handling. Using the C backend wouldn't help there.
>
> I would think a C backend would be converting exceptions into portable setjmp/longjmp. That's the only way to emulate exceptions in C as far as I know. Not so?
>
> --bb
It could, but then it still wouldn't necessarily interact properly with other C++ or D code eh mechanisms which aren't sjlj based. On unix, sjlj exceptions aren't used anymore. I'm not sure about windows. The presentation I saw that went through win64 showed that at least those weren't sjlj but rather closely matched unix, using lookup tables to do the unwinding.
Later,
Brad
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply