0

I have a .c source file and i want to analysis the output of the source file after parsing stage of gcc and generate report on basis of it.what could be the possible methods to do so
How can i do this with gcc

In case of preprocessing the code can be generated by passing -E argument to gcc but what would be the way to do to generate parsed output of the code only??

  • 1
    possible duplicate of [How can I see parse tree, intermediate code, optimization code and assembly code during COMPILATION?](http://stackoverflow.com/questions/1496497/how-can-i-see-parse-tree-intermediate-code-optimization-code-and-assembly-code) – nhahtdh Dec 03 '14 at 09:54
  • @nhahtdh what "-fdump-tree-all" really does?? – user4255847 Dec 03 '14 at 10:14
  • @nhahtdh the question doesn't have enough answers, I can't rely on it for my query – user4255847 Dec 03 '14 at 10:17
  • can I recommend `clang`? it has really nice tools for these kind of tasks. nice colored trees blossoming in the spring... – Karoly Horvath Dec 03 '14 at 11:15
  • @KarolyHorvath but there must some way where you can generate ast in xml format through gcc of c source file .is there way around for this? – user4255847 Dec 03 '14 at 11:18
  • @user4255847: surely there is (if there isn't, write your own extension)... I just tried to be pragmatic. – Karoly Horvath Dec 03 '14 at 11:21
  • @KarolyHorvath but according to this link: http://stackoverflow.com/questions/5309405/can-i-get-an-xml-ast-dump-of-c-c-code-with-clang-without-using-the-compiler?rq=1 xml support is ommited in clang – user4255847 Dec 03 '14 at 11:33
  • @user4255847: uh.. 2.8? :) dunno. are you sure you want XML? the language is so (ridiculously) complex I doubt you need the complete AST, analysing the complete tree is an immense task. My guess would be you need stats on some *specific* things. In that case, clang has nice support for extensions for the whole toolchain (haven't tried it though)... just intercept the things you're interested in. Also: http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Karoly Horvath Dec 03 '14 at 11:42
  • @KarolyHorvath to clear things so we don't lead further in XY problem: i am trying to obtain output of soure file(xy.c) when it is passed to parser take ex: gcc(it is more i am familiar with) and that would be an ast and based on that generate report in xml format for some xml template purposes?? – user4255847 Dec 03 '14 at 11:54
  • @KarolyHorvath hey buddy as you suggested to use clang to generate ast in xml i use "-ast-dump-xml" with clang but it return error:unknown argument: '-ast-dump-xml'. so what should i do now?? – user4255847 Dec 04 '14 at 07:56

0 Answers0