libtooling ClangTool::run question for EmitLLVMOnlyAction

Hello,

I am trying to run an EmitLLVMOnlyAction using libtooling. I am following this webpage http://llvm.org/releases/3.4/tools/clang/docs/LibTooling.html

And it actually works, but what I'm trying to do next is to get the llvm::Module by using the llvm::CodeGenAction::takeModule() method. I took a quick look at the code, and seems that for every translation unit a different FrontendAction (EmitLLVMOnlyAction).

The question is:
Is there a way to get a pointer to that FrontendAction (EmitLLVMOnlyAction) created by ClangTool so I can play with the llvm::Modules?

You can write your own FronendActionFactory, and then you have total control over the Action you create and what you want to do with it. I have never done anything with llvm::Modules, so unforeseen problems might arise :wink:

Thanks for confirming my suspicious… hopefully no unforeseen problems arise while I do that:)

Regards

FWIW, here's an example of a FrontendActionFactory which performs a custom
action on the module:

https://github.com/google/souper/blob/master/lib/ClangTool/Actions.cpp

Thanks Peter, that will help!