[clang-tools]How to make clang tool execute the CodeGen process

I created a clang tool to analyze AST and get the required information. I add a “FrontendAction”. I also noticed “CodegenAction” class. But I can’t use “CodegenAction” class in same way.

Can anyone help me? Thank you anyway.

code: main()

int main(int argc, const char **argv)
{
    cout<<"tools start"<<endl;
    auto Op = CommonOptionsParser::create(argc, argv, MyToolCategory);
    if(!Op){llvm::errs()<<Op.takeError();return 1;}
    CommonOptionsParser &Opg=Op.get();
    
    ClangTool Tool(Opg.getCompilations(),Opg.getSourcePathList());
    Matrix_ident matrixidenter;
    MatchFinder Finder;
    Finder.addMatcher(MatrixMatcher, &matrixidenter);
    Tool.run(newFrontendActionFactory(&Finder).get());
    
    cout<<"tools finish"<<endl;
    return 0;
}

My target is output the information obtained by clangtool to metadata. So I want execute the Codegen process in my clang tool. Thank you again.

I don’t know what you want exactly to do but I think it is best way to use functions, classes from the library is searching for an example usage in the source code. (maybe you need more classes)

So, for CodeGenAction search on github: Search · codegenaction · GitHub
In doxygen: clang: clang::CodeGenAction Class Reference

And you can see some examples:

Thank you for your reply.
I find another way to achieve my target ----- modify the source code of codegen.
In this way, I can get the information and setmetadata without Clang tooling.