Hi. I am a beginner in clang/llvm. When I use the option -ast-print, I found that clang does not generate executable files from source files. If I want clang to generate an executable file at the same time when using such AST related options, what should I do? Or what should I mainly modify in the source code? Thanks!
Hi @cokeom !
-ast-print is an “action” flag - it specifies what action the frontend driver (
clang -cc1) is meant to run. See the definition here (highlighting the whole block so that you can see
Action_Group flag). Now, the frontend driver will run only one action at a time, the rightmost one on the command line [*].
In other words, it’s not possible to generate an executable when using
-ast-print. And I’m referring to
clang -cc1 rather than
clang just to highlight that this design decision was made in the frontend rather than the compiler driver.
I hope that this helps.
[*] This happens when parsing command line arguments in CompilerInvocation.cpp.
Thank you for your reply.
Because now I want to add an option that not only has access to the AST node information, but also lets the compiler run to the stage of generating the executable. At first I wanted to use the ASTFrontendAction interface to implement this option (like -ast-print), but it doesn’t seem to work at the moment. Is there any other way to achieve this option requirement in clang?
Do you really need both at the same time?
Clang tooling helps you write your own ASTWalkers.
Thanks for your reply, this is very helpful for me.