How to run FrontendAction over multiply TU

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to run FrontendAction over multiply TU

Keane, Erich via cfe-dev
Hello!
How can we run ClangTool based AST action over multiply source files.
 
For example command line tool:
./loop-convert --extra-arg-before=-I'/media/sf_share/llvm_9/llvm9-build/lib/clang/9.0.0/include' \
-p '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0' \
'/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/rtc.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/ubi.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/dump.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/loop.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/mtab.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/read.c'
 
 
and code (taken from https://clang.llvm.org/docs/LibASTMatchersTutorial.html)
 
CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList());
LoopPrinter Printer;
MatchFinder Finder;
Finder.addMatcher(LoopMatcher, &Printer);
return Tool.run(newFrontendActionFactory(&Finder).get());
 
 
 
I can iterate over the compilation database entries inside my program or write python wrapper. But I beleive there is an easier way.
newFrontendActionFactory(&Finder).get() works only for last source file in list (libbb/read.c). So how can I match AST nodes over multiply TU in one clang tool?
 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to run FrontendAction over multiply TU

Keane, Erich via cfe-dev
Hey!

Check out this class: https://clang.llvm.org/doxygen/AllTUsExecution_8h_source.html, and its usages. Might be the one you're looking for. It takes care of going over every TU. And it's also doing it multithreaded!


samins KAlex via cfe-dev <[hidden email]> ezt írta (időpont: 2020. júl. 26., V, 10:23):
Hello!
How can we run ClangTool based AST action over multiply source files.
 
For example command line tool:
./loop-convert --extra-arg-before=-I'/media/sf_share/llvm_9/llvm9-build/lib/clang/9.0.0/include' \
-p '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0' \
'/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/rtc.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/ubi.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/dump.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/loop.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/mtab.c' '/home/fvmu/scnd_disk/my_projects/for_code_data_divider/busybox-1.32.0/libbb/read.c'
 
 
 
CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList());
LoopPrinter Printer;
MatchFinder Finder;
Finder.addMatcher(LoopMatcher, &Printer);
return Tool.run(newFrontendActionFactory(&Finder).get());
 
 
 
I can iterate over the compilation database entries inside my program or write python wrapper. But I beleive there is an easier way.
newFrontendActionFactory(&Finder).get() works only for last source file in list (libbb/read.c). So how can I match AST nodes over multiply TU in one clang tool?
 
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to run FrontendAction over multiply TU

Keane, Erich via cfe-dev
+ cfe-dev@
 
Thank you. I found that passing many files (144) to ClangTool-based app causing it to process only last file. But when I pass 5-10 source files it works well as expected. The exact amount of files that does not cause problem I'm going to determine. I use clang 9.0.0.



_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev