NAPA Compiler V4.50
Author: Yves Leduc, yves.leduc.be@gmail.com
Loading...
Searching...
No Matches
C:/Simulate/Napados/Source/nd.c
Go to the documentation of this file.
1/* *** DETERMINATION OF THE TYPES OF NODES ************************************************************************************** */
2
3#undef EXTERN
4#define EXTERN extern
5
6#include "./napa.h"
7#include "./proto.h"
8
9
10/* *** In this file: ************************************************************************************************************ */
11
12/* void node_determination(void) */
13
14
15/* ****************************************************************************************************************************** */
16
17/* The goal of "node_determination()" is to determine the TYPE of the nodes by inspection. */
18/* Some nodes have a fixed type (e.g. a "sin" is outputting always a double, a "nand" is outputting always a long). Some node */
19/* types depend on the type of their input (e.g. a delay node takes the type of its input), we call them 'chameleonic'. */
20
21/* Determined nodes are moved in the beginning of the node arrays "Node_List" by swapping elements. During the process, only */
22/* input nodes are considered, other parameters are skipped. At the end of this process, all nodes should be determined. */
23
24/* It is however possible to have an undetermination. Undetermination could be caused by incorrect network description. If not, */
25/* it means that NAPA has no way to understand what type of node to handle: rework your netlist to give to NAPA some hints */
26/* (e.g. thanks to instruction 'declare'...). */
27
28/* It is important to note that, for speed reason, a minimum is done to determine the type of the output node. In particular, */
29/* no effort is done here to check input consistency. Full verifications will be performed during the following syntax check. */
30
31/* During the process, definition of nodes are completed to authorize initialization when it is possible */
32/* (input of delays, output of latches, ...) */
33
34
35/* ****************************************************************************************************************************** */
36
38 long out;
39 long in;
40 long kd;
41 char sgn[2] = {'\0'};
42 char brc[3] = {'\0'};
43 char tok1[STRLENGTH] = {'\0'};
44 char tok2[STRLENGTH] = {'\0'};
45 char *s = (char*) NULL;
46 char *str = (char*) NULL;
47 long msg;
48 long determined_ptr = 0L;
49
50 for (out = 0L; out < Num_Nodes; out++) {
51 str = Node_List[out].value; /* get the unprocessed node_value */
52 kd = Node_List[out].kind;
53
54 switch (kd) {
55
56 /* *** CHAMELEONIC TYPES *** */
57
58
59 /* COPY, RECT: chameleonic type depending on single input */
60 /* type determined only if input type is determined */
61 /* - input node mandatory, defined */
62
63 case COPY_KIND :
64 case RECT_KIND :
65 str = get_sign_and_token(str, sgn, tok1);
66 in = node_id(tok1);
67 if (UNKNOWN_TYPE != Node_List[in].type) {
68 Node_List[out].type = Node_List[in].type;
69 swap_nodes(out, determined_ptr);
70 out = determined_ptr;
71 determined_ptr++;
72 }
73 break;
74
75
76 /* DELAY chameleonic type depending on single input */
77 /* type determined only if input type is determined */
78 /* - number of delays mandatory */
79 /* - input node mandatory, unsigned, defined */
80
81 case DELAY_KIND :
82 case DELAY1_KIND :
83 case DELAY2_KIND :
84 case DELAY3_KIND :
85 str = get_sign_and_token(str, sgn, tok1);
86 str = get_sign_and_token(str, sgn, tok1);
87 in = node_id(tok1);
88 if (UNKNOWN_TYPE != Node_List[in].type) {
89 Node_List[out].type = Node_List[in].type;
90 swap_nodes(out, determined_ptr);
91 out = determined_ptr;
92 determined_ptr++;
93 }
94 if (NO != Node_List[in].flag) { /* if not forbidden, */
95 Node_List[in].flag = YES; /* flag node as allowed to be initialized */
96 }
97 break;
98
99
100 /* DIFFERENTIATOR chameleonic type depending on single input */
101 /* type determined only if input type is determined */
102 /* - input node mandatory, defined */
103
105 str = get_sign_and_token(str, sgn, tok1);
106 in = node_id(tok1);
107 if (UNKNOWN_TYPE != Node_List[in].type) {
108 Node_List[out].type = Node_List[in].type;
109 swap_nodes(out, determined_ptr);
110 out = determined_ptr;
111 determined_ptr++;
112 }
113 break;
114
115
116 /* INTEGRATOR chameleonic type depending on single input */
117 /* type determined only if input type is determined */
118 /* - input node mandatory, defined */
119
120 case INTEGRATOR_KIND :
121 str = get_sign_and_token(str, sgn, tok1);
122 in = node_id(tok1);
123 if (UNKNOWN_TYPE != Node_List[in].type) {
124 Node_List[out].type = Node_List[in].type;
125 swap_nodes(out, determined_ptr);
126 out = determined_ptr;
127 determined_ptr++;
128 }
129 if (NO != Node_List[out].flag) { /* if not forbidden, */
130 Node_List[out].flag = YES; /* flag node as allowed to be initialized */
131 }
132 break;
133
134
135
136 /* GAIN, OFFSET, QUANT: chameleonic type depending on single input */
137 /* type determined only if input type is determined */
138 /* - parameter mandatory */
139 /* - input node mandatory, unsigned, defined */
140
141
142 /* RELAY: chameleonic type depending on input */
143 /* type determined only if input type is determined */
144 /* - control mandatory, unsigned, defined, variable or node */
145 /* - input node exactly one, defined, unsigned */
146 /* - setting value optional, variable or number (not a node) */
147
148 case GAIN_KIND :
149 case OFFSET_KIND :
150 case QUANT_KIND :
151 case RELAY_KIND :
152 str = get_sign_and_token(str, sgn, tok1);
153 str = get_sign_and_token(str, sgn, tok1);
154 in = node_id(tok1);
155 if (UNKNOWN_TYPE != Node_List[in].type) {
156 Node_List[out].type = Node_List[in].type;
157 swap_nodes(out, determined_ptr);
158 out = determined_ptr;
159 determined_ptr++;
160 }
161 break;
162
163
164 /* ZERO: chameleonic type depending on input */
165 /* type determined only if input type is determined */
166 /* - decim factor mandatory, unsigned, defined, variable or node */
167 /* - decim offset mandatory, unsigned, defined, variable or node */
168 /* - input node exactly one, defined, unsigned */
169
170 case ZERO_KIND :
171 str = get_sign_and_token(str, sgn, tok1);
172 str = get_sign_and_token(str, sgn, tok1);
173 str = get_sign_and_token(str, sgn, tok1);
174 in = node_id(tok1);
175 if (UNKNOWN_TYPE != Node_List[in].type) {
176 Node_List[out].type = Node_List[in].type;
177 swap_nodes(out, determined_ptr);
178 out = determined_ptr;
179 determined_ptr++;
180 }
181 break;
182
183
184 /* HOLD, TRACK: chameleonic type depending on single input */
185 /* type determined only if input type is determined */
186 /* - control node mandatory, unsigned, defined */
187 /* - input node mandatory, unsigned, defined */
188
189 case HOLD_KIND :
190 case TRACK_KIND :
191 str = get_sign_and_token(str, sgn, tok1);
192 str = get_sign_and_token(str, sgn, tok1);
193 in = node_id(tok1);
194 if (UNKNOWN_TYPE != Node_List[in].type) {
195 Node_List[out].type = Node_List[in].type;
196 swap_nodes(out, determined_ptr);
197 out = determined_ptr;
198 determined_ptr++;
199 }
200 if (NO != Node_List[out].flag) { /* if not forbidden, */
201 Node_List[out].flag = YES; /* flag node as allowed to be initialized */
202 }
203 break;
204
205
206 /* CLIP: chameleonic type depending on single input */
207 /* type determined only if input type is determined */
208 /* - clip level low mandatory */
209 /* - clip level high mandatory */
210 /* - input node mandatory, unsigned, defined */
211
212 case CLIP_KIND :
213 str = get_sign_and_token(str, sgn, tok1);
214 str = get_sign_and_token(str, sgn, tok1);
215 str = get_sign_and_token(str, sgn, tok1);
216 in = node_id(tok1);
217 if (UNKNOWN_TYPE != Node_List[in].type) {
218 Node_List[out].type = Node_List[in].type;
219 swap_nodes(out, determined_ptr);
220 out = determined_ptr;
221 determined_ptr++;
222 }
223 break;
224
225
226 /* SUB, DIV, MOD: chameleonic type depending on 2 inputs */
227 /* type determined only if input types are determined */
228 /* - input nodes 1 node followed by a node, a variable or a constant */
229 /* - qualifier optional for DIV and MOD, no check */
230
231 case DIV_KIND :
232 case MOD_KIND :
233 case SUB_KIND :
234 str = get_sign_and_token(str, sgn, tok1);
235 in = node_id(tok1);
236 if (UNKNOWN_TYPE != Node_List[in].type) {
237 Node_List[out].type = Node_List[in].type;
238 swap_nodes(out, determined_ptr);
239 out = determined_ptr;
240 determined_ptr++;
241 break;
242 }
243 str = get_sign_and_token(str, sgn, tok1);
244 in = node_id(tok1);
245 if (UNDEFINED != in) { /* type used for node determination, only if a node */
246 if (UNKNOWN_TYPE != Node_List[in].type) {
247 Node_List[out].type = Node_List[in].type;
248 swap_nodes(out, determined_ptr);
249 out = determined_ptr;
250 determined_ptr++;
251 break;
252 }
253 }
254 break;
255
256
257 /* MUX: chameleonic type depending on input */
258 /* type determined only if input types are determined */
259 /* - control mandatory, unsigned, defined, variable or node */
260 /* - input nodes at least two, defined */
261
262 /* MERGE: chameleonic type depending on input */
263 /* type determined only if input types are determined */
264 /* - input nodes at least two, defined */
265
266 case MUX_KIND :
267 case MERGE_KIND :
268 if (MUX_KIND == kd) {
269 str = get_sign_and_token(str, sgn, tok1);
270 }
271 for (;;) {
272 str = get_sign_and_token(str, sgn, tok1);
273 if (ISEMPTY(tok1)) {
274 break;
275 }
276 in = node_id(tok1);
277 if (UNKNOWN_TYPE != Node_List[in].type) {
278 Node_List[out].type = Node_List[in].type;
279 swap_nodes(out, determined_ptr);
280 out = determined_ptr;
281 determined_ptr++;
282 break;
283 }
284 }
285 break;
286
287
288 /* SUM, PROD, MIN, MAX: chameleonic type depending on N inputs */
289 /* type determined only if input types are determined */
290 /* - input nodes at least 1, defined */
291
292 case MIN_KIND :
293 case MAX_KIND :
294 case PROD_KIND :
295 case SUM_KIND :
296 for (;;) {
297 str = get_sign_and_token(str, sgn, tok1);
298 if (ISEMPTY(tok1)) {
299 break;
300 }
301 in = node_id(tok1);
302 if (UNKNOWN_TYPE != Node_List[in].type) {
303 Node_List[out].type = Node_List[in].type;
304 swap_nodes(out, determined_ptr);
305 out = determined_ptr;
306 determined_ptr++;
307 break;
308 }
309 }
310 break;
311
312
313 /* WSUM: chameleonic type depending on 2*N inputs */
314 /* type determined only if input types are determined */
315 /* - input parms at least 1, defined */
316 /* - input nodes at least 1, defined */
317
318 case WSUM_KIND :
319 for (;;) {
320 str = get_sign_and_token(str, sgn, tok1); /* skip parameter */
321 if (ISEMPTY(tok1)) {
322 break;
323 }
324 str = get_sign_and_token(str, sgn, tok1);
325 if (ISEMPTY(tok1)) {
326 break;
327 }
328 in = node_id(tok1);
329 if (UNKNOWN_TYPE != Node_List[in].type) {
330 Node_List[out].type = Node_List[in].type;
331 swap_nodes(out, determined_ptr);
332 out = determined_ptr;
333 determined_ptr++;
334 break;
335 }
336 }
337 break;
338
339
340 /* ALU: chameleonic type depending on N inputs */
341 /* type determined only if input types are determined */
342 /* - input nodes at least 2, defined */
343
344 case ALU_KIND :
345 str = get_sign_and_token(str, sgn, tok1);
346 str = get_sign_and_token(str, sgn, tok1);
347 for (;;) {
348 str = get_sign_and_token(str, sgn, tok1);
349 if (ISEMPTY(tok1)) {
350 break;
351 }
352 in = node_id(tok1);
353 if (UNKNOWN_TYPE != Node_List[in].type) {
354 Node_List[out].type = Node_List[in].type;
355 swap_nodes(out, determined_ptr);
356 out = determined_ptr;
357 determined_ptr++;
358 break;
359 }
360 }
361 break;
362
363
364 /* ALGEBRA: chameleonic type depending on input variables or nodes */
365 /* type determined only if input types are determined */
366 /* priority: 1st node, 1st variable. Constants are ignored */
367 /* - input nodes no check */
368
369 case ALGEBRA_KIND :
370 s = str;
371 for (;;) {
372 str = get_sign_and_token(str, sgn, tok1);
373 if (ISEMPTY(tok1)) {
374 break;
375 }
376 in = node_id(tok1);
377 if ((UNDEFINED != in) && (UNKNOWN_TYPE != Node_List[in].type)) {
378 Node_List[out].type = Node_List[in].type;
379 swap_nodes(out, determined_ptr);
380 out = determined_ptr;
381 determined_ptr++;
382 break;
383 }
384 }
385 str = s;
386 for (;;) {
387 str = get_sign_and_token(str, sgn, tok1);
388 if (ISEMPTY(tok1)) {
389 break;
390 }
391 in = var_id(tok1);
392 if ((UNDEFINED != in) && (UNKNOWN_TYPE != Var_List[in].type)) {
393 Node_List[out].type = Var_List[in].type;
394 swap_nodes(out, determined_ptr);
395 out = determined_ptr;
396 determined_ptr++;
397 break;
398 }
399 }
400 break;
401
402
403 /* *** digital types *** */
404
405
406 /* ITOB: digital type */
407 /* type unconditionally determined */
408 /* - bit number mandatory, unsigned */
409 /* - input node mandatory, unsigned, defined */
410
411 /* BUFF, INV digital type */
412 /* type unconditionally determined */
413 /* - input node mandatory, unsigned, defined */
414
415 /* AND, NAND, NOR, XOR, XNOR: digital type */
416 /* type unconditionally determined */
417 /* - input nodes at least 2, unsigned, defined */
418
419 /* COMP: digital type */
420 /* type unconditionally determined */
421 /* - input 2, unsigned, defined */
422
423 /* EQUAL: digital type */
424 /* type unconditionally determined */
425 /* - input 2 or 3, unsigned, defined */
426
427 /* TRIG: digital type */
428 /* type unconditionally determined */
429 /* - trigger level mandatory */
430 /* - input node mandatory, unsigned, defined */
431 /* - qualifier optional, no check */
432
433 /* CHG: digital type */
434 /* type unconditionally determined */
435 /* - input node mandatory, unsigned, defined */
436
437 /* SIGN: digital type */
438 /* type unconditionally determined */
439 /* - input node mandatory, unsigned, defined */
440
441 /* CLOCK: digital type */
442 /* type unconditionally determined */
443 /* - parameters no check */
444
445 case AND_KIND :
446 case BUF_KIND :
447 case CHG_KIND :
448 case CLOCK_KIND :
449 case COMP_KIND :
450 case EQUAL_KIND :
451 case INV_KIND :
452 case ITOB_KIND :
453 case MULLER_KIND :
454 case NAND_KIND :
455 case NOR_KIND :
456 case OR_KIND :
457 case SIGN_KIND :
458 case TRIG_KIND :
459 case XOR_KIND :
460 case XNOR_KIND :
461 if (0L != Node_List[out].width) {
462 print_warning_location("node", Node_List[out].mline, Node_List[out].mfile);
463 (void) fprintf(STDERR, " Width limitation has no effect on node <%s>\n", Node_List[out].name1);
464 Node_List[out].width = 0L;
465 }
466 Node_List[out].type = DIGITAL_DATA_TYPE;
467 Node_List[out].declare = DIGITAL_DATA_TYPE;
468 swap_nodes(out, determined_ptr);
469 out = determined_ptr;
470 determined_ptr++;
471 break;
472
473
474 /* LATCH: digital type */
475 /* type unconditionally determined */
476 /* - input nodes exactly 2, unsigned, defined */
477
478 /* TOGGLE: digital type */
479 /* type unconditionally determined */
480 /* - input node exactly 1, unsigned, defined */
481
482 case LATCH_KIND :
483 case TOGGLE_KIND :
484 Node_List[out].type = DIGITAL_DATA_TYPE;
485 Node_List[out].declare = DIGITAL_DATA_TYPE;
486 swap_nodes(out, determined_ptr);
487 out = determined_ptr;
488 determined_ptr++;
489 if (NO != Node_List[out].flag) { /* if not forbidden, */
490 Node_List[out].flag = YES; /* flag node as allowed to be initialized */
491 }
492 if (0L != Node_List[out].width) {
493 print_warning_location("node", Node_List[out].mline, Node_List[out].mfile);
494 (void) fprintf(STDERR, " Width limitation has no effect on node <%s>\n", Node_List[out].name1);
495 Node_List[out].width = 0L;
496 }
497 break;
498
499
500 /* BWINV: digital type */
501 /* type unconditionally determined */
502 /* - input node mandatory, unsigned, defined */
503 /* SHOULD BE WIDTH LIMITED */
504
505 /* BWAND, BWNAND, BWNOR, BWXOR, BWXNOR: digital type */
506 /* type unconditionally determined */
507 /* - input nodes at least 2, unsigned, defined */
508 /* SHOULD BE WIDTH LIMITED */
509
510 case BWAND_KIND :
511 case BWINV_KIND :
512 case BWNAND_KIND :
513 case BWNOR_KIND :
514 case BWOR_KIND :
515 case BWXNOR_KIND :
516 case BWXOR_KIND :
517 Node_List[out].type = DIGITAL_DATA_TYPE;
518 Node_List[out].declare = DIGITAL_DATA_TYPE;
519 swap_nodes(out, determined_ptr);
520 out = determined_ptr;
521 determined_ptr++;
522 break;
523
524
525 /* DTOI: digital type */
526 /* type unconditionally determined */
527 /* - input node mandatory, unsigned, defined */
528
529 /* RSHIFT, RSHIT1, RSHIFT2, LSHIFT, BSHIFT: output type is always integer */
530 /* - shift value mandatory */
531 /* - input node mandatory, unsigned, defined */
532
533 /* IALGEBRA: digital type */
534 /* type unconditionally determined */
535 /* - input nodes no check */
536
537 /* TEST: digital type */
538 /* type unconditionally determined */
539 /* - input nodes no check */
540
541 /* ADC, UADC: digital type */
542 /* type unconditionally determined */
543 /* - number of levels mandatory */
544 /* - input node mandatory, unsigned, defined */
545 /* - reference node mandatory, unsigned, defined */
546
547 /* BTOI: digital type */
548 /* type unconditionally determined */
549 /* - input at least two, unsigned, either defined nodes or constants 0, 1 */
550 /* MUST BE BIT LIMITED */
551
552 case ADC_KIND :
553 case BTOI_KIND :
554 case BSHIFT_KIND :
555 case DTOI_KIND :
556 case IALGEBRA_KIND :
557 case LSHIFT_KIND :
558 case RIP_KIND :
559 case RSHIFT_KIND :
560 case RSHIFT1_KIND :
561 case RSHIFT2_KIND :
562 case TEST_KIND :
563 case UADC_KIND :
564 Node_List[out].type = DIGITAL_DATA_TYPE;
565 Node_List[out].declare = DIGITAL_DATA_TYPE;
566 swap_nodes(out, determined_ptr);
567 out = determined_ptr;
568 determined_ptr++;
569 break;
570
571
572 /* IUSER, ITOOL: digital type */
573 /* type unconditionally determined */
574 /* an input node is allowed to be initialized */
575 /* - parameters optional */
576
577 case ITOOL_KIND :
578 case IUSER_KIND :
579 Node_List[out].type = DIGITAL_DATA_TYPE;
580 Node_List[out].declare = DIGITAL_DATA_TYPE;
581 swap_nodes(out, determined_ptr);
582 out = determined_ptr;
583 determined_ptr++;
584 for (;;) {
585 str = get_sign_and_token(str, sgn, tok1);
586 if (ISEMPTY(tok1)) {
587 break;
588 }
589 in = node_id(tok1);
590 if (UNDEFINED != in) {
591 if (NO != Node_List[in].flag) { /* if not forbidden, */
592 Node_List[in].flag = YES; /* flag node as allowed to be initialized */
593 }
594 }
595 }
596 break;
597
598
599 /* *** ANALOG TYPES *** */
600
601
602 /* ITOD: analog type */
603 /* type unconditionally determined */
604 /* - input node mandatory, unsigned, defined */
605
606 /* OSC, SIN, COS, TRIANGLE, SQUARE, STEP: analog type */
607 /* type unconditionally determined */
608 /* - parameters no check */
609
610 /* FZINV, FZBUF: analog type */
611 /* type unconditionally determined */
612 /* - input node mandatory, unsigned, defined */
613
614 /* FZAND, FZOR, FZNAND, FZNOR, FZXNOR, FZXOR: analog type */
615 /* type unconditionally determined */
616 /* - input nodes unsigned, defined */
617
618 /* DAC, UDAC: analog type */
619 /* type unconditionally determined */
620 /* - number of levels mandatory */
621 /* - input node mandatory, unsigned, defined */
622 /* - reference node mandatory, unsigned, defined */
623
624 /* AVERAGE: analog type */
625 /* type unconditionally determined */
626
627 /* DALGEBRA: analog type */
628 /* type unconditionally determined */
629 /* - input nodes no check */
630
631 case AVERAGE_KIND :
632 case COS_KIND :
633 case DAC_KIND :
634 case DALGEBRA_KIND :
635 case ITOD_KIND :
636 case FZAND_KIND :
637 case FZBUF_KIND :
638 case FZINV_KIND :
639 case FZNAND_KIND :
640 case FZNOR_KIND :
641 case FZOR_KIND :
642 case FZXNOR_KIND :
643 case FZXOR_KIND :
644 case OSC_KIND :
645 case SIN_KIND :
646 case SQUARE_KIND :
647 case STEP_KIND :
648 case TRIANGLE_KIND :
649 case UDAC_KIND :
650 Node_List[out].type = ANALOG_DATA_TYPE;
651 Node_List[out].declare = ANALOG_DATA_TYPE;
652 swap_nodes(out, determined_ptr);
653 out = determined_ptr;
654 determined_ptr++;
655 break;
656
657
658 /* POLY: chameleonic type */
659 /* type determined by input node */
660 /* - input at least two */
661
662 case POLY_KIND :
663 for (;;) {
664 str = get_sign_and_token(str, sgn, tok1);
665 if (ISEMPTY(tok1)) {
666 break;
667 }
668 (void) strcpy(tok2, tok1);
669 }
670 in = node_id(tok2); /* last entry is the input node */
671 if (UNKNOWN_TYPE != Node_List[in].type) {
672 Node_List[out].type = Node_List[in].type;
673 swap_nodes(out, determined_ptr);
674 out = determined_ptr;
675 determined_ptr++;
676 }
677 break;
678
679
680 /* DUSER, DTOOL: analog type */
681 /* type unconditionally determined */
682 /* an input node is allowed to be initialized */
683 /* - parameters optional */
684
685 case DTOOL_KIND :
686 case DUSER_KIND :
687 Node_List[out].type = ANALOG_DATA_TYPE;
688 Node_List[out].declare = ANALOG_DATA_TYPE;
689 swap_nodes(out, determined_ptr);
690 out = determined_ptr;
691 determined_ptr++;
692 for (;;) {
693 str = get_sign_and_token(str, sgn, tok1);
694 if (ISEMPTY(tok1)) {
695 break;
696 }
697 in = node_id(tok1);
698 if (UNDEFINED != in) {
699 if (NO != Node_List[in].flag) { /* if not forbidden, */
700 Node_List[in].flag = YES; /* flag node as allowed to be initialized */
701 }
702 }
703 }
704 break;
705
706
707 /* NOISE: analog type */
708 /* type unconditionally determined */
709 /* - mean value mandatory, variable */
710 /* - rms value mandatory, unsigned variable */
711
712 case NOISE_KIND :
713 Node_List[out].type = ANALOG_DATA_TYPE;
714 Node_List[out].declare = ANALOG_DATA_TYPE;
715 swap_nodes(out, determined_ptr);
716 out = determined_ptr;
717 determined_ptr++;
718 break;
719
720
721 /* *** DECLARED TYPES *** */
722
723
724 /* DC: analog type if qualifier (analog) or without qualifier */
725 /* digital type if qualifier (digital) */
726 /* type unconditionally determined */
727 /* - parameters mandatory */
728
729 case DC_KIND :
730 str = get_token_between_braces(str, brc, tok1);
731 if (0 == strcmp(brc, "()")) {
732 if (0 == strcmp(tok1, "digital")) {
733 Node_List[out].type = DIGITAL_DATA_TYPE;
734 Node_List[out].declare = DIGITAL_DATA_TYPE; /* explicit declaration */
735 (void) strcpy(Node_List[out].value, str); /* store val without qualifier */
736 } else if (0 == strcmp(tok1, "analog")) {
737 Node_List[out].type = ANALOG_DATA_TYPE;
738 Node_List[out].declare = ANALOG_DATA_TYPE; /* explicit declaration */
739 (void) strcpy(Node_List[out].value, str); /* store val without qualifier */
740 } else {
741 Node_List[out].type = ANALOG_DATA_TYPE; /* no explicit declaration */
742 Node_List[out].declare = UNKNOWN_TYPE;
743 }
744 } else {
745 Node_List[out].type = ANALOG_DATA_TYPE; /* no explicit declaration */
746 Node_List[out].declare = UNKNOWN_TYPE;
747 }
748 swap_nodes(out, determined_ptr);
749 out = determined_ptr;
750 determined_ptr++;
751 Node_List[out].flag = NO; /* flag node as NOT allowed to be initialized */
752 if ((ANALOG_DATA_TYPE == Node_List[out].type) && (Node_List[out].inject)) {
753 Node_List[out].kind = DALGEBRA_KIND; /* dc node with injection! */
754 }
755 break;
756
757 /* CONST: digital type if qualifier (digital) or without qualifier */
758 /* analog type if qualifier (analog) */
759 /* type unconditionally determined */
760 /* - parameters mandatory */
761
762 case CONST_KIND :
763 Node_List[out].kind = DC_KIND; /* node redefinition */
764 str = get_token_between_braces(str, brc, tok1);
765 if (0 == strcmp(brc, "()")) {
766 if (0 == strcmp(tok1, "analog")) {
767 Node_List[out].type = ANALOG_DATA_TYPE;
768 Node_List[out].declare = ANALOG_DATA_TYPE; /* explicit declaration */
769 (void) strcpy(Node_List[out].value, str); /* store val without qualifier */
770 } else if (0 == strcmp(tok1, "digital")) {
771 Node_List[out].type = DIGITAL_DATA_TYPE;
772 Node_List[out].declare = DIGITAL_DATA_TYPE; /* explicit declaration */
773 (void) strcpy(Node_List[out].value, str); /* store val without qualifier */
774 } else {
775 Node_List[out].type = DIGITAL_DATA_TYPE; /* no explicit declaration */
776 Node_List[out].declare = UNKNOWN_TYPE;
777 }
778 } else {
779 Node_List[out].type = DIGITAL_DATA_TYPE; /* no explicit declaration */
780 Node_List[out].declare = UNKNOWN_TYPE;
781 }
782 swap_nodes(out, determined_ptr);
783 out = determined_ptr;
784 determined_ptr++;
785 Node_List[out].flag = NO; /* flag node as NOT allowed to be initialized */
786 if ((ANALOG_DATA_TYPE == Node_List[out].type) && (Node_List[out].inject)) {
787 Node_List[out].kind = DALGEBRA_KIND; /* dc node with injection! */
788 }
789 break;
790
791
792 /* ROM & ROM2 type declared */
793 /* - address mandatory, unsigned node, defined */
794 /* - chip select mandatory, unsigned */
795
796 /* RAM & RAM2 type declared */
797 /* - address already checked by READ counterpart */
798 /* - chip select mandatory, unsigned */
799 /* - read/write mandatory, unsigned node, defined */
800 /* - input node mandatory, unsigned node, defined */
801
802 case RAM_KIND :
803 case ROM_KIND :
804 case RAM2_KIND :
805 case ROM2_KIND :
806 str = get_sign_and_token(str, sgn, tok1);
807 switch (Array_List[array_id(tok1)].type) {
809 case HEX_DATA_TYPE :
810 Node_List[out].type = DIGITAL_DATA_TYPE;
811 Node_List[out].declare = DIGITAL_DATA_TYPE;
812 break;
813 case ANALOG_DATA_TYPE :
814 Node_List[out].type = ANALOG_DATA_TYPE;
815 Node_List[out].declare = ANALOG_DATA_TYPE;
816 break;
817 }
818 swap_nodes(out, determined_ptr);
819 out = determined_ptr;
820 determined_ptr++;
821 break;
822
823
824 /* *** UNRECOGNIZED KIND *** */
825
826
827 case UNKNOWN_KIND :
828 default :
829 Error_Flag++;
830 Node_List[out].type = UNKNOWN_TYPE;
831 }
832
833
834 /* check that declaration and netlist are consistent, use declaration as hint if needed */
835
836 if (UNKNOWN_TYPE != Node_List[out].declare) {
837 if ((UNKNOWN_TYPE != Node_List[out].type) && (Node_List[out].type != Node_List[out].declare) && (0 == Error_Flag)) {
838 print_error_location("declare", Node_List[out].mline, Node_List[out].mfile);
839 (void) fprintf(STDERR, " the type of node <%s> is not compatible with type declaration\n", Node_List[out].name1);
840 } else if (UNKNOWN_TYPE == Node_List[out].type) {
841 Node_List[out].type = Node_List[out].declare;
842 swap_nodes(out, determined_ptr);
843 out = determined_ptr;
844 determined_ptr++;
845 }
846 }
847 }
848
849 if (Terminate_Flag) {
850 str = Terminate_List.condition; /* examine cond. for node that could be initialized */
851 for (;;) {
852 str = get_sign_and_token(str, sgn, tok1);
853 if (ISEMPTY(tok1)) {
854 break;
855 }
856 in = node_id(tok1);
857 if (UNDEFINED != in) {
858 if (NO != Node_List[in].flag) { /* if not forbidden, */
859 Node_List[in].flag = YES; /* flag node as allowed to be initialized */
860 }
861 }
862 }
863 }
864
865 if (Dump_Flag) {
866 str = Dump_List.condition; /* examine cond. for node that could be initialized */
867 for (;;) {
868 str = get_sign_and_token(str, sgn, tok1);
869 if (ISEMPTY(tok1)) {
870 break;
871 }
872 in = node_id(tok1);
873 if (UNDEFINED != in) {
874 if (NO != Node_List[in].flag) { /* if not forbidden, */
875 Node_List[in].flag = YES; /* flag node as allowed to be initialized */
876 }
877 }
878 }
879 }
880
881 for (out = 0L; out < Num_Nodes; out++) {
882 if ((ANALOG_DATA_TYPE == Node_List[out].type) && (0L != Node_List[out].width)) {
883 print_error_location("node", Node_List[out].mline, Node_List[out].mfile);
884 (void) fprintf(STDERR, " being analog type, node <%s> cannot be width limited\n", Node_List[out].name1);
885 }
886 }
887 msg = false;
888 for (out = 0L; out < Num_Nodes; out++) {
889 if (UNKNOWN_TYPE == Node_List[out].type) {
890 print_error_location("node", Node_List[out].mline, Node_List[out].mfile);
891 (void) fprintf(STDERR, " Sorry, there is no way to determine the type of\n");
892 (void) fprintf(STDERR, " node <%s> by simple inspection of the netlist\n", Node_List[out].name1);
893 msg = true;
894 }
895 }
896 if (msg) {
897 (void) fprintf(STDERR, "\n Probable cause of type undetermination is an incorrect description.\n");
898 (void) fprintf(STDERR, " Chameleonic nodes may introduce also an undetermination. In this case, NAPA\n");
899 (void) fprintf(STDERR, " needs a hint. Use a 'declare' instruction to remove an undetermination of type.\n");
900 (void) fprintf(STDERR, " You will never hide nor introduce a mistake with a declaration. As NAPA\n");
901 (void) fprintf(STDERR, " determines the type of the nodes by inspection of the netlist, any mismatch\n");
902 (void) fprintf(STDERR, " will be safely reported.\n\n");
903 }
904 return;
905}
906
907
908/* ****************************************************************************************************************************** */
909/* end of file */
void print_warning_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1484
void print_error_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1476
void swap_nodes(long i, long j)
Definition id.c:590
long array_id(const char *identifier)
Definition id.c:635
long node_id(const char *identifier)
Definition id.c:718
long var_id(const char *identifier)
Definition id.c:855
#define DELAY2_KIND
Definition napa.h:255
#define MUX_KIND
Definition napa.h:288
EXTERN VAR_TYPE Var_List[2047L]
Definition napa.h:970
EXTERN int Error_Flag
Definition napa.h:853
#define EQUAL_KIND
Definition napa.h:262
#define ITOD_KIND
Definition napa.h:278
#define MOD_KIND
Definition napa.h:286
#define RIP_KIND
Definition napa.h:302
EXTERN ARRAY_TYPE Array_List[63L]
Definition napa.h:950
#define MULLER_KIND
Definition napa.h:287
#define WSUM_KIND
Definition napa.h:323
#define TRACK_KIND
Definition napa.h:318
#define UNKNOWN_TYPE
Definition napa.h:332
#define UNDEFINED
Definition napa.h:331
#define RSHIFT2_KIND
Definition napa.h:307
#define AND_KIND
Definition napa.h:229
#define ROM2_KIND
Definition napa.h:304
#define TRIANGLE_KIND
Definition napa.h:319
#define STDERR
Definition napa.h:105
EXTERN NODE_TYPE Node_List[4095L]
Definition napa.h:962
#define LATCH_KIND
Definition napa.h:281
#define DIFFERENTIATOR_KIND
Definition napa.h:257
#define RSHIFT1_KIND
Definition napa.h:306
#define LSHIFT_KIND
Definition napa.h:282
#define INV_KIND
Definition napa.h:276
#define BWNAND_KIND
Definition napa.h:236
EXTERN int Dump_Flag
Definition napa.h:852
#define DTOI_KIND
Definition napa.h:259
#define FZNOR_KIND
Definition napa.h:267
#define OSC_KIND
Definition napa.h:294
#define CONST_KIND
Definition napa.h:246
#define DELAY3_KIND
Definition napa.h:256
#define CLOCK_KIND
Definition napa.h:244
#define NOR_KIND
Definition napa.h:291
#define ANALOG_DATA_TYPE
Definition napa.h:338
#define ADC_KIND
Definition napa.h:226
#define COPY_KIND
Definition napa.h:247
#define OFFSET_KIND
Definition napa.h:292
#define OR_KIND
Definition napa.h:293
#define CLIP_KIND
Definition napa.h:243
#define RELAY_KIND
Definition napa.h:301
#define SQUARE_KIND
Definition napa.h:312
#define MIN_KIND
Definition napa.h:285
#define UADC_KIND
Definition napa.h:321
#define IUSER_KIND
Definition napa.h:280
#define NAND_KIND
Definition napa.h:289
#define AVERAGE_KIND
Definition napa.h:230
#define PROD_KIND
Definition napa.h:296
#define DUSER_KIND
Definition napa.h:261
#define TEST_KIND
Definition napa.h:316
EXTERN long Num_Nodes
Definition napa.h:824
#define DELAY1_KIND
Definition napa.h:254
#define GAIN_KIND
Definition napa.h:271
#define ITOB_KIND
Definition napa.h:277
#define BUF_KIND
Definition napa.h:233
#define HOLD_KIND
Definition napa.h:273
#define XOR_KIND
Definition napa.h:325
#define RAM_KIND
Definition napa.h:298
#define SIN_KIND
Definition napa.h:310
#define YES
Definition napa.h:407
#define TOGGLE_KIND
Definition napa.h:317
#define XNOR_KIND
Definition napa.h:324
#define BWXNOR_KIND
Definition napa.h:239
#define DALGEBRA_KIND
Definition napa.h:251
#define RECT_KIND
Definition napa.h:300
#define MERGE_KIND
Definition napa.h:284
#define ROM_KIND
Definition napa.h:303
#define FZBUF_KIND
Definition napa.h:264
#define DC_KIND
Definition napa.h:252
#define SIGN_KIND
Definition napa.h:309
#define NO
Definition napa.h:406
#define FZXNOR_KIND
Definition napa.h:269
#define IALGEBRA_KIND
Definition napa.h:274
#define ALU_KIND
Definition napa.h:228
#define SUM_KIND
Definition napa.h:315
#define BWXOR_KIND
Definition napa.h:240
#define BTOI_KIND
Definition napa.h:232
#define FZNAND_KIND
Definition napa.h:266
#define ITOOL_KIND
Definition napa.h:279
#define DTOOL_KIND
Definition napa.h:260
#define RAM2_KIND
Definition napa.h:299
#define SUB_KIND
Definition napa.h:314
#define DIV_KIND
Definition napa.h:258
#define FZOR_KIND
Definition napa.h:268
#define BWOR_KIND
Definition napa.h:238
#define FZXOR_KIND
Definition napa.h:270
#define POLY_KIND
Definition napa.h:295
#define RSHIFT_KIND
Definition napa.h:305
#define UDAC_KIND
Definition napa.h:322
#define ZERO_KIND
Definition napa.h:326
#define INTEGRATOR_KIND
Definition napa.h:275
#define MAX_KIND
Definition napa.h:283
EXTERN int Terminate_Flag
Definition napa.h:880
EXTERN TERMINATE_TYPE Terminate_List
Definition napa.h:980
#define STRLENGTH
Definition napa.h:217
#define BWNOR_KIND
Definition napa.h:237
#define COMP_KIND
Definition napa.h:245
#define ISEMPTY(s)
Definition napa.h:394
#define BSHIFT_KIND
Definition napa.h:231
#define DELAY_KIND
Definition napa.h:253
#define FZINV_KIND
Definition napa.h:265
#define ALGEBRA_KIND
Definition napa.h:227
#define HEX_DATA_TYPE
Definition napa.h:340
#define BWINV_KIND
Definition napa.h:235
#define FZAND_KIND
Definition napa.h:263
#define QUANT_KIND
Definition napa.h:297
#define STEP_KIND
Definition napa.h:313
#define UNKNOWN_KIND
Definition napa.h:224
#define CHG_KIND
Definition napa.h:242
EXTERN DUMP_TYPE Dump_List
Definition napa.h:972
#define BWAND_KIND
Definition napa.h:234
#define DAC_KIND
Definition napa.h:250
#define TRIG_KIND
Definition napa.h:320
#define COS_KIND
Definition napa.h:248
#define NOISE_KIND
Definition napa.h:290
#define DIGITAL_DATA_TYPE
Definition napa.h:337
void node_determination(void)
Definition nd.c:37
char * get_token_between_braces(char *str, char *brc, char *tok)
Definition tk.c:1110
char * get_sign_and_token(char *str, char *sgn, char *tok)
Definition tk.c:1188