File: acc_prtchg.c

package info (click to toggle)
gplcver 2.12a-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,604 kB
  • ctags: 9,129
  • sloc: ansic: 126,201; sh: 1,539; makefile: 86; perl: 22
file content (288 lines) | stat: -rw-r--r-- 7,947 bytes parent folder | download | duplicates (4)
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
/* Copyright (c) 1995-2003 Pragmatic C Software Corp. */

/*
 * test of acc vcls
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "acc_user.h"
#include "cv_acc_user.h"
#include "veriuser.h"
#include "cv_veriuser.h"

/* local function prototypes */
static int process_inst(handle); 
static void setup_1scope_chgcbs(handle);
static void add_vcl(handle);

/* global function prototypes */
extern int process_all_insts(int, int);
extern int setup_varchgcbs(handle);
extern int wire_prt_vclchg(p_vc_record);
extern int var_prt_vclchg(p_vc_record);

/*
 * routine to get and zero all delays in design 
 */
int process_all_insts(int reason, int udata)
{
 handle topinst;

 for (topinst = NULL;;)
  {
   if ((topinst = acc_next_child(NULL, topinst)) == NULL) break;
   process_inst(topinst);
  }
 io_printf("  >>> All instances processed\n");
 return(0);
}

/*
 * process one instance and recursively process all under instances
 * processing is top down depth first
 */
static int process_inst(handle upinst) 
{
 handle scope, inst, net, bit, var, prim, term, port;
 static int varlist[] = { accReg, accIntegerVar, accTimeVar, 0 };

 io_printf("... setting up vcls for instance %s\n",
  acc_fetch_fullname(upinst));

 /* first strength vcls on all nets */
 /* first add vcls for nets */
 io_printf("... vcls for wires\n");
 for (net = acc_next_net(upinst, NULL); net != NULL;
  net = acc_next_net(upinst, net))
  {
   if (acc_fetch_size(net) == 1) add_vcl(net);
   else
    {
     /* for vector wires, must put vcl on bit - need to access strength */
     for (bit = acc_next_bit(net, NULL); bit != NULL;
      bit = acc_next_bit(net, bit)) add_vcl(bit);
    }
  }
 /* then variables */
 io_printf("... vcls for variables\n"); 
 for (var = acc_next(varlist, upinst, NULL); var != NULL;
  var = acc_next(varlist, upinst, var)) add_vcl(var);

 io_printf("... vcls for primitive terminals\n"); 
 /* then primitives output terminals */
 for (prim = acc_next_primitive(upinst, NULL); prim != NULL;
  prim = acc_next_primitive(upinst, prim))
   {
    for (term = acc_next_terminal(prim, NULL); term != NULL;
     term = acc_next_terminal(prim, term))
     {
      /* only output terminals can have vcl added */
      if (acc_fetch_direction(term) == accInput) continue;
      add_vcl(term);
     }
   }

 /* then module ports */
 io_printf("... vcls for ports\n"); 
 for (port = acc_next_port(upinst, NULL); port != NULL;
  port = acc_next_port(upinst, port))
  {
   if (acc_fetch_size(port) == 1) add_vcl(port);
   else
    {
     /* for vector ports, must put vcl on bit - need to access strength */
     for (bit = acc_next_bit(port, NULL); bit != NULL;
      bit = acc_next_bit(port, bit)) add_vcl(bit);
    }
  }

 /* finally all variables in contained scopes */
 for (scope = acc_next_scope(upinst, NULL); scope != NULL;
  scope = acc_next_scope(upinst, scope))
  {
   /* final step setup vcls for contained scopes */
   setup_1scope_chgcbs(scope);
  }

 for (inst = NULL;;)
  {
   if ((inst = acc_next_child(upinst, inst)) == NULL) break;
   process_inst(inst);
  }
 return(0);
}

/*
 * set up change call back for all nets/regs of some type in iter
 *
 * now sure how acc_supposed to work - scopes inside module instance
 * are all tasks, functions, and labeled blocks in init/always blocks
 */
static void setup_1scope_chgcbs(handle scope)
{
 static int varlist[] = { accReg, accIntegerVar, accTimeVar, 0 };
 handle inscope, var;

 io_printf("... setting up vcls for scope %s\n", acc_fetch_fullname(scope));

 /* set up value change call backs for all variables in this scope */
 for (var = acc_next(varlist, scope, NULL); var != NULL;
  var = acc_next(varlist, scope, var)) add_vcl(var);

 /* also or all contained scopes */
 for (inscope = acc_next_scope(scope, NULL); inscope != NULL;
  inscope = acc_next_scope(scope, inscope)) setup_1scope_chgcbs(inscope);
}

/*
 * routine to add vcl to one net/reg/var/event
 */
static void add_vcl(handle net)
{
 int typ, fulltyp;
 char s1[1024];

 /* DBG remove -- */
 typ = acc_fetch_type(net);
 fulltyp = acc_fetch_fulltype(net);
 if (typ != accTerminal) strcpy(s1, acc_fetch_fullname(net));
 else strcpy(s1, "**terminal**");
 io_printf("Adding vcl for %s type %s (fulltype %s)\n", s1,
  acc_fetch_type_str(typ), acc_fetch_type_str(fulltyp));
 /* --- */

 if (typ == accNet)
  {
   acc_vcl_add(net, wire_prt_vclchg, (void *) net, vcl_verilog_strength);  
  }
 else acc_vcl_add(net, var_prt_vclchg, (void *) net, vcl_verilog_logic);  
}

/*
 * wire strength change value change call back routine
 */
int wire_prt_vclchg(p_vc_record vcp)
{
 /* unsigned long long now, chgtim; */
 int typ, ltime, htime;
 handle net;
 char s1[1024], s2[1024], s3[1024];

 /* current time */
 ltime = tf_getlongsimtime(&htime);
 /* ---
 now = ((unsigned long long) ((unsigned long) htime)) << 32
  | ((unsigned long long) ((unsigned long) ltime));

 -* vc record time *- 
 chgtim = ((unsigned long long) ((unsigned long) vcp->vc_hightime)) << 32
  | ((unsigned long long) ((unsigned long) vcp->vc_lowtime));
 --- */

 /* net handle assigned to user data field */
 net = (handle) vcp->user_data; 

 /* build strength value string */
 sprintf(s1, "<%d, %d>=%d", (int) vcp->out_value.strengths_s.strength1, 
  (int) vcp->out_value.strengths_s.strength2,   
  (int) vcp->out_value.strengths_s.logic_value);
 
 /* also get value as internal strength %v string */
 strcpy(s2, acc_fetch_value(net, "%v", NULL));

 if (vcp->vc_reason != strength_value_change)
  {
   io_printf("*** ERROR: wire change reason %d - strength change expected\n",
    vcp->vc_reason);
  }
 /* ---
 io_printf("--> now %uL (chg time %uL): %s=%s(%s)\n", now, chgtim,
 -- */

 /* terminals do not have names */
 typ = acc_fetch_type(net);
 if (typ != accTerminal) strcpy(s3, acc_fetch_fullname(net));
 else strcpy(s3, "**terminal**");

 io_printf("--> now %d (chg time %d): %s=%s(%s)\n", ltime, vcp->vc_lowtime,
  s3, s2, s1); 
 return(0);
}

/*
 * variable value change call back routine
 */
int var_prt_vclchg(p_vc_record vcp)
{
 /* unsigned long long now, chgtim; */
 int otyp, ltime, htime;
 handle net;
 char s1[1024], s2[1024], s3[1024];

 /* current time */
 ltime = tf_getlongsimtime(&htime);
 /* -- 
 now = ((unsigned long long) ((unsigned long) htime)) << 32
  | ((unsigned long long) ((unsigned long) ltime));

 -* vc record time *- 
 chgtim = ((unsigned long long) ((unsigned long) vcp->vc_hightime)) << 32
  | ((unsigned long long) ((unsigned long) vcp->vc_lowtime));
 -- */

 /* net handle assigned to user data field */
 net = (handle) vcp->user_data; 
 otyp = acc_fetch_type(net);

 if (vcp->vc_reason != event_value_change)
  {
   /* these do not have value, i.e. get va8ue return NULL with error */
   if (otyp == accPort || otyp == accPortBit || otyp == accTerminal)
    {
     sprintf(s1, "obj=%s", acc_fetch_type_str(otyp));
    }
   else strcpy(s1, acc_fetch_value(net, "%b", NULL));
  }

 switch (vcp->vc_reason) {
  case logic_value_change:
   sprintf(s2, "scalar=%u(%s)", (unsigned) vcp->out_value.logic_value, s1); 
   break;
  case sregister_value_change:
   sprintf(s2, "sr-scalar=%u(%s)", (unsigned) vcp->out_value.logic_value, s1); 
   break;
  case real_value_change: case realtime_value_change:
   sprintf(s2, "**error**");
   break;
  case event_value_change:
   strcpy(s2, "**event**");
   break;
  default:
   sprintf(s2, "vector=%s", s1);
 }  

 /* --
 io_printf("--> now %uL (chg time %uL): %s=%s\n", now, chgtim,
 -- */

 if (otyp != accTerminal) strcpy(s3, acc_fetch_fullname(net));
 else strcpy(s3, "**terminal**");

 io_printf("--> now %d (chg time %d): %s=%s\n", ltime, vcp->vc_lowtime, s3,
  s2); 
 return(0);
}

s_tfcell veriusertfs[] = {
 { usertask, 0, 0, 0, (int (*)()) process_all_insts, 0, "$test", 0 }, 
 {0} /* this line must always be last */
};

/* dummy +loadpli1 boostrap routine - return old style veriusertfs tab */
s_tfcell *pli1_compat_bootstrap(void)
{
 return(veriusertfs);
}