facebookarchive / facebook-clang-plugins

Plugins to clang-analyzer and clang-frontend
MIT License
482 stars 85 forks source link

Basic documentation on how to get an OCaml AST dumper of a c++ program #25

Open aryx opened 3 years ago

aryx commented 3 years ago

I could not find any documentation on how to install and use facebook-clang-plugins and its ocaml library to get a simple AST dump of a c++ program.

Let's say I have this simple c++ program:

void main() { return 1 + 2; }

Which OCaml program do I need to write to access its AST from OCaml?

jvillard commented 3 years ago

To get a dump you need to run clang with the plugin attached:

./facebook-clang-plugins/clang/install/bin/clang \
  -Xclang -load -Xclang facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib \
  -Xclang -add-plugin -Xclang YojsonASTExporter \
  -c examples/hello.c

To read that data from OCaml you can take a look at the clang-ocaml/ directory, which has a README.md, or at how infer does it.

aryx commented 3 years ago

Thx a lot! I think you should put such information in the toplevel README of this project.