Dumping Clang AST to a file

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 9 05:24:00 PDT 2019


On Tue, Jul 9, 2019 at 8:11 AM Monalisa Rout via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
> Hello, Currently I am dumping the Clang AST to the console but I want to write it to a file.
>
> I have pasted the code snippet.
>
> bool HandleTopLevelDecl(DeclGroupRef DR) override {
> for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
> (*b)->dump(llvm::errs(), false,clang::ADOF_JSON);
> }
> return true;
> }
>
> How this can be done ?? Any help is appreciated.

You are currently using llvm::errs() as the output stream for dumping.
To dump to a file, you would want to use a raw_fd_ostream object
(raw_ostream.h) instead.

HTH!

~Aaron

>
> Regards,
> Mona
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list