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.
Celuk
August 21, 2022, 12:54pm
3
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:
lang_opts.ThreadsafeStatics = false;
lang_opts.AccessControl = false; // Debuggers get universal access
lang_opts.DollarIdents = true; // $ indicates a persistent variable name
// We enable all builtin functions beside the builtins from libc/libm (e.g.
// 'fopen'). Those libc functions are already correctly handled by LLDB, and
// additionally enabling them as expandable builtins is breaking Clang.
lang_opts.NoBuiltin = true;
// Set CodeGen options
m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
m_compiler->getCodeGenOpts().InstrumentFunctions = false;
m_compiler->getCodeGenOpts().setFramePointer(
CodeGenOptions::FramePointerKind::All);
if (generate_debug_info)
m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
else
m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::NoDebugInfo);
// Disable some warnings.
SetupDefaultClangDiagnostics(*m_compiler);
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.