~ubuntu-branches/ubuntu/jaunty/electric/jaunty

« back to all changes in this revision

Viewing changes to src/sim/simalscom.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-01-08 02:05:08 UTC
  • mfrom: (1.3.1 upstream) (3.1.3 sid)
  • mto: (3.1.4 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20090108020508-3e7e6241i7bkit2l
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Electric(tm) VLSI Design System
3
 
 *
4
 
 * File: simalscom.c
5
 
 * Asynchronous Logic Simulator command handler
6
 
 * From algorithms by: Brent Serbin and Peter J. Gallant
7
 
 * Last maintained by: Steven M. Rubin
8
 
 *
9
 
 * Copyright (c) 2000 Static Free Software.
10
 
 *
11
 
 * Electric(tm) is free software; you can redistribute it and/or modify
12
 
 * it under the terms of the GNU General Public License as published by
13
 
 * the Free Software Foundation; either version 2 of the License, or
14
 
 * (at your option) any later version.
15
 
 *
16
 
 * Electric(tm) is distributed in the hope that it will be useful,
17
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 * GNU General Public License for more details.
20
 
 *
21
 
 * You should have received a copy of the GNU General Public License
22
 
 * along with Electric(tm); see the file COPYING.  If not, write to
23
 
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
24
 
 * Boston, Mass 02111-1307, USA.
25
 
 *
26
 
 * Static Free Software
27
 
 * 4119 Alpine Road
28
 
 * Portola Valley, California 94028
29
 
 * info@staticfreesoft.com
30
 
 */
31
 
 
32
 
#include "config.h"
33
 
#if SIMTOOL
34
 
 
35
 
#include "global.h"
36
 
#include "sim.h"
37
 
#include "simals.h"
38
 
#include "usrdiacom.h"
39
 
 
40
 
/* prototypes for local routines */
41
 
static void     simals_erase_submod(CONPTR);
42
 
static void     simals_print_in_entry(ROWPTR);
43
 
static void      simals_print_out_entry(ROWPTR);
44
 
static void      simals_print_xref_entry(CONPTR, INTBIG);
45
 
static char     *simals_strengthstring(INTSML);
46
 
static void      simals_makeactelmodel(char *name, FILE *io, LIBRARY *lib);
47
 
static void      simals_sdfannotate(CONPTR cellhead);
48
 
static NODEINST *simals_getcellinstance(char *celltype, char *instance);
49
 
static void      simals_sdfportdelay(CONPTR cellhead, NODEINST *ni, char *path);
50
 
static INTBIG    simals_getportdelayvalue(char *datastring, char *transition, DELAY_TYPES delaytype);
51
 
static INTBIG    simals_getdval(char *tstring, DELAY_TYPES delaytype);
52
 
static void      simals_order_save(void);
53
 
static void      simals_order_restore(char *list);
54
 
static void      simals_update_netlist(void);
55
 
static char     *simals_parent_level(char *child);
56
 
static INTBIG    simals_get_tdindex(char *name);
57
 
 
58
 
/* local variables */
59
 
static DELAY_TYPES simals_sdfdelaytype;
60
 
static char *simals_tnames[] = {"01", "10", "0Z", "Z1", "1Z", "Z0", "0X", "X1", "1X", "X0", "XZ", "ZX"};
61
 
 
62
 
/****************************** ACTEL MODELS ******************************/
63
 
 
64
 
typedef enum {inputparam, outputparam, bidirparam, edgesenseinputparam,
65
 
        fourstatebiputparam} PARAMTYPE;
66
 
 
67
 
typedef struct Iactelparam
68
 
{
69
 
        char               *paramname;
70
 
        PARAMTYPE           paramtype;
71
 
        BOOLEAN             duplicate;
72
 
        struct Iactelparam *next;
73
 
} ACTELPARAM;
74
 
 
75
 
#define MAXCHRS 300
76
 
 
77
 
/*
78
 
 * Name: simals_build_actel_command
79
 
 *
80
 
 * Description:
81
 
 *      This procedure reads an Actel table file and creates a library with
82
 
 * ALS-netlist facets.
83
 
 */
84
 
void simals_build_actel_command(INTBIG count, char *par[])
85
 
{
86
 
        FILE *io;
87
 
        INTBIG len, i, filecount;
88
 
        char *filename, line[MAXCHRS], **filelist;
89
 
        REGISTER char *pt, *start;
90
 
        static INTBIG filetypeacteltab = -1;
91
 
 
92
 
        if (count == 0)
93
 
        {
94
 
                ttyputusage("telltool simulation als build-actel-model TABLEFILE");
95
 
                return;
96
 
        }
97
 
        len = strlen(par[0]);
98
 
        for(i=len-1; i>0; i--) if (par[0][i] == DIRSEP) break;
99
 
        par[0][i] = 0;
100
 
        filecount = filesindirectory(par[0], &filelist);
101
 
        if (filecount == 0)
102
 
        {
103
 
                ttyputerr(M_("There are no files in directory '%s'"), par[0]);
104
 
                return;
105
 
        }
106
 
        for(i=0; i<filecount; i++)
107
 
        {
108
 
                (void)initinfstr();
109
 
                (void)addstringtoinfstr(par[0]);
110
 
                (void)addtoinfstr(DIRSEP);
111
 
                (void)addstringtoinfstr(filelist[i]);
112
 
                pt = returninfstr();
113
 
                if (filetypeacteltab < 0)
114
 
                        filetypeacteltab = setupfiletype("tab", "*.tab", MACFSTAG('TEXT'), FALSE, "actel", M_("QuickPartTable"));
115
 
                io = xopen(pt, filetypeacteltab, "", &filename);
116
 
                if (io == 0)
117
 
                {
118
 
                        ttyputerr(M_("Cannot find Actel file %s"), pt);
119
 
                        break;
120
 
                }
121
 
                for(;;)
122
 
                {
123
 
                        if (xfgets(line, MAXCHRS, io) != 0) break;
124
 
                        pt = line;
125
 
                        while (*pt == ' ' || *pt == '\t') pt++;
126
 
                        if (*pt == 0 || *pt == '#') continue;
127
 
 
128
 
                        if (namesamen(pt, "model ", 6) != 0) continue;
129
 
                        pt += 6;
130
 
                        while (*pt == ' ' || *pt == '\t') pt++;
131
 
                        start = pt;
132
 
                        while (*pt != 0 && *pt != ':') pt++;
133
 
                        if (*pt != 0) *pt = 0;
134
 
                        simals_makeactelmodel(start, io, el_curlib);
135
 
                }
136
 
                xclose(io);
137
 
        }
138
 
}
139
 
 
140
 
void simals_makeactelmodel(char *name, FILE *io, LIBRARY *lib)
141
 
{
142
 
        char line[MAXCHRS];
143
 
        REGISTER char *pt, *start, save, *facetname;
144
 
        REGISTER NODEPROTO *np;
145
 
        INTBIG statetablestate;
146
 
        BOOLEAN doinginput, edgesense, fourstate;
147
 
        ACTELPARAM *ap, *lastap, *inputlist, *outputlist, *paramlist, *paramtail, *nextap, *newap;
148
 
        void *sa;
149
 
 
150
 
        sa = newstringarray(sim_tool->cluster);
151
 
        if (sa == 0) return;
152
 
 
153
 
        /* dump header information for the model */
154
 
        (void)initinfstr();
155
 
        (void)addstringtoinfstr("# Actel model for ");
156
 
        (void)addstringtoinfstr(name);
157
 
        addtostringarray(sa, returninfstr());
158
 
 
159
 
        inputlist = outputlist = paramlist = 0;
160
 
        statetablestate = 0;
161
 
        for(;;)
162
 
        {
163
 
                if (xfgets(line, MAXCHRS, io) != 0) break;
164
 
 
165
 
                /* find the first keyword */
166
 
                pt = line;
167
 
                while (*pt == ' ' || *pt == '\t') pt++;
168
 
                if (*pt == '#') continue;
169
 
                if (*pt == 0) continue;
170
 
 
171
 
                /* stop if done with table */
172
 
                if (namesamen(pt, "end", 3) == 0) break;
173
 
 
174
 
                /* see if gathering state table information */
175
 
                if (statetablestate != 0)
176
 
                {
177
 
                        if (statetablestate == 1)
178
 
                        {
179
 
                                /* get state table header */
180
 
                                statetablestate = 2;
181
 
                                doinginput = TRUE;
182
 
                                paramtail = 0;
183
 
                                for(;;)
184
 
                                {
185
 
                                        while (*pt == ' ' || *pt == '\t') pt++;
186
 
                                        start = pt;
187
 
                                        while (*pt != 0 && *pt != ' ' && *pt != '\t' && *pt != ',' && *pt != ';' &&
188
 
                                                *pt != ':') pt++;
189
 
                                        save = *pt;   *pt = 0;
190
 
                                        if (doinginput)
191
 
                                        {
192
 
                                                /* search input list for this one */
193
 
                                                lastap = 0;
194
 
                                                for(ap = inputlist; ap != 0; ap = ap->next)
195
 
                                                {
196
 
                                                        if (strcmp(ap->paramname, start) == 0) break;
197
 
                                                        lastap = ap;
198
 
                                                }
199
 
                                                if (ap == 0)
200
 
                                                {
201
 
                                                        /* see if it is on the output list */
202
 
                                                        for(ap = outputlist; ap != 0; ap = ap->next)
203
 
                                                                if (strcmp(ap->paramname, start) == 0) break;
204
 
                                                        if (ap == 0)
205
 
                                                        {
206
 
                                                                ttyputerr(M_("In model %s, symbol %s not found in parameter lists"),
207
 
                                                                        name, start);
208
 
                                                                return;
209
 
                                                        }
210
 
                                                        newap = (ACTELPARAM *)emalloc(sizeof (ACTELPARAM), sim_tool->cluster);
211
 
                                                        if (newap == 0) return;
212
 
                                                        (void)allocstring(&newap->paramname, ap->paramname, sim_tool->cluster);
213
 
                                                        newap->paramtype = ap->paramtype;
214
 
                                                        newap->duplicate = TRUE;
215
 
                                                        ap = newap;
216
 
                                                } else
217
 
                                                {
218
 
                                                        if (lastap == 0) inputlist = ap->next; else
219
 
                                                                lastap->next = ap->next;
220
 
                                                }
221
 
                                        } else
222
 
                                        {
223
 
                                                /* search output list for this one */
224
 
                                                lastap = 0;
225
 
                                                for(ap = outputlist; ap != 0; ap = ap->next)
226
 
                                                {
227
 
                                                        if (strcmp(ap->paramname, start) == 0) break;
228
 
                                                        lastap = ap;
229
 
                                                }
230
 
                                                if (ap == 0)
231
 
                                                {
232
 
                                                        /* see if it is already on the input list */
233
 
                                                        for(ap = paramlist; ap != 0; ap = ap->next)
234
 
                                                                if (strcmp(ap->paramname, start) == 0) break;
235
 
                                                        if (ap == 0)
236
 
                                                        {
237
 
                                                                ttyputerr(M_("In model %s, symbol %s not found in parameter lists"),
238
 
                                                                        name, start);
239
 
                                                                return;
240
 
                                                        }
241
 
                                                        newap = (ACTELPARAM *)emalloc(sizeof (ACTELPARAM), sim_tool->cluster);
242
 
                                                        if (newap == 0) return;
243
 
                                                        (void)allocstring(&newap->paramname, ap->paramname, sim_tool->cluster);
244
 
                                                        newap->paramtype = ap->paramtype;
245
 
                                                        newap->duplicate = TRUE;
246
 
                                                        ap = newap;
247
 
                                                } else
248
 
                                                {
249
 
                                                        if (lastap == 0) outputlist = ap->next; else
250
 
                                                                lastap->next = ap->next;
251
 
                                                }
252
 
                                        }
253
 
                                        ap->next = 0;
254
 
                                        if (paramtail == 0) paramlist = paramtail = ap; else
255
 
                                        {
256
 
                                                paramtail->next = ap;
257
 
                                                paramtail = ap;
258
 
                                        }
259
 
                                        *pt = save;
260
 
                                        while (*pt == ' ' || *pt == '\t') pt++;
261
 
                                        if (*pt == ';') break;
262
 
                                        if (*pt == ':') { pt += 2;   doinginput = FALSE;   continue; }
263
 
                                        if (*pt == ',') { pt++;   continue; }
264
 
                                        ttyputerr(M_("In model %s, missing comma in Actel symbol list"), name);
265
 
                                        return;
266
 
                                }
267
 
 
268
 
                                /* now dump the model header */
269
 
                                (void)initinfstr();
270
 
                                (void)addstringtoinfstr("gate ");
271
 
                                (void)addstringtoinfstr(name);
272
 
                                (void)addstringtoinfstr("(");
273
 
                                for(ap = paramlist; ap != 0; ap = ap->next)
274
 
                                {
275
 
                                        if (ap->duplicate) continue;
276
 
                                        if (ap != paramlist) (void)addstringtoinfstr(", ");
277
 
                                        (void)addstringtoinfstr(ap->paramname);
278
 
                                }
279
 
                                (void)addstringtoinfstr(")");
280
 
                                addtostringarray(sa, returninfstr());
281
 
                                addtostringarray(sa, "t: delta=1.0e-9");
282
 
                                continue;
283
 
                        } else
284
 
                        {
285
 
                                /* get state table entry */
286
 
                                ap = paramlist;
287
 
                                (void)initinfstr();
288
 
                                (void)addstringtoinfstr("i: ");
289
 
                                for(;;)
290
 
                                {
291
 
                                        while (*pt == ' ' || *pt == '\t') pt++;
292
 
                                        (void)addstringtoinfstr(ap->paramname);
293
 
                                        (void)addstringtoinfstr("=");
294
 
                                        switch (*pt)
295
 
                                        {
296
 
                                                case '0': (void)addstringtoinfstr("L");   break;
297
 
                                                case '1': (void)addstringtoinfstr("H");   break;
298
 
                                                case '?': (void)addstringtoinfstr("X");   break;
299
 
                                                case '[': (void)addstringtoinfstr("E");   break;
300
 
                                                case '(': (void)addstringtoinfstr("F");   break;
301
 
                                                case 'Z': (void)addstringtoinfstr("Z");   break;
302
 
                                                case 'X': (void)addstringtoinfstr("XX");  break;
303
 
                                                case '!': (void)addstringtoinfstr("N");   break;
304
 
                                        }
305
 
                                        (void)addstringtoinfstr(" ");
306
 
 
307
 
                                        while (*pt != 0 && *pt != ',' && *pt != ';' && *pt != ':') pt++;
308
 
                                        if (*pt == ';') break;
309
 
                                        if (*pt == ':') { (void)addstringtoinfstr("o: ");   pt++; }
310
 
                                        pt++;
311
 
                                        ap = ap->next;
312
 
                                }
313
 
                                addtostringarray(sa, returninfstr());
314
 
                                continue;
315
 
                        }
316
 
                }
317
 
 
318
 
                /* handle "edge_sense" prefix */
319
 
                edgesense = FALSE;
320
 
                if (namesamen(pt, "edge_sense", 10) == 0)
321
 
                {
322
 
                        edgesense = TRUE;
323
 
                        pt += 10;
324
 
                        while (*pt == ' ' || *pt == '\t') pt++;
325
 
                }
326
 
 
327
 
                /* handle "four_state" prefix */
328
 
                fourstate = FALSE;
329
 
                if (namesamen(pt, "four_state", 10) == 0)
330
 
                {
331
 
                        fourstate = TRUE;
332
 
                        pt += 10;
333
 
                        while (*pt == ' ' || *pt == '\t') pt++;
334
 
                }
335
 
 
336
 
                /* gather inputs */
337
 
                if (namesamen(pt, "input", 5) == 0)
338
 
                {
339
 
                        pt += 5;
340
 
                        for(;;)
341
 
                        {
342
 
                                while (*pt == ' ' || *pt == '\t') pt++;
343
 
                                start = pt;
344
 
                                while (*pt != 0 && *pt != ' ' && *pt != '\t' && *pt != ',' && *pt != ';') pt++;
345
 
                                save = *pt;   *pt = 0;
346
 
                                ap = (ACTELPARAM *)emalloc(sizeof (ACTELPARAM), sim_tool->cluster);
347
 
                                if (ap == 0) break;
348
 
                                (void)allocstring(&ap->paramname, start, sim_tool->cluster);
349
 
                                if (edgesense) ap->paramtype = edgesenseinputparam; else
350
 
                                        ap->paramtype = inputparam;
351
 
                                ap->duplicate = FALSE;
352
 
                                ap->next = inputlist;
353
 
                                inputlist = ap;
354
 
                                *pt = save;
355
 
                                while (*pt == ' ' || *pt == '\t') pt++;
356
 
                                if (*pt == ';') break;
357
 
                                if (*pt == ',') { pt++;   continue; }
358
 
                                ttyputerr(M_("In model %s, missing comma in Actel input list"), name);
359
 
                                return;
360
 
                        }
361
 
                        continue;
362
 
                }
363
 
 
364
 
                /* gather outputs */
365
 
                if (namesamen(pt, "output", 6) == 0)
366
 
                {
367
 
                        pt += 6;
368
 
                        for(;;)
369
 
                        {
370
 
                                while (*pt == ' ' || *pt == '\t') pt++;
371
 
                                start = pt;
372
 
                                while (*pt != 0 && *pt != ' ' && *pt != '\t' && *pt != ',' && *pt != ';') pt++;
373
 
                                save = *pt;   *pt = 0;
374
 
                                ap = (ACTELPARAM *)emalloc(sizeof (ACTELPARAM), sim_tool->cluster);
375
 
                                if (ap == 0) break;
376
 
                                (void)allocstring(&ap->paramname, start, sim_tool->cluster);
377
 
                                ap->paramtype = outputparam;
378
 
                                ap->duplicate = FALSE;
379
 
                                ap->next = outputlist;
380
 
                                outputlist = ap;
381
 
                                *pt = save;
382
 
                                while (*pt == ' ' || *pt == '\t') pt++;
383
 
                                if (*pt == ';') break;
384
 
                                if (*pt == ',') { pt++;   continue; }
385
 
                                ttyputerr(M_("In model %s, missing comma in Actel output list"), name);
386
 
                                return;
387
 
                        }
388
 
                        continue;
389
 
                }
390
 
 
391
 
                /* gather bidirectionals */
392
 
                if (namesamen(pt, "biput", 5) == 0)
393
 
                {
394
 
                        pt += 5;
395
 
                        for(;;)
396
 
                        {
397
 
                                while (*pt == ' ' || *pt == '\t') pt++;
398
 
                                start = pt;
399
 
                                while (*pt != 0 && *pt != ' ' && *pt != '\t' && *pt != ',' && *pt != ';') pt++;
400
 
                                save = *pt;   *pt = 0;
401
 
                                ap = (ACTELPARAM *)emalloc(sizeof (ACTELPARAM), sim_tool->cluster);
402
 
                                if (ap == 0) break;
403
 
                                (void)allocstring(&ap->paramname, start, sim_tool->cluster);
404
 
                                if (fourstate) ap->paramtype = fourstatebiputparam; else
405
 
                                        ap->paramtype = bidirparam;
406
 
                                ap->duplicate = FALSE;
407
 
                                ap->next = inputlist;
408
 
                                inputlist = ap;
409
 
                                *pt = save;
410
 
                                while (*pt == ' ' || *pt == '\t') pt++;
411
 
                                if (*pt == ';') break;
412
 
                                if (*pt == ',') { pt++;   continue; }
413
 
                                ttyputerr(M_("In model %s, missing comma in Actel biput list"), name);
414
 
                                return;
415
 
                        }
416
 
                        continue;
417
 
                }
418
 
 
419
 
                /* start state table */
420
 
                if (namesamen(pt, "state_table", 11) == 0)
421
 
                {
422
 
                        statetablestate = 1;
423
 
                        continue;
424
 
                }
425
 
        }
426
 
        (void)initinfstr();
427
 
        (void)addstringtoinfstr("load");
428
 
        for(ap = paramlist; ap != 0; ap = nextap)
429
 
        {
430
 
                nextap = ap->next;
431
 
                if (ap->paramtype == inputparam || ap->paramtype == edgesenseinputparam)
432
 
                {
433
 
                        (void)addstringtoinfstr(" ");
434
 
                        (void)addstringtoinfstr(ap->paramname);
435
 
                        (void)addstringtoinfstr("=1.0");
436
 
                }
437
 
                efree(ap->paramname);
438
 
                efree((char *)ap);
439
 
        }
440
 
        addtostringarray(sa, returninfstr());
441
 
 
442
 
        /* now put strings onto a facet */
443
 
        (void)initinfstr();
444
 
        (void)addstringtoinfstr(name);
445
 
        (void)addstringtoinfstr("{net-als}");
446
 
        facetname = returninfstr();
447
 
        np = newnodeproto(facetname, lib);
448
 
        if (np == NONODEPROTO)
449
 
        {
450
 
                ttyputerr(M_("Cannot create facet %s"), facetname);
451
 
                return;
452
 
        }
453
 
        stringarraytotextfacet(sa, np, TRUE);
454
 
        killstringarray(sa);
455
 
        ttyputmsg(M_("Created %s"), describenodeproto(np));
456
 
}
457
 
 
458
 
/****************************** CLOCK ******************************/
459
 
 
460
 
/*
461
 
 * Name: simals_clock_command
462
 
 *
463
 
 * Description:
464
 
 *      This procedure enters a complex clock vector into the user defined
465
 
 * event list.  The user is polled for the node name and timing parameters
466
 
 * before any entry is made into the linklist.
467
 
 */
468
 
void simals_clock_command(INTBIG count, char *par[])
469
 
{
470
 
        double   time, totaltime;
471
 
        NODEPTR  nodehead;
472
 
        NODEPROTO *np;
473
 
        LINKPTR  vectptr1, vectptr2, sethead;
474
 
        ROWPTR   clokhead;
475
 
        float    linear;
476
 
        LINKPTR  vectroot;
477
 
        char     **vectptr;
478
 
        INTSML    strength;
479
 
        INTBIG    num, l, i;
480
 
 
481
 
        if (sim_window_isactive(&np) == 0)
482
 
        {
483
 
                ttyputerr(M_("No simulator active"));
484
 
                return;
485
 
        }
486
 
        if (count < 1)
487
 
        {
488
 
                ttyputusage("telltool simulation als clock NODENAME (freq | period | custom)");
489
 
                return;
490
 
        }
491
 
 
492
 
        simals_convert_to_upper(par[0]);
493
 
        nodehead = simals_find_node(par[0]);
494
 
        if (! nodehead)
495
 
        {
496
 
                ttyputerr(M_("ERROR: Unable to find node %s"), par[0]);
497
 
                return;
498
 
        }
499
 
 
500
 
        if (count < 2)
501
 
        {
502
 
                count = sim_alsclockdlog(&par[1]) + 1;
503
 
                if (count < 2) return;
504
 
        }
505
 
 
506
 
        /* see if there are frequency/period parameters */
507
 
        l = strlen(par[1]);
508
 
        if (namesamen(par[1], "frequency", l) == 0 || namesamen(par[1], "period", l) == 0)
509
 
        {
510
 
                if (count < 3)
511
 
                {
512
 
                        ttyputusage("telltool simulation als clock NODENAME frequency/period PERIOD");
513
 
                        return;
514
 
                }
515
 
                time = atof(par[2]);
516
 
                if (time <= 0.0)
517
 
                {
518
 
                        ttyputerr(M_("Clock timing parameter must be greater than 0"));
519
 
                        return;
520
 
                }
521
 
 
522
 
                if (namesamen(par[1], "frequency", l) == 0) time = 1.0f / time;
523
 
 
524
 
                vectptr2 = simals_alloc_link_mem();
525
 
                if (vectptr2 == 0) return;
526
 
                vectptr2->type = 'N';
527
 
                vectptr2->ptr = (char *)nodehead;
528
 
                vectptr2->state = LOGIC_HIGH;
529
 
                vectptr2->strength = VDD_STRENGTH;
530
 
                vectptr2->priority = 1;
531
 
                vectptr2->time = 0.0;
532
 
                vectptr2->right = 0;
533
 
 
534
 
                vectptr1 = simals_alloc_link_mem();
535
 
                if (vectptr1 == 0) return;
536
 
                vectptr1->type = 'N';
537
 
                vectptr1->ptr = (char *)nodehead;
538
 
                vectptr1->state = LOGIC_LOW;
539
 
                vectptr1->strength = VDD_STRENGTH;
540
 
                vectptr1->priority = 1;
541
 
                vectptr1->time = time / 2.0f;
542
 
                vectptr1->right = vectptr2;
543
 
 
544
 
                clokhead = (ROWPTR)simals_alloc_mem((INTBIG)sizeof(ROW));
545
 
                if (clokhead == 0) return;
546
 
                clokhead->inptr = (IOPTR)vectptr1;
547
 
                clokhead->outptr = 0;
548
 
                clokhead->delta = (float)time;
549
 
                clokhead->linear = 0.0;
550
 
                clokhead->exp = 0.0;
551
 
                clokhead->abs = 0.0;
552
 
                clokhead->random = 0.0;
553
 
                clokhead->next = 0;
554
 
                clokhead->delay = 0;
555
 
 
556
 
                sethead = simals_alloc_link_mem();
557
 
                if (sethead == 0) return;
558
 
                sethead->type = 'C';
559
 
                sethead->ptr = (char *)clokhead;
560
 
                sethead->state = 0;
561
 
                sethead->priority = 1;
562
 
                sethead->time = 0.0;
563
 
                sethead->right = 0;
564
 
                simals_insert_set_list(sethead);
565
 
 
566
 
                (void)simals_initialize_simulator(FALSE);
567
 
                return;
568
 
        }
569
 
 
570
 
        if (namesamen(par[1], "custom", l) != 0)
571
 
        {
572
 
                ttyputbadusage("telltool simulation als clock");
573
 
                return;
574
 
        }
575
 
 
576
 
        /* handle custom clock specification */
577
 
        if (count < 7)
578
 
        {
579
 
                ttyputusage("telltool simulation als clock custom RAN STR CY (L D) *");
580
 
                return;
581
 
        }
582
 
 
583
 
        linear = (float)atof(par[2]);
584
 
        strength = (INTSML)simals_atoi(par[3])*2;
585
 
        num = simals_atoi(par[4]);
586
 
 
587
 
        totaltime = 0.0;
588
 
        vectroot = 0;
589
 
        vectptr = (char**) &vectroot;
590
 
        for(i=5; i<count; i += 2)
591
 
        {
592
 
                vectptr2 = simals_alloc_link_mem();
593
 
                if (vectptr2 == 0) return;
594
 
                vectptr2->type = 'N';
595
 
                vectptr2->ptr = (char *) nodehead;
596
 
                vectptr2->state = simals_trans_state_to_number(par[i]);
597
 
                vectptr2->strength = strength;
598
 
                vectptr2->priority = 1;
599
 
                vectptr2->time = atof(par[i+1]);
600
 
                totaltime += vectptr2->time;
601
 
                vectptr2->right = 0;
602
 
                *vectptr = (char*) vectptr2;
603
 
                vectptr = (char**) &(vectptr2->right);
604
 
        }
605
 
        vectptr2->time = 0.0;
606
 
 
607
 
        clokhead = (ROWPTR) simals_alloc_mem((INTBIG)sizeof(ROW));
608
 
        if (clokhead == 0) return;
609
 
        clokhead->inptr = (IOPTR) vectroot;
610
 
        clokhead->outptr = 0;
611
 
        clokhead->delta = (float)totaltime;
612
 
        clokhead->linear = linear;
613
 
        clokhead->exp = 0.0;
614
 
        clokhead->abs = 0.0;
615
 
        clokhead->random = 0.0;
616
 
        clokhead->next = 0;
617
 
        clokhead->delay = 0;
618
 
 
619
 
        sethead = simals_alloc_link_mem();
620
 
        if (sethead == 0) return;
621
 
        sethead->type = 'C';
622
 
        sethead->ptr = (char *) clokhead;
623
 
        sethead->state = num;
624
 
        sethead->priority = 1;
625
 
        sethead->time = 0.0;
626
 
        sethead->right = 0;
627
 
        simals_insert_set_list(sethead);
628
 
 
629
 
        (void)simals_initialize_simulator(FALSE);
630
 
}
631
 
 
632
 
/****************************** ERASE ******************************/
633
 
 
634
 
void simals_erase_model(void)
635
 
{
636
 
        MODPTR modptr, nextmodptr;
637
 
        EXPTR exptr, nextexptr;
638
 
        CONPTR conptr, nextconptr;
639
 
        IOPTR ioptr, nextioptr;
640
 
        ROWPTR rowptr, nextrowptr;
641
 
        LOADPTR loadptr, nextloadptr;
642
 
        FUNCPTR funcptr;
643
 
        NODEPTR node, nextnode;
644
 
        STATPTR statptr, nextstatptr;
645
 
 
646
 
        /* reset miscellaneous simulation variables */
647
 
        simals_linkfront = 0;
648
 
        simals_linkback = 0;
649
 
 
650
 
        /* loop through all test vectors */
651
 
        simals_clearallvectors(TRUE);
652
 
 
653
 
        /* loop throuth all cells in flattened network */
654
 
        if (simals_cellroot != 0)
655
 
        {
656
 
                simals_erase_submod(simals_cellroot);
657
 
                efree((char *)simals_cellroot);
658
 
                simals_cellroot = 0;
659
 
        }
660
 
        simals_levelptr = 0;
661
 
 
662
 
        /* loop through all nodes in flattened network */
663
 
        for(node = simals_noderoot; node != 0; node = nextnode)
664
 
        {
665
 
                nextnode = node->next;
666
 
 
667
 
                /* erase all loads on the nodes */
668
 
                for(loadptr = node->pinptr; loadptr != 0; loadptr = nextloadptr)
669
 
                {
670
 
                        nextloadptr = loadptr->next;
671
 
                        efree((char *)loadptr);
672
 
                }
673
 
 
674
 
                /* erase all stats on the nodes */
675
 
                for(statptr = node->statptr; statptr != 0; statptr = nextstatptr)
676
 
                {
677
 
                        nextstatptr = statptr->next;
678
 
                        efree((char *)statptr);
679
 
                }
680
 
                efree((char *)node);
681
 
        }
682
 
        simals_noderoot = 0;
683
 
 
684
 
        /* loop through all primitives in flattened network */
685
 
        for(modptr = simals_primroot; modptr != 0; modptr = nextmodptr)
686
 
        {
687
 
                nextmodptr = modptr->next;
688
 
                if (modptr->type == 'F')
689
 
                {
690
 
                        /* loop through each formal port on the function */
691
 
                        for(exptr = modptr->exptr; exptr != 0; exptr = nextexptr)
692
 
                        {
693
 
                                nextexptr = exptr->next;
694
 
                                efree((char *)exptr);
695
 
                        }
696
 
 
697
 
                        /* loop through each parameter on the function */
698
 
                        funcptr = (FUNCPTR)modptr->ptr;
699
 
                        for(exptr = funcptr->inptr; exptr != 0; exptr = nextexptr)
700
 
                        {
701
 
                                nextexptr = exptr->next;
702
 
                                efree((char *)exptr);
703
 
                        }
704
 
 
705
 
                        efree((char *)funcptr);
706
 
                }
707
 
                if (modptr->type == 'G')
708
 
                {
709
 
                        /* loop through each row in the gate */
710
 
                        for(rowptr = (ROWPTR)modptr->ptr; rowptr != 0; rowptr = nextrowptr)
711
 
                        {
712
 
                                nextrowptr = rowptr->next;
713
 
 
714
 
                                /* loop through each input on the row */
715
 
                                for(ioptr = rowptr->inptr; ioptr != 0; ioptr = nextioptr)
716
 
                                {
717
 
                                        nextioptr = ioptr->next;
718
 
                                        efree((char *)ioptr);
719
 
                                }
720
 
 
721
 
                                /* loop through each output on the row */
722
 
                                for(ioptr = rowptr->outptr; ioptr != 0; ioptr = nextioptr)
723
 
                                {
724
 
                                        nextioptr = ioptr->next;
725
 
                                        efree((char *)ioptr);
726
 
                                }
727
 
                                if (rowptr->delay != 0) efree((char *)rowptr->delay);
728
 
                                efree((char *)rowptr);
729
 
                        }
730
 
                }
731
 
                if (modptr->level != 0) efree((char *)modptr->level);
732
 
                efree((char *)modptr);
733
 
        }
734
 
        simals_primroot = 0;
735
 
 
736
 
        /* loop through each model/gate/function in hierarchical description */
737
 
        for(modptr = simals_modroot; modptr != 0; modptr = nextmodptr)
738
 
        {
739
 
                nextmodptr = modptr->next;
740
 
                efree((char *)modptr->name);
741
 
 
742
 
                /* loop through each formal port on the model/gate/function */
743
 
                for(exptr = modptr->exptr; exptr != 0; exptr = nextexptr)
744
 
                {
745
 
                        nextexptr = exptr->next;
746
 
                        efree((char *)exptr->node_name);
747
 
                        efree((char *)exptr);
748
 
                }
749
 
 
750
 
                /* loop through each "SET" instruction in the model/gate/function */
751
 
                for(ioptr = modptr->setptr; ioptr != 0; ioptr = nextioptr)
752
 
                {
753
 
                        nextioptr = ioptr->next;
754
 
                        efree((char *)ioptr->nodeptr);
755
 
                        efree((char *)ioptr);
756
 
                }
757
 
 
758
 
                /* special cleanup for functions */
759
 
                if (modptr->type == 'F')
760
 
                {
761
 
                        funcptr = (FUNCPTR)modptr->ptr;
762
 
 
763
 
                        /* loop through each load in the function */
764
 
                        for(loadptr = modptr->loadptr; loadptr != 0; loadptr = nextloadptr)
765
 
                        {
766
 
                                nextloadptr = loadptr->next;
767
 
                                efree((char *)loadptr->ptr);
768
 
                                efree((char *)loadptr);
769
 
                        }
770
 
 
771
 
                        /* loop through each input on the function */
772
 
                        for(exptr = funcptr->inptr; exptr != 0; exptr = nextexptr)
773
 
                        {
774
 
                                nextexptr = exptr->next;
775
 
                                efree((char *)exptr->node_name);
776
 
                                efree((char *)exptr);
777
 
                        }
778
 
                        efree((char *)funcptr);
779
 
                }
780
 
 
781
 
                /* special cleanup for models */
782
 
                if (modptr->type == 'M')
783
 
                {
784
 
                        /* loop through each instance in the model */
785
 
                        for(conptr = (CONPTR)modptr->ptr; conptr != 0; conptr = nextconptr)
786
 
                        {
787
 
                                nextconptr = conptr->next;
788
 
                                efree((char *)conptr->inst_name);
789
 
                                if (conptr->model_name != 0) efree(conptr->model_name);
790
 
 
791
 
                                /* loop through each actual port on the instance */
792
 
                                for(exptr = conptr->exptr; exptr != 0; exptr = nextexptr)
793
 
                                {
794
 
                                        nextexptr = exptr->next;
795
 
                                        efree((char *)exptr->node_name);
796
 
                                        efree((char *)exptr);
797
 
                                }
798
 
                                efree((char *)conptr);
799
 
                        }
800
 
                }
801
 
 
802
 
                /* special cleanup for gates */
803
 
                if (modptr->type == 'G')
804
 
                {
805
 
                        /* loop through each row in the gate */
806
 
                        for(rowptr = (ROWPTR)modptr->ptr; rowptr != 0; rowptr = nextrowptr)
807
 
                        {
808
 
                                nextrowptr = rowptr->next;
809
 
 
810
 
                                /* loop through each input on the row */
811
 
                                for(ioptr = rowptr->inptr; ioptr != 0; ioptr = nextioptr)
812
 
                                {
813
 
                                        nextioptr = ioptr->next;
814
 
                                        efree((char *)ioptr->nodeptr);
815
 
                                        efree((char *)ioptr);
816
 
                                }
817
 
 
818
 
                                /* loop through each output on the row */
819
 
                                for(ioptr = rowptr->outptr; ioptr != 0; ioptr = nextioptr)
820
 
                                {
821
 
                                        nextioptr = ioptr->next;
822
 
                                        efree((char *)ioptr->nodeptr);
823
 
                                        efree((char *)ioptr);
824
 
                                }
825
 
                                if (rowptr->delay != 0) efree((char *)rowptr->delay);
826
 
                                efree((char *)rowptr);
827
 
                        }
828
 
 
829
 
                        /* loop through each load in the gate */
830
 
                        for(loadptr = modptr->loadptr; loadptr != 0; loadptr = nextloadptr)
831
 
                        {
832
 
                                nextloadptr = loadptr->next;
833
 
                                efree((char *)loadptr->ptr);
834
 
                                efree((char *)loadptr);
835
 
                        }
836
 
                }
837
 
 
838
 
                if (modptr->level != 0) efree((char *)modptr->level);
839
 
                efree((char *)modptr);
840
 
        }
841
 
        simals_modroot = 0;
842
 
}
843
 
 
844
 
/*
845
 
 * Routine to clear all test vectors (even the power and ground vectors if "pwrgnd"
846
 
 * is true).
847
 
 */
848
 
void simals_clearallvectors(BOOLEAN pwrgnd)
849
 
{
850
 
        LINKPTR thisset, vecthead, nextvec, nextset, lastset;
851
 
        ROWPTR clokhead;
852
 
 
853
 
        lastset = 0;
854
 
        for(thisset = simals_setroot; thisset != 0; thisset = nextset)
855
 
        {
856
 
                nextset = thisset->right;
857
 
                if (pwrgnd || thisset->strength != VDD_STRENGTH)
858
 
                {
859
 
                        if (thisset->type == 'C')
860
 
                        {
861
 
                                clokhead = (ROWPTR)thisset->ptr;
862
 
                                for (vecthead = (LINKPTR)clokhead->inptr; vecthead; vecthead = nextvec)
863
 
                                {
864
 
                                        nextvec = vecthead->right;
865
 
                                        simals_free_link_mem(vecthead);
866
 
                                }
867
 
                                efree((char *)clokhead);
868
 
                        }
869
 
                        simals_free_link_mem(thisset);
870
 
 
871
 
                        if (lastset == 0) simals_setroot = nextset; else
872
 
                                lastset->right = nextset;
873
 
                } else
874
 
                {
875
 
                        lastset = thisset;
876
 
                }
877
 
        }
878
 
}
879
 
 
880
 
void simals_erase_submod(CONPTR conhead)
881
 
{
882
 
        CONPTR conptr, nextconptr;
883
 
        EXPTR exptr, nextexptr;
884
 
        REGISTER INTBIG chn, i;
885
 
 
886
 
        for(conptr = conhead->child; conptr != 0; conptr = nextconptr)
887
 
        {
888
 
                nextconptr = conptr->next;
889
 
                simals_erase_submod(conptr);
890
 
                for(exptr = conptr->exptr; exptr != 0; exptr = nextexptr)
891
 
                {
892
 
                        nextexptr = exptr->next;
893
 
                        efree((char *)exptr);
894
 
                }
895
 
                efree((char *)conptr);
896
 
        }
897
 
        if (conhead->display_page != 0)
898
 
        {
899
 
                chn = conhead->num_chn + 1;
900
 
                for (i = 1; i < chn; i++)
901
 
                        efree((char *)conhead->display_page[i].name);
902
 
                efree((char *)conhead->display_page);
903
 
        }
904
 
}
905
 
 
906
 
/****************************** GO ******************************/
907
 
 
908
 
/*
909
 
 * Name: simals_go_command
910
 
 *
911
 
 * Description:
912
 
 *      This procedure parses the command line for the go command from the
913
 
 * keyboard.  The maximum execution time must also be specified for the
914
 
 * simulation run.
915
 
 */
916
 
void simals_go_command(INTBIG count, char *par[])
917
 
{
918
 
        double max;
919
 
        NODEPROTO *np;
920
 
 
921
 
        if (sim_window_isactive(&np) == 0)
922
 
        {
923
 
                ttyputerr(M_("No simulator active"));
924
 
                return;
925
 
        }
926
 
        if (count < 1)
927
 
        {
928
 
                ttyputerr(M_("Must specify simulation time"));
929
 
                return;
930
 
        }
931
 
        max = atof(par[0]);
932
 
        if (max <= 0.0)
933
 
        {
934
 
                ttyputerr(M_("Simulation time must be greater than 0 seconds"));
935
 
                return;
936
 
        }
937
 
        sim_window_settimerange(0.0, max);
938
 
 
939
 
        (void)simals_initialize_simulator(TRUE);
940
 
}
941
 
 
942
 
/****************************** HELP ******************************/
943
 
 
944
 
/*
945
 
 * Name: simals_help_command
946
 
 *
947
 
 * Description:
948
 
 *      This procedure process the help command and display help information.
949
 
 */
950
 
void simals_help_command(void)
951
 
{
952
 
        (void)us_helpdlog("ALS");
953
 
}
954
 
 
955
 
/****************************** LEVEL ******************************/
956
 
 
957
 
/*
958
 
 * Name: simals_level_up_command
959
 
 *
960
 
 * Description:
961
 
 *      This procedure changes the level of hierarchy up one level.
962
 
 */
963
 
void simals_level_up_command(void)
964
 
{
965
 
        CONPTR  cellptr;
966
 
        INTBIG   l;
967
 
        double mintime, maxtime, maintime, exttime;
968
 
        NODEPROTO *np;
969
 
 
970
 
        if (sim_window_isactive(&np) == 0)
971
 
        {
972
 
                ttyputerr(_("No simulator active"));
973
 
                return;
974
 
        }
975
 
 
976
 
        if (simals_levelptr == 0)
977
 
        {
978
 
                ttyputerr(_("No simulation is running"));
979
 
                return;
980
 
        }
981
 
        cellptr = simals_levelptr->parent;
982
 
        if (! cellptr)
983
 
        {
984
 
                ttyputerr(_("ERROR: Currently at top level of hierarchy"));
985
 
                return;
986
 
        }
987
 
 
988
 
        simals_levelptr = cellptr;
989
 
 
990
 
        /* reinitialize simulator while preserving time information */
991
 
        sim_window_gettimerange(&mintime, &maxtime);
992
 
        maintime = sim_window_getmaincursor();
993
 
        exttime = sim_window_getextensioncursor();
994
 
        if (simals_set_current_level()) return;
995
 
        sim_window_settimerange(mintime, maxtime);
996
 
        sim_window_setmaincursor(maintime);
997
 
        sim_window_setextensioncursor(exttime);
998
 
 
999
 
        l = simals_levelptr->num_chn;
1000
 
        sim_window_setlines(l);
1001
 
        sim_window_settopline(0);
1002
 
        (void)simals_initialize_simulator(TRUE);
1003
 
}
1004
 
 
1005
 
/*
1006
 
 * Name: simals_level_set_command
1007
 
 *
1008
 
 * Description:
1009
 
 *      This procedure changes the level of hierarchy to a specified new (lower) level.
1010
 
 */
1011
 
void simals_level_set_command(char *instname)
1012
 
{
1013
 
        CONPTR  cellptr;
1014
 
        INTBIG   l;
1015
 
        double mintime, maxtime, maintime, exttime;
1016
 
        char    *pt;
1017
 
        NODEPROTO *np;
1018
 
 
1019
 
        if (sim_window_isactive(&np) == 0)
1020
 
        {
1021
 
                ttyputerr(_("No simulator active"));
1022
 
                return;
1023
 
        }
1024
 
 
1025
 
        for(pt = instname; *pt != 0; pt++) if (*pt == ' ') break;
1026
 
        *pt = 0;
1027
 
        simals_convert_to_upper(instname);
1028
 
        cellptr = simals_find_level(instname);
1029
 
        if (! cellptr)
1030
 
        {
1031
 
                ttyputerr(M_("ERROR: Unable to find level %s"), instname);
1032
 
                return;
1033
 
        }
1034
 
 
1035
 
        simals_levelptr = cellptr;
1036
 
 
1037
 
        /* reinitialize simulator while preserving time information */
1038
 
        sim_window_gettimerange(&mintime, &maxtime);
1039
 
        maintime = sim_window_getmaincursor();
1040
 
        exttime = sim_window_getextensioncursor();
1041
 
        if (simals_set_current_level()) return;
1042
 
        sim_window_settimerange(mintime, maxtime);
1043
 
        sim_window_setmaincursor(maintime);
1044
 
        sim_window_setextensioncursor(exttime);
1045
 
 
1046
 
        l = simals_levelptr->num_chn;
1047
 
        sim_window_setlines(l);
1048
 
        sim_window_settopline(0);
1049
 
        (void)simals_initialize_simulator(TRUE);
1050
 
}
1051
 
 
1052
 
/****************************** PRINT ******************************/
1053
 
 
1054
 
/*
1055
 
 * routine to print out the display screen status and information
1056
 
 */
1057
 
void simals_print_command(INTBIG count, char *par[])
1058
 
{
1059
 
        INTBIG l;
1060
 
        char *pt, s1[256];
1061
 
        LINKPTR  linkhead;
1062
 
        NODEPTR  nodehead;
1063
 
        STATPTR  stathead;
1064
 
        MODPTR   primhead;
1065
 
        ROWPTR   rowhead;
1066
 
        EXPTR    exhead;
1067
 
        FUNCPTR  funchead;
1068
 
        CONPTR   cellhead;
1069
 
 
1070
 
        if (count < 1)
1071
 
        {
1072
 
                ttyputusage("telltool simulation als print OPTION");
1073
 
                return;
1074
 
        }
1075
 
        l = strlen(pt = par[0]);
1076
 
 
1077
 
        if (namesamen(pt, "size", l) == 0 && l >= 2)
1078
 
        {
1079
 
                ttyputmsg(M_("Number of Primitive Elements in Database = %ld"), simals_pseq);
1080
 
                ttyputmsg(M_("Number of Nodes in Database = %ld"), simals_nseq);
1081
 
                return;
1082
 
        }
1083
 
 
1084
 
        if (namesamen(pt, "vector", l) == 0 && l >= 1)
1085
 
        {
1086
 
                linkhead = simals_setroot;
1087
 
                ttyputmsg(M_("** VECTOR LINKLIST **"));
1088
 
                while (linkhead)
1089
 
                {
1090
 
                        switch (linkhead->type)
1091
 
                        {
1092
 
                                case 'N':
1093
 
                                        nodehead = (NODEPTR)linkhead->ptr;
1094
 
                                        simals_trans_number_to_state(linkhead->state, s1);
1095
 
                                        ttyputmsg(M_("***** vector: $N%ld, state = %s, strength = %s, time = %g, priority = %d"),
1096
 
                                                nodehead->num, s1, simals_strengthstring(linkhead->strength),
1097
 
                                                        linkhead->time, linkhead->priority);
1098
 
                                        break;
1099
 
                                case 'F':
1100
 
                                        stathead = (STATPTR)linkhead->ptr;
1101
 
                                        nodehead = stathead->nodeptr;
1102
 
                                        simals_trans_number_to_state(linkhead->state, s1);
1103
 
                                        ttyputmsg(M_("***** function: $N%ld, state = %s, strength = %s, time = %g, priority = %d"),
1104
 
                                                nodehead->num, s1, simals_strengthstring(linkhead->strength),
1105
 
                                                        linkhead->time, linkhead->priority);
1106
 
                                        break;
1107
 
                                case 'R':
1108
 
                                        ttyputmsg(M_("***** rowptr = %ld, time = %g, priority = %d"),
1109
 
                                                linkhead->ptr, linkhead->time, linkhead->priority);
1110
 
                                        break;
1111
 
                                case 'C':
1112
 
                                        ttyputmsg(M_("***** clokptr = %ld, time = %g, priority = %d"),
1113
 
                                                linkhead->ptr, linkhead->time, linkhead->priority);
1114
 
                        }
1115
 
                        linkhead = linkhead->right;
1116
 
                }
1117
 
                return;
1118
 
        }
1119
 
 
1120
 
        if (namesamen(pt, "netlist", l) == 0 && l >= 1)
1121
 
        {
1122
 
                ttyputmsg(M_("** NETWORK DESCRIPTION **"));
1123
 
                for (primhead = simals_primroot; primhead; primhead = primhead->next)
1124
 
                {
1125
 
                        if (stopping(STOPREASONDISPLAY)) return;
1126
 
                        switch (primhead->type)
1127
 
                        {
1128
 
                                case 'F':
1129
 
                                        (void)initinfstr();
1130
 
                                        (void)formatinfstr(M_("FUNCTION %ld: %s (instance %s) ["), primhead->num, primhead->name,
1131
 
                                                (primhead->level == NULL) ? M_("null") : primhead->level);
1132
 
                                        for (exhead = primhead->exptr; exhead; exhead=exhead->next)
1133
 
                                        {
1134
 
                                                if (exhead != primhead->exptr) (void)addstringtoinfstr(", ");
1135
 
                                                (void)formatinfstr("N%ld", exhead->nodeptr->num);
1136
 
                                        }
1137
 
                                        (void)addstringtoinfstr("]");
1138
 
                                        ttyputmsg("%s", returninfstr());
1139
 
                                        (void)initinfstr();
1140
 
                                        (void)addstringtoinfstr(M_("  Event Driving Inputs:"));
1141
 
                                        funchead = (FUNCPTR)primhead->ptr;
1142
 
                                        for (exhead = funchead->inptr; exhead; exhead=exhead->next)
1143
 
                                                (void)formatinfstr(" N%ld", exhead->nodeptr->num);
1144
 
                                        ttyputmsg("%s", returninfstr());
1145
 
                                        (void)initinfstr();
1146
 
                                        (void)addstringtoinfstr(M_("  Output Ports:"));
1147
 
                                        for (exhead = primhead->exptr; exhead; exhead=exhead->next)
1148
 
                                        {
1149
 
                                                if (exhead->node_name)
1150
 
                                                        (void)formatinfstr(" N%ld", ((STATPTR)exhead->node_name)->nodeptr->num);
1151
 
                                        }
1152
 
                                        ttyputmsg("%s", returninfstr());
1153
 
                                        ttyputmsg(M_("  Timing: D=%g, L=%g, E=%g, R=%g, A=%g"), funchead->delta,
1154
 
                                                funchead->linear, funchead->exp, funchead->random, funchead->abs);
1155
 
                                        ttyputmsg(M_("  Firing Priority = %d"), primhead->priority);
1156
 
                                        break;
1157
 
                                case 'G':
1158
 
                                        ttyputmsg(M_("GATE %ld: %s (instance %s)"), primhead->num, primhead->name,
1159
 
                                                (primhead->level == NULL) ? M_("null") : primhead->level);
1160
 
                                        for (rowhead = (ROWPTR)primhead->ptr; rowhead; rowhead=rowhead->next)
1161
 
                                        {
1162
 
                                                ttyputmsg(M_("  Timing: D=%g, L=%g, E=%g, R=%g, A=%g"), rowhead->delta,
1163
 
                                                        rowhead->linear, rowhead->exp, rowhead->random, rowhead->abs);
1164
 
                                                ttyputmsg(M_("  Delay type: %s"), (rowhead->delay == NULL) ? M_("null") : rowhead->delay);
1165
 
                                                simals_print_in_entry(rowhead);
1166
 
                                                simals_print_out_entry(rowhead);
1167
 
                                        }
1168
 
                                        ttyputmsg(M_("  Firing Priority = %d"), primhead->priority);
1169
 
                                        break;
1170
 
                                default:
1171
 
                                        ttyputerr(M_("Illegal primitive type '%c', database is bad"), primhead->type);
1172
 
                                        break;
1173
 
                        }
1174
 
                }
1175
 
                return;
1176
 
        }
1177
 
 
1178
 
        if (namesamen(pt, "xref", l) == 0 && l >= 1)
1179
 
        {
1180
 
                ttyputmsg(M_("** CROSS REFERENCE TABLE **"));
1181
 
                simals_print_xref_entry(simals_levelptr, 0);
1182
 
                return;
1183
 
        }
1184
 
 
1185
 
        if (namesamen(pt, "state", l) == 0 && l >= 2)
1186
 
        {
1187
 
                if (count < 2)
1188
 
                {
1189
 
                        ttyputusage("telltool simulation als print state NODENAME");
1190
 
                        return;
1191
 
                }
1192
 
                simals_convert_to_upper(par[1]);
1193
 
                nodehead = simals_find_node(par[1]);
1194
 
                if (nodehead == 0)
1195
 
                {
1196
 
                        ttyputerr(M_("ERROR: Unable to find node %s"), par[1]);
1197
 
                        return;
1198
 
                }
1199
 
 
1200
 
                simals_trans_number_to_state(nodehead->new_state, s1);
1201
 
                ttyputmsg(M_("Node %s: State = %s, Strength = %s"), par[1], s1,
1202
 
                        simals_strengthstring(nodehead->new_strength));
1203
 
                stathead = nodehead->statptr;
1204
 
                while (stathead)
1205
 
                {
1206
 
                        simals_trans_number_to_state(stathead->new_state, s1);
1207
 
                        ttyputmsg(M_("Primitive %ld:    State = %s, Strength = %s"), stathead->primptr->num,
1208
 
                                s1, simals_strengthstring(stathead->new_strength));
1209
 
                        stathead = stathead->next;
1210
 
                }
1211
 
                return;
1212
 
        }
1213
 
 
1214
 
        if (namesamen(pt, "instances", l) == 0 && l >= 1)
1215
 
        {
1216
 
                ttyputmsg(M_("Instances at level: %s"), simals_compute_path_name(simals_levelptr));
1217
 
                for (cellhead = simals_levelptr->child; cellhead; cellhead = cellhead->next)
1218
 
                {
1219
 
                        if (stopping(STOPREASONDISPLAY)) break;
1220
 
                        ttyputmsg(M_("Name: %s, Model: %s"), cellhead->inst_name, cellhead->model_name);
1221
 
                }
1222
 
                return;
1223
 
        }
1224
 
        ttyputbadusage("telltool simulation als print");
1225
 
}
1226
 
 
1227
 
char *simals_strengthstring(INTSML strength)
1228
 
{
1229
 
        if (strength == OFF_STRENGTH) return(_("off"));
1230
 
        if (strength <= NODE_STRENGTH) return(_("node"));
1231
 
        if (strength <= GATE_STRENGTH) return(_("gate"));
1232
 
        return(_("power"));
1233
 
}
1234
 
 
1235
 
/*
1236
 
 * Name: simals_print_in_entry
1237
 
 *
1238
 
 * Description:
1239
 
 *      This procedure examines an input entry and prints out the condition
1240
 
 * that it represents.  It is possible for an input entry operand to represent
1241
 
 * a logic value, integer value, or another node address.
1242
 
 *
1243
 
 * Calling Arguments:
1244
 
 *      rowhead = pointer to the row being printed
1245
 
 */
1246
 
void simals_print_in_entry(ROWPTR rowhead)
1247
 
{
1248
 
        INTBIG      num;
1249
 
        char       flag, s1[15];
1250
 
        unsigned char  operatr;
1251
 
        IOPTR     iohead;
1252
 
        NODEPTR nodehead;
1253
 
 
1254
 
        flag = 0;
1255
 
        (void)initinfstr();
1256
 
        (void)addstringtoinfstr(M_("  Input: "));
1257
 
 
1258
 
        for (iohead = rowhead->inptr; iohead; iohead = iohead->next)
1259
 
        {
1260
 
                if (flag) (void)addstringtoinfstr("& ");
1261
 
                flag = 1;
1262
 
 
1263
 
                nodehead = (NODEPTR)iohead->nodeptr;
1264
 
                (void)sprintf(s1, "N%ld", nodehead->num);
1265
 
                (void)addstringtoinfstr(s1);
1266
 
 
1267
 
                if (iohead->operatr > 127)
1268
 
                {
1269
 
                        operatr = iohead->operatr - 128;
1270
 
                        nodehead = (NODEPTR) iohead->operand;
1271
 
                        (void)sprintf(s1, "%cN%ld", operatr, nodehead->num);
1272
 
                        (void)addstringtoinfstr(s1);
1273
 
                        continue;
1274
 
                }
1275
 
 
1276
 
                (void)addtoinfstr(iohead->operatr);
1277
 
 
1278
 
                num = (INTBIG)iohead->operand;
1279
 
                simals_trans_number_to_state(num, s1);
1280
 
                (void)addstringtoinfstr(s1);
1281
 
                (void)addstringtoinfstr(" ");
1282
 
        }
1283
 
        ttyputmsg("%s", returninfstr());
1284
 
}
1285
 
 
1286
 
/*
1287
 
 * Name: simals_print_out_entry
1288
 
 *
1289
 
 * Description:
1290
 
 *      This procedure examines an output entry and prints out the condition
1291
 
 * that it represents.  It is possible for an output entry operand to represent
1292
 
 * a logic value, integer value, or another node address.
1293
 
 *
1294
 
 * Calling Arguments:
1295
 
 *      rowhead = pointer to the row being printed
1296
 
 */
1297
 
void simals_print_out_entry(ROWPTR rowhead)
1298
 
{
1299
 
        INTBIG      num;
1300
 
        char       flag, s1[50];
1301
 
        unsigned char  operatr;
1302
 
        IOPTR     iohead;
1303
 
        STATPTR stathead;
1304
 
        NODEPTR nodehead;
1305
 
 
1306
 
        flag = 0;
1307
 
        (void)initinfstr();
1308
 
        (void)addstringtoinfstr(M_("  Output: "));
1309
 
 
1310
 
        for (iohead = rowhead->outptr; iohead; iohead = iohead->next)
1311
 
        {
1312
 
                if (flag) (void)addstringtoinfstr("& ");
1313
 
                flag = 1;
1314
 
 
1315
 
                stathead = (STATPTR)iohead->nodeptr;
1316
 
                nodehead = stathead->nodeptr;
1317
 
                (void)sprintf(s1, "N%ld", nodehead->num);
1318
 
                (void)addstringtoinfstr(s1);
1319
 
 
1320
 
                if (iohead->operatr > 127)
1321
 
                {
1322
 
                        operatr = iohead->operatr - 128;
1323
 
                        nodehead = (NODEPTR) iohead->operand;
1324
 
                        (void)sprintf(s1, "%cN%ld@%d ", operatr, nodehead->num, (iohead->strength+1)/2);
1325
 
                        (void)addstringtoinfstr(s1);
1326
 
                        continue;
1327
 
                }
1328
 
 
1329
 
                (void)addtoinfstr(iohead->operatr);
1330
 
 
1331
 
                num = (INTBIG)iohead->operand;
1332
 
                simals_trans_number_to_state(num, s1);
1333
 
                (void)addstringtoinfstr(s1);
1334
 
                (void)sprintf(s1, "@%d ", (iohead->strength+1)/2);
1335
 
                (void)addstringtoinfstr(s1);
1336
 
        }
1337
 
        ttyputmsg("%s", returninfstr());
1338
 
}
1339
 
 
1340
 
/*
1341
 
 * Name: simals_print_xref_entry
1342
 
 *
1343
 
 * Description:
1344
 
 *      This procedure prints entries from the cross reference table that was
1345
 
 * generated to transform the hierarchical network description into a totally flat
1346
 
 * network description.  The calling arguments define the root of the reference
1347
 
 * table column and the level of indentation for the column.
1348
 
 *
1349
 
 * Calling Arguments:
1350
 
 *      cellhead = pointer to cross reference table
1351
 
 *      tab     = integer value indicating level of output indentation
1352
 
 */
1353
 
void simals_print_xref_entry(CONPTR cellhead, INTBIG tab)
1354
 
{
1355
 
        INTBIG  i, k, delay;
1356
 
        char    tabsp[200], ts[256];
1357
 
        EXPTR   exhead;
1358
 
        CONPTR  subcell;
1359
 
 
1360
 
        if (stopping(STOPREASONDISPLAY)) return;
1361
 
        for (i = 0; i < tab; ++i) tabsp[i] = ' ';
1362
 
        tabsp[tab] = 0;
1363
 
        ttyputmsg(M_("%sLevel: %s, Model: %s"), tabsp, simals_compute_path_name(cellhead),
1364
 
                cellhead->model_name);
1365
 
 
1366
 
        for (exhead = cellhead->exptr; exhead; exhead = exhead->next)
1367
 
        {
1368
 
                if (stopping(STOPREASONDISPLAY)) return;
1369
 
                k = 0;
1370
 
                for (i=0; i<12; i++)
1371
 
                {
1372
 
                        delay = exhead->td[i];
1373
 
                        if (delay != 0)
1374
 
                        {
1375
 
                                if (k == 0) (void)initinfstr();
1376
 
                                (void)sprintf(ts, "%s=%ld ", simals_tnames[i], delay);
1377
 
                                (void)addstringtoinfstr(ts);
1378
 
                                k++;
1379
 
                        }
1380
 
                }
1381
 
                if (k == 0) ttyputmsg("%s%14s --> N%ld", tabsp, exhead->node_name, exhead->nodeptr->num); else
1382
 
                        ttyputmsg("%s%14s --> N%ld (%s)", tabsp, exhead->node_name, exhead->nodeptr->num, returninfstr());
1383
 
        }
1384
 
 
1385
 
        if (simals_instbuf[simals_instptr[1]] == 'X') return;
1386
 
 
1387
 
        for (subcell = cellhead->child; subcell; subcell = subcell->next)
1388
 
                simals_print_xref_entry(subcell, tab + 10);
1389
 
}
1390
 
 
1391
 
/****************************** SEED ******************************/
1392
 
 
1393
 
/*
1394
 
 * Name: simals_seed_command
1395
 
 *
1396
 
 * Description:
1397
 
 *      This procedure sets a flag which tells the simulator if it is necessary
1398
 
 * to reseed the Random Number Generator each time a simulation is run.
1399
 
 */
1400
 
void simals_seed_command(INTBIG count, char *par[])
1401
 
{
1402
 
        if (count < 1)
1403
 
        {
1404
 
                ttyputusage("telltool simulation als seed (reset | no-reset)");
1405
 
                return;
1406
 
        }
1407
 
        if (namesamen(par[0], "reset", strlen(par[0])) == 0)
1408
 
                simals_seed_flag = FALSE; else simals_seed_flag = TRUE;
1409
 
}
1410
 
 
1411
 
/****************************** SET ******************************/
1412
 
 
1413
 
/*
1414
 
 * Name: simals_set_command
1415
 
 *
1416
 
 * Description:
1417
 
 *      This procedure sets the specified node to the state that is indicated
1418
 
 * in the command line.
1419
 
*/
1420
 
void simals_set_command(INTBIG count, char *par[])
1421
 
{
1422
 
        INTBIG  state;
1423
 
        INTSML  strength;
1424
 
        double   time;
1425
 
        NODEPTR  nodehead;
1426
 
        LINKPTR  sethead;
1427
 
        NODEPROTO *np;
1428
 
 
1429
 
        if (sim_window_isactive(&np) == 0)
1430
 
        {
1431
 
                ttyputerr(_("No simulator active"));
1432
 
                return;
1433
 
        }
1434
 
        if (count < 4)
1435
 
        {
1436
 
                ttyputusage("telltool simulation als set NODE LEVEL STRENGTH TIME");
1437
 
                return;
1438
 
        }
1439
 
        simals_convert_to_upper(par[0]);
1440
 
        nodehead = simals_find_node(par[0]);
1441
 
        if (! nodehead)
1442
 
        {
1443
 
                ttyputerr(_("ERROR: Unable to find node %s"), par[0]);
1444
 
                return;
1445
 
        }
1446
 
 
1447
 
        state = simals_trans_state_to_number(par[1]);
1448
 
        strength = (INTSML)simals_atoi(par[2])*2;
1449
 
        time = atof(par[3]);
1450
 
 
1451
 
        sethead = simals_alloc_link_mem();
1452
 
        if (sethead == 0) return;
1453
 
        sethead->type = 'N';
1454
 
        sethead->ptr = (char *)nodehead;
1455
 
        sethead->state = state;
1456
 
        sethead->strength = strength;
1457
 
        sethead->priority = 2;
1458
 
        sethead->time = time;
1459
 
        sethead->right = 0;
1460
 
        simals_insert_set_list(sethead);
1461
 
 
1462
 
        ttyputmsg(M_("Node '%s' scheduled, state = %s, strength = %s, time = %g"), par[0], par[1],
1463
 
                simals_strengthstring(strength), time);
1464
 
        (void)simals_initialize_simulator(FALSE);
1465
 
}
1466
 
 
1467
 
/****************************** TRACE ******************************/
1468
 
 
1469
 
/*
1470
 
 * Name: simals_trace_command
1471
 
 *
1472
 
 * Description:
1473
 
 *      This procedure turns on/off the trace buffer.  If it is turned off, no
1474
 
 * timing diagram information will be stored in memory for plotting.
1475
 
 */
1476
 
void simals_trace_command(INTBIG count, char *par[])
1477
 
{
1478
 
        INTBIG l;
1479
 
        char *pt;
1480
 
 
1481
 
        if (count < 1)
1482
 
        {
1483
 
                ttyputusage("telltool simulation als trace OPTION");
1484
 
                return;
1485
 
        }
1486
 
        l = strlen(pt = par[0]);
1487
 
        if (namesamen(pt, "on", l) == 0 && l >= 2)
1488
 
        {
1489
 
                (void)setvalkey((INTBIG)sim_tool, VTOOL, simals_no_update_key, 0, VINTEGER);
1490
 
                return;
1491
 
        }
1492
 
        if (namesamen(pt, "off", l) == 0 && l >= 2)
1493
 
        {
1494
 
                (void)setvalkey((INTBIG)sim_tool, VTOOL, simals_no_update_key, 1, VINTEGER);
1495
 
                return;
1496
 
        }
1497
 
        ttyputbadusage("telltool simulation als trace");
1498
 
}
1499
 
 
1500
 
/****************************** VECTOR ******************************/
1501
 
 
1502
 
void simals_vector_command(INTBIG count, char *par[])
1503
 
{
1504
 
        INTBIG   l, flag;
1505
 
        INTSML   strength;
1506
 
        char     s1[256], s2[80], *pt, **vectptr1, **backptr;
1507
 
        char    *filename, *truename;
1508
 
        FILE    *vin, *vout;
1509
 
        LINKPTR  sethead, vecthead, vectptr2, nextvec;
1510
 
        ROWPTR   clokhead;
1511
 
        NODEPTR  nodehead;
1512
 
        double   time;
1513
 
        NODEPROTO *np;
1514
 
 
1515
 
        if (sim_window_isactive(&np) == 0)
1516
 
        {
1517
 
                ttyputerr(_("No simulator active"));
1518
 
                return;
1519
 
        }
1520
 
        if (count < 1)
1521
 
        {
1522
 
                ttyputusage("telltool simulation als vector OPTION");
1523
 
                return;
1524
 
        }
1525
 
        l = strlen(pt = par[0]);
1526
 
 
1527
 
        if (namesamen(pt, "load", l) == 0)
1528
 
        {
1529
 
                if (count < 2)
1530
 
                {
1531
 
                        par[1] = fileselect(_("ALS vector file"), sim_filetypealsvec, "");
1532
 
                        if (par[1] == 0) return;
1533
 
                }
1534
 
                vin = xopen(par[1], sim_filetypealsvec, "", &filename);
1535
 
                if (! vin)
1536
 
                {
1537
 
                        ttyputerr(_("ERROR: Can't open %s"), par[1]);
1538
 
                        return;
1539
 
                }
1540
 
 
1541
 
                /* clear all vectors */
1542
 
                while (simals_setroot)
1543
 
                {
1544
 
                        sethead = simals_setroot;
1545
 
                        simals_setroot = simals_setroot->right;
1546
 
                        if (sethead->type == 'C')
1547
 
                        {
1548
 
                                clokhead = (ROWPTR) sethead->ptr;
1549
 
                                for (vectptr2 = (LINKPTR) clokhead->inptr; vectptr2; vectptr2 = nextvec)
1550
 
                                {
1551
 
                                        nextvec = vectptr2->right;
1552
 
                                        simals_free_link_mem(vectptr2);
1553
 
                                }
1554
 
                                efree((char *)clokhead);
1555
 
                        }
1556
 
                        simals_free_link_mem(sethead);
1557
 
                }
1558
 
 
1559
 
                flag = 1;
1560
 
                for(;;)
1561
 
                {
1562
 
                        if (flag)
1563
 
                        {
1564
 
                                if (xfgets(s1, 255, vin))
1565
 
                                {
1566
 
                                        xclose(vin);
1567
 
                                        (void)simals_initialize_simulator(FALSE);
1568
 
                                        break;
1569
 
                                }
1570
 
                                simals_convert_to_upper(s1);
1571
 
                                if (simals_fragment_command(s1)) break;
1572
 
                        }
1573
 
 
1574
 
                        if (! strcmp(simals_instbuf, "CLOCK"))
1575
 
                        {
1576
 
                                simals_convert_to_upper(&(simals_instbuf[simals_instptr[1]]));
1577
 
                                nodehead = simals_find_node(&(simals_instbuf[simals_instptr[1]]));
1578
 
                                if (! nodehead)
1579
 
                                {
1580
 
                                        ttyputerr(_("ERROR: Unable to find node %s"),
1581
 
                                                &(simals_instbuf[simals_instptr[1]]));
1582
 
                                        flag = 1;
1583
 
                                        continue;
1584
 
                                }
1585
 
                                strength = atoi(&(simals_instbuf[simals_instptr[9]]))*2;
1586
 
 
1587
 
                                sethead = simals_alloc_link_mem();
1588
 
                                if (sethead == 0) return;
1589
 
                                sethead->type = 'C';
1590
 
                                sethead->ptr = (char*)(clokhead = (ROWPTR) simals_alloc_mem((INTBIG)sizeof(ROW)));
1591
 
                                if (sethead->ptr == 0) return;
1592
 
                                sethead->state = atoi(&(simals_instbuf[simals_instptr[13]]));
1593
 
                                sethead->priority = 1;
1594
 
                                sethead->time = atof(&(simals_instbuf[simals_instptr[11]]));
1595
 
                                sethead->right = 0;
1596
 
                                simals_insert_set_list(sethead);
1597
 
 
1598
 
                                clokhead->delta = (float)atof(&(simals_instbuf[simals_instptr[3]]));
1599
 
                                clokhead->linear = (float)atof(&(simals_instbuf[simals_instptr[5]]));
1600
 
                                clokhead->exp = (float)atof(&(simals_instbuf[simals_instptr[7]]));
1601
 
                                clokhead->abs = 0.0;
1602
 
                                clokhead->random = 0.0;
1603
 
                                clokhead->next = 0;
1604
 
                                clokhead->delay = 0;
1605
 
 
1606
 
                                vectptr1 = (char**) &(clokhead->inptr);
1607
 
                                for(;;)
1608
 
                                {
1609
 
                                        if (xfgets(s1, 255, vin))
1610
 
                                        {
1611
 
                                                xclose(vin);
1612
 
                                                (void)simals_initialize_simulator(FALSE);
1613
 
                                                return;
1614
 
                                        }
1615
 
                                        simals_convert_to_upper(s1);
1616
 
                                        if (simals_fragment_command(s1)) return;
1617
 
                                        if (!strcmp(simals_instbuf, "CLOCK") || !strcmp(simals_instbuf, "SET"))
1618
 
                                        {
1619
 
                                                flag = 0;
1620
 
                                                break;
1621
 
                                        }
1622
 
                                        vectptr2 = simals_alloc_link_mem();
1623
 
                                        if (vectptr2 == 0) return;
1624
 
                                        vectptr2->type = 'N';
1625
 
                                        vectptr2->ptr = (char *)nodehead;
1626
 
                                        vectptr2->state = simals_trans_state_to_number(simals_instbuf);
1627
 
                                        vectptr2->strength = strength;
1628
 
                                        vectptr2->priority = 1;
1629
 
                                        vectptr2->time = atof(&(simals_instbuf[simals_instptr[1]]));
1630
 
                                        vectptr2->right = 0;
1631
 
                                        *vectptr1 = (char*) vectptr2;
1632
 
                                        vectptr1 = (char**) &(vectptr2->right);
1633
 
                                }
1634
 
                        }
1635
 
 
1636
 
                        if (! strcmp(simals_instbuf, "SET"))
1637
 
                        {
1638
 
                                simals_convert_to_upper(&(simals_instbuf[simals_instptr[1]]));
1639
 
                                nodehead = simals_find_node(&(simals_instbuf[simals_instptr[1]]));
1640
 
                                if (! nodehead)
1641
 
                                {
1642
 
                                        ttyputerr(_("ERROR: Unable to find node %s"),
1643
 
                                                &(simals_instbuf[simals_instptr[1]]));
1644
 
                                        flag = 1;
1645
 
                                        continue;
1646
 
                                }
1647
 
 
1648
 
                                sethead = simals_alloc_link_mem();
1649
 
                                if (sethead == 0) return;
1650
 
                                sethead->type = 'N';
1651
 
                                sethead->ptr = (char *) nodehead;
1652
 
                                sethead->state = simals_trans_state_to_number(&(simals_instbuf[simals_instptr[2]]));
1653
 
                                sethead->strength = atoi(&(simals_instbuf[simals_instptr[3]]))*2;
1654
 
                                sethead->priority = 2;
1655
 
                                sethead->time = atof(&(simals_instbuf[simals_instptr[5]]));
1656
 
                                sethead->right = 0;
1657
 
                                simals_insert_set_list(sethead);
1658
 
                                flag = 1;
1659
 
                        }
1660
 
                }
1661
 
                return;
1662
 
        }
1663
 
 
1664
 
        if (namesamen(pt, "new", l) == 0)
1665
 
        {
1666
 
                /* clear all vectors */
1667
 
                simals_clearallvectors(FALSE);
1668
 
                (void)simals_initialize_simulator(FALSE);
1669
 
                return;
1670
 
        }
1671
 
 
1672
 
        if (namesamen(pt, "save", l) == 0)
1673
 
        {
1674
 
                if (count < 2)
1675
 
                {
1676
 
                        (void)initinfstr();
1677
 
                        (void)formatinfstr("%s.vec", el_curlib->libname);
1678
 
                        par[1] = fileselect(_("ALS vector file"), sim_filetypealsvec|FILETYPEWRITE,
1679
 
                                returninfstr());
1680
 
                        if (par[1] == 0) return;
1681
 
                }
1682
 
                vout = xcreate(par[1], sim_filetypealsvec, 0, &truename);
1683
 
                if (vout == 0)
1684
 
                {
1685
 
                        if (truename != 0) ttyputerr(_("ERROR: Can't create %s"), truename);
1686
 
                        return;
1687
 
                }
1688
 
 
1689
 
                for (sethead = simals_setroot; sethead; sethead = sethead->right)
1690
 
                {
1691
 
                        switch (sethead->type)
1692
 
                        {
1693
 
                                case 'C':
1694
 
                                        clokhead = (ROWPTR)sethead->ptr;
1695
 
                                        vecthead = (LINKPTR)clokhead->inptr;
1696
 
                                        simals_compute_node_name((NODEPTR)vecthead->ptr, s1);
1697
 
                                        xprintf(vout, "CLOCK %s D=%g L=%g E=%g ", s1, clokhead->delta,
1698
 
                                                clokhead->linear, clokhead->exp);
1699
 
                                        xprintf(vout, "STRENGTH=%d TIME=%g CYCLES=%ld\n", vecthead->strength/2,
1700
 
                                                sethead->time, sethead->state);
1701
 
                                        for (; vecthead; vecthead = vecthead->right)
1702
 
                                        {
1703
 
                                                simals_trans_number_to_state(vecthead->state, s2);
1704
 
                                                xprintf(vout, "  %s %g\n", s2, vecthead->time);
1705
 
                                        }
1706
 
                                        break;
1707
 
                                case 'N':
1708
 
                                        simals_compute_node_name((NODEPTR)sethead->ptr, s1);
1709
 
                                        simals_trans_number_to_state(sethead->state, s2);
1710
 
                                        xprintf(vout, "SET %s=%s@%d TIME=%g\n", s1, s2, sethead->strength/2,
1711
 
                                                sethead->time);
1712
 
                        }
1713
 
                }
1714
 
                xclose(vout);
1715
 
                return;
1716
 
        }
1717
 
 
1718
 
        if (namesamen(pt, "delete", l) == 0)
1719
 
        {
1720
 
                if (count < 3)
1721
 
                {
1722
 
                        ttyputusage("telltool simulation als vector delete NODE OPTIONS");
1723
 
                        return;
1724
 
                }
1725
 
                simals_convert_to_upper(par[1]);
1726
 
                nodehead = simals_find_node(par[1]);
1727
 
                if (! nodehead)
1728
 
                {
1729
 
                        ttyputerr(_("ERROR: Unable to find node %s"), par[1]);
1730
 
                        return;
1731
 
                }
1732
 
 
1733
 
                backptr = (char**) &simals_setroot;
1734
 
                sethead = simals_setroot;
1735
 
 
1736
 
                if (par[2][0] == 'a')
1737
 
                {
1738
 
                        while (sethead)
1739
 
                        {
1740
 
                                if (sethead->type == 'C')
1741
 
                                {
1742
 
                                        clokhead = (ROWPTR)sethead->ptr;
1743
 
                                        vecthead = (LINKPTR)clokhead->inptr;
1744
 
                                        if ((NODEPTR)vecthead->ptr == nodehead)
1745
 
                                        {
1746
 
                                                *backptr = (char *)sethead->right;
1747
 
                                                simals_free_link_mem(sethead);
1748
 
                                                sethead = (LINKPTR)*backptr;
1749
 
                                                efree((char *)clokhead);
1750
 
                                                for (; vecthead; vecthead = nextvec)
1751
 
                                                {
1752
 
                                                        nextvec = vecthead->right;
1753
 
                                                        simals_free_link_mem(vecthead);
1754
 
                                                }
1755
 
                                                continue;
1756
 
                                        }
1757
 
                                } else
1758
 
                                {
1759
 
                                        if ((NODEPTR)sethead->ptr == nodehead)
1760
 
                                        {
1761
 
                                                *backptr = (char *)sethead->right;
1762
 
                                                simals_free_link_mem(sethead);
1763
 
                                                sethead = (LINKPTR)*backptr;
1764
 
                                                continue;
1765
 
                                        }
1766
 
                                }
1767
 
 
1768
 
                                backptr = (char**) &(sethead->right);
1769
 
                                sethead = sethead->right;
1770
 
                        }
1771
 
                        (void)simals_initialize_simulator(FALSE);
1772
 
                        return;
1773
 
                }
1774
 
 
1775
 
                if (count < 4)
1776
 
                {
1777
 
                        ttyputusage("telltool simulation als vector delete time TIME");
1778
 
                        return;
1779
 
                }
1780
 
                time = atof(par[2]);
1781
 
                while (sethead)
1782
 
                {
1783
 
                        if (sethead->time == time)
1784
 
                        {
1785
 
                                if (sethead->type == 'C')
1786
 
                                {
1787
 
                                        clokhead = (ROWPTR)sethead->ptr;
1788
 
                                        vecthead = (LINKPTR)clokhead->inptr;
1789
 
                                        if ((NODEPTR)vecthead->ptr == nodehead)
1790
 
                                        {
1791
 
                                                *backptr = (char*)sethead->right;
1792
 
                                                simals_free_link_mem(sethead);
1793
 
                                                sethead = (LINKPTR)*backptr;
1794
 
                                                efree((char *)clokhead);
1795
 
                                                for (; vecthead; vecthead = nextvec)
1796
 
                                                {
1797
 
                                                        nextvec = vecthead->right;
1798
 
                                                        simals_free_link_mem(vecthead);
1799
 
                                                }
1800
 
                                                (void)simals_initialize_simulator(FALSE);
1801
 
                                                return;
1802
 
                                        }
1803
 
                                } else
1804
 
                                {
1805
 
                                        if ((NODEPTR)sethead->ptr == nodehead)
1806
 
                                        {
1807
 
                                                *backptr = (char *)sethead->right;
1808
 
                                                simals_free_link_mem(sethead);
1809
 
                                                sethead = (LINKPTR)*backptr;
1810
 
                                                (void)simals_initialize_simulator(FALSE);
1811
 
                                                return;
1812
 
                                        }
1813
 
                                }
1814
 
                        }
1815
 
 
1816
 
                        backptr = (char**) &(sethead->right);
1817
 
                        sethead = sethead->right;
1818
 
                }
1819
 
                return;
1820
 
        }
1821
 
 
1822
 
        ttyputbadusage("telltool simulation als vector");
1823
 
}
1824
 
 
1825
 
/****************************** ANNOTATE ******************************/
1826
 
 
1827
 
/*
1828
 
 * Name: simals_annotate_command
1829
 
 *
1830
 
 * Description:
1831
 
 *   Annotate node information onto corresponding schematic.
1832
 
 */
1833
 
void simals_annotate_command(INTBIG count, char *par[])
1834
 
{
1835
 
        if (count < 1)
1836
 
        {
1837
 
                ttyputusage("telltool simulation als annotate [minimum | typical | maximum]");
1838
 
                return;
1839
 
        }
1840
 
 
1841
 
        if (simals_levelptr == 0)
1842
 
        {
1843
 
                ttyputerr(M_("Must start simulator before annotating delay information"));
1844
 
                return;
1845
 
        }
1846
 
 
1847
 
        if (namesamen(par[0], "min", 3) == 0) simals_sdfdelaytype = DELAY_MIN;
1848
 
                else if (namesamen(par[0], "typ", 3) == 0) simals_sdfdelaytype = DELAY_TYP;
1849
 
                        else if (namesamen(par[0], "max", 3) == 0) simals_sdfdelaytype = DELAY_MAX;
1850
 
                                else
1851
 
        {
1852
 
                ttyputbadusage("telltool simulation als annotate");
1853
 
                return;
1854
 
        }
1855
 
 
1856
 
        simals_sdfannotate(simals_levelptr);
1857
 
        simals_update_netlist();
1858
 
        ttyputmsg(M_("Completed annotation of SDF %s delay values"), par[0]);
1859
 
}
1860
 
 
1861
 
/*
1862
 
 * Routine to annotate SDF port delay info onto ALS netlist.
1863
 
 */
1864
 
void simals_sdfannotate(CONPTR cellhead)
1865
 
{
1866
 
        char    *s1;
1867
 
        CONPTR  subcell;
1868
 
        NODEINST *ni;
1869
 
 
1870
 
        if (stopping(STOPREASONDISPLAY)) return;
1871
 
        s1 = simals_compute_path_name(cellhead);
1872
 
 
1873
 
        ni = simals_getcellinstance(cellhead->model_name, s1);
1874
 
        if (ni != NONODEINST)
1875
 
        {
1876
 
                simals_sdfportdelay(cellhead, ni, s1);
1877
 
        }
1878
 
 
1879
 
        if (simals_instbuf[simals_instptr[1]] == 'X') return;
1880
 
 
1881
 
        for (subcell = cellhead->child; subcell; subcell = subcell->next)
1882
 
                simals_sdfannotate(subcell);
1883
 
}
1884
 
 
1885
 
/*
1886
 
 * Routine to get a NODEINST for specified cell instance.
1887
 
 */
1888
 
NODEINST *simals_getcellinstance(char *celltype, char *instance)
1889
 
{
1890
 
        NODEINST *ni;
1891
 
        NODEPROTO *np;
1892
 
        VARIABLE *var;
1893
 
        char *pt, **instlist, *str, tmp[256];
1894
 
        INTBIG i, j, count = 1;
1895
 
 
1896
 
        np = getcurfacet();
1897
 
        ni = NONODEINST;
1898
 
 
1899
 
        /* count number of hierarchy levels */
1900
 
        (void)sprintf(tmp, "%s", instance);
1901
 
        for (pt = tmp; *pt != 0; pt++) if (*pt == '.') count++;
1902
 
 
1903
 
        /* separate out each hiearchy level - skip first level which is the top */
1904
 
        instlist = (char **)emalloc(count * (sizeof(char *)), el_tempcluster);
1905
 
        pt = instance;
1906
 
        for (i=0, j=0; i<count; i++)
1907
 
        {
1908
 
                str = getkeyword(&pt, ".");
1909
 
                if (i >= 2) if (allocstring(&instlist[j++], str, el_tempcluster))
1910
 
                        return(NONODEINST);
1911
 
                (void)tonextchar(&pt);
1912
 
        }
1913
 
        count -= 2;
1914
 
 
1915
 
        if (count == 0) return(NONODEINST);
1916
 
 
1917
 
        /* find the NODEINST corresponding to bottom level of hierarchy */
1918
 
        for(i=0; i<count; i++)
1919
 
        {
1920
 
                for (ni = np->firstnodeinst; ni != NONODEINST; ni = ni->nextnodeinst)
1921
 
                {
1922
 
                        var = getvalkey((INTBIG)ni, VNODEINST, VSTRING, el_node_name_key);
1923
 
                        if (var == NOVARIABLE) continue;
1924
 
                        if (namesame((char *)var->addr, instlist[i]) != 0) continue;
1925
 
                        np = ni->proto;
1926
 
                        break;
1927
 
                }
1928
 
                if (ni == NONODEINST) break;
1929
 
                if (np->primindex != 0) break;
1930
 
        }
1931
 
 
1932
 
        return(ni);
1933
 
}
1934
 
 
1935
 
/*
1936
 
 * Routine to extract SDF port delay information and annotate it to ALS netlist.
1937
 
 */
1938
 
void simals_sdfportdelay(CONPTR cellhead, NODEINST *ni, char *path)
1939
 
{
1940
 
        VARIABLE *var;
1941
 
        PORTARCINST *pi;
1942
 
        INTBIG len, i, j, delay;
1943
 
        EXPTR exhead;
1944
 
 
1945
 
        for (exhead = cellhead->exptr; exhead; exhead = exhead->next)
1946
 
        {
1947
 
                for (pi = ni->firstportarcinst; pi != NOPORTARCINST; pi = pi->nextportarcinst)
1948
 
                {
1949
 
                        if (namesame(pi->proto->protoname, exhead->node_name) == 0)
1950
 
                        {
1951
 
                                var = getval((INTBIG)pi, VPORTARCINST, VSTRING|VISARRAY, "SDF_absolute_port_delay");
1952
 
                                if (var != NOVARIABLE)
1953
 
                                {
1954
 
                                        len = getlength(var);
1955
 
                                        for (i=0; i<len; i++)
1956
 
                                        {
1957
 
                                                if (namesamen(path, ((char **)var->addr)[i], strlen(path)) == 0)
1958
 
                                                {
1959
 
                                                        for (j=0; j<12; j++)
1960
 
                                                        {
1961
 
                                                                delay = simals_getportdelayvalue(((char **)var->addr)[i],
1962
 
                                                                        simals_tnames[j], simals_sdfdelaytype);
1963
 
                                                                if (delay != -1) exhead->td[j] = delay; else
1964
 
                                                                        exhead->td[j] = 0;
1965
 
                                                        }
1966
 
                                                }
1967
 
                                        }
1968
 
                                }
1969
 
                        }
1970
 
                }
1971
 
        }
1972
 
}
1973
 
 
1974
 
/*
1975
 
 * Routine to extract delay value from delay data string.
1976
 
 */
1977
 
INTBIG simals_getportdelayvalue(char *datastring, char *transition, DELAY_TYPES delaytype)
1978
 
{
1979
 
        char *pt, *ts, **instlist, *str, tmp[256];
1980
 
        INTBIG i, count = 1;
1981
 
 
1982
 
        /* count number of parts in data string */
1983
 
        (void)sprintf(tmp, "%s", datastring);
1984
 
        for (pt = tmp; *pt != 0; pt++) if (*pt == ' ') count++;
1985
 
 
1986
 
        /* split data string into separate pieces */
1987
 
        instlist = (char **)emalloc(count * (sizeof(char *)), el_tempcluster);
1988
 
        pt = datastring;
1989
 
        for (i=0; i<count; i++)
1990
 
        {
1991
 
                str = getkeyword(&pt, " ");
1992
 
                if (allocstring(&instlist[i], str, el_tempcluster)) return(-1);
1993
 
        }
1994
 
 
1995
 
        /* get piece that corresponds to specified transition */
1996
 
        for (i=0; i<count; i++)
1997
 
        {
1998
 
                if (namesamen(instlist[i], transition, strlen(transition)) == 0)
1999
 
                {
2000
 
                        if (allocstring(&ts, instlist[i], el_tempcluster)) return(-1);
2001
 
                        return(simals_getdval(ts, delaytype));
2002
 
                }
2003
 
        }
2004
 
 
2005
 
        return(-1);
2006
 
}
2007
 
 
2008
 
/*
2009
 
 * Routine to get a delay value string from a transition string.
2010
 
 *     if tstring is '01(111:222:333)' and delaytype is DELAY_TYP return 222
2011
 
 */
2012
 
INTBIG simals_getdval(char *tstring, DELAY_TYPES delaytype)
2013
 
{
2014
 
        char *pt, *str, *bs, ts[256], *t1, *t2, *t3;
2015
 
        INTBIG i, start = 0, stop = 0;
2016
 
 
2017
 
        bs = str = (char *)emalloc(strlen(tstring), el_tempcluster);
2018
 
        for (pt = tstring; *pt != 0; pt++)
2019
 
        {
2020
 
                if (*pt == ')') stop++;
2021
 
                if (start && !stop) *str++ = *pt;
2022
 
                if (*pt == '(') start++;
2023
 
        }
2024
 
        *str = 0;
2025
 
 
2026
 
        (void)sprintf(ts, "%s", bs);
2027
 
 
2028
 
        /* delay string is not a triple, only one delay value implies typical */
2029
 
        if (strstr(ts, ":") == NULL)
2030
 
        {
2031
 
                if (delaytype == DELAY_TYP) return(atoi(ts));
2032
 
                return(-1);
2033
 
        }
2034
 
 
2035
 
        pt = ts;
2036
 
        for (i=0; i<3; i++)
2037
 
        {
2038
 
                str = getkeyword(&pt, ":");
2039
 
                if (i == 0) if (allocstring(&t1, str, el_tempcluster)) return(-1);
2040
 
                if (i == 1) if (allocstring(&t2, str, el_tempcluster)) return(-1);
2041
 
                if (i == 2) if (allocstring(&t3, str, el_tempcluster)) return(-1);
2042
 
                (void)tonextchar(&pt);
2043
 
        }
2044
 
 
2045
 
        switch (delaytype)
2046
 
        {
2047
 
                case DELAY_MIN:
2048
 
                        return(atoi(t1));
2049
 
                case DELAY_TYP:
2050
 
                        return(atoi(t2));
2051
 
                case DELAY_MAX:
2052
 
                        return(atoi(t3));
2053
 
                default:
2054
 
                        return(-1);
2055
 
        }
2056
 
}
2057
 
 
2058
 
/****************************** ORDER ******************************/
2059
 
 
2060
 
/*
2061
 
 * Name: simals_order_command
2062
 
 *
2063
 
 * Description:
2064
 
 *   Save/restore signal trace order for waveform display.
2065
 
 */
2066
 
void simals_order_command(INTBIG count, char *par[])
2067
 
{
2068
 
        if (count < 1)
2069
 
        {
2070
 
                ttyputusage("telltool simulation als order [save | restore]");
2071
 
                return;
2072
 
        }
2073
 
 
2074
 
        if (namesamen(par[0], "sav", 3) == 0) simals_order_save();
2075
 
                else if (namesamen(par[0], "res", 3) == 0)
2076
 
        {
2077
 
                if (count != 2)
2078
 
                {
2079
 
                        ttyputusage("telltool simulation als order restore OPTION");
2080
 
                        return;
2081
 
                }
2082
 
                simals_order_restore(par[1]);
2083
 
        } else
2084
 
        {
2085
 
                ttyputbadusage("telltool simulation als order");
2086
 
                return;
2087
 
        }
2088
 
}
2089
 
 
2090
 
void simals_order_save(void)
2091
 
{
2092
 
        INTBIG tr;
2093
 
        BOOLEAN first = FALSE;
2094
 
        char str[256], *ts;
2095
 
        NODEPROTO *curfacet;
2096
 
 
2097
 
        sim_window_inittraceloop();
2098
 
        while ((tr = sim_window_nexttraceloop()) != 0)
2099
 
        {
2100
 
                if (!first) (void)initinfstr();
2101
 
                (void)sprintf(str, "%s:", sim_window_gettracename(tr));
2102
 
                (void)addstringtoinfstr(str);
2103
 
                first = TRUE;
2104
 
        }
2105
 
 
2106
 
        if (first)
2107
 
        {
2108
 
                ts = returninfstr();
2109
 
                ts[(strlen(ts)-1)] = 0;  /* chop off trailing ":" */
2110
 
 
2111
 
                /* save on current facet */
2112
 
                curfacet = getcurfacet();
2113
 
                if (curfacet != NULL) (void)setval((INTBIG)curfacet, VNODEPROTO,
2114
 
                        "SIM_als_trace_order", (INTBIG)ts, VSTRING);
2115
 
        }
2116
 
}
2117
 
 
2118
 
void simals_order_restore(char *list)
2119
 
{
2120
 
        INTBIG tc = 0, i, found, lines, thispos, pos, fromlib = 0;
2121
 
        INTBIG tr, trl;
2122
 
        NODEPTR node;
2123
 
        VARIABLE *var;
2124
 
        NODEPROTO *curfacet;
2125
 
        char *pt, *str, **tl, tmp[256];
2126
 
 
2127
 
        if (namesame(list, "fromlib") == 0)
2128
 
        {
2129
 
                curfacet = getcurfacet();
2130
 
                if (curfacet != NONODEPROTO)
2131
 
                {
2132
 
                        var = getval((INTBIG)curfacet, VNODEPROTO, VSTRING, "SIM_als_trace_order");
2133
 
                        if (var != NOVARIABLE)
2134
 
                        {
2135
 
                                (void)sprintf(tmp, "%s", (char *)var->addr);
2136
 
                                fromlib++;
2137
 
                        }
2138
 
                        else return;
2139
 
                }
2140
 
                else return;
2141
 
        }
2142
 
        else (void)sprintf(tmp, "%s", list);
2143
 
 
2144
 
        /* count number of traces and fill trace list array */
2145
 
        for (pt = tmp; *pt != 0; pt++) if (*pt == ':') tc++;
2146
 
        if (tc == 0) return;
2147
 
        tc++;
2148
 
        tl = (char **)emalloc(tc * (sizeof(char *)), el_tempcluster);
2149
 
        pt = tmp;
2150
 
        for (i=0; i<tc; i++)
2151
 
        {
2152
 
                str = getkeyword(&pt, ":");
2153
 
                (void)allocstring(&tl[i], str, el_tempcluster);
2154
 
                (void)tonextchar(&pt);
2155
 
        }
2156
 
 
2157
 
        /* delete traces not in restored list */
2158
 
        sim_window_cleartracehighlight();
2159
 
        sim_window_inittraceloop();
2160
 
        while ((tr = sim_window_nexttraceloop()) != 0)
2161
 
        {
2162
 
                found = 0;
2163
 
                for (i=0; i<tc; i++)
2164
 
                {
2165
 
                        if (namesame(sim_window_gettracename(tr), tl[i]) == 0) found++;
2166
 
                }
2167
 
                if (!found)
2168
 
                {
2169
 
                        thispos = sim_window_gettraceline(tr);
2170
 
                        sim_window_inittraceloop2();
2171
 
                        for(;;)
2172
 
                        {
2173
 
                                trl = sim_window_nexttraceloop2();
2174
 
                                if (trl == 0) break;
2175
 
                                pos = sim_window_gettraceline(trl);
2176
 
                                if (pos > thispos) sim_window_settraceline(trl, pos-1);
2177
 
                        }
2178
 
                        lines = sim_window_getlines();
2179
 
                        if (lines > 1) sim_window_setlines(lines-1);
2180
 
 
2181
 
                        /* remove from the simulator's list */
2182
 
                        for(i=0; i<simals_levelptr->num_chn; i++)
2183
 
                        {
2184
 
                                node = simals_levelptr->display_page[i+1].nodeptr;
2185
 
                                if (node == 0) continue;
2186
 
                                if (simals_levelptr->display_page[i+1].displayptr == tr)
2187
 
                                {
2188
 
                                        simals_levelptr->display_page[i+1].displayptr = 0;
2189
 
                                        break;
2190
 
                                }
2191
 
                        }
2192
 
 
2193
 
                        /* kill trace, redraw */
2194
 
                        sim_window_killtrace(tr);
2195
 
                }
2196
 
        }
2197
 
 
2198
 
        /* order the traces */
2199
 
        sim_window_setlines(tc);
2200
 
        sim_window_inittraceloop();
2201
 
        while ((tr = sim_window_nexttraceloop()) != 0)
2202
 
        {
2203
 
                for (i=0; i<tc; i++)
2204
 
                   if (namesame(tl[i], sim_window_gettracename(tr)) == 0) break;
2205
 
                if (fromlib) sim_window_settraceline(tr, tc-i-1); else  /* order from library save is bottom to top */
2206
 
                        sim_window_settraceline(tr, i);
2207
 
        }
2208
 
 
2209
 
        sim_window_redraw();
2210
 
}
2211
 
 
2212
 
/*
2213
 
 * Update the flattened netlist with the annotated delay values.
2214
 
 */
2215
 
void simals_update_netlist(void)
2216
 
{
2217
 
        MODPTR primhead;
2218
 
        CONPTR cellhead;
2219
 
        ROWPTR rowhead;
2220
 
        EXPTR exhead;
2221
 
        INTBIG delay, max_delay;
2222
 
 
2223
 
        for (primhead = simals_primroot; primhead; primhead = primhead->next)
2224
 
        {
2225
 
                switch(primhead->type)
2226
 
                {
2227
 
                        case 'F':
2228
 
                                break;
2229
 
 
2230
 
                        case 'G':
2231
 
                                /* cycle through all entries in table */
2232
 
                                for (rowhead = (ROWPTR)primhead->ptr; rowhead; rowhead=rowhead->next)
2233
 
                                {
2234
 
                                        /* check for valid delay transition name for current entry */
2235
 
                                        if (strcmp(rowhead->delay, "XX"))
2236
 
                                        {
2237
 
                                                /* TESTING - get the max delay value of all input ports matching transition */
2238
 
                                                cellhead = simals_find_level(simals_parent_level(primhead->level));
2239
 
                                                max_delay = 0;
2240
 
                                                for (exhead = cellhead->exptr; exhead; exhead = exhead->next)
2241
 
                                                {
2242
 
                                                        delay = exhead->td[simals_get_tdindex(rowhead->delay)];
2243
 
                                                        if (max_delay < delay) max_delay = delay;
2244
 
                                                }
2245
 
                                                if (max_delay != 0)
2246
 
                                                {
2247
 
                                                        rowhead->abs = (float)max_delay * 1.0e-12f;
2248
 
                                                }
2249
 
                                                ttyputmsg(M_("*** DEBUG *** gate: %s, level: %s, delay: %g(%s)"),
2250
 
                                                        primhead->name, primhead->level, (float)max_delay * 1.0e-12, rowhead->delay);
2251
 
                                                ttyputmsg(M_("  Timing: D=%g, L=%g, E=%g, R=%g, A=%g"),
2252
 
                                                        rowhead->delta, rowhead->linear, rowhead->exp, rowhead->random, rowhead->abs);
2253
 
                                                simals_print_in_entry(rowhead);
2254
 
                                                simals_print_out_entry(rowhead);
2255
 
                                        }
2256
 
                                }
2257
 
                                break;
2258
 
 
2259
 
                        default:
2260
 
                                ttyputerr(M_("Illegal primitive type '%c', database is bad"), primhead->type);
2261
 
                                break;
2262
 
                }
2263
 
        }
2264
 
}
2265
 
 
2266
 
/*
2267
 
 * Return index for transition delays given text name.
2268
 
 */
2269
 
INTBIG simals_get_tdindex(char *name)
2270
 
{
2271
 
        INTBIG i;
2272
 
 
2273
 
        for (i=0; i<12; i++)
2274
 
        {
2275
 
                if (!strcmp(simals_tnames[i], name)) return(i);
2276
 
        }
2277
 
        return(0);  /* return '01' index */
2278
 
}
2279
 
 
2280
 
/*
2281
 
 * Return the parent level of the given child.
2282
 
 *     if .TOP.NODE3.G1 is child, .TOP.NODE3 is parent
2283
 
 */
2284
 
char *simals_parent_level(char *child)
2285
 
{
2286
 
        char tmp[256], *pt, *str, **instlist;
2287
 
        INTBIG i, count = 1;
2288
 
 
2289
 
        (void)sprintf(tmp, "%s", child);
2290
 
        for (pt = tmp; *pt != 0; pt++) if (*pt == '.') count++;
2291
 
 
2292
 
        /* separate out each hiearchy level */
2293
 
        instlist = (char **)emalloc(count * (sizeof(char *)), el_tempcluster);
2294
 
        pt = child;
2295
 
        for (i=0; i<count; i++)
2296
 
        {
2297
 
                str = getkeyword(&pt, ".");
2298
 
                (void)allocstring(&instlist[i], str, el_tempcluster);
2299
 
                (void)tonextchar(&pt);
2300
 
        }
2301
 
 
2302
 
        /* create the parent level name */
2303
 
        (void)initinfstr();
2304
 
        for (i=0; i<count-1; i++)
2305
 
        {
2306
 
                (void)addstringtoinfstr(instlist[i]);
2307
 
                if (i != (count - 2)) (void)addstringtoinfstr(".");
2308
 
        }
2309
 
 
2310
 
        return(returninfstr());
2311
 
}
2312
 
 
2313
 
#endif  /* SIMTOOL - at top */