Question about dump-ast and logging the output to file

Hello everybody,

I am planning in doing some research and analysis with the ASTs of swift
programs and, for that reason, *I am trying to modify the compiler to
always generate a file with the contents of the -dump-ast flag when
building a project.*

However, I wanted to do this even *without the -dump-ast flag*, since it
can't be used in conjunction with -emit-modules flags. This is also
necessary because I'm using this modified version as a custom toolchain in
Xcode, so all the building process (and flags) are being handed by it.

Apart from the files that handles the flags (e.g.. lib/Immediate/REPL.cpp,
lib/Frontend/CompilerInvocation.cpp), *I am having problems to find
how/where the act of dumping actually starts (where the visitor to
print/dump starts)*. From that point, I could then try to "force" the
dumping, and change the output to a file. I am not familiar with the
project nor C++, so it is being a challenge.

Any thoughts on how I could achieve this? Any directions on how to do it
would be appreciated.

Thanks,
Marcel

Hi Marcel,

dump-ast format is not machine-parseable. It was never designed to be
such (so it is irregular), and it will change in incompatible ways in
future. And of course '-dump-ast' is not a publicly documented
compiler flag, so it can go away at any point, for example, it can be
removed from compilers built as public releases to save code size.

If you want to (eventually) use your tool in a production environment,
you should consider building your tool on top of SourceKit, possibly
extending SourceKit along the way.

Dmitri

···

On Wed, Aug 24, 2016 at 10:27 AM, Marcel Rebouças <swift-dev@swift.org> wrote:

Hello everybody,

I am planning in doing some research and analysis with the ASTs of swift
programs and, for that reason, I am trying to modify the compiler to always
generate a file with the contents of the -dump-ast flag when building a
project.

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

Hello Dmitri,

Thank you for your answer. Although I didn't tell, I was already able to
generate the output of the astdumper to a file (without using the flag,
just reusing the AstDumper class) when building through Xcode. I understand
that the output is irregular, but I plan to eventually modify the dumper
according to my needs to make the output usable.

Also, I will take a deeper look at SourceKit. It seems to be the correct
way to do it. Thank you very much for the tip.

Thanks,
Marcel

···

Em domingo, 28 de agosto de 2016, Dmitri Gribenko <gribozavr@gmail.com> escreveu:

On Wed, Aug 24, 2016 at 10:27 AM, Marcel Rebouças <swift-dev@swift.org > <javascript:;>> wrote:
> Hello everybody,
>
> I am planning in doing some research and analysis with the ASTs of swift
> programs and, for that reason, I am trying to modify the compiler to
always
> generate a file with the contents of the -dump-ast flag when building a
> project.

Hi Marcel,

dump-ast format is not machine-parseable. It was never designed to be
such (so it is irregular), and it will change in incompatible ways in
future. And of course '-dump-ast' is not a publicly documented
compiler flag, so it can go away at any point, for example, it can be
removed from compilers built as public releases to save code size.

If you want to (eventually) use your tool in a production environment,
you should consider building your tool on top of SourceKit, possibly
extending SourceKit along the way.

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com
<javascript:;>>*/