Automated porting of druntime to new platforms using libclang
Joakim
joakim at airpost.net
Mon Jan 6 22:02:13 PST 2014
I've been porting dmd to Android/x86 recently and I've been
thinking about whether there's an easier way to handle such
porting in the future. The vast majority of my druntime patches
simply find the equivalent function or macro in the Android C
library, bionic. This is just a lot of name and parameter type
checking most of the time: couldn't this be automated for new
platforms with libclang?
Write a D utility that finds all the platform blocks in druntime
and calls libclang to parse the headers and translate the results
into D, like htod does, then inserts the new version blocks into
druntime, which you can then quickly manually check. Perhaps
this can be built on top of dstep, which I just found while
googling about htod for this post: :)
https://github.com/jacob-carlborg/dstep
Obviously no utility will catch everything, for example, it's not
going to know how to replace missing functions. I'm not sure if
libclang provides for a way to handle architecture-specific
declarations either. But it will save a bunch of time for
druntime porters, and even catch bugs in the existing manually
ported platforms for druntime. Of course, it will only work on
existing clang platforms, but I doubt we're going to beat clang
to a platform. ;)
It could also provide a way to separate out glibc from linux, as
we've been talking about on my Android stdc pull request. After
checking the relevant C header against druntime, this utility
could query the local package manager, pacman in the case of Arch
linux, to see what package owned that C header and then separate
glibc from linux version blocks by using that info.
I don't have any experience with libclang, so I thought I'd run
the idea by you all first. Let me know if you see any problems
with this idea.
More information about the digitalmars-d-ldc
mailing list