File: analyzer.c

package info (click to toggle)
irsim 9.7.104-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,964 kB
  • sloc: ansic: 24,763; sh: 7,499; makefile: 418; csh: 269; tcl: 88
file content (373 lines) | stat: -rw-r--r-- 7,046 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
 *     ********************************************************************* 
 *     * Copyright (C) 1988, 1990 Stanford University.                     * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  Stanford University                 * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 */

#include <stdio.h>
#include <string.h>  /* for strlen() */

#include "globals.h"
#include "ana.h"
#include "ana_glob.h"

private	int    numAdded;


public char *SetName( n )
  register char  *n;
  {
    int   i;

    i = strlen( n );
    if( i > max_name_len )
      {
	i -= max_name_len;
	n += i;
      }
    return( n );
  }


private void AddTrace( t )
  Trptr  t;
  {
    if( traces.first == NULL )
      {
	t->next = t->prev = NULL;
	traces.first = traces.last = t;
      }
    else
      {
	t->next = NULL;
	t->prev = traces.last;
	traces.last->next = t;
	traces.last = t;
      }
    numAdded++;
  }

public int OffsetNode( nd, flag )
  nptr  nd;
  int	*flag;
{
   /* do nothing */
   return 1;
}

public int OffsetVector( vec, flag )
  bptr  vec;
  int	*flag;
{
   /* do nothing */
   return 1;
}

public int AddNode( nd, flag )
  nptr  nd;
  int   *flag;
  {
    Trptr  t;
    
    while( nd->nflags & ALIAS )
	nd = nd->nlink;

    if( nd->nflags & MERGED )
      {
	fprintf( stderr, "can't watch node %s\n", nd->nname );
	return( 1 );
      }
    if( (t = (Trptr) Valloc( sizeof( TraceEnt ), 0 )) == NULL )
      {
	fprintf( stderr, "Out of memory, can't add %s to analyzer\n",
	  nd->nname );
	return( 0 );
      }
    t->name = SetName( nd->nname );
    t->len = strlen( t->name );
    t->bdigit = 1;
    t->vector = FALSE;
    t->n.nd = nd;
    t->cache[0].wind = t->cache[0].cursor = &(nd->head);
    AddTrace( t );
    return( 1 );
  }


public int AddVector( vec, flag )
  bptr  vec;
  int   *flag;
  {
    Trptr  t;
    int    n;

    n = vec->nbits;
    t = (Trptr) Valloc( sizeof( TraceEnt ) + sizeof( Cache ) * (n - 1), 0 );
    if( t == NULL )
      {
	fprintf( stderr, "Out of memory, can't add %s to analyzer\n",
	  vec->name );
	return( 0 );
      }
    t->name = SetName( vec->name );
    t->len = strlen( t->name );
    if( *flag != 0 )
	t->bdigit = *flag;
    else
	t->bdigit = ( n > 5 ) ? 5 : 1;	/* > 5 bits defaults to decimal fmt */
    t->vector = TRUE;
    t->n.vec = vec;
    for( n--; n >= 0; n-- )
	t->cache[n].wind = t->cache[n].cursor = &(vec->nodes[n]->head);
    AddTrace( t );
    return( 1 );
  }



public void DisplayTraces( isMapped )
  int  isMapped;
  {
    int  change;

    DisableInput();
   
    traces.total += numAdded;
    numAdded = 0;

    if( not isMapped )				/* only the first time */
      {
	FlushTraceCache();
	XMapWindow( display, window );
      }
    else if( not (windowState.iconified or windowState.tooSmall) )
      {
	change = WindowChanges();

	if( change & NTRACE_CHANGE )
	  {
	    RedrawNames( namesBox );
	    DrawCursVal( cursorBox );
	    if( change & WIDTH_CHANGE )
	      {
		DrawScrollBar( FALSE );
		RedrawTimes();
	      }
	    DrawTraces( tims.start, tims.end );
	  }
      }

    EnableInput();
  }


public void StopAnalyzer()
  {
    DisableAnalyzer();
  }


public void RestartAnalyzer( first_time, last_time, same_hist )
  Ulong  first_time, last_time;
  int   same_hist;
  {
    register Trptr  t;
    register int    i, n;

    printf("restarting analyzer\n");
    for( t = traces.first, i = traces.total; i != 0; i--, t = t->next )
      {
	if( t->vector )
	  {
	    for( n = t->n.vec->nbits - 1; n >= 0; n-- )
	      {
		t->cache[n].wind = t->cache[n].cursor = 
		  &(t->n.vec->nodes[n]->head);
	      }
	  }
	else
	    t->cache[0].wind = t->cache[0].cursor = &(t->n.nd->head);
      }

    InitTimes( first_time, tims.steps / DEF_STEPS, last_time, 1);
    if( same_hist )
	UpdateTraceCache( 0 );
    else
	FlushTraceCache();
    EnableAnalyzer( /* same_hist */ );
  }


public void RemoveTrace( t )
  Trptr  t;
  {
    traces.total--;
    if( t == traces.first )
      {
	traces.first = t->next;
	if( t->next )
            t->next->prev = NULL;
        else
            traces.last = NULL;
      }
    else
      {
        t->prev->next = t->next;
        if( t->next )
            t->next->prev = t->prev;
        else
            traces.last = t->prev;
      }
    
    if( selectedTrace == t )
        selectedTrace = NULL;
    Vfree( t );
  }


public void ClearTraces()
  {
    int  change, wasTooSmall;

    DisableInput();
   
    while( traces.total != 0 )
	RemoveTrace( traces.first );


    if( windowState.iconified )
      {
	EnableInput();
	return;
      }

    wasTooSmall = windowState.tooSmall;

    change = WindowChanges();
    if( windowState.tooSmall )
      {
	RedrawSmallW();
	EnableInput();
	return;
      }

    if( wasTooSmall )
      {
	RedrawBanner();
	RedrawText();
	DrawCursVal( cursorBox );
      }
    RedrawNames( namesBox );
    DrawScrollBar( wasTooSmall );
    RedrawTimes();
    DrawTraces( tims.start, tims.end );

    EnableInput();
  }


public void UpdateWinRemove()
  {
    int  change;

    change = WindowChanges();

    if( change & RESIZED )
        return;

    DisableInput();

    if( not (change & NTRACE_CHANGE) )          /* no trace became visible */
        SetSignalPos();

    if( change & WIDTH_CHANGE )
      {
        DrawScrollBar( FALSE );
        RedrawTimes();
      }

    RedrawNames( namesBox );
    DrawCursVal( cursorBox );
    DrawTraces( tims.start, tims.end );

    EnableInput();
  }


public void RemoveVector( b )
  bptr  b;
  {
    Trptr  t, tmp;
    int    i = FALSE;

    for( t = traces.first; t != NULL; )
      {
	if( t->vector and (t->n.vec == b) )
	  {
	    tmp = t->next;
	    RemoveTrace( t );
	    t = tmp;
	    i = TRUE;
	  }
	else
	    t = t->next;
      }
    if( i )
	UpdateWinRemove();
  }



public void RemoveNode( n )
  nptr  n;
  {
    Trptr  t, tmp;
    int    i = FALSE;

    for( t = traces.first; t != NULL; )
      {
	if( not t->vector and (t->n.nd == n) )
	  {
	    tmp = t->next;
	    RemoveTrace( t );
	    t = tmp;
	    i = TRUE;
	  }
	else
	    t = t->next;
      }
    if( i )
	UpdateWinRemove();
  }


public void RemoveAllDeleted()
  {
    Trptr  t, tmp;
    int    i = FALSE;

    for( t = traces.first; t != NULL; )
      {
	if( (t->vector and (t->n.vec->traced & DELETED)) or
	  (not t->vector and (t->n.nd->nflags & DELETED)) )
	  {
	    tmp = t->next;
	    RemoveTrace( t );
	    t = tmp;
	    i = TRUE;
	  }
	else
	    t = t->next;
      }
    if( i )
	UpdateWinRemove();
  }