1

I would like to make a LibTooling tool that takes precisely the same compilation string as clang. For example clang a.c -O3 b.c -I/myinclude -DMY_DEFINE c.c. Should be replaced by my-tool a.c -O3 b.c -I/myinclude -DMY_DEFINE c.c

Officially suggested by clang documentation way to parse arguments in LibTooling-based tools is CommonOptionsParser. It expects a different format of command-line string and by default relies on the compile_commands.json file. I can simulate desired behavior if I put all source files before -- and everything else after it, like this: my-tool a.c b.c c.c -- -O3 -I/myinclude -DMY_DEFINE. Is it possible to implement this without such hacking of parameter string using llvm/clang API?

  • 1
    Clang doesn't have an API (it's not a library even if large parts of the functioality is in one library or another) and LLVM's libraries don't have "compatibility with that not-an-API" as a project goal, so I'm afraid you'll have to write some code yourself to make that happen. Probably you can copy code from clang's command-line parsing to make it do the same. – arnt Feb 15 '21 at 20:36
  • You could also consider writing some [GCC plugin](https://gcc.gnu.org/onlinedocs/gccint/Plugins.html) for your tool, or extend [Frama-C](https://frama-c.com/) – Basile Starynkevitch Feb 16 '21 at 07:17

0 Answers0