www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Question over C++ to D conversion

reply Richard <garlicbready googlemail.com> writes:
Hi,
I'm sure this question has been asked a few times before
But I'm currently looking at something that will convert Cpp code 
to D

I've recently setup a proof of concept demo which uses mbed for 
an embedded LPC1769 Arm board
This is just a test, but I've recently managed to get debugging 
working across both C and D files at the same time.
This means single stepping code on a remotely attached Arm board 
in VSCode, while being able to inspect registers with an svd file
https://github.com/grbd/GBD.Dlang.MbedBlinkyTest

There's a couple of outstanding things at the moment though

The first is the use of BetterC, although from what I can tell 
DMD now has support for a minimal runtime feature as part of 
2.079.0
https://dlang.org/changelog/2.079.0.html#minimal_runtime
so hopefully when this makes it's way into LDC I can then make 
use of it for an Arm MCU for creating class's without the full 
runtime.
https://github.com/ldc-developers/ldc/pull/2587

These were also mentioned in a separate thread.
   * https://bitbucket.org/timosi/minlibd
   * https://github.com/JinShil/stm32f42_discovery_demo
   * https://github.com/kubo39/stm32f407discovery


The second is that mbed uses C++ class's for it's API
most of this is just headers such as DigitalOut.h
https://github.com/ARMmbed/mbed-os/blob/master/drivers/DigitalOut.h
So ideally I've been looking for something that can translate 
those headers into Dlang so they can be used there instead.

   * The first two utils I've found were DStep and htod, however 
they seem to only hand C
     https://github.com/jacob-carlborg/dstep

   * I discovered some examples of libraries over here
     https://github.com/D-Programming-Deimos

   * There's CPP2D but the last update was around 2016
     https://github.com/lhamot/CPP2D

   * Calypso seems to be a Fork of LDC, but I think it might be a 
while before 2.079.0 makes it in.
     https://github.com/Syniurge/Calypso

     One possibility I might look into is a D backend for CppSharp 

   * https://github.com/mono/CppSharp

I was wondering if there are any other ways that are known about 
for translating C++ into D, or accessing C++ libraries.

Many Thanks
Richard
Mar 11 2018
next sibling parent Mike Parker <aldacron gmail.com> writes:
On Monday, 12 March 2018 at 01:10:41 UTC, Richard wrote:

 I was wondering if there are any other ways that are known 
 about for translating C++ into D, or accessing C++ libraries.
If you have access to a Windows box, this might help get you there: http://rainers.github.io/visuald/visuald/CppConversion.html
Mar 11 2018
prev sibling next sibling parent Mike Franklin <slavo5150 yahoo.com> writes:
On Monday, 12 March 2018 at 01:10:41 UTC, Richard wrote:

 There's a couple of outstanding things at the moment though

 The first is the use of BetterC, although from what I can tell 
 DMD now has support for a minimal runtime feature as part of 
 2.079.0
 https://dlang.org/changelog/2.079.0.html#minimal_runtime
 so hopefully when this makes it's way into LDC I can then make 
 use of it for an Arm MCU for creating class's without the full 
 runtime.
 https://github.com/ldc-developers/ldc/pull/2587
I'm hoping for that to land soon as well. The minimal runtime features and -betterC do have some overlap, but there are some specific things -betterC does that the minimal runtime doesn't do. See https://dlang.org/spec/betterc.html. At least one such feature is "assert failures are directed to the C runtime library". The minimal runtime has uses for those wishing to port the druntime to a new platform or architecture and do so incrementally. It's also useful for those that may choose to implement minimal subset of runtime features or provide an alternate implementation of a runtime feature for their application. This is especially useful in the embedded domain where there is typically one process running, and you know upfront what features you will need or not need; and you won't have to do the work of porting everything just to get a build. -betterC, on the other hand, is somewhat of a blunt instrument, and removes certain features of the runtime wholesale. With the minimal runtime features, you will be able to create a betterC-like application by simply avoiding features that you haven not implemented in your port of the runtime. That wasn't possible prior to 2.079.0.
 I was wondering if there are any other ways that are known 
 about for translating C++ into D, or accessing C++ libraries.
I'm sorry I don't know of any reliable tool that can create bindings to C++ libraries automatically. Mike
Mar 11 2018
prev sibling next sibling parent reply Laeeth Isharc <Laeeth laeeth.com> writes:
On Monday, 12 March 2018 at 01:10:41 UTC, Richard wrote:
 The second is that mbed uses C++ class's for it's API
 most of this is just headers such
 I was wondering if there are any other ways that are known 
 about for translating C++ into D, or accessing C++ libraries.

 Many Thanks
 Richard
See Gooberman fork of binderoo. It only worked on Windows and X Box before, but now it should work on Linux. That's for C++ For conversion of C headers, watch this space. C first, C++ eventually. Might be a talk at Dconf on it. Also see the tool in Visual D, which I haven't yet used myself.
Mar 11 2018
parent reply jmh530 <john.michael.hall gmail.com> writes:
On Monday, 12 March 2018 at 02:48:17 UTC, Laeeth Isharc wrote:
 [snip]
 For conversion of C headers, watch this space.  C first, C++ 
 eventually.  Might be a talk at Dconf on it.
I think I saw a reference to this somewhere else. Sounds pretty darn cool.
Mar 11 2018
parent reply Richard <garlicbready googlemail.com> writes:
On Monday, 12 March 2018 at 03:42:41 UTC, jmh530 wrote:
 On Monday, 12 March 2018 at 02:48:17 UTC, Laeeth Isharc wrote:
 [snip]
 For conversion of C headers, watch this space.  C first, C++ 
 eventually.  Might be a talk at Dconf on it.
I think I saw a reference to this somewhere else. Sounds pretty darn cool.
This might be it https://github.com/atilaneves/dpp I noticed it mentioned on the online DConf 2018 youtube video
May 15 2018
parent reply Filipe =?UTF-8?B?TGHDrW5z?= <filipe.lains gmail.com> writes:
On Tuesday, 15 May 2018 at 21:00:25 UTC, Richard wrote:
 On Monday, 12 March 2018 at 03:42:41 UTC, jmh530 wrote:
 On Monday, 12 March 2018 at 02:48:17 UTC, Laeeth Isharc wrote:
 [snip]
 For conversion of C headers, watch this space.  C first, C++ 
 eventually.  Might be a talk at Dconf on it.
I think I saw a reference to this somewhere else. Sounds pretty darn cool.
This might be it https://github.com/atilaneves/dpp I noticed it mentioned on the online DConf 2018 youtube video
Are you aware of DStep? It has been working great for me. The only downside is that it doesn't do C++ at all :/ . https://github.com/jacob-carlborg/dstep
May 15 2018
parent Filipe =?UTF-8?B?TGHDrW5z?= <filipe.lains gmail.com> writes:
On Tuesday, 15 May 2018 at 22:07:02 UTC, Filipe LaĆ­ns wrote:
 On Tuesday, 15 May 2018 at 21:00:25 UTC, Richard wrote:
 On Monday, 12 March 2018 at 03:42:41 UTC, jmh530 wrote:
 On Monday, 12 March 2018 at 02:48:17 UTC, Laeeth Isharc wrote:
 [snip]
 For conversion of C headers, watch this space.  C first, C++ 
 eventually.  Might be a talk at Dconf on it.
I think I saw a reference to this somewhere else. Sounds pretty darn cool.
This might be it https://github.com/atilaneves/dpp I noticed it mentioned on the online DConf 2018 youtube video
Are you aware of DStep? It has been working great for me. The only downside is that it doesn't do C++ at all :/ . https://github.com/jacob-carlborg/dstep
Oh sorry, my mistake. I missed your link above.
May 15 2018
prev sibling parent Johan Engelen <j j.nl> writes:
On Monday, 12 March 2018 at 01:10:41 UTC, Richard wrote:
 
 The first is the use of BetterC, although from what I can tell 
 DMD now has support for a minimal runtime feature as part of 
 2.079.0
 https://dlang.org/changelog/2.079.0.html#minimal_runtime
 so hopefully when this makes it's way into LDC I can then make 
 use of it for an Arm MCU for creating class's without the full 
 runtime.
Have you tried with LDC 1.9.0? (dlang 2.079) Would be very interesting to hear about your experiences in trying to put together / use a minimal runtime. Cheers, Johan
May 15 2018