Tuesday, 15 July 2014

c++ - How to parse a function in a cpp file to access the loops -



c++ - How to parse a function in a cpp file to access the loops -

i working on c++ project has gcc defined compiler in makefile. cannot utilize different compiler. need parse through .cc files override particular method called behavior(), inherited parent class. method not have arguments , has void homecoming type. need find out presence of loops (for, while , do-while) within behavior() method , analyze them in various ways finding number of times executed etc. example, allow sample.h , sample.cc header , source files respectively.

sample.h class sample_class: public base of operations { ....; ....; void behavior(); //inherited base of operations }; sample.cc void sample_class::behavior() { ....; ....; int n=10; int count=0; int c=2; for(int x=0;x<n;x++) { count=count+n; //loop1 } while(int z<5) { c=c*5; //loop2 } }

what want access contents of , while , able write like:

exec_time(behavior)=n*exec_time(loop1)+5*exec_time(loop2)

could please guide me how can while using gcc compiler? give thanks much help.

"finding number of times executed" - (and this) requirement requires runtime counting... either modify relevant functions count how they're called , save phone call stack each time, analysis on output, or seek using profiling tool captures same kind of info - perhaps gprof, or quantify or valgrind.

c++ parsing gcc

No comments:

Post a Comment