[cfe-dev] converting a LibTooling tool to a library

Manuel Klimek klimek at google.com
Fri Oct 26 09:02:47 PDT 2012


On Fri, Oct 26, 2012 at 5:48 PM, Eric Schulte <schulte.eric at gmail.com>wrote:

> Hi,
>
> I've written a simple command-line code-mutation tool using the Tooling
> infrastructure [1].  The tooling framework handled many of the difficult
> portions of this task (handling compilation databases etc...) allowing
> me to focus on writing a RecursiveASTVisitor -- my thanks to everyone
> who worked on the tooling setup and on clang in general.
>

:)

I would now like to expose the functionality of this ASTVisitor as a C
> library so that I can call these functions programatically and chain
> multiple ASTConsumers without the overhead of multiple shell calls,
> repeatedly parsing of the original source, etc...
>
> Is this possible?  Is this difficult?  Is there a best practice for
> transitioning from a command-line Tooling tool to a library?  Should I
> just look though the clang/Tooling source?  Any pointers or suggestions
> would be greatly appreciated.
>

I think you're the first one to go this route - one thing I notice is that
you say "C library". I assume that's a requirement? In general, the way I'd
go about this is:
- build a C++ library
- build a C wrapper that exposes the functionality

That's pretty much the way libclang does it (minus some stuff that's only
in libclang, but we've already noticed some of that stuff would be very
nice to have in a C++ layer).

Your tool is also sufficiently narrow focus currently that I think it might
make sense to go into clang mainline as a library and be useful from
libclang, but Doug might have a different opinion.


> Thanks,
>
> Footnotes:
> [1]  https://github.com/eschulte/clang-mutate


Nice! Looks awesome :)
/me wonders whether it would be a perfect fit for the extra-tools
repository...

Cheers,
/Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121026/9736a7fa/attachment.html>


More information about the cfe-dev mailing list