www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Transform/Compile to C/CPP as a target

reply ParticlePeter <ParticlePeter gmx.de> writes:
Is there any kind of project or workflow that converts D (subset) 
to C/CPP ?
Jul 23 2016
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
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
Jul 23 2016
parent ParticlePeter <ParticlePeter gmx.de> writes:
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.
Jul 23 2016
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
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
Jul 23 2016
parent ParticlePeter <ParticlePeter gmx.de> writes:
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.
Jul 24 2016
prev sibling next sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
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.
Jul 25 2016
parent Sebastien Alaiwan <ace17 free.fr> writes:
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: $ ldc2 hello.d -c -output-ll -ofhello.ll $ ldc2 lib.d -c -output-ll -oflib.ll $ llvm-link-3.8 hello.ll lib.ll -o full.bc $ llvm-dis-3.8 full.bc -o=full.ll $ llvm-cbe full.ll $ 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 $ 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 ).
Jul 28 2016
prev sibling parent Seb <seb wilzba.ch> writes:
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
Jul 28 2016