[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / misc / spat-analysers / icount.c
1 #define VERSION         "24-Jan-94"
2 #define PROGNAME        "ICount"
3
4 #define SHADE
5
6 #include <stdio.h>
7
8 #include <IHASH.h>
9 #include <ITYPES.h>
10 #include <instr.h>
11 #include <inames.h>
12
13 #include <shade.h>
14 #define TR_REGS
15 #include <trace.h>
16 #include <stdtr.h>
17 #include <trctl.h>
18
19 static long long info[NIHASH];
20
21 #define STATS_FILE      "ICNT"
22
23 /* fwd decls */
24 void print_results();
25
26 #define CHECKPOINT 1000000      /* reporting frequency */
27 static long countdown = CHECKPOINT;
28
29 char    *anal_usage = "";
30 char    *anal_version = VERSION;
31
32 initialize(argc,argv,envp)
33   int    argc;
34   char **argv, envp;
35 {
36     unsigned i, j;
37
38     /* Setup the trace */
39     shade_trctl_trsize(sizeof(Trace));
40
41     shade_trctl_it (IT_ANY, 1, 0, TC_IH);
42
43     /* init table */
44     for (j = 0; j < NIHASH; j++)
45         info[j] = 0LL;
46 }
47
48 int analyze(argc,argv,envp)
49   int    argc;
50   char **argv, envp;
51 {
52     Trace *tr;
53     int i;
54
55     for (i = 0; tr = shade_step(); i++) {
56
57         info[tr->tr_ih] += 1LL;
58
59         if (countdown-- < 0) {
60           print_results("Intermediate:");
61           countdown = CHECKPOINT;
62         }
63     }
64     return(0);
65 }
66
67 void
68 terminate()
69 {
70     print_results("Final:");
71 }
72
73 void
74 print_results(header)
75   char *header;
76 {
77     int i, j;
78     static FILE *statf = NULL;
79
80     if ((statf = fopen("ICNT", "w")) == NULL) {
81       fprintf(stderr, "Cannot open statistics file ICNT\n");
82       exit(1);
83     }
84     fprintf(statf, "%s\n\n", header);
85
86     for (i = 0; i < NIHASH; i++) {
87         fprintf(statf, "%8x: %8ld\n", i, (long) info[i]);
88     }
89
90     fclose(statf);
91 }