[cfe-dev] libclang or libtooling for transpiler

Jacob Carlborg via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 29 03:06:25 PDT 2019


On 2019-04-28 19:57, Andrei Damian via cfe-dev wrote:
> Hello. First time here, no tomatoes please.
> 
> 
> Long story short, I want to attempt to make a cpp to rust transpiler. I 
> know it’s a very big task with a lot of work, but let’s ignore that for 
> a moment.
> 
> Like any sane person who doesn’t want to parse cpp himself (or any text 
> format for that matter), I’m counting on clang to be able to give me 
> enough information (the whole AST?) so that I’d be able to translate it.
> 
>  From what I can see my options are the following:
> 
> 1. libtooling, which from what I understand can do „everything”, but is 
> somewhat unstable;
> 
> 2. libclang, which is a C interface to the AST. So basically a stable C 
> API to libtooling.
> 
> So, here’s the question(s): Will libclang suffice my need? Which option 
> would you consider is the best?

I've created a tool that does basically the same thing. It generate D 
bindings to C and Objective-C libraries. This tool is written in D and 
is using libclang [1]. It's been working for me so far, but I haven't 
got to the point of trying to translate C++ headers yet.

This tool is only focusing on generating bindings. That means only the 
header files are translated, not full C/Objective-C code with function 
bodies with statements and expressions.

The current libclang bindings DStep is using are generated with DStep 
itself. The initial bindings were created by had. It was very easy to 
do, just some search and replace. libclang contains the most forgiving 
header files, from this point of view, I have ever seen.

[1] http://github.com/jacob-carlborg/dstep

-- 
/Jacob Carlborg



More information about the cfe-dev mailing list