Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
July 23, 2016 Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Is there any kind of project or workflow that converts D (subset) to C/CPP ? |
July 24, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to ParticlePeter | On 24/07/2016 12:27 AM, ParticlePeter wrote: > Is there any kind of project or workflow that converts D (subset) to > C/CPP ? This probably will interest you for ldc: http://stackoverflow.com/questions/5180914/llvm-ir-back-to-human-readable-source-language |
July 23, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Saturday, 23 July 2016 at 12:29:45 UTC, rikki cattermole wrote:
> On 24/07/2016 12:27 AM, ParticlePeter wrote:
>> Is there any kind of project or workflow that converts D (subset) to
>> C/CPP ?
>
> This probably will interest you for ldc: http://stackoverflow.com/questions/5180914/llvm-ir-back-to-human-readable-source-language
Cool, I didn't know that one but I also didn't invest time in LLVM till now.
However, this converts bitcode to C/CPP, my guess would be that the job can be done much better if the original D source would be used in tandem.
|
July 23, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to ParticlePeter | On 2016-07-23 14:27, ParticlePeter wrote: > Is there any kind of project or workflow that converts D (subset) to > C/CPP ? No idea about the status but: https://github.com/adamdruppe/tools/blob/dtoh/dtoh.d -- /Jacob Carlborg |
July 24, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 23 July 2016 at 19:20:10 UTC, Jacob Carlborg wrote:
> On 2016-07-23 14:27, ParticlePeter wrote:
>> Is there any kind of project or workflow that converts D (subset) to
>> C/CPP ?
>
> No idea about the status but: https://github.com/adamdruppe/tools/blob/dtoh/dtoh.d
Thanks, I am looking into this, but I think its still not that what I am searching, it seems to create only C/CPP headers for D libs. I would like to have the whole source code transformed.
|
July 25, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to ParticlePeter | On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote:
> Is there any kind of project or workflow that converts D (subset) to C/CPP ?
The short answer is no, not for any recent version of D.
|
July 28, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, 25 July 2016 at 07:53:17 UTC, Stefan Koch wrote: > On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote: >> Is there any kind of project or workflow that converts D (subset) to C/CPP ? > > The short answer is no, not for any recent version of D. The long answer is it's kind of possible, but the resulting C code is not human-readable. I just managed today to achieve some transformation to C with the below script: # compile the D modules to llvm bitcode $ ldc2 hello.d -c -output-ll -ofhello.ll $ ldc2 lib.d -c -output-ll -oflib.ll # merge them into one LLVM bitcode module $ llvm-link-3.8 hello.ll lib.ll -o full.bc $ llvm-dis-3.8 full.bc -o=full.ll # convert bitcode to C $ llvm-cbe full.ll # patch the generated C, so it's compilable $ sed -i "s/.*APInt.*//" full.cbe.c $ sed -i "s/^uint32_t main(uint32_t llvm_cbe_argc_arg, uint8_t\*\* llvm_cbe_argv_arg)/int main(int llvm_cbe_argc_arg, char** llvm_cbe_argv_arg)/" full.cbe.c $ sed -i "s/^uint32_t main(uint32_t, uint8_t\*\*)/int main(int, char**)/" full.cbe.c # compile the C program and run it. $ gcc -w full.cbe.c -o full.exe -lphobos2 $ ./full.exe Hello, world: 46 I only tried this with a very minimalistic subset of D at the moment. Most of the magic occurs in the "llvm-cbe" program, which is a "resurrected LLVM C backend" ( https://github.com/JuliaComputing/llvm-cbe ). |
July 28, 2016 Re: Transform/Compile to C/CPP as a target | ||||
---|---|---|---|---|
| ||||
Posted in reply to ParticlePeter | On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote: > Is there any kind of project or workflow that converts D (subset) to C/CPP ? Just FYI there is a project that does the reverse. > Calypso creates a bridge between DMD/LDC and Clang, both at the AST level (DMD <=> Clang's AST, Sema, ...) and at the code generation level (LDC <=> Clang's Codegen) to make D interface directly with the almost full set of C++ features, and no binding is needed. https://github.com/Syniurge/Calypso |
Copyright © 1999-2021 by the D Language Foundation