#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "rtl.h"
#include "tm_p.h"
#include "hard-reg-set.h"
#include "basic-block.h"
#include "output.h"
#include "flags.h"
#include "function.h"
#include "expr.h"
#include "ggc.h"
#include "langhooks.h"
#include "diagnostic.h"
#include "tree-flow.h"
#include "timevar.h"
#include "tree-dump.h"
#include "tree-pass.h"
#include "toplev.h"
#include "except.h"
#include "cfgloop.h"
#include "cfglayout.h"
#include "tree-ssa-propagate.h"
#include "value-prof.h"
#include "pointer-set.h"
#include "tree-inline.h"


/* global declarations */
extern FILE * dump_file;
int numassigns,totalassigns,varexpr;

void initialize_stats(void)
{
  numassigns=0;
  varexpr=0;
  totalassigns=0;
}

void printstatistics(void)
{
  printf("\n\n************Number of assignment statements:: %d\n\n",numassigns);	
  printf("\n\n************Total Number of assignment statements (including temp vars):: %d\n\n",totalassigns);
  printf("\n\n************total no of increment count :: %d\n\n",varexpr);

  if(flag_pass_gccwk09){
     fprintf(dump_file,"\n\n************Number of assignment statements:: %d\n\n",numassigns);
     fprintf("\n\n************total no of init expr :: %d\n\n",varexpr);
     fprintf(dump_file,"\n\n************Total Number of assignment statements (including temp vars):: %d\n\n",totalassigns);
  } 
}



void process_statement(tree stmt)
{
  tree lval,rval;
		switch (TREE_CODE(stmt)){
			case GIMPLE_MODIFY_STMT:					 
				lval=GIMPLE_STMT_OPERAND(stmt,0);
				rval=GIMPLE_STMT_OPERAND(stmt,1);
				if(TREE_CODE(lval) == VAR_DECL) {
					if(!DECL_ARTIFICIAL(lval)){
						//print_generic_stmt(stderr,stmt,0);
						numassigns++;
					}	
					totalassigns++;				
				}
				break;
			case 	VAR_DECL:
				//if(TREE_CODE(stmt) == VAR_DECL){
						varexpr++;
//					}
			//	}
			      break;
					
			default :
				break;	
		}    		
}


/* Note the return type of the below function */

static unsigned int gccwk09_main(void)
{


   basic_block bb;
   block_stmt_iterator si;

   initialize_stats();   
 
   FOR_EACH_BB (bb)
	{			
		for (si=bsi_start(bb); !bsi_end_p(si)  ; bsi_next(&si) )
		 {
			tree stmt = bsi_stmt(si);	
			print_generic_stmt(stderr,stmt,0);
			process_statement(stmt); 
		 }
	}        

   printstatistics();  
   
  return 0;
}



struct tree_opt_pass pass_gccwk09 =
{ "gccwk09",
 NULL,
 gccwk09_main,
 NULL,
 NULL,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0
};


