File: netlist.h

package info (click to toggle)
iverilog 12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,148 kB
  • sloc: cpp: 109,972; ansic: 62,713; yacc: 10,216; sh: 3,470; vhdl: 3,246; perl: 1,814; makefile: 1,774; python: 78; csh: 2
file content (5267 lines) | stat: -rw-r--r-- 170,919 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
#ifndef IVL_netlist_H
#define IVL_netlist_H
/*
 * Copyright (c) 1998-2021 Stephen Williams (steve@icarus.com)
 * Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
 *
 *    This source code is free software; you can redistribute it
 *    and/or modify it in source code form under the terms of the GNU
 *    General Public License as published by the Free Software
 *    Foundation; either version 2 of the License, or (at your option)
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/*
 * The netlist types, as described in this header file, are intended
 * to be the output from elaboration of the source design. The design
 * can be passed around in this form to the various stages and design
 * processors.
 */
# include  <string>
# include  <map>
# include  <list>
# include  <memory>
# include  <vector>
# include  <set>
# include  <utility>
# include  "ivl_target.h"
# include  "ivl_target_priv.h"
# include  "pform_types.h"
# include  "config.h"
# include  "nettypes.h"
# include  "verinum.h"
# include  "verireal.h"
# include  "StringHeap.h"
# include  "HName.h"
# include  "LineInfo.h"
# include  "Attrib.h"
# include  "PScope.h"
# include  "PUdp.h"

#ifdef HAVE_IOSFWD
# include  <iosfwd>
#else
# include  <iostream>
#endif

class Design;
class Link;
class Nexus;
class NetEvent;
class NetNet;
class NetNode;
class NetObj;
class NetPins;
class NetProc;
class NetProcTop;
class NetRelease;
class NetScope;
class NetEvProbe;
class NetExpr;
class NetEAccess;
class NetEConstEnum;
class NetESignal;
class NetFuncDef;
class NetRamDq;
class NetTaskDef;
class NetEvTrig;
class NetEvNBTrig;
class NetEvWait;
class PClass;
class PExpr;
class PFunction;
class PPackage;
class PTaskFunc;
class data_type_t;
struct enum_type_t;
class netclass_t;
class netdarray_t;
class netparray_t;
class netqueue_t;
class netenum_t;
class netstruct_t;
class netvector_t;

struct target;
struct functor_t;

#if defined(__cplusplus) && defined(_MSC_VER)
# define ENUM_UNSIGNED_INT : unsigned int
#else
# define ENUM_UNSIGNED_INT
#endif

std::ostream& operator << (std::ostream&o, ivl_variable_type_t val);

extern void join_island(NetPins*obj);

class Link {

      friend void connect(Link&, Link&);
      friend class NetPins;
      friend class Nexus;
      friend class NexusSet;

    public:
      enum DIR ENUM_UNSIGNED_INT { PASSIVE, INPUT, OUTPUT };
    private: // Only NetPins can create/delete Link objects
      Link();
      ~Link();

    public:
	// Manipulate the link direction.
      void set_dir(DIR d);
      DIR get_dir() const;

	// Set the delay for all the drivers to this nexus.
      void drivers_delays(NetExpr*rise, NetExpr*fall, NetExpr*decay);

	// A link has a drive strength for 0 and 1 values. The drive0
	// strength is for when the link has the value 0, and drive1
	// strength is for when the link has a value 1.
      void drive0(ivl_drive_t);
      void drive1(ivl_drive_t);

	// This sets the drives for all drivers of this link, and not
	// just the current link.
      void drivers_drive(ivl_drive_t d0, ivl_drive_t d1);

      ivl_drive_t drive0() const;
      ivl_drive_t drive1() const;

      void cur_link(NetPins*&net, unsigned &pin);
      void cur_link(const NetPins*&net, unsigned &pin) const;

	// Get a pointer to the nexus that represents all the links
	// connected to me.
      Nexus* nexus();
      const Nexus* nexus()const;

	// Return a pointer to the next link in the nexus.
      Link* next_nlink();
      const Link* next_nlink() const;

	// Remove this link from the set of connected pins. The
	// destructor will automatically do this if needed.
      void unlink();

	// Return true if this link is connected to anything else.
      bool is_linked() const;

	// Return true if these pins are connected.
      bool is_linked(const Link&that) const;

	// Return true if this is the same pin of the same object of
	// that link.
      bool is_equal(const Link&that) const;

	// Return information about the object that this link is
	// a part of. Note that the get_obj() method can return NIL if
	// this Link is part of a NexusSet. That should be OK, because
	// they are collection variables, and not functional parts of
	// a design.
      const NetPins*get_obj() const;
      NetPins*get_obj();
      unsigned get_pin() const;

      void dump_link(std::ostream&fd, unsigned ind) const;

    private:
	// The NetNode manages these. They point back to the
	// NetNode so that following the links can get me here.
      union {
	    NetPins *node_;
	    unsigned pin_;
      };

      bool pin_zero_     : 1;
      DIR dir_           : 2;
      ivl_drive_t drive0_ : 3;
      ivl_drive_t drive1_ : 3;

    private:
      Nexus* find_nexus_() const;

    private:
	// The Nexus uses these to maintain its list of Link
	// objects. If this link is not connected to anything,
	// then these pointers are both nil.
      Link *next_;
      Nexus*nexus_;

    private: // not implemented
      Link(const Link&);
      Link& operator= (const Link&);
};


class NetPins : public LineInfo {

    public:
      explicit NetPins(unsigned npins);
      virtual ~NetPins();

      unsigned pin_count() const { return npins_; }

      Link&pin(unsigned idx);
      const Link&pin(unsigned idx) const;

      void dump_node_pins(std::ostream&, unsigned, const char**pin_names =0) const;
      void set_default_dir(Link::DIR d);

      bool is_linked() const;
      bool pins_are_virtual(void) const;
      void devirtualize_pins(void);

	// This is for showing a brief description of the object to
	// the stream. It is used for debug and diagnostics.
      virtual void show_type(std::ostream&fd) const;

    private:
      Link*pins_;
      const unsigned npins_;
      Link::DIR default_dir_;
};

/* =========
 * A NetObj is anything that has any kind of behavior in the
 * netlist. Nodes can be gates, registers, etc. and are linked
 * together to form a design web.
 *
 * The web of nodes that makes up a circuit is held together by the
 * Link class. There is a link for each pin. All mutually connected
 * pins form a ring of links.
 *
 * A link can be INPUT, OUTPUT or PASSIVE. An input never drives the
 * signal, and PASSIVE never receives the value of the signal. Wires
 * are PASSIVE, for example.
 *
 * A NetObj also has delays specified as rise_time, fall_time and
 * decay_time. The rise and fall time are the times to transition to 1
 * or 0 values. The decay_time is the time needed to decay to a 'bz
 * value, or to decay of the net is a trireg. The exact and precise
 * interpretation of the rise/fall/decay times is typically left to
 * the target to properly interpret.
 */
class NetObj  : public NetPins, public Attrib {

    public:
	// The name of the object must be a permallocated string. A
	// lex_strings string, for example.
      explicit NetObj(NetScope*s, perm_string n, unsigned npins);
      virtual ~NetObj();

      NetScope* scope();
      const NetScope* scope() const;

      perm_string name() const { return name_; }
      void rename(perm_string n) { name_ = n; }

      const NetExpr* rise_time() const { return delay1_; }
      const NetExpr* fall_time() const { return delay2_; }
      const NetExpr* decay_time() const { return delay3_; }

      void rise_time(const NetExpr* d) { delay1_ = d; }
      void fall_time(const NetExpr* d) { delay2_ = d; }
      void decay_time(const NetExpr* d) { delay3_ = d; }

      void dump_obj_attr(std::ostream&, unsigned) const;

      virtual void show_type(std::ostream&fd) const;

    private:
      NetScope*scope_;
      perm_string name_;
      const NetExpr* delay1_;
      const NetExpr* delay2_;
      const NetExpr* delay3_;
};

/*
* Objects that can be island branches are derived from this. (It is
* possible for an object to be a NetObj and an IslandBranch.) This is
* used to collect island information about the node.
*/

class IslandBranch {
    public:
      explicit IslandBranch(ivl_discipline_t dis =0) : island_(0), discipline_(dis) { }

      ivl_island_t get_island() const { return island_; }

      friend void join_island(NetPins*);

    private:
      ivl_island_t island_;
      ivl_discipline_t discipline_;
};

/*
 * A NetBranch is a construct of Verilog-A that is a branch between
 * two nodes. The branch has exactly 2 pins and a discipline.
 *
 * pin(0) is the source of flow through a branch and the plus side of
 * potential. Pin(1) is the sink of flow and the minus (or ground) of
 * potential.
 */
class NetBranch  : public NetPins, public IslandBranch {

    public:
      explicit NetBranch(ivl_discipline_t dis);
      explicit NetBranch(ivl_discipline_t dis, perm_string name);
      ~NetBranch();

	// If the branch is named, this returns the name.
      perm_string name() const { return name_; }

      ivl_branch_s* target_obj() const { return &target_obj_; }

      void dump(std::ostream&, unsigned) const;

    private:
      perm_string name_;

      mutable ivl_branch_s target_obj_;

	// The design class uses this member to list the branches.
      friend class Design;
      NetBranch*next_;
};

/*
 * The Nexus represents a collection of links that are joined
 * together. Each link has its own properties, this class holds the
 * properties of the group.
 *
 * The links in a nexus are grouped into a circularly linked list,
 * with the nexus pointing to the last Link. Each link in turn points
 * to the next link in the nexus, with the last link pointing back to
 * the first. The last link also has a non-nil nexus_ pointer back to
 * this nexus.
 *
 * The t_cookie() is an ivl_nexus_t that the code generator uses to
 * store data in the nexus. When a Nexus is created, this cookie is
 * set to nil. The code generator may set the cookie once. This locks
 * the nexus, and rewrites the Link list to be optimal for the code
 * generator. In the process, *all* of the other methods are no longer
 * functional.
 */
class Nexus {

      friend void connect(Link&, Link&);
      friend class Link;

    private:
	// Only Link objects can create (or delete) Nexus objects
      explicit Nexus(Link&r);
      ~Nexus();

    public:

      void connect(Link&r);

      const char* name() const;

      void drivers_delays(NetExpr*rise, NetExpr*fall, NetExpr*decay);
      void drivers_drive(ivl_drive_t d0, ivl_drive_t d1);

      Link*first_nlink();
      const Link* first_nlink()const;

	/* Get the width of the Nexus, or 0 if there are no vectors
	   (in the form of NetNet objects) linked. */
      unsigned vector_width() const;

      NetNet* pick_any_net();

      NetNode* pick_any_node();

      /* This method counts the number of input and output links for
         this nexus, and assigns the results to the output arguments. */
      void count_io(unsigned&inp, unsigned&out) const;

	/* This method returns true if there are any assignments that
	   use this nexus as an l-value. This can be true if the nexus
	   is a variable, but also if this is a net with a force. */
      bool assign_lval() const;

	/* This method returns true if there are any inputs
	   attached to this nexus but no drivers. */
      bool has_floating_input() const;

	/* This method returns true if there are any drivers
	   (including variables) attached to this nexus. */
      bool drivers_present() const;

	/* This method returns true if all the possible drivers of
	   this nexus are constant. It will also return true if there
	   are no drivers at all. */
      bool drivers_constant() const;

	/* Given the nexus has constant drivers, this method returns
	   the value that has been driven. */
      verinum::V driven_value() const;
      verinum driven_vector() const;

	/* Return a mask of the bits of this vector that are
	   driven. This is usually all false or all true, but in
	   special cases it may be a blend. */
      std::vector<bool> driven_mask(void)const;

	/* The code generator sets an ivl_nexus_t to attach code
	   generation details to the nexus. */
      ivl_nexus_t t_cookie() const { return t_cookie_; }
      void t_cookie(ivl_nexus_t) const;

    private:
      Link*list_;
      void unlink(Link*);

      mutable char* name_; /* Cache the calculated name for the Nexus. */
      mutable ivl_nexus_t t_cookie_;

      enum VALUE { NO_GUESS, V0, V1, Vx, Vz, VAR };
      mutable VALUE driven_;

    private: // not implemented
      Nexus(const Nexus&);
      Nexus& operator= (const Nexus&);
};

inline void connect(Nexus*l, Link&r) { l->connect(r); }

class NexusSet {

    public:
      struct elem_t {
	    inline elem_t(Nexus*n, unsigned b, unsigned w)
	    : base(b), wid(w)
	    {
		  lnk.set_dir(Link::PASSIVE);
		  n->connect(lnk);
	    }
	    inline elem_t() : base(0), wid(0)
	    {
	    }
	    inline bool operator == (const struct elem_t&that) const
	    { return lnk.is_linked(that.lnk) && base==that.base && wid==that.wid; }

	    bool contains(const struct elem_t&that) const;

	    Link lnk;
	    unsigned base;
	    unsigned wid;
	  private:
	    elem_t(const elem_t&);
	    elem_t& operator= (elem_t&);
      };

    public:
      ~NexusSet();
      NexusSet();

      size_t size() const;

	// Add the nexus/part to the set, if it is not already present.
      void add(Nexus*that, unsigned base, unsigned wid);
      void add(NexusSet&that);

	// Remove the nexus from the set, if it is present.
      void rem(const NexusSet&that);

      unsigned find_nexus(const elem_t&that) const;

      elem_t& at(unsigned idx);
      inline elem_t& operator[] (unsigned idx) { return at(idx); }

	// Return true if this set contains every nexus/part in that
	// set. That means that every bit of that set is accounted for
	// this set.
      bool contains(const NexusSet&that) const;

	// Return true if this set contains any nexus in that set.
      bool intersect(const NexusSet&that) const;

    private:
	// NexSet items are canonical part selects of vectors.
      std::vector<struct elem_t*> items_;

      size_t bsearch_(const struct elem_t&that) const;
      void rem_(const struct elem_t*that);
      bool contains_(const elem_t&that) const;

    private: // not implemented
      NexusSet(const NexusSet&);
      NexusSet& operator= (const NexusSet&);
};

/*
 * A NetBus is a transparent device that is merely a bunch of pins
 * used to tie some pins to. It is a convenient way to collect a
 * bundle of pins and pass that bundle around.
 */
class NetBus  : public NetObj {

    public:
      NetBus(NetScope*scope, unsigned pin_count);
      ~NetBus();

      unsigned find_link(const Link&that) const;

    private: // not implemented
      NetBus(const NetBus&);
      NetBus& operator= (const NetBus&);
};

/*
 * A NetNode is a device of some sort, where each pin has a different
 * meaning. (i.e., pin(0) is the output to an and gate.) NetNode
 * objects are listed in the nodes_ of the Design object.
 */
class NetNode  : public NetObj {

    public:
	// The name parameter must be a permallocated string.
      explicit NetNode(NetScope*s, perm_string n, unsigned npins);

      virtual ~NetNode();

      virtual bool emit_node(struct target_t*) const;
      virtual void dump_node(std::ostream&, unsigned) const;

	// This is used to scan a modifiable netlist, one node at a time.
      virtual void functor_node(Design*, functor_t*);

    private:
      friend class Design;
      NetNode*node_next_, *node_prev_;
      Design*design_;
};

/*
 * A NetDelaySrc is an input-only device that calculates a path delay
 * based on the time that the inputs change. This class is used by the
 * NetNet class, and NetDelaySrc objects cannot exist outside of its
 * association with NetNet objects.
 */
class NetDelaySrc  : public NetObj {

    public:
      explicit NetDelaySrc(NetScope*s, perm_string n, unsigned nsrc,
                           bool condit_src, bool conditional, bool parallel);
      ~NetDelaySrc();

	// These functions set the delays from the values in the
	// source. These set_delays functions implement the various
	// rules wrt collections of transitions.

	// One transition specified.
      void set_delays(uint64_t del);
	// Two transitions: rise and fall
      void set_delays(uint64_t rise, uint64_t fall);
	// Three transitions
      void set_delays(uint64_t rise, uint64_t fall, uint64_t tz);
      void set_delays(uint64_t t01, uint64_t t10, uint64_t t0z,
		      uint64_t tz1, uint64_t t1z, uint64_t tz0);
      void set_delays(uint64_t t01, uint64_t t10, uint64_t t0z,
		      uint64_t tz1, uint64_t t1z, uint64_t tz0,
		      uint64_t t0x, uint64_t tx1, uint64_t t1x,
		      uint64_t tx0, uint64_t txz, uint64_t tzx);

      uint64_t get_delay(unsigned pe) const;

      void set_posedge();
      void set_negedge();
      bool is_posedge() const;
      bool is_negedge() const;

      unsigned src_count() const;
      Link&src_pin(unsigned);
      const Link&src_pin(unsigned) const;

      bool is_condit() const;
      bool has_condit() const;
      Link&condit_pin();
      const Link&condit_pin() const;

      bool is_parallel() const;

      void dump(std::ostream&, unsigned ind) const;

    private:
      uint64_t transition_delays_[12];
      bool condit_flag_;
      bool conditional_;
      bool parallel_;
      bool posedge_;
      bool negedge_;

    private: // Not implemented
      NetDelaySrc(const NetDelaySrc&);
      NetDelaySrc& operator= (const NetDelaySrc&);
};

/*
 * NetNet is a special kind of NetObj that doesn't really do anything,
 * but carries the properties of the wire/reg/trireg, including its
 * name. Scalars and vectors are all the same thing here, a NetNet
 * with a single pin. The difference between a scalar and vector is
 * the width of the atomic vector datum it carries.
 *
 * NetNet objects can also appear as side effects of synthesis or
 * other abstractions.
 *
 * Note that INTEGER types are an alias for a ``reg signed [31:0]''.
 *
 * NetNet objects have a name and exist within a scope, so the
 * constructor takes a pointer to the containing scope. The object
 * automatically adds itself to the scope.
 *
 * NetNet objects are located by searching NetScope objects.
 *
 * The pins of a NetNet object are usually PASSIVE: they do not drive
 * anything and they are not a data sink, per se. The pins follow the
 * values on the nexus. The exceptions are reg, trireg, tri0, tri1,
 * supply0, and supply1 objects, whose pins are classed as OUTPUT.
 */

class PortType
{
public:
	enum Enum ENUM_UNSIGNED_INT { NOT_A_PORT, PIMPLICIT, PINPUT, POUTPUT, PINOUT, PREF };

    /*
     * Merge Port types (used to construct a sane combined port-type
     * for module ports with complex defining expressions).
     *
     */
    static Enum merged( Enum lhs, Enum rhs );
};

extern std::ostream& operator << (std::ostream&, PortType::Enum);

  /*
   * Information on actual ports (rather than port-connected signals) of
   * module.
   * N.b. must be POD as passed through a "C" interface in the t-dll-api.
   */
struct PortInfo
{
    PortType::Enum  type;
    unsigned long   width;
    perm_string     name;
};


class NetNet  : public NetObj, public PortType {

    public:
      enum Type ENUM_UNSIGNED_INT { NONE, IMPLICIT, IMPLICIT_REG, WIRE, TRI, TRI1,
		  SUPPLY0, SUPPLY1, WAND, TRIAND, TRI0, WOR, TRIOR, REG,
		  UNRESOLVED_WIRE };

      typedef PortType::Enum PortType;

      static const std::list<netrange_t>not_an_array;

    public:
	// This form is the more generic form of the constructor. For
	// now, the unpacked type is not buried into an ivl_type_s object.
      explicit NetNet(NetScope*s, perm_string n, Type t,
		      const std::list<netrange_t>&unpacked,
		      ivl_type_t type);

      explicit NetNet(NetScope*s, perm_string n, Type t, ivl_type_t type);

      virtual ~NetNet();

      Type type() const;
      void type(Type t);

      PortType port_type() const;
      void port_type(PortType t);

      // If this net net is a port (i.e. a *sub*port net of a module port)
      // its port index is number of the module it connects through
      int get_module_port_index() const;                // -1 Not connected to port...
      void set_module_port_index(unsigned idx);

      ivl_variable_type_t data_type() const;

	/* If a NetNet is signed, then its value is to be treated as
	   signed. Otherwise, it is unsigned. */
      bool get_signed() const;

      bool get_scalar() const;

      inline const ivl_type_s* net_type(void) const { return net_type_; }
      const netenum_t*enumeration(void) const;
      const netstruct_t*struct_type(void) const;
      const netdarray_t*darray_type(void) const;
      const netqueue_t*queue_type(void) const;
      const netclass_t*class_type(void) const;

	/* Attach a discipline to the net. */
      ivl_discipline_t get_discipline() const;
      void set_discipline(ivl_discipline_t dis);

	/* This method returns a reference to the packed dimensions
	   for the vector. These are arranged as a list where the
	   first range in the list (front) is the left-most range in
	   the Verilog declaration. These packed dims are compressed
	   to represent the dimensions of all the subtypes. */
      const std::vector<netrange_t>& packed_dims() const { return slice_dims_; }

      const std::vector<netrange_t>& unpacked_dims() const { return unpacked_dims_; }

	/* The vector_width returns the bit width of the packed array,
	   vector or scalar that is this NetNet object.  */
      inline unsigned long vector_width() const { return slice_width(0); }

	/* Given a prefix of indices, figure out how wide the
	   resulting slice would be. This is a generalization of the
	   vector_width(), where the depth would be 0. */
      unsigned long slice_width(size_t depth) const;

	/* This method converts a signed index (the type that might be
	   found in the Verilog source) to canonical. It accounts
	   for variation in the definition of the
	   reg/wire/whatever. Note that a canonical index of a
	   multi-dimensioned packed array is a single dimension. For
	   example, "reg [4:1][3:0]..." has the canonical dimension
	   [15:0] and the sb_to_idx() method will convert [2][2] to
	   the canonical index [6]. */
      long sb_to_idx(const std::list<long>&prefix, long sb) const;

	/* This method converts a partial packed indices list and a
	   tail index, and generates a canonical slice offset and
	   width. */
      bool sb_to_slice(const std::list<long>&prefix, long sb, long&off, unsigned long&wid) const;

	/* This method checks that the signed index is valid for this
	   signal. If it is, the above sb_to_idx can be used to get
	   the pin# from the index. */
      bool sb_is_valid(const std::list<long>&prefix, long sb) const;

	/* This method returns 0 for scalars and vectors, and greater
	   for arrays. The value is the number of array
	   indices. (Currently only one array index is supported.) */
      inline unsigned unpacked_dimensions() const { return unpacked_dims_.size(); }

	/* This method returns 0 for scalars, but vectors and other
	   PACKED arrays have packed dimensions. */
      inline size_t packed_dimensions() const { return slice_dims_.size(); }

	// This is the number of array elements.
      unsigned unpacked_count() const;

      bool local_flag() const { return local_flag_; }
      void local_flag(bool f) { local_flag_ = f; }

	// NetESignal objects may reference this object. Keep a
	// reference count so that I keep track of them.
      void incr_eref();
      void decr_eref();
      unsigned peek_eref() const;

	// Assignment statements count their lrefs here. And by
	// assignment statements, we mean BEHAVIORAL assignments.
      void incr_lref();
      void decr_lref();
      unsigned peek_lref() const { return lref_count_; }

	// Treating this node as a uwire, this function tests whether
	// any bits in the canonical part are already driven. This is
	// only useful for UNRESOLVED_WIRE objects. The msb and lsb
	// are the part select of the signal, and the widx is the word
	// index if this is an unpacked array.
      bool test_and_set_part_driver(unsigned msb, unsigned lsb, int widx =0);

      unsigned get_refs() const;

	/* Manage path delays */
      void add_delay_path(class NetDelaySrc*path);
      unsigned delay_paths(void) const;
      const class NetDelaySrc*delay_path(unsigned idx) const;

      virtual void dump_net(std::ostream&, unsigned) const;

    private:
      void initialize_dir_();

    private:
      Type   type_    : 5;
      PortType port_type_ : 3;
      bool local_flag_: 1;
      ivl_type_t net_type_;
      ivl_discipline_t discipline_;

      std::vector<netrange_t> unpacked_dims_;

	// These are the widths of the various slice depths. There is
	// one entry in this vector for each packed dimension. The
	// value at N is the slice width if N indices are provided.
	//
	// For example: slice_wids_[0] is vector_width().
      void calculate_slice_widths_from_packed_dims_(void);
      std::vector<netrange_t> slice_dims_;
      std::vector<unsigned long> slice_wids_;

      unsigned eref_count_;
      unsigned lref_count_;

	// When the signal is an unresolved wire, we need more detail
	// which bits are assigned. This mask is true for each bit
	// that is known to be driven.
      std::vector<bool> lref_mask_;

      std::vector<class NetDelaySrc*> delay_paths_;
      int       port_index_;
};

/*
 * This object type is used for holding local variable values when
 * evaluating constant user functions.
 */
struct LocalVar {
      int nwords;  // zero for a simple variable, -1 for reference
      union {
	    NetExpr*  value;  // a simple variable
	    NetExpr** array;  // an array variable
	    LocalVar* ref;    // A reference to a previous scope
      };
};

class NetBaseDef {
    public:
      NetBaseDef(NetScope*n, const std::vector<NetNet*>&po,
		 const std::vector<NetExpr*>&pd);
      virtual ~NetBaseDef();

      const NetScope*scope() const;
      NetScope*scope();

      unsigned port_count() const;
      NetNet*port(unsigned idx) const;
      NetExpr*port_defe(unsigned idx) const;

      void set_proc(NetProc*p);

	//const string& name() const;
      const NetProc*proc() const;

      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      NetScope*scope_;
      std::vector<NetNet*>ports_;
      std::vector<NetExpr*>pdefaults_;

    protected:
      NetProc*proc_;
};

/*
 * Some definitions (and methods to manipulate them) are common to a
 * couple of types. Keep them here.
 */
class Definitions {

    public:
      Definitions();
      ~Definitions();

	// Add the enumeration to the set of enumerations in this
	// scope. Include a key that the elaboration can use to look
	// up this enumeration based on the pform type.
      void add_enumeration_set(const enum_type_t*key, netenum_t*enum_set);

      bool add_enumeration_name(netenum_t*enum_set, perm_string enum_name);

	// Look up the enumeration set that was added with the given
	// key. This is used by enum_type_t::elaborate_type to locate
	// a previously elaborated enumeration.
      netenum_t* enumeration_for_key(const enum_type_t*key) const;

	// Look up an enumeration literal in this scope. If the
	// literal is present, return the expression that defines its
	// value.
      const NetExpr* enumeration_expr(perm_string key);

	// Definitions scopes can also hold classes, by name.
      void add_class(netclass_t*class_type);

    protected:
	// Enumerations. The enum_sets_ is a list of all the
	// enumerations present in this scope. The enum_names_ is a
	// map of all the enumeration names back to the sets that
	// contain them.
      std::map<const enum_type_t*,netenum_t*> enum_sets_;
      std::map<perm_string,NetEConstEnum*> enum_names_;

	// This is a map of all the classes (by name) in this scope.
      std::map<perm_string,netclass_t*> classes_;

};

/*
 * This object type is used to contain a logical scope within a
 * design. The scope doesn't represent any executable hardware, but is
 * just a handle that netlist processors can use to grab at the design.
 */
class NetScope : public Definitions, public Attrib {

    public:
      enum TYPE { MODULE, CLASS, TASK, FUNC, BEGIN_END, FORK_JOIN, GENBLOCK, PACKAGE };

	/* Create a new scope associated with a given compilation unit,
	   and attach it to the given parent. If no compilation unit is
	   specified, the parent's compilation unit is used. The name
	   is expected to have been permallocated. */
      NetScope(NetScope*up, const hname_t&name, TYPE t, NetScope*in_unit=0,
	       bool nest=false, bool program=false, bool interface=false,
               bool compilation_unit=false);
      ~NetScope();

	/* Rename the scope using the name generated by inserting as
	   many pad characters as required between prefix and suffix
	   to make the name unique in the parent scope. Return false
	   if a unique name couldn't be generated. */
      bool auto_name(const char* prefix, char pad, const char* suffix);

      void add_imports(const std::map<perm_string,PPackage*>*imports);
      NetScope*find_import(const Design*des, perm_string name);

      void add_typedefs(const std::map<perm_string,typedef_t*>*typedefs);

        /* Search the scope hierarchy for the scope where 'type' was defined. */
      NetScope*find_typedef_scope(const Design*des, const typedef_t*type);

	/* Parameters exist within a scope, and these methods allow
	   one to manipulate the set. In these cases, the name is the
	   *simple* name of the parameter, the hierarchy is implicit in
	   the scope. */

      struct range_t;
      void set_parameter(perm_string name, bool is_annotatable,
			 const LexicalScope::param_expr_t &param,
			 NetScope::range_t *range_list);
      void set_parameter(perm_string name, NetExpr*val,
			 const LineInfo&file_line);

      const NetExpr*get_parameter(Design*des, const char* name,
				  ivl_type_t&ivl_type);
      const NetExpr*get_parameter(Design*des, perm_string name,
				  ivl_type_t&ivl_type);

	/* These are used by defparam elaboration to replace the
	   expression with a new expression, without affecting the
	   range or signed_flag. Return false if the name does not
	   exist. */
      void replace_parameter(Design *des, perm_string name, PExpr*val,
			     NetScope*scope, bool defparam = false);

	/* This is used to ensure the value of a parameter cannot be
	   changed at run-time. This is required if a specparam is used
	   in an expression that must be evaluated at compile-time.
	   Returns true if the named parameter is a specparam and has
	   not already been set to be unannotatable. */
      bool make_parameter_unannotatable(perm_string name);

	/* These methods set or access events that live in this
	   scope. */

      void add_event(NetEvent*);
      void rem_event(NetEvent*);
      NetEvent*find_event(perm_string name);

	/* These methods add or find a genvar that lives in this scope. */
      void add_genvar(perm_string name, LineInfo *li);
      LineInfo* find_genvar(perm_string name);

	/* These methods manage signals. The add_ and rem_signal
	   methods are used by the NetNet objects to make themselves
	   available to the scope, and the find_signal method can be
	   used to locate signals within a scope. */

      void add_signal(NetNet*);
      void rem_signal(NetNet*);
      NetNet* find_signal(perm_string name);

      netclass_t* find_class(const Design*des, perm_string name);

	/* The unit(), parent(), and child() methods allow users of
	   NetScope objects to locate nearby scopes. */
      NetScope* unit() { return unit_; }
      NetScope* parent() { return up_; }
      NetScope* child(const hname_t&name);
      const NetScope* unit() const { return unit_; }
      const NetScope* parent() const { return up_; }
      const NetScope* child(const hname_t&name) const;

	/* A helper function to find the enclosing class scope. */
      const NetScope* get_class_scope() const;

	// Look for a child scope by name. This ignores the number
	// part of the child scope name, so there may be multiple
	// matches. Only return one. This function is only really
	// useful for some elaboration error checking.
      const NetScope* child_byname(perm_string name) const;

	// Nested modules have slightly different scope search rules.
      inline bool nested_module() const { return nested_module_; }
	// Program blocks and interfaces have elaboration constraints.
      inline bool program_block() const { return program_block_; }
      inline bool is_interface() const { return is_interface_; }
      inline bool is_unit() const { return is_unit_; }
      inline TYPE type() const { return type_; }
      void print_type(std::ostream&) const;

	// This provides a link to the variable initialisation process
	// for use when evaluating a constant function. Note this is
	// only used for static functions - the variable initialization
	// for automatic functions is included in the function definition.
      void set_var_init(const NetProc*proc) { var_init_ = proc; }
      const NetProc* var_init() const { return var_init_; }

      void set_task_def(NetTaskDef*);
      void set_func_def(NetFuncDef*);
      void set_class_def(netclass_t*);
      void set_module_name(perm_string);

      NetTaskDef* task_def();
      NetFuncDef* func_def();

	// This is used by the evaluate_function setup to collect
	// local variables from the scope.
      void evaluate_function_find_locals(const LineInfo&loc,
					 std::map<perm_string,LocalVar>&ctx) const;

      void set_line(perm_string file, perm_string def_file,
                    unsigned lineno, unsigned def_lineno);
      void set_line(perm_string file, unsigned lineno);
      void set_line(const LineInfo *info);
      perm_string get_file() const { return file_; };
      perm_string get_def_file() const { return def_file_; };
      unsigned get_lineno() const { return lineno_; };
      unsigned get_def_lineno() const { return def_lineno_; };

      std::string get_fileline() const;
      std::string get_def_fileline() const;

      bool in_func() const;

	/* Provide a link back to the pform to allow early elaboration of
           constant functions. */
      void set_func_pform(const PFunction*pfunc) { func_pform_ = pfunc; };
      const PFunction*func_pform() const { return func_pform_; };

        /* Allow tracking of elaboration stages. The three stages are:
             1 - scope elaboration
             2 - signal elaboration
             3 - statement elaboration
           This is only used for functions, to support early elaboration.
        */
      void set_elab_stage(unsigned stage) { elab_stage_ = stage; };
      unsigned elab_stage() const { return elab_stage_; };

	/* Is this a function called in a constant expression. */
      void need_const_func(bool need_const) { need_const_func_ = need_const; };
      bool need_const_func() const { return need_const_func_; };

	/* Is this a constant function. */
      void is_const_func(bool is_const) { is_const_func_ = is_const; };
      bool is_const_func() const { return is_const_func_; };

	/* Is the task or function automatic. */
      void is_auto(bool is_auto__) { is_auto_ = is_auto__; };
      bool is_auto() const { return is_auto_; };

	/* Is the module a cell (is in a `celldefine) */
      void is_cell(bool is_cell__) { is_cell_ = is_cell__; };
      bool is_cell() const { return is_cell_; };

	/* Is there a call to a system task in this scope. */
      void calls_sys_task(bool calls_stask__) { calls_stask_ = calls_stask__; };
      bool calls_sys_task() const { return calls_stask_; };

        /* Is this scope elaborating a final procedure? */
      void in_final(bool in_final__) { in_final_ = in_final__; };
      bool in_final() const { return in_final_; };

      const NetTaskDef* task_def() const;
      const NetFuncDef* func_def() const;
      const netclass_t* class_def() const;

	/* If the scope represents a module instance, the module_name
	   is the name of the module itself. */
      perm_string module_name() const;
	/* If the scope is a module then it may have ports that we need
	 * to keep track of. */

      void set_num_ports(unsigned int num_ports);
      void add_module_port_net(NetNet*port);
      unsigned module_port_nets() const;
      NetNet*module_port_net(unsigned idx) const;

      void add_module_port_info( unsigned idx,
                            perm_string name,  // May be "" for undeclared port
                            PortType::Enum type,
                            unsigned long width );

      const std::vector<PortInfo> &module_port_info() const;

	/* Scopes have their own time units and time precision. The
	   unit and precision are given as power of 10, i.e., -3 is
	   units of milliseconds.

	   If a NetScope is created with a parent scope, the new scope
	   will initially inherit the unit and precision of the
	   parent scope. */

      void time_unit(int);
      void time_precision(int);
      void time_from_timescale(bool);

      int time_unit() const;
      int time_precision() const;
      bool time_from_timescale() const;

	/* The fullname of the scope is the hierarchical name
	   component (which includes the name and array index) whereas
	   the basename is just my name. */
      perm_string basename() const;
      const hname_t& fullname() const { return name_; }

      void run_defparams(class Design*);
      void run_defparams_later(class Design*);

      void evaluate_parameters(class Design*);

	// Look for defparams that never matched, and print warnings.
      void residual_defparams(class Design*);

      bool symbol_exists(perm_string sym);

	/* This method generates a non-hierarchical name that is
	   guaranteed to be unique within this scope. */
      perm_string local_symbol();

      void dump(std::ostream&) const;
	// Check to see if the scope has items that are not allowed
	// in an always_comb/ff/latch process.
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      void emit_scope(struct target_t*tgt) const;
      bool emit_defs(struct target_t*tgt) const;

	/* This method runs the functor on me. Recurse through the
	   children of this node as well. */
      void run_functor(Design*des, functor_t*fun);

	/* These are used in synthesis. They provide shared pullup and
	   pulldown nodes for this scope. */
      void add_tie_hi(Design*des);
      void add_tie_lo(Design*des);
      Link&tie_hi() const { return tie_hi_->pin(0); };
      Link&tie_lo() const { return tie_lo_->pin(0); };

	/* This member is used during elaboration to pass defparam
	   assignments from the scope pass to the parameter evaluation
	   step. After that, it is not used. */

      std::list<std::pair<pform_name_t,PExpr*> > defparams;
      std::list<std::pair<std::list<hname_t>,PExpr*> > defparams_later;

    public:
      struct range_t {
	    bool exclude_flag;
	      // Lower bound
	    bool low_open_flag;
	    NetExpr*low_expr;
	      // Upper bound
	    bool high_open_flag;
	    NetExpr*high_expr;
	      // Link to the next range specification
	    struct range_t*next;
      };

	/* After everything is all set up, the code generators like
	   access to these things to make up the parameter lists. */
      struct param_expr_t : public LineInfo {
	    param_expr_t() : val_expr(0), val_type(0), val_scope(0),
		             solving(false), is_annotatable(false),
		             local_flag(false),
		             range(0), val(0), ivl_type(0) { }
	    // Source expression and data type (before elaboration)
	    PExpr*val_expr;
	    data_type_t*val_type;
	    // Scope information
            NetScope*val_scope;
	    // Evaluation status
	    bool solving;
	    // specparam status
	    bool is_annotatable;
	    // Is this a localparam?
	    bool local_flag;
	    // Can it be overriden?
	    bool overridable = false;
	    // Is it a type parameter
	    bool type_flag = false;
	    // range constraints
	    struct range_t*range;

	    // Expression value. Elaborated version of val_expr.
	    // For type parameters this will always be 0.
	    NetExpr*val;

	    // For non-type parameter this contains the elaborate type of the
	    // parameter itself. For type parameters this contains the
	    // elaborated assigned type value.
	    ivl_type_t ivl_type;
      };
      std::map<perm_string,param_expr_t>parameters;

      typedef std::map<perm_string,param_expr_t>::iterator param_ref_t;

      LineInfo get_parameter_line_info(perm_string name) const;

	/* Module instance arrays are collected here for access during
	   the multiple elaboration passes. */
      typedef std::vector<NetScope*> scope_vec_t;
      std::map<perm_string, scope_vec_t>instance_arrays;

	/* Loop generate uses this as scratch space during
	   elaboration. Expression evaluation can use this to match
	   names. */
      perm_string genvar_tmp;
      long genvar_tmp_val;

      std::map<perm_string,LocalVar> loop_index_tmp;

    private:
      void evaluate_type_parameter_(Design*des, param_ref_t cur);
      void evaluate_parameter_logic_(Design*des, param_ref_t cur);
      void evaluate_parameter_real_(Design*des, param_ref_t cur);
      void evaluate_parameter_string_(Design*des, param_ref_t cur);
      void evaluate_parameter_(Design*des, param_ref_t cur);

    private:
      TYPE type_;
      hname_t name_;

	// True if the scope is a nested module/program block
      bool nested_module_;
	// True if the scope is a program block
      bool program_block_;
	// True if the scope is an interface
      bool is_interface_;
	// True if the scope is a compilation unit
      bool is_unit_;

      perm_string file_;
      perm_string def_file_;
      unsigned lineno_;
      unsigned def_lineno_;

      signed char time_unit_, time_prec_;
      bool time_from_timescale_;

      const std::map<perm_string,PPackage*>*imports_;

      std::map<perm_string,typedef_t*>typedefs_;

      NetEvent *events_;

      std::map<perm_string,LineInfo*> genvars_;

      typedef std::map<perm_string,NetNet*>::const_iterator signals_map_iter_t;
      std::map <perm_string,NetNet*> signals_map_;
      perm_string module_name_;
      std::vector<NetNet*> port_nets;

      std::vector<PortInfo> ports_;

      const NetProc*var_init_;

      union {
	    NetTaskDef*task_;
	    NetFuncDef*func_;
	    netclass_t*class_def_;
      };
      const PFunction*func_pform_;
      unsigned elab_stage_;

      NetScope*unit_;
      NetScope*up_;
      std::map<hname_t,NetScope*> children_;

      unsigned lcounter_;
      bool need_const_func_, is_const_func_, is_auto_, is_cell_, calls_stask_;

      /* Final procedures sets this to notify statements that
	 they are part of a final procedure. */
      bool in_final_;

      NetNode*tie_hi_;
      NetNode*tie_lo_;
};

/*
 * This class implements the LPM_ABS component. The node has a single
 * input, a signed expression, that it converts to the absolute
 * value. The gate is simple: pin(0) is the output and pin(1) is the input.
 */
class NetAbs  : public NetNode {

    public:
      NetAbs(NetScope*s, perm_string n, unsigned width);
      ~NetAbs();

      unsigned width() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_;
};

/*
 * This class implements the LPM_ADD_SUB component as described in the
 * EDIF LPM Version 2 1 0 standard. It is used as a structural
 * implementation of the + and - operators.
 */
class NetAddSub  : public NetNode {

    public:
      NetAddSub(NetScope*s, perm_string n, unsigned width);
      ~NetAddSub();

	// Get the width of the device (that is, the width of the
	// operands and results).
      unsigned width() const;

      Link& pin_Cout();
      Link& pin_DataA();
      Link& pin_DataB();
      Link& pin_Result();

      const Link& pin_Cout() const;
      const Link& pin_DataA() const;
      const Link& pin_DataB() const;
      const Link& pin_Result() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_;
};

/*
 * The NetArrayDq node represents an array dereference. The NetNet
 * that this object refers to is an array, and the Address pin selects
 * which word of the array to place on the Result.
*/
class NetArrayDq  : public NetNode {

    public:
      NetArrayDq(NetScope*s, perm_string name, NetNet*mem, unsigned awid);
      ~NetArrayDq();

      unsigned width() const;
      unsigned awidth() const;
      unsigned size() const;
      const NetNet*mem() const;

      Link& pin_Address();
      Link& pin_Result();

      const Link& pin_Address() const;
      const Link& pin_Result() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      NetNet*mem_;
      unsigned awidth_;

};

/*
 * Convert an IVL_VT_REAL input to a logical value with the
 * given width. The input is pin(1) and the output is pin(0).
 */
class NetCastInt4  : public NetNode {

    public:
      NetCastInt4(NetScope*s, perm_string n, unsigned width);

      unsigned width() const { return width_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
};

class NetCastInt2  : public NetNode {

    public:
      NetCastInt2(NetScope*s, perm_string n, unsigned width);

      unsigned width() const { return width_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
};

/*
 * Convert an input to IVL_VT_REAL. The input is pin(1), which can be
 * any vector type (VT_BOOL or VT_LOGIC) and the output is pin(0),
 * which is IVL_VT_REAL. The conversion interprets the input as an
 * unsigned value unless the signed_flag is true.
 */
class NetCastReal  : public NetNode {

    public:
      NetCastReal(NetScope*s, perm_string n, bool signed_flag);

      bool signed_flag() const { return signed_flag_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      bool signed_flag_;
};

/*
 * This type represents the LPM_CLSHIFT device.
 */
class NetCLShift  : public NetNode {

    public:
      NetCLShift(NetScope*s, perm_string n, unsigned width,
		 unsigned width_dist, bool right_flag, bool signed_flag);
      ~NetCLShift();

      unsigned width() const;
      unsigned width_dist() const;

      bool right_flag() const;
      bool signed_flag() const;

      Link& pin_Data();
      Link& pin_Result();
      Link& pin_Distance();

      const Link& pin_Data() const;
      const Link& pin_Result() const;
      const Link& pin_Distance() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
      unsigned width_dist_;
      bool right_flag_;
      bool signed_flag_;
};

/*
 * This class supports the LPM_COMPARE device.
 *
 * The width of the device is the width of the inputs. If one of the
 * inputs is narrower than the other, it is up to the generator to
 * make sure all the data pins are properly driven.
 *
 * The signed() property is true if the comparison is to be done to
 * signed arguments. The result is always UNsigned.
 *
 * NOTE: This is not the same as the device used to support case
 * compare. Case comparisons handle Vx and Vz values, whereas this
 * device need not.
 */
class NetCompare  : public NetNode {

    public:
      NetCompare(NetScope*scope, perm_string n, unsigned width);
      ~NetCompare();

      unsigned width() const;

      bool get_signed() const;
      void set_signed(bool);

      Link& pin_AGB();
      Link& pin_AGEB();
      Link& pin_AEB();
      Link& pin_ANEB();
      Link& pin_ALB();
      Link& pin_ALEB();

      Link& pin_DataA();
      Link& pin_DataB();

      const Link& pin_AGB() const;
      const Link& pin_AGEB() const;
      const Link& pin_AEB() const;
      const Link& pin_ANEB() const;
      const Link& pin_ALB() const;
      const Link& pin_ALEB() const;

      const Link& pin_DataA() const;
      const Link& pin_DataB() const;

      virtual void functor_node(Design*, functor_t*);
      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
      bool signed_flag_;
};


/*
 * This node is a means to connect net inputs together to form a wider
 * vector. The output (pin 0) is a concatenation of the input vectors,
 * with pin-1 at the LSB, pin-2 next, and so on. This node is most
 * like the NetLogic node, as it has one output at pin 0 and the
 * remaining pins are the input that are combined to make the
 * output. It is separated out because it it generally a special case
 * for the code generators.
 *
 * When constructing the node, the width is the vector_width of the
 * output, and the cnt is the number of pins. (the number of input
 * vectors.)
 */
class NetConcat  : public NetNode {

    public:
      NetConcat(NetScope*scope, perm_string n, unsigned wid, unsigned cnt,
		bool transparent_flag = false);
      ~NetConcat();

      unsigned width() const;
	// This is true if the concatenation is a transparent
	// concatenation, meaning strengths are passed through as
	// is. In this case, the output strengths of this node will be
	// ignored.
      bool transparent() const { return transparent_; }

      void dump_node(std::ostream&, unsigned ind) const;
      bool emit_node(struct target_t*) const;
      void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_;
      bool transparent_;
};


/*
 * This class represents a theoretical (though not necessarily
 * practical) integer divider gate. This is not to represent any real
 * hardware, but to support the / operator in Verilog, when it shows
 * up in structural contexts.
 *
 * The operands of the operation are the DataA<i> and DataB<i> inputs,
 * and the Result<i> output reflects the value DataA/DataB.
 */

class NetDivide  : public NetNode {

    public:
      NetDivide(NetScope*scope, perm_string n,
		unsigned width, unsigned wa, unsigned wb);
      ~NetDivide();

      unsigned width_r() const;
      unsigned width_a() const;
      unsigned width_b() const;

      void set_signed(bool);
      bool get_signed() const;

      Link& pin_DataA();
      Link& pin_DataB();
      Link& pin_Result();

      const Link& pin_DataA() const;
      const Link& pin_DataB() const;
      const Link& pin_Result() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_r_;
      unsigned width_a_;
      unsigned width_b_;

      bool signed_flag_;
};

/*
 * This class represents a theoretical (though not necessarily
 * practical) integer modulo gate. This is not to represent any real
 * hardware, but to support the % operator in Verilog, when it shows
 * up in structural contexts.
 *
 * The operands of the operation are the DataA<i> and DataB<i> inputs,
 * and the Result<i> output reflects the value DataA%DataB.
 */

class NetModulo  : public NetNode {

    public:
      NetModulo(NetScope*s, perm_string n,
		unsigned width, unsigned wa, unsigned wb);
      ~NetModulo();

      unsigned width_r() const;
      unsigned width_a() const;
      unsigned width_b() const;

      void set_signed(bool);
      bool get_signed() const;

      Link& pin_DataA();
      Link& pin_DataB();
      Link& pin_Result();

      const Link& pin_DataA() const;
      const Link& pin_DataB() const;
      const Link& pin_Result() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_r_;
      unsigned width_a_;
      unsigned width_b_;

      bool signed_flag_;
};

/*
 * This class represents an LPM_FF device. There is no literal gate
 * type in Verilog that maps, but gates of this type can be inferred.
 */
class NetFF  : public NetNode {

    public:
      NetFF(NetScope*s, perm_string n, bool negedge, unsigned vector_width);
      ~NetFF();

      bool is_negedge() const;
      unsigned width() const;

      Link& pin_Clock();
      Link& pin_Enable();
      Link& pin_Aset();
      Link& pin_Aclr();
      Link& pin_Sset();
      Link& pin_Sclr();
      Link& pin_Data();
      Link& pin_Q();

      const Link& pin_Clock() const;
      const Link& pin_Enable() const;
      const Link& pin_Aset() const;
      const Link& pin_Aclr() const;
      const Link& pin_Sset() const;
      const Link& pin_Sclr() const;
      const Link& pin_Data() const;
      const Link& pin_Q() const;

      void aset_value(const verinum&val);
      const verinum& aset_value() const;

      void sset_value(const verinum&val);
      const verinum& sset_value() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      bool negedge_;
      unsigned width_;
      verinum aset_value_;
      verinum sset_value_;
};


/*
 * This class represents an LPM_LATCH device. There is no literal gate
 * type in Verilog that maps, but gates of this type can be inferred.
 */
class NetLatch  : public NetNode {

    public:
      NetLatch(NetScope*s, perm_string n, unsigned vector_width);
      ~NetLatch();

      unsigned width() const;

      Link& pin_Enable();
      Link& pin_Data();
      Link& pin_Q();

      const Link& pin_Enable() const;
      const Link& pin_Data() const;
      const Link& pin_Q() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_;
};

/*
 * This class implements a basic LPM_MULT combinational multiplier. It
 * is used as a structural representation of the * operator. The
 * device has inputs A and B and output Result all with independent
 * widths.
 *
 * NOTE: Check this width thing. I think that the independence of the
 * widths is not necessary or even useful.
 */
class NetMult  : public NetNode {

    public:
      NetMult(NetScope*sc, perm_string n, unsigned width,
	      unsigned wa, unsigned wb);
      ~NetMult();

      bool get_signed() const;
      void set_signed(bool);

	// Get the width of the device bussed inputs. There are these
	// parameterized widths:
      unsigned width_r() const; // Result
      unsigned width_a() const; // DataA
      unsigned width_b() const; // DataB

      Link& pin_DataA();
      Link& pin_DataB();
      Link& pin_Result();

      const Link& pin_DataA() const;
      const Link& pin_DataB() const;
      const Link& pin_Result() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      bool signed_;
      unsigned width_r_;
      unsigned width_a_;
      unsigned width_b_;
};


/*
 * This class represents an LPM_MUX device. This device has some
 * number of Result points (the width of the device) and some number
 * of input choices. There is also a selector of some width. The
 * parameters are:
 *
 *      width  -- Width of the result and each possible Data input
 *      size   -- Number of Data input (each of width)
 *      selw   -- Width in bits of the select input
 *
 * All the data inputs must have the same type, and are the type of
 * the result. The actual type does not matter, as the mux does not
 * process data, just selects alternatives.
 *
 * The select input must be an integral type of some sort. Not real.
 */
class NetMux  : public NetNode {

    public:
      NetMux(NetScope*scope, perm_string n,
	     unsigned width, unsigned size, unsigned selw);
      ~NetMux();

      unsigned width() const;
      unsigned size() const;
      unsigned sel_width() const;

      Link& pin_Result();
      Link& pin_Data(unsigned si);
      Link& pin_Sel();

      const Link& pin_Result() const;
      const Link& pin_Data(unsigned) const;
      const Link& pin_Sel() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned width_;
      unsigned size_;
      unsigned swidth_;
};


/*
 * This class implements a basic LPM_POW combinational power. It
 * is used as a structural representation of the ** operator. The
 * device has inputs A and B and output Result all with independent
 * widths.
 *
 * NOTE: Check this width thing. I think that the independence of the
 * widths is not necessary or even useful.
 */
class NetPow  : public NetNode {

    public:
      NetPow(NetScope*sc, perm_string n, unsigned width,
	      unsigned wa, unsigned wb);
      ~NetPow();

      bool get_signed() const;
      void set_signed(bool);

	// Get the width of the device bussed inputs. There are these
	// parameterized widths:
      unsigned width_r() const; // Result
      unsigned width_a() const; // DataA
      unsigned width_b() const; // DataB

      Link& pin_DataA();
      Link& pin_DataB();
      Link& pin_Result();

      const Link& pin_DataA() const;
      const Link& pin_DataB() const;
      const Link& pin_Result() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      bool signed_;
      unsigned width_r_;
      unsigned width_a_;
      unsigned width_b_;
};


/*
 * The NetReplicate node takes a vector input and makes it into a larger
 * vector by repeating the input vector some number of times. The
 * repeat count is a fixed value. This is just like the repeat
 * concatenation of Verilog: {<repeat>{<vector>}}.
 *
 * When constructing this node, the wid is the vector width of the
 * output, and the rpt is the repeat count. The wid must be an even
 * multiple of the cnt, and wid/cnt is the expected input width.
 *
 * The device has exactly 2 pins: pin(0) is the output and pin(1) the
 * input.
 */
class NetReplicate  : public NetNode {

    public:
      NetReplicate(NetScope*scope, perm_string n, unsigned wid, unsigned rpt);
      ~NetReplicate();

      unsigned width() const;
      unsigned repeat() const;

      void dump_node(std::ostream&, unsigned ind) const;
      bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
      unsigned repeat_;
};

/*
 * This node represents the call of a user defined function in a
 * structural context. The pin count is the same as the port count,
 * with pin0 the return value.
 */
class NetUserFunc  : public NetNode {

    public:
      NetUserFunc(NetScope*s, perm_string n, NetScope*def, NetEvWait*trigger__);
      ~NetUserFunc();

      unsigned port_width(unsigned port) const;

      const NetScope* def() const;

      const NetEvWait* trigger() const { return trigger_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      NetScope*def_;
      NetEvWait*trigger_;
};

/*
 * The number of ports includes the return value, so will always be at
 * least 1.
 */
class NetSysFunc  : public NetNode {

    public:
      NetSysFunc(NetScope*s, perm_string n,
		 const struct sfunc_return_type*def,
		 unsigned ports, NetEvWait*trigger__);
      ~NetSysFunc();

      ivl_variable_type_t data_type() const;
      unsigned vector_width() const;
      const char* func_name() const;

      const NetEvWait* trigger() const { return trigger_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      const struct sfunc_return_type*def_;
      NetEvWait*trigger_;
};

class NetTran  : public NetNode, public IslandBranch {

    public:
	// Tran devices other than TRAN_VP
      NetTran(NetScope*scope, perm_string n, ivl_switch_type_t type,
              unsigned wid);
	// Create a TRAN_VP
      NetTran(NetScope*scope, perm_string n, unsigned wid,
	      unsigned part, unsigned off);
      ~NetTran();

      ivl_switch_type_t type() const { return type_; }

	// These are only used for IVL_SW_TRAN_PV
      unsigned vector_width() const;
      unsigned part_width() const;
      unsigned part_offset() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      ivl_switch_type_t type_;
      unsigned wid_;
      unsigned part_;
      unsigned off_;
};

/* =========
 * There are cases where expressions need to be represented. The
 * NetExpr class is the root of a hierarchy that serves that purpose.
 *
 * The expr_width() is the width of the expression, which is calculated
 * before the expression is elaborated.
 */
class NetExpr  : public LineInfo {
    public:
      explicit NetExpr(unsigned w =0);
      explicit NetExpr(ivl_type_t t);
      virtual ~NetExpr() =0;

      virtual void expr_scan(struct expr_scan_t*) const =0;
      virtual void dump(std::ostream&) const;

	// This is the advanced description of the type. I think I
	// want to replace the other type description members with
	// this single method. The default for this method returns
	// nil.
      ivl_type_t net_type() const;

	// Expressions have type.
      virtual ivl_variable_type_t expr_type() const;

	// How wide am I?
      unsigned expr_width() const { return width_; }

	// This method returns true if the expression is
	// signed. Unsigned expressions return false.
      bool has_sign() const { return signed_flag_; }
      virtual void cast_signed(bool flag);

	// This returns true if the expression has a definite
	// width. This is generally true, but in some cases the
	// expression is amorphous and desires a width from its
	// environment. For example, 'd5 has indefinite width, but
	// 5'd5 has a definite width.

	// This method is only really used within concatenation
	// expressions to check validity.
      virtual bool has_width() const;

	// Return the enumeration set that defines this expressions
	// enumeration type, or return nil if the expression is not
	// part of the enumeration.
      virtual const netenum_t*enumeration() const;

	// This method evaluates the expression and returns an
	// equivalent expression that is reduced as far as compile
	// time knows how. Essentially, this is designed to fold
	// constants.
      virtual NetExpr*eval_tree();

	// Make a duplicate of myself, and subexpressions if I have
	// any. This is a deep copy operation.
      virtual NetExpr*dup_expr() const =0;

	// Evaluate the expression at compile time, a la within a
	// constant function. This is used by the constant function
	// evaluation function code, and the return value is an
	// allocated constant, or nil if the expression cannot be
	// evaluated for any reason.
      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;

	// Get the Nexus that are the input to this
	// expression. Normally this descends down to the reference to
	// a signal that reads from its input.
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const =0;

	// Return a version of myself that is structural. This is used
	// for converting expressions to gates. The arguments are:
	//
	//  des, scope:  The context where this work is done
	//
        //  root: The root expression of which this expression is a part.
        //
	//  rise/fall/decay: Attach these delays to the driver for the
	//                   expression output.
	//
	//  drive0/drive1: Attach these strengths to the driver for
	//                 the expression output.
      virtual NetNet*synthesize(Design*des, NetScope*scope, NetExpr*root);

    protected:
      void expr_width(unsigned wid) { width_ = wid; }
      void cast_signed_base_(bool flag) { signed_flag_ = flag; }

    private:
      ivl_type_t net_type_;
      unsigned width_;
      bool signed_flag_;

    private: // not implemented
      NetExpr(const NetExpr&);
      NetExpr& operator=(const NetExpr&);
};

class NetEArrayPattern  : public NetExpr {

    public:
      NetEArrayPattern(ivl_type_t lv_type, std::vector<NetExpr*>&items);
      ~NetEArrayPattern();

      inline size_t item_size() const { return items_.size(); }
      const NetExpr* item(size_t idx) const { return items_[idx]; }

      void expr_scan(struct expr_scan_t*) const;
      void dump(std::ostream&) const;

      NetEArrayPattern* dup_expr() const;
      NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                          bool nested_func = false) const;

    private:
      std::vector<NetExpr*> items_;
};

/*
 * The expression constant is slightly special, and is sometimes
 * returned from other classes that can be evaluated at compile
 * time. This class represents constant values in expressions.
 */
class NetEConst  : public NetExpr {

    public:
      explicit NetEConst(const verinum&val);
      ~NetEConst();

      const verinum&value() const;

      virtual void cast_signed(bool flag);
      virtual bool has_width() const;
      virtual ivl_variable_type_t expr_type() const;

        /* This method allows the constant value to be converted
           to an unsized value. This is used after evaluating a
           unsized constant expression. */
      void trim();

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

      virtual NetEConst* dup_expr() const;
      virtual NetNet*synthesize(Design*, NetScope*scope, NetExpr*);
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;

    private:
      verinum value_;
};

class NetEConstEnum  : public NetEConst {

    public:
      explicit NetEConstEnum(perm_string name, const netenum_t*enum_set,
			     const verinum&val);
      ~NetEConstEnum();

      perm_string name() const;
      const netenum_t*enumeration() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

      virtual NetEConstEnum* dup_expr() const;

    private:
      const netenum_t*enum_set_;
      perm_string name_;
};

class NetEConstParam  : public NetEConst {

    public:
      explicit NetEConstParam(const NetScope*scope, perm_string name,
			      const verinum&val);
      ~NetEConstParam();

      perm_string name() const;
      const NetScope*scope() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

      virtual NetEConstParam* dup_expr() const;

    private:
      const NetScope*scope_;
      perm_string name_;
};

/*
 * This class represents a constant real value.
 */
class NetECReal  : public NetExpr {

    public:
      explicit NetECReal(const verireal&val);
      ~NetECReal();

      const verireal&value() const;

	// The type of this expression is ET_REAL
      ivl_variable_type_t expr_type() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

      virtual NetECReal* dup_expr() const;
      virtual NetNet*synthesize(Design*, NetScope*scope, NetExpr*);
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;

    private:
      verireal value_;
};

class NetECString  : public NetEConst {
    public:
      explicit NetECString(const std::string& val);
      ~NetECString();

      // The type of a string is IVL_VT_STRING
      ivl_variable_type_t expr_type() const;
};

class NetECRealParam  : public NetECReal {

    public:
      explicit NetECRealParam(const NetScope*scope, perm_string name,
			      const verireal&val);
      ~NetECRealParam();

      perm_string name() const;
      const NetScope*scope() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

      virtual NetECRealParam* dup_expr() const;

    private:
      const NetScope*scope_;
      perm_string name_;
};

/*
 * The NetPartSelect device represents a netlist part select of a
 * signal vector. Pin 0 is a vector that is a part select of pin 1,
 * which connected to the NetNet of the signal being selected from.
 *
 * The part to be selected is the canonical (0-based) offset and the
 * specified number of bits (wid).
 *
 * If the offset is non-constant, then pin(2) is the input vector for
 * the selector. If this pin is present, then use the non-constant
 * selector as the input.
 *
 * The NetPartSelect can be output from the signal (i.e. reading a
 * part) or input into the signal. The DIR method gives the type of
 * the node.
 *
 * VP (Vector-to-Part)
 *  Output pin 0 is the part select, and input pin 1 is connected to
 *  the NetNet object.
 *
 * PV (Part-to-Vector)
 *  Output pin 1 is connected to the NetNet, and input pin 0 is the
 *  part select. In this case, the node is driving the NetNet.
 *
 * Note that whatever the direction that data is intended to flow,
 * pin-0 is the part select and pin-1 is connected to the NetNet.
 */
class NetPartSelect  : public NetNode {

    public:
	// enum for the device direction
      enum dir_t { VP, PV};

      explicit NetPartSelect(NetNet*sig,
			     unsigned off, unsigned wid, dir_t dir,
			     bool signed_flag__ = false);
      explicit NetPartSelect(NetNet*sig, NetNet*sel,
			     unsigned wid, bool signed_flag__ = false);
      ~NetPartSelect();

      unsigned base()  const;
      unsigned width() const;
      inline dir_t dir()   const { return dir_; }
	/* Is the select signal signed? */
      inline bool signed_flag() const { return signed_flag_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      bool emit_node(struct target_t*tgt) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned off_;
      unsigned wid_;
      dir_t    dir_;
      bool signed_flag_;
};

/*
 * This device supports simple substitution of a part within a wider
 * vector. For example, this:
 *
 *      wire [7:0] foo = NetSubstitute(bar, bat, off);
 *
 * means that bar is a vector the same width as foo, bat is a narrower
 * vector. The off is a constant offset into the bar vector. This
 * looks something like this:
 *
 *      foo = bar;
 *      foo[off +: <width_of_bat>] = bat;
 *
 * There is no direct way in Verilog to express this (as a single
 * device), it instead turns up in certain synthesis situation,
 * i.e. the example above.
 */
class NetSubstitute : public NetNode {

    public:
      NetSubstitute(NetNet*sig, NetNet*sub, unsigned wid, unsigned off);
      ~NetSubstitute();

      inline unsigned width() const { return wid_; }
      inline unsigned base() const  { return off_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*tgt) const;
      virtual void functor_node(Design*des, functor_t*fun);

    private:
      unsigned wid_;
      unsigned off_;
};

/*
 * The NetBUFZ is a magic device that represents the continuous
 * assign, with the output being the target register and the input
 * the logic that feeds it. The netlist preserves the directional
 * nature of that assignment with the BUFZ. The target may elide it if
 * that makes sense for the technology.
 *
 * A NetBUFZ is transparent if strengths are passed through it without
 * change. A NetBUFZ is non-transparent if values other than HiZ are
 * converted to the strength of the output.
 */
class NetBUFZ  : public NetNode {

    public:
      explicit NetBUFZ(NetScope*s, perm_string n, unsigned wid, bool transp);
      ~NetBUFZ();

      unsigned width() const;
      bool transparent() const { return transparent_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
      bool transparent_;
};

/*
 * This node is used to represent case equality in combinational
 * logic. Although this is not normally synthesizable, it makes sense
 * to support an abstract gate that can compare x and z. This node
 * always generates a single bit result, no matter the width of the
 * input. The elaboration, btw, needs to make sure the input widths
 * match.
 *
 * The case compare can be generated to handle ===/!==, or also
 * to test guards in the case/casez/casex statements.
 *
 * This pins are assigned as:
 *
 *     0   -- Output (always returns 0 or 1)
 *     1   -- Input
 *     2   -- Input (wildcard input for EQX and EQZ variants)
 */
class NetCaseCmp  : public NetNode {

    public:
      enum kind_t {
	    EEQ, // ===
	    NEQ, // !==
	    WEQ, // ==?
	    WNE, // !=?
	    XEQ, // casex guard tests
	    ZEQ  // casez guard tests
      };

    public:
      explicit NetCaseCmp(NetScope*s, perm_string n, unsigned wid, kind_t eeq);
      ~NetCaseCmp();

      unsigned width() const;
	// What kind of case compare?
      inline kind_t kind() const { return kind_; }

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;

    private:
      unsigned width_;
      const kind_t kind_;
};

extern std::ostream& operator << (std::ostream&fd, NetCaseCmp::kind_t that);

/* NOTE: This class should be replaced with the NetLiteral class
 * below, that is more general in that it supports different types of
 * values.
 *
 * This class represents instances of the LPM_CONSTANT device. The
 * node has only outputs and a constant value. The width is available
 * by getting the pin_count(), and the value bits are available one at
 * a time. There is no meaning to the aggregation of bits to form a
 * wide NetConst object, although some targets may have an easier time
 * detecting interesting constructs if they are combined.
 */
class NetConst  : public NetNode {

    public:
      explicit NetConst(NetScope*s, perm_string n, verinum::V v);
      explicit NetConst(NetScope*s, perm_string n, const verinum&val);
      ~NetConst();

      inline const verinum&value(void) const { return value_; }
      verinum::V value(unsigned idx) const;
      inline unsigned width() const { return value_.len(); }
      inline bool is_string() const { return value_.is_string(); }

      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*, functor_t*);
      virtual void dump_node(std::ostream&, unsigned ind) const;

    private:
      verinum value_;
};

/*
 * This class represents instances of the LPM_CONSTANT device. The
 * node has only outputs and a constant value. The width is available
 * by getting the pin_count(), and the value bits are available one at
 * a time. There is no meaning to the aggregation of bits to form a
 * wide NetConst object, although some targets may have an easier time
 * detecting interesting constructs if they are combined.
 */
class NetLiteral  : public NetNode {

    public:
	// A read-valued literal.
      explicit NetLiteral(NetScope*s, perm_string n, const verireal&val);
      ~NetLiteral();

      ivl_variable_type_t data_type() const;

      const verireal& value_real() const;

      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*, functor_t*);
      virtual void dump_node(std::ostream&, unsigned ind) const;

    private:
      verireal real_;
};

/*
 * This class represents all manner of logic gates. Pin 0 is OUTPUT and
 * all the remaining pins are INPUT. The BUFIF[01] gates have the
 * more specific pinout as follows:
 *
 *     bufif<N>
 *       0  -- output
 *       1  -- input data
 *       2  -- enable
 *
 * The pullup and pulldown gates have no inputs at all, and pin0 is
 * the output 1 or 0, depending on the gate type. It is the strength
 * of that value that is important.
 *
 * All these devices process vectors bitwise, so each bit can be
 * logically separated. The exception is the CONCAT gate, which is
 * really an abstract gate that takes the inputs and turns it into a
 * vector of bits.
 */
class NetLogic  : public NetNode {

    public:
      enum TYPE { AND, BUF, BUFIF0, BUFIF1, CMOS, EQUIV, IMPL, NAND, NMOS,
		  NOR, NOT, NOTIF0, NOTIF1, OR, PULLDOWN, PULLUP, RCMOS,
		  RNMOS, RPMOS, PMOS, XNOR, XOR };

      explicit NetLogic(NetScope*s, perm_string n, unsigned pins,
			TYPE t, unsigned wid, bool is_cassign__=false);

      TYPE type() const;
      unsigned width() const;
      bool is_cassign() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*, functor_t*);

    private:
      TYPE type_;
      unsigned width_;
      bool is_cassign_;
};

/*
 * This class represents a structural sign extension. The pin-0 is a
 * vector of the input pin-1 sign-extended. The input is taken to be
 * signed. This generally matches a hardware implementation of
 * replicating the top bit enough times to create the desired output
 * width.
 */
class NetSignExtend  : public NetNode {

    public:
      explicit NetSignExtend(NetScope*s, perm_string n, unsigned wid);
      ~NetSignExtend();

      unsigned width() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*, functor_t*);

    private:
      unsigned width_;
};

/*
 * This class represents *reduction* logic operators. Certain boolean
 * logic operators have reduction forms which take in a vector and
 * return a single bit that is calculated by applying the logic
 * operation through the width of the input vector. These correspond
 * to reduction unary operators in Verilog.
 */
class NetUReduce  : public NetNode {

    public:
      enum TYPE {NONE, AND, OR, XOR, NAND, NOR, XNOR};

      NetUReduce(NetScope*s, perm_string n, TYPE t, unsigned wid);

      TYPE type() const;
      unsigned width() const;

      virtual void dump_node(std::ostream&, unsigned ind) const;
      virtual bool emit_node(struct target_t*) const;
      virtual void functor_node(Design*, functor_t*);

    private:
      TYPE type_;
      unsigned width_;
};

/*
 * The UDP is a User Defined Primitive from the Verilog source. Do not
 * expand it out any further than this in the netlist, as this can be
 * used to represent target device primitives.
 *
 * The UDP can be combinational or sequential. The sequential UDP
 * includes the current output in the truth table, and supports edges,
 * whereas the combinational does not and is entirely level sensitive.
 * In any case, pin 0 is an output, and all the remaining pins are
 * inputs.
 *
 * Set_table takes as input a string with one letter per pin. The
 * parser translates the written sequences to one of these. The
 * valid characters are:
 *
 *      0, 1, x  -- The levels
 *      r   -- (01)
 *      R   -- (x1)
 *      f   -- (10)
 *      F   -- (x0)
 *      P   -- (0x)
 *      N   -- (1x)
 *
 * It also takes one of the following glob letters to represent more
 * than one item.
 *
 *      p   -- 01, 0x or x1 // check this with the lexer
 *      n   -- 10, 1x or x0 // check this with the lexer
 *      ?   -- 0, 1, or x
 *      *   -- any edge
 *      +   -- 01 or x1
 *      _   -- 10 or x0  (Note that this is not the output '-'.)
 *      %   -- 0x or 1x
 *
 * SEQUENTIAL
 * These objects have a single bit of memory. The logic table includes
 * an entry for the current value, and allows edges on the inputs. In
 * canonical form, only the entries that generate 0, 1 or - (no change)
 * are listed.
 *
 * COMBINATIONAL
 * The logic table is a map between the input levels and the
 * output. Each input pin can have the value 0, 1 or x and the output
 * can have the values 0 or 1. If the input matches nothing, the
 * output is x. In canonical form, only the entries that generate 0 or
 * 1 are listed.
 *
 */

class NetUDP  : public NetNode {

    public:
      explicit NetUDP(NetScope*s, perm_string n, unsigned pins, PUdp*u);

      virtual bool emit_node(struct target_t*) const;
      virtual void dump_node(std::ostream&, unsigned ind) const;

	/* Use these methods to scan the truth table of the
	   device. "first" returns the first item in the table, and
	   "next" returns the next item in the table. The method will
	   return false when the scan is done. */
      bool first(std::string&inp, char&out) const;
      bool next(std::string&inp, char&out) const;
      unsigned rows() const { return udp->tinput.size(); }

      unsigned nin() const { return pin_count()-1; }
      bool is_sequential() const { return udp->sequential; }
      perm_string udp_name() const { return udp->name_; }
      perm_string udp_file() const { return udp->get_file(); }
      unsigned udp_lineno() const { return udp->get_lineno(); }
      char get_initial() const;

      unsigned port_count() const;
      std::string port_name(unsigned idx) const;

    private:
      mutable unsigned table_idx;
      PUdp *udp;
};

enum DelayType { NO_DELAY, ZERO_DELAY, POSSIBLE_DELAY, DEFINITE_DELAY };

/* =========
 * A process is a behavioral-model description. A process is a
 * statement that may be compound. The various statement types may
 * refer to places in a netlist (by pointing to nodes) but is not
 * linked into the netlist. However, elaborating a process may cause
 * special nodes to be created to handle things like events.
 */
class NetProc : public virtual LineInfo {

    public:
      explicit NetProc();
      virtual ~NetProc();

	// Find the nexa that are input by the statement. This is used
	// for example by @* to find the inputs to the process for the
	// sensitivity list.
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

	// Find the nexa that are set by the statement. Add the output
	// values to the set passed as a parameter.
      virtual void nex_output(NexusSet&);

	// This method is called to emit the statement to the
	// target. The target returns true if OK, false for errors.
      virtual bool emit_proc(struct target_t*) const;

	// This method is used by the NetFuncDef object to evaluate a
	// constant function at compile time. The loc is the location
	// of the function call, and is used for error messages. The
	// ctx is a map of name to expression. This is for mapping
	// identifiers to values. The function returns true if the
	// processing succeeds, or false otherwise.
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

	// This method is called by functors that want to scan a
	// process in search of matchable patterns.
      virtual int match_proc(struct proc_match_t*);

	// Return true if this represents the root of a combinational
	// process. Most process types are not.
      virtual bool is_asynchronous();

	// Return true if this represents the root of a synchronous
	// process. Most process types are not.
      virtual bool is_synchronous();

	// Synthesize as asynchronous logic, and return true on success.
	//
	// nex_map holds the set of nexuses that are driven by this
	// process, nex_out holds the accumulated outputs from this and
	// preceding sequential processes (i.e statements in the same
	// block), enables holds the accumulated clock/gate enables,
	// and bitmasks holds the accumulated masks that flag which bits
	// are unconditionally driven (i.e. driven by every clause in
	// every statement). On output, the values passed in to nex_out,
	// enables, and bitmasks may either be merged with or replaced
	// by the values originating from this process, depending on the
	// type of statement this process represents.
	//
	// The clock/gate enables generated by synthesis operate at a
	// vector level (i.e. they are asserted if any bit(s) in the
	// vector are driven).
      typedef std::vector<bool> mask_t;
      virtual bool synth_async(Design*des, NetScope*scope,
			       NexusSet&nex_map, NetBus&nex_out,
			       NetBus&enables, std::vector<mask_t>&bitmasks);

	// Synthesize as synchronous logic, and return true on success.
	// That means binding the outputs to the data port of a FF, and
	// the event inputs to a FF clock. Only some key NetProc sub-types
	// that have specific meaning in synchronous statements. The
	// remainder reduce to a call to synth_async that connects the
	// output to the Data input of the FF.
	//
	// The nex_map, nex_out, ff_ce, and bitmasks arguments serve
	// the same purpose as in the synth_async method (where ff_ce
	// is equivalent to enables). The events argument is filled
	// in by the NetEvWait implementation of this method with the
	// probes that it does not itself pick off as a clock. These
	// events should be picked off by e.g. condit statements as
	// asynchronous set/reset inputs to the flipflop being generated.
      virtual bool synth_sync(Design*des, NetScope*scope,
			      bool&ff_negedge,
			      NetNet*ff_clock, NetBus&ff_ce,
			      NetBus&ff_aclr,  NetBus&ff_aset,
			      std::vector<verinum>&ff_aset_value,
			      NexusSet&nex_map, NetBus&nex_out,
			      std::vector<mask_t>&bitmasks,
			      const std::vector<NetEvProbe*>&events);

      virtual void dump(std::ostream&, unsigned ind) const;

	// Recursively checks to see if there is delay in this element.
      virtual DelayType delay_type(bool print_delay=false) const;
	// Check to see if the item is synthesizable.
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    protected:
      bool synth_async_block_substatement_(Design*des, NetScope*scope,
					   NexusSet&nex_map,
					   NetBus&nex_out,
					   NetBus&enables,
					   std::vector<mask_t>&bitmasks,
					   NetProc*substmt);
    private:
      friend class NetBlock;
      NetProc*next_;

    private: // not implemented
      NetProc(const NetProc&);
      NetProc& operator= (const NetProc&);
};

class NetAlloc  : public NetProc {

    public:
      explicit NetAlloc(NetScope*);
      ~NetAlloc();

      const std::string name() const;

      const NetScope* scope() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;

    private:
      NetScope*scope_;
};

/*
 * Procedural assignment is broken into a suite of classes. These
 * classes represent the various aspects of the assignment statement
 * in behavioral code. (The continuous assignment is *not*
 * represented here.)
 *
 * The NetAssignBase carries the common aspects of an assignment,
 * including the r-value. This class has no cares of blocking vs
 * non-blocking, however it carries nearly all the other properties
 * of the assignment statement. It is abstract because it does not
 * differentiate the virtual behaviors.
 *
 * The NetAssign and NetAssignNB classes are the concrete classes that
 * give the assignment its final, precise meaning. These classes fill
 * in the NetProc behaviors.
 *
 * The l-value of the assignment is a collection of NetAssign_
 * objects that are connected to the structural netlist where the
 * assignment has its effect. The NetAssign_ class is not to be
 * derived from.
 *
 * The collection is arranged from lsb up to msb, and represents the
 * concatenation of l-values. The elaborator may collapse some
 * concatenations into a single NetAssign_. The "more" member of the
 * NetAssign_ object points to the next most significant bits of l-value.
 *
 * NOTE: The elaborator will make an effort to match the width of the
 * r-value to the width of the l-value, but targets and functions
 * should know that this is not a guarantee.
 */

class NetAssign_ {

    public:
      explicit NetAssign_(NetAssign_*nest);
      explicit NetAssign_(NetNet*sig);
      ~NetAssign_();

	// This is so NetAssign_ objects can be passed to ivl_assert
	// and other macros that call this method.
      std::string get_fileline() const;

	// If this expression exists, then it is used to select a word
	// from an array/memory.
      NetExpr*word();
      const NetExpr*word() const;

      NetScope*scope()const;

	// Get the base index of the part select, or 0 if there is no
	// part select.
      const NetExpr* get_base() const;
      ivl_select_type_t select_type() const;

      void set_word(NetExpr*);
	// Set a part select expression for the l-value vector. Note
	// that the expression calculates a CANONICAL bit address.
      void set_part(NetExpr* loff, unsigned wid,
                    ivl_select_type_t = IVL_SEL_OTHER);
	// Set the member or property name if the signal type is a
	// class.
      void set_property(const perm_string&name, unsigned int idx);
      inline int get_property_idx(void) const { return member_idx_; }

	// Determine if the assigned object is signed or unsigned.
	// This is used when determining the expression type for
	// a compressed assignment statement.
      bool get_signed() const { return signed_; }
      void set_signed(bool flag) { signed_ = flag; }

	// Get the width of the r-value that this node expects. This
	// method accounts for the presence of the mux, so it is not
	// necessarily the same as the pin_count().
      unsigned lwidth() const;
      ivl_variable_type_t expr_type() const;

	// Get the expression type of the l-value. This may be
	// different from the type of the contained signal if for
	// example a darray is indexed.
      const ivl_type_s* net_type() const;

	// Return the enumeration type of this l-value, or nil if it's
	// not an enumeration.
      const netenum_t*enumeration() const;

	// Get the name of the underlying object.
      perm_string name() const;

      NetNet* sig() const;
      inline const NetAssign_* nest() const { return nest_; }

	// Mark that the synthesizer has worked with this l-value, so
	// when it is released, the l-value signal should be turned
	// into a wire.
      void turn_sig_to_wire_on_release();

	// It is possible that l-values can have *inputs*, as well as
	// being outputs. For example foo[idx] = ... is the l-value
	// (NetAssign_ object) with a foo l-value and the input
	// expression idx.
      NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                          bool nested_func = false) const;

	// Figuring out nex_output to process ultimately comes down to
	// this method.
      void nex_output(NexusSet&);

	// This pointer is for keeping simple lists.
      NetAssign_* more;

      void dump_lval(std::ostream&o) const;

    private:
	// Nested l-value. If this is set, sig_ must NOT be set!
      NetAssign_*nest_;
      NetNet *sig_;
	// Memory word index
      NetExpr*word_;
	// member/property if signal is a class.
      perm_string member_;
      int member_idx_ = -1;

      bool signed_;
      bool turn_sig_to_wire_on_release_;
	// indexed part select base
      NetExpr*base_;
      unsigned lwid_;
      ivl_select_type_t sel_type_;
};

class NetAssignBase : public NetProc {

    public:
      NetAssignBase(NetAssign_*lv, NetExpr*rv);
      virtual ~NetAssignBase() =0;

	// This is the (procedural) value that is to be assigned when
	// the assignment is executed.
      NetExpr*rval();
      const NetExpr*rval() const;

      void set_rval(NetExpr*);

      NetAssign_* l_val(unsigned);
      const NetAssign_* l_val(unsigned) const;
      unsigned l_val_count() const;

      void set_delay(NetExpr*);
      const NetExpr* get_delay() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&o);


	// This returns the total width of the accumulated l-value. It
	// accounts for any grouping of NetAssign_ objects that might happen.
      unsigned lwidth() const;

      bool synth_async(Design*des, NetScope*scope,
		       NexusSet&nex_map, NetBus&nex_out,
		       NetBus&enables, std::vector<mask_t>&bitmasks);

	// This dumps all the lval structures.
      void dump_lval(std::ostream&) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      NetAssign_*lval_;
      NetExpr   *rval_;
      NetExpr   *delay_;
};

class NetAssign : public NetAssignBase {

    public:
      explicit NetAssign(NetAssign_*lv, NetExpr*rv);
      explicit NetAssign(NetAssign_*lv, char op, NetExpr*rv);
      ~NetAssign();

      bool is_asynchronous();

      inline char assign_operator(void) const { return op_; }

      virtual bool emit_proc(struct target_t*) const;
      virtual int match_proc(struct proc_match_t*);
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      void eval_func_lval_op_real_(const LineInfo&loc, verireal&lv, const verireal&rv) const;
      void eval_func_lval_op_(const LineInfo&loc, verinum&lv, verinum&rv) const;
      bool eval_func_lval_(const LineInfo&loc, std::map<perm_string,LocalVar>&ctx,
			   const NetAssign_*lval, NetExpr*rval_result) const;

      char op_;
};

class NetAssignNB  : public NetAssignBase {
    public:
      explicit NetAssignNB(NetAssign_*lv, NetExpr*rv, NetEvWait*ev,
                           NetExpr*cnt);
      ~NetAssignNB();


      virtual bool emit_proc(struct target_t*) const;
      virtual int match_proc(struct proc_match_t*);
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

      unsigned nevents() const;
      const NetEvent*event(unsigned) const;
      const NetExpr* get_count() const;

    private:
      NetEvWait*event_;
      NetExpr*count_;
};

/*
 * A block is stuff like begin-end blocks, that contain an ordered
 * list of NetProc statements.
 *
 * NOTE: The emit method calls the target->proc_block function but
 * does not recurse. It is up to the target-supplied proc_block
 * function to call emit_recurse.
 */
class NetBlock  : public NetProc {

    public:
      enum Type { SEQU, PARA, PARA_JOIN_ANY, PARA_JOIN_NONE };

      NetBlock(Type t, NetScope*subscope);
      ~NetBlock();

      Type type() const    { return type_; }
      NetScope* subscope() const { return subscope_; }

      void append(NetProc*);
      void prepend(NetProc*);

      const NetProc*proc_first() const;
      const NetProc*proc_next(const NetProc*cur) const;

      bool evaluate_function(const LineInfo&loc,
			     std::map<perm_string,LocalVar>&ctx) const;

	// synthesize as asynchronous logic, and return true.
      bool synth_async(Design*des, NetScope*scope,
		       NexusSet&nex_map, NetBus&nex_out,
		       NetBus&enables, std::vector<mask_t>&bitmasks);

      bool synth_sync(Design*des, NetScope*scope,
		      bool&ff_negedge,
		      NetNet*ff_clk, NetBus&ff_ce,
		      NetBus&ff_aclr,NetBus&ff_aset,
		      std::vector<verinum>&ff_aset_value,
		      NexusSet&nex_map, NetBus&nex_out,
		      std::vector<mask_t>&bitmasks,
		      const std::vector<NetEvProbe*>&events);

	// This version of emit_recurse scans all the statements of
	// the begin-end block sequentially. It is typically of use
	// for sequential blocks.
      void emit_recurse(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual int match_proc(struct proc_match_t*);
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      const Type type_;
      NetScope*subscope_;

      NetProc*last_;
};

/*
 * A CASE statement in the Verilog source leads, eventually, to one of
 * these. This is different from a simple conditional because of the
 * way the comparisons are performed. Also, it is likely that the
 * target may be able to optimize differently.
 *
 * Case statements can have unique, unique0, or priority attached to
 * them. If not otherwise adorned, it is QBASIC.
 *
 * Case can be one of three types:
 *    EQ  -- All bits must exactly match
 *    EQZ -- z bits are don't care
 *    EQX -- x and z bits are don't care.
 */
class NetCase  : public NetProc {

    public:
      enum TYPE { EQ, EQX, EQZ };

      NetCase(ivl_case_quality_t q, TYPE c, NetExpr*ex, unsigned cnt);
      ~NetCase();

      void set_case(unsigned idx, NetExpr*ex, NetProc*st);

      void prune();

      inline ivl_case_quality_t case_quality() const { return quality_; }
      TYPE type() const;
      const NetExpr*expr() const { return expr_; }
      inline unsigned nitems() const { return items_.size(); }

      inline const NetExpr*expr(unsigned idx) const { return items_[idx].guard;}
      inline const NetProc*stat(unsigned idx) const { return items_[idx].statement; }

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&out);

      bool synth_async(Design*des, NetScope*scope,
		       NexusSet&nex_map, NetBus&nex_out,
		       NetBus&enables, std::vector<mask_t>&bitmasks);

      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      bool evaluate_function_vect_(const LineInfo&loc,
				   std::map<perm_string,LocalVar>&ctx) const;
      bool evaluate_function_real_(const LineInfo&loc,
				   std::map<perm_string,LocalVar>&ctx) const;

      bool synth_async_casez_(Design*des, NetScope*scope,
			      NexusSet&nex_map, NetBus&nex_out,
			      NetBus&enables, std::vector<mask_t>&bitmasks);

      ivl_case_quality_t quality_;
      TYPE type_;

      struct Item {
	    inline Item() : guard(0), statement(0) { }
	    NetExpr*guard;
	    NetProc*statement;
      };

      NetExpr* expr_;
      std::vector<Item>items_;
};

/*
 * The cassign statement causes the r-val net to be forced onto the
 * l-val reg when it is executed. The code generator is expected to
 * know what that means.
 */
class NetCAssign  : public NetAssignBase {

    public:
      explicit NetCAssign(NetAssign_*lv, NetExpr*rv);
      ~NetCAssign();

      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool emit_proc(struct target_t*) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private: // not implemented
      NetCAssign(const NetCAssign&);
      NetCAssign& operator= (const NetCAssign&);
};


/*
 * A condit represents a conditional. It has an expression to test,
 * and a pair of statements to select from. If the original statement
 * has empty clauses, then the NetProc for it will be a null pointer.
 */
class NetCondit  : public NetProc {

    public:
      explicit NetCondit(NetExpr*ex, NetProc*i, NetProc*e);
      ~NetCondit();

      const NetExpr*expr() const;
      NetExpr*expr();

      NetProc* if_clause();
      NetProc* else_clause();

	// Replace the condition expression.
      void set_expr(NetExpr*ex);

      bool emit_recurse_if(struct target_t*) const;
      bool emit_recurse_else(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&o);

      bool is_asynchronous();
      bool synth_async(Design*des, NetScope*scope,
		       NexusSet&nex_map, NetBus&nex_out,
		       NetBus&enables, std::vector<mask_t>&bitmasks);

      bool synth_sync(Design*des, NetScope*scope,
		      bool&ff_negedge,
		      NetNet*ff_clk, NetBus&ff_ce,
		      NetBus&ff_aclr,NetBus&ff_aset,
		      std::vector<verinum>&ff_aset_value,
		      NexusSet&nex_map, NetBus&nex_out,
		      std::vector<mask_t>&bitmasks,
		      const std::vector<NetEvProbe*>&events);

      virtual bool emit_proc(struct target_t*) const;
      virtual int match_proc(struct proc_match_t*);
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      NetExpr* expr_;
      NetProc*if_;
      NetProc*else_;
};

/*
 * This represents the analog contribution statement. The l-val is a
 * branch expression, and the r-value is an arbitrary expression that
 * may include branches and real values.
 */
class NetContribution : public NetProc {

    public:
      explicit NetContribution(NetEAccess*lval, NetExpr*rval);
      ~NetContribution();

      const NetEAccess* lval() const;
      const NetExpr* rval() const;

      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;

    private:
      NetEAccess*lval_;
      NetExpr*rval_;
};

/*
 * The procedural deassign statement (the opposite of assign) releases
 * any assign expressions attached to the bits of the reg. The
 * lval is the expression of the "deassign <expr>;" statement with the
 * expr elaborated to a net.
 */
class NetDeassign : public NetAssignBase {

    public:
      explicit NetDeassign(NetAssign_*l);
      ~NetDeassign();

      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private: // not implemented
      NetDeassign(const NetDeassign&);
      NetDeassign& operator= (const NetDeassign&);
};

/*
 * This node represents the behavioral disable statement. The Verilog
 * source that produces it looks like:
 *
 *          disable <scope>;
 *
 * Where the scope is a named block or a task. It cannot be a module
 * instance scope because module instances cannot be disabled.
 */
class NetDisable  : public NetProc {

    public:
      explicit NetDisable(NetScope*tgt, bool flow_control = false);
      ~NetDisable();

      const NetScope*target() const;
      bool flow_control() const { return flow_control_; }

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      NetScope*target_;
       // If false all threads in the target_ scope are disabled. If true only
       // the closest thread in thread hierachy of the target_ scope is
       // disabled. The latter is used to implement flow control statements like
       // `return`.
      bool flow_control_;

    private: // not implemented
      NetDisable(const NetDisable&);
      NetDisable& operator= (const NetDisable&);
};

/*
 * The do/while statement is a condition that is tested at the end of
 * each iteration, and a statement (a NetProc) that is executed once and
 * then again as long as the condition is true.
 */
class NetDoWhile  : public NetProc {

    public:
      NetDoWhile(NetExpr*c, NetProc*p)
      : cond_(c), proc_(p) { }

      const NetExpr*expr() const { return cond_; }

      void emit_proc_recurse(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      NetExpr* cond_;
      NetProc*proc_;
};

/*
 * A NetEvent is an object that represents an event object, that is
 * objects declared like so in Verilog:
 *
 *        event foo;
 *
 * Once an object of this type exists, behavioral code can wait on the
 * event or trigger the event. Event waits refer to this object, as do
 * the event trigger statements. The NetEvent class may have a name and
 * a scope. The name is a simple name (no hierarchy) and the scope is
 * the NetScope that contains the object. The scope member is written
 * by the NetScope object when the NetEvent is stored.
 *
 * The NetEvWait class represents a thread wait for an event. When
 * this statement is executed, it starts waiting on the
 * event. Conceptually, it puts itself on the event list for the
 * referenced event. When the event is triggered, the wait ends its
 * block and starts the associated statement.
 *
 * The NetEvTrig class represents trigger statements. Executing this
 * statement causes the referenced event to be triggered, which in
 * turn awakens the waiting threads. Each NetEvTrig object references
 * exactly one event object.
 *
 * The NetEvNBTrig class represents non-blocking trigger statements.
 * Executing this statement causes the referenced event to be triggered
 * at some time in the future, which in turn awakens the waiting threads.
 * Each NetEvNBTrig object references exactly one event object.
 *
 * The NetEvProbe class is the structural equivalent of the NetEvTrig,
 * in that it is a node and watches bit values that it receives. It
 * checks for edges then if appropriate triggers the associated
 * NetEvent. Each NetEvProbe references exactly one event object, and
 * the NetEvent objects have a list of NetEvProbe objects that
 * reference it.
 */
class NetEvent : public LineInfo {

      friend class NetScope;
      friend class NetEvProbe;
      friend class NetEvTrig;
      friend class NetEvNBTrig;
      friend class NetEvWait;
      friend class NetEEvent;

    public:
	// The name of the event is the basename, and should not
	// include the scope. Also, the name passed here should be
	// perm-allocated.
      explicit NetEvent (perm_string n);
      ~NetEvent();

      perm_string name() const;

      bool local_flag() const { return local_flag_; }
      void local_flag(bool f) { local_flag_ = f; }

	// Get information about probes connected to me.
      unsigned nprobe() const;
      NetEvProbe* probe(unsigned);
      const NetEvProbe* probe(unsigned) const;

	// Return the number of NetEvWait nodes that reference me.
      unsigned nwait() const;
      unsigned ntrig() const;
      unsigned nexpr() const;

      NetScope* scope();
      const NetScope* scope() const;

      void nex_output(NexusSet&);

	// Locate the first event that matches my behavior and
	// monitors the same signals.
      void find_similar_event(std::list<NetEvent*>&);

	// This method replaces pointers to me with pointers to
	// that. It is typically used to replace similar events
	// located by the find_similar_event method.
      void replace_event(NetEvent*that);

    private:
	// This returns a nexus set if it represents possibly
	// asynchronous inputs, otherwise 0.
      NexusSet*nex_async_();

    private:
      perm_string name_;
      bool local_flag_;

	// The NetScope class uses these to list the events.
      NetScope*scope_;
      NetEvent*snext_;

	// Use these methods to list the probes attached to me.
      NetEvProbe*probes_;

	// Use these methods to list the triggers attached to me.
      NetEvTrig* trig_;

	// Use these methods to list the non-blocking triggers attached to me.
      NetEvNBTrig* nb_trig_;

	// Use This member to count references by NetEvWait objects.
      unsigned waitref_;
      struct wcell_ {
	    NetEvWait*obj;
	    struct wcell_*next;
      };
      struct wcell_ *wlist_;

	// expression references, ala. task/funcs
      unsigned exprref_;

    private: // not implemented
      NetEvent(const NetEvent&);
      NetEvent& operator= (const NetEvent&);
};

class NetEvTrig  : public NetProc {

      friend class NetEvent;

    public:
      explicit NetEvTrig(NetEvent*tgt);
      ~NetEvTrig();

      const NetEvent*event() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      NetEvent*event_;
	// This is used to place me in the NetEvents lists of triggers.
      NetEvTrig*enext_;
};

class NetEvNBTrig  : public NetProc {

      friend class NetEvent;

    public:
      explicit NetEvNBTrig(NetEvent*tgt, NetExpr*dly);
      ~NetEvNBTrig();

      const NetExpr*delay() const;
      const NetEvent*event() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      NetEvent*event_;
      NetExpr*dly_;
	// This is used to place me in the NetEvents lists of triggers.
      NetEvNBTrig*enext_;
};

class NetEvWait  : public NetProc {

    public:
      explicit NetEvWait(NetProc*st);
      ~NetEvWait();

      void add_event(NetEvent*tgt);
      void replace_event(NetEvent*orig, NetEvent*repl);
      inline void set_t0_trigger() { has_t0_trigger_ = true; };

      inline unsigned nevents() const { return events_.size(); }
      inline const NetEvent*event(unsigned idx) const { return events_[idx]; }
      inline NetEvent*event(unsigned idx) { return events_[idx]; }
      inline bool has_t0_trigger() const { return has_t0_trigger_; };

      NetProc*statement();
      const NetProc*statement() const;

      virtual bool emit_proc(struct target_t*) const;
      bool emit_recurse(struct target_t*) const;
      virtual int match_proc(struct proc_match_t*);

	// It is possible that this is the root of a combinational
	// process. This method checks.
      virtual bool is_asynchronous();

	// It is possible that this is the root of a synchronous
	// process? This method checks.
      virtual bool is_synchronous();

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&out);

      virtual bool synth_async(Design*des, NetScope*scope,
			       NexusSet&nex_map, NetBus&nex_out,
			       NetBus&enables, std::vector<mask_t>&bitmasks);

      virtual bool synth_sync(Design*des, NetScope*scope,
			      bool&ff_negedge,
			      NetNet*ff_clk, NetBus&ff_ce,
			      NetBus&ff_aclr,NetBus&ff_aset,
			      std::vector<verinum>&ff_aset_value,
			      NexusSet&nex_map, NetBus&nex_out,
			      std::vector<mask_t>&bitmasks,
			      const std::vector<NetEvProbe*>&events);

      virtual void dump(std::ostream&, unsigned ind) const;
	// This will ignore any statement.
      virtual void dump_inline(std::ostream&) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      NetProc*statement_;
	// Events that I might wait for.
      std::vector<NetEvent*>events_;
      bool has_t0_trigger_;
};

std::ostream& operator << (std::ostream&out, const NetEvWait&obj);

class NetEvProbe  : public NetNode {

      friend class NetEvent;

    public:
      enum edge_t { ANYEDGE, POSEDGE, NEGEDGE, EDGE };

      explicit NetEvProbe(NetScope*s, perm_string n,
			  NetEvent*tgt, edge_t t, unsigned p);
      ~NetEvProbe();

      edge_t edge() const;
      NetEvent* event();
      const NetEvent* event() const;

      void find_similar_probes(std::list<NetEvProbe*>&);

      virtual bool emit_node(struct target_t*) const;
      virtual void dump_node(std::ostream&, unsigned ind) const;

    private:
      NetEvent*event_;
      edge_t edge_;
	// The NetEvent class uses this to list me.
      NetEvProbe*enext_;
};

/*
 * The force statement causes the r-val net to be forced onto the
 * l-val net when it is executed. The code generator is expected to
 * know what that means.
 */
class NetForce  : public NetAssignBase {

    public:
      explicit NetForce(NetAssign_*l, NetExpr*r);
      ~NetForce();

      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool emit_proc(struct target_t*) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
};

/*
 * A forever statement is executed over and over again forever. Or
 * until its block is disabled.
 */
class NetForever : public NetProc {

    public:
      explicit NetForever(NetProc*s);
      ~NetForever();

      void emit_recurse(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      NetProc*statement_;
};

class NetForLoop : public NetProc {

    public:
      explicit NetForLoop(NetNet*index, NetExpr*initial_expr, NetExpr*cond,
			  NetProc*sub, NetProc*step);
      ~NetForLoop();

      void wrap_up();

      void emit_recurse(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

	// synthesize as asynchronous logic, and return true.
      bool synth_async(Design*des, NetScope*scope,
		       NexusSet&nex_map, NetBus&nex_out,
		       NetBus&enables, std::vector<mask_t>&bitmasks);

    private:
      NetNet*index_;
      NetExpr*init_expr_;
      NetExpr*condition_;
      NetProc*statement_;
      NetProc*step_statement_;

	// The code generator needs to see this rewritten as a while
	// loop with synthetic statements. This is a hack that I
	// should probably take out later as the ivl_target learns
	// about for loops.
      NetBlock*as_block_;
};

class NetFree   : public NetProc {

    public:
      explicit NetFree(NetScope*);
      ~NetFree();

      const std::string name() const;

      const NetScope* scope() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;

    private:
      NetScope*scope_;
};

/*
 * A function definition is elaborated just like a task, though by now
 * it is certain that the first parameter (a phantom parameter) is the
 * output and all the remaining parameters are the inputs. This makes
 * for easy code generation in targets that support behavioral
 * descriptions.
 *
 * The NetNet array that is passed in as a parameter is the set of
 * signals that make up its parameter list. These are all internal to
 * the scope of the function.
 */
class NetFuncDef : public NetBaseDef {

    public:
      NetFuncDef(NetScope*, NetNet*result, const std::vector<NetNet*>&po,
		 const std::vector<NetExpr*>&pd);
      ~NetFuncDef();

	// Return true if the function returns "void". We still treat
	// it as a function since we need to check that the contents
	// meet the requirements of a function, but we need to know
	// that it is void because it can be evaluated differently.
      inline bool is_void() const { return result_sig_ == 0; }

	// Non-void functions have a return value as a signal.
      const NetNet*return_sig() const;

	// When we want to evaluate the function during compile time,
	// use this method to pass in the argument and get out a
	// result. The result should be a constant. If the function
	// cannot evaluate to a constant, this returns nil.
      NetExpr* evaluate_function(const LineInfo&loc, const std::vector<NetExpr*>&args) const;

      void dump(std::ostream&, unsigned ind) const;

    private:
      NetNet*result_sig_;
};

/*
 * This class represents delay statements of the form:
 *
 *     #<expr> <statement>
 *
 * Where the statement may be null. The delay is evaluated at
 * elaboration time to make a constant unsigned long that is the delay
 * in simulation ticks.
 *
 * If the delay expression is non-constant, construct the NetPDelay
 * object with a NetExpr* instead of the d value, and use the expr()
 * method to get the expression. If expr() returns 0, use the delay()
 * method to get the constant delay.
 */
class NetPDelay  : public NetProc {

    public:
      NetPDelay(uint64_t d, NetProc*st);
      NetPDelay(NetExpr* d, NetProc*st);
      ~NetPDelay();

      uint64_t delay() const;
      const NetExpr*expr() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);

      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

      bool emit_proc_recurse(struct target_t*) const;

    private:
      uint64_t delay_;
      NetExpr*expr_;
      NetProc*statement_;
};

/*
 * A repeat statement is executed some fixed number of times.
 */
class NetRepeat : public NetProc {

    public:
      explicit NetRepeat(NetExpr*e, NetProc*s);
      ~NetRepeat();

      const NetExpr*expr() const;
      void emit_recurse(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      NetExpr*expr_;
      NetProc*statement_;
};

/*
 * The procedural release statement (the opposite of force) releases
 * any force expressions attached to the bits of the wire or reg. The
 * lval is the expression of the "release <expr>;" statement with the
 * expr elaborated to a net.
 */
class NetRelease : public NetAssignBase {

    public:
      explicit NetRelease(NetAssign_*l);
      ~NetRelease();

      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
};


/*
 * The NetSTask class is a call to a system task. These kinds of tasks
 * are generally handled very simply in the target. They certainly are
 * handled differently from user defined tasks because ivl knows all
 * about the user defined tasks.
 */
class NetSTask  : public NetProc {

    public:
      NetSTask(const char*na, ivl_sfunc_as_task_t sfat,
               const std::vector<NetExpr*>&);
      ~NetSTask();

      const char* name() const;
      ivl_sfunc_as_task_t sfunc_as_task() const;

      unsigned nparms() const;

      const NetExpr* parm(unsigned idx) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      const char* name_;
      ivl_sfunc_as_task_t sfunc_as_task_;
      std::vector<NetExpr*>parms_;
};

/*
 * This class represents an elaborated class definition. NetUTask
 * classes may refer to objects of this type to get the meaning of the
 * defined task.
 *
 * The task also introduces a scope, and the parameters are actually
 * reg objects in the new scope. The task is called by the calling
 * thread assigning (blocking assignment) to the in and inout
 * parameters, then invoking the thread, and finally assigning out the
 * output and inout variables. The variables accessible as ports are
 * also elaborated and accessible as ordinary reg objects.
 */
class NetTaskDef : public NetBaseDef {

    public:
      NetTaskDef(NetScope*n, const std::vector<NetNet*>&po,
		 const std::vector<NetExpr*>&pd);
      ~NetTaskDef();

      void dump(std::ostream&, unsigned) const;
      DelayType delay_type(bool print_delay=false) const;

    private: // not implemented
      NetTaskDef(const NetTaskDef&);
      NetTaskDef& operator= (const NetTaskDef&);
};

/*
 * The NetELast expression node takes as an argument a net, that is
 * intended to be a queue or dynamic array object. The return value is
 * the index of the last item in the node. This is intended to
 * implement the '$' is the expression "foo[$]".
 */
class NetELast : public NetExpr {

    public:
      explicit NetELast(NetNet*sig);
      ~NetELast();

      inline const NetNet*sig() const { return sig_; }

      virtual ivl_variable_type_t expr_type() const;
      virtual void dump(std::ostream&) const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetELast*dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

    private:
      NetNet*sig_;
};

/*
 * This node represents a function call in an expression. The object
 * contains a pointer to the function definition, which is used to
 * locate the value register and input expressions.
 */
class NetEUFunc  : public NetExpr {

    public:
      NetEUFunc(NetScope*, NetScope*, NetESignal*, std::vector<NetExpr*>&, bool);
      ~NetEUFunc();

      const NetESignal*result_sig() const;

      unsigned parm_count() const;
      const NetExpr* parm(unsigned idx) const;

      const NetScope* func() const;

      virtual ivl_variable_type_t expr_type() const;
      virtual const netenum_t* enumeration() const;
      virtual void dump(std::ostream&) const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEUFunc*dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual NetExpr* eval_tree();
      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;

      virtual NetNet* synthesize(Design*des, NetScope*scope, NetExpr*root);

    private:
      NetScope*scope_;
      NetScope*func_;
      NetESignal*result_sig_;
      std::vector<NetExpr*> parms_;
      bool need_const_;

    private: // not implemented
      NetEUFunc(const NetEUFunc&);
      NetEUFunc& operator= (const NetEUFunc&);
};

/*
 * A call to a nature access function for a branch.
 */
class NetEAccess : public NetExpr {

    public:
      explicit NetEAccess(NetBranch*br, ivl_nature_t nat);
      ~NetEAccess();

      ivl_nature_t get_nature() const { return nature_; }
      NetBranch*   get_branch() const { return branch_; }

      virtual ivl_variable_type_t expr_type() const;
      virtual void dump(std::ostream&) const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEAccess*dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

    private:
      NetBranch*branch_;
      ivl_nature_t nature_;
};

/*
 * A call to a user defined task is elaborated into this object. This
 * contains a pointer to the elaborated task definition, but is a
 * NetProc object so that it can be linked into statements.
 */
class NetUTask  : public NetProc {

    public:
      explicit NetUTask(NetScope*);
      ~NetUTask();

      const std::string name() const;

      const NetScope* task() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;

    private:
      NetScope*task_;
};

/*
 * The while statement is a condition that is tested in the front of
 * each iteration, and a statement (a NetProc) that is executed as
 * long as the condition is true.
 */
class NetWhile  : public NetProc {

    public:
      NetWhile(NetExpr*c, NetProc*p)
      : cond_(c), proc_(p) { }

      const NetExpr*expr() const { return cond_; }

      void emit_proc_recurse(struct target_t*) const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void nex_output(NexusSet&);
      virtual bool emit_proc(struct target_t*) const;
      virtual void dump(std::ostream&, unsigned ind) const;
      virtual DelayType delay_type(bool print_delay=false) const;
      virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const;
      virtual bool evaluate_function(const LineInfo&loc,
				     std::map<perm_string,LocalVar>&ctx) const;

    private:
      NetExpr*cond_;
      NetProc*proc_;
};


/*
 * The is the top of any process. It carries the type (initial or
 * always) and a pointer to the statement, probably a block, that
 * makes up the process.
 */
class NetProcTop  : public LineInfo, public Attrib {

    public:
      NetProcTop(NetScope*s, ivl_process_type_t t, class NetProc*st);
      ~NetProcTop();

      ivl_process_type_t type() const { return type_; }
      NetProc*statement();
      const NetProc*statement() const;

      NetScope*scope();
      const NetScope*scope() const;

	/* Return true if this process represents combinational logic. */
      bool is_asynchronous() const;

	/* Create asynchronous logic from this thread and return true,
	   or return false if that cannot be done. */
      bool synth_async(Design*des);

	/* Return true if this process represents synchronous logic. */
      bool is_synchronous();

	/* Create synchronous logic from this thread and return true,
	   or return false if that cannot be done. */
      bool synth_sync(Design*des);

      void dump(std::ostream&, unsigned ind) const;
      bool emit(struct target_t*tgt) const;

    private:
      bool tie_off_floating_inputs_(Design*des,
				    NexusSet&nex_map, NetBus&nex_in,
				    std::vector<NetProc::mask_t>&bitmasks,
				    bool is_ff_input);

      const ivl_process_type_t type_;
      NetProc*const statement_;
      Design*synthesized_design_;

      NetScope*scope_;
      friend class Design;
      NetProcTop*next_;
};

class NetAnalogTop  : public LineInfo, public Attrib {

    public:
      NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetProc*st);
      ~NetAnalogTop();

      ivl_process_type_t type() const { return type_; }

      NetProc*statement();
      const NetProc*statement() const;

      NetScope*scope();
      const NetScope*scope() const;

      void dump(std::ostream&, unsigned ind) const;
      bool emit(struct target_t*tgt) const;

    private:
      const ivl_process_type_t type_;
      NetProc* statement_;

      NetScope*scope_;
      friend class Design;
      NetAnalogTop*next_;
};

/*
 * This class represents a binary operator, with the left and right
 * operands and a single character for the operator. The operator
 * values are:
 *
 *   ^  -- Bit-wise exclusive OR
 *   +  -- Arithmetic add
 *   -  -- Arithmetic minus
 *   *  -- Arithmetic multiply
 *   /  -- Arithmetic divide
 *   %  -- Arithmetic modulus
 *   p  -- Arithmetic power (**)
 *   &  -- Bit-wise AND
 *   |  -- Bit-wise OR
 *   <  -- Less than
 *   >  -- Greater than
 *   e  -- Logical equality (==)
 *   E  -- Case equality (===)
 *   L  -- Less or equal
 *   G  -- Greater or equal
 *   n  -- Logical inequality (!=)
 *   N  -- Case inequality (!==)
 *   a  -- Logical AND (&&)
 *   A  -- Bitwise NAND (~&)
 *   o  -- Logical OR (||)
 *   O  -- Bit-wise NOR (~|)
 *   l  -- Left shift (<<)
 *   r  -- Right shift (>>)
 *   R  -- signed right shift (>>>)
 *   X  -- Bitwise exclusive NOR (~^)
 *   m  -- min(a,b)
 *   M  -- max(a,b)
 */
class NetEBinary  : public NetExpr {

    public:
      NetEBinary(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBinary();

      const NetExpr*left() const { return left_; }
      const NetExpr*right() const { return right_; }

      char op() const { return op_; }

	// A binary expression node only has a definite
	// self-determinable width if the operands both have definite
	// widths.
      virtual bool has_width() const;

      virtual NetEBinary* dup_expr() const;
      virtual NetExpr* eval_tree();
      virtual NetExpr* evaluate_function(const LineInfo&loc,
					 std::map<perm_string,LocalVar>&ctx) const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

    protected:
      char op_;
      NetExpr* left_;
      NetExpr* right_;

      virtual NetExpr* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * The addition operators have slightly more complex width
 * calculations because there is the optional carry bit that can be
 * used. The operators covered by this class are:
 *   +  -- Arithmetic add
 *   -  -- Arithmetic minus
 */
class NetEBAdd : public NetEBinary {

    public:
      NetEBAdd(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBAdd();

      virtual ivl_variable_type_t expr_type() const;

      virtual NetEBAdd* dup_expr() const;
      virtual NetExpr* eval_tree();
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetExpr  * eval_arguments_(const NetExpr*l, const NetExpr*r) const;
      NetECReal* eval_tree_real_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * This class represents the integer division operators.
 *   /  -- Divide
 *   %  -- Modulus
 */
class NetEBDiv : public NetEBinary {

    public:
      NetEBDiv(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBDiv();

      virtual ivl_variable_type_t expr_type() const;

      virtual NetEBDiv* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetExpr* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
      NetExpr* eval_tree_real_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * The bitwise binary operators are represented by this class. This is
 * a specialization of the binary operator, so is derived from
 * NetEBinary. The particular constraints on these operators are that
 * operand and result widths match exactly, and each bit slice of the
 * operation can be represented by a simple gate. The operators
 * covered by this class are:
 *
 *   ^  -- Bit-wise exclusive OR
 *   &  -- Bit-wise AND
 *   |  -- Bit-wise OR
 *   O  -- Bit-wise NOR
 *   X  -- Bit-wise XNOR (~^)
 */
class NetEBBits : public NetEBinary {

    public:
      NetEBBits(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBBits();

      virtual NetEBBits* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetEConst* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * The binary comparison operators are handled by this class. This
 * this case the bit width of the expression is 1 bit, and the
 * operands take their natural widths. The supported operators are:
 *
 *   <  -- Less than
 *   >  -- Greater than
 *   e  -- Logical equality (==)
 *   E  -- Case equality (===)
 *   L  -- Less or equal (<=)
 *   G  -- Greater or equal (>=)
 *   n  -- Logical inequality (!=)
 *   N  -- Case inequality (!==)
 */
class NetEBComp : public NetEBinary {

    public:
      NetEBComp(char op, NetExpr*l, NetExpr*r);
      ~NetEBComp();

	/* A compare expression has a definite width. */
      virtual bool has_width() const;
      virtual ivl_variable_type_t expr_type() const;
      virtual NetEBComp* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetEConst* must_be_leeq_(const NetExpr*le, const verinum&rv, bool eq_flag) const;

      NetEConst*eval_arguments_(const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_eqeq_(bool ne_flag, const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_eqeq_real_(bool ne_flag, const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_less_(const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_leeq_(const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_leeq_real_(const NetExpr*le, const NetExpr*ri, bool eq_flag) const;
      NetEConst*eval_gt_(const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_gteq_(const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_eqeqeq_(bool ne_flag, const NetExpr*le, const NetExpr*re) const;
      NetEConst*eval_weqeq_(bool ne_flag, const NetExpr*le, const NetExpr*re) const;
};

/*
 * The binary logical operators are those that return boolean
 * results. The supported operators are:
 *
 *   a  -- Logical AND (&&)
 *   o  -- Logical OR (||)
 */
class NetEBLogic : public NetEBinary {

    public:
      NetEBLogic(char op, NetExpr*l, NetExpr*r);
      ~NetEBLogic();

      virtual NetEBLogic* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetEConst* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * Support the binary min(l,r) and max(l,r) operators. The opcodes
 * supported are:
 *
 *   m -- min
 *   M -- max
 */
class NetEBMinMax : public NetEBinary {

    public:
      NetEBMinMax(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBMinMax();

      virtual ivl_variable_type_t expr_type() const;

    private:
      NetExpr* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
      NetExpr* eval_tree_real_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * Support the binary multiplication (*) operator.
 */
class NetEBMult : public NetEBinary {

    public:
      NetEBMult(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBMult();

      virtual ivl_variable_type_t expr_type() const;

      virtual NetEBMult* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetExpr* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
      NetExpr* eval_tree_real_(const NetExpr*l, const NetExpr*r) const;
};

/*
 * Support the binary power (**) operator.
 */
class NetEBPow : public NetEBinary {

    public:
      NetEBPow(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBPow();

      virtual ivl_variable_type_t expr_type() const;

      virtual NetEBPow* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetExpr* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
      NetExpr* eval_tree_real_(const NetExpr*l, const NetExpr*r) const;
};


/*
 * Support the binary shift operators. The supported operators are:
 *
 *   l  -- left shift (<<)
 *   r  -- right shift (>>)
 *   R  -- right shift arithmetic (>>>)
 */
class NetEBShift : public NetEBinary {

    public:
      NetEBShift(char op, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag);
      ~NetEBShift();

	// A shift expression only needs the left expression to have a
	// definite width to give the expression a definite width.
      virtual bool has_width() const;

      virtual NetEBShift* dup_expr() const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
      NetEConst* eval_arguments_(const NetExpr*l, const NetExpr*r) const;
};


/*
 * This expression node supports the concat expression. This is an
 * operator that just glues the results of many expressions into a
 * single value.
 *
 * Note that the class stores the parameter expressions in source code
 * order. That is, the parm(0) is placed in the most significant
 * position of the result.
 */
class NetEConcat  : public NetExpr {

    public:
      NetEConcat(unsigned cnt, unsigned repeat, ivl_variable_type_t vt);
      ~NetEConcat();

	// Manipulate the parameters.
      void set(unsigned idx, NetExpr*e);

      unsigned repeat() const { return repeat_; }
      unsigned nparms() const { return parms_.size() ; }
      NetExpr* parm(unsigned idx) const { return parms_[idx]; }

      virtual ivl_variable_type_t expr_type() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual NetEConcat* dup_expr() const;
      virtual NetEConst*  eval_tree();
      virtual NetExpr* evaluate_function(const LineInfo&loc,
					 std::map<perm_string,LocalVar>&ctx) const;
      virtual NetNet*synthesize(Design*, NetScope*scope, NetExpr*root);
      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

    private:
      std::vector<NetExpr*>parms_;
      unsigned repeat_;
      ivl_variable_type_t expr_type_;

      NetEConst* eval_arguments_(const std::vector<NetExpr*>&vals, unsigned gap) const;
};


/*
 * This expression node supports bit/part selects from general
 * expressions. The sub-expression is self-sized, and has bits
 * selected from it. The base is the expression that identifies the
 * lsb of the expression, and the wid is the width of the part select,
 * or 1 for a bit select. No matter what the subexpression is, the
 * base is translated in canonical bits. It is up to the elaborator
 * to figure this out and adjust the expression if the subexpression
 * has a non-canonical base or direction.
 *
 * If the base expression is null, then this expression node can be
 * used to express width expansion, signed or unsigned depending on
 * the has_sign() flag.
 *
 * An alternative form of this expression node is used for dynamic
 * array word selects and for packed struct member selects. In this
 * case use_type indicates the type of the selected element/member.
 */
class NetESelect  : public NetExpr {

    public:
      NetESelect(NetExpr*exp, NetExpr*base, unsigned wid,
                 ivl_select_type_t sel_type = IVL_SEL_OTHER);
      NetESelect(NetExpr*exp, NetExpr*base, unsigned wid,
                 ivl_type_t use_type);
      ~NetESelect();

      const NetExpr*sub_expr() const;
      const NetExpr*select() const;
      ivl_select_type_t select_type() const;

	// The type of a bit/part select is the base type of the
	// sub-expression. The type of an array/member select is
	// the base type of the element/member.
      virtual ivl_variable_type_t expr_type() const;
      virtual const netenum_t* enumeration() const;

      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEConst* eval_tree();
      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;
      virtual NetESelect* dup_expr() const;
      virtual NetNet*synthesize(Design*des, NetScope*scope, NetExpr*root);
      virtual void dump(std::ostream&) const;

    private:
      NetExpr*expr_;
      NetExpr*base_;
      ivl_type_t use_type_;
      ivl_select_type_t sel_type_;
};

/*
 * This node is for representation of named events.
 */
class NetEEvent : public NetExpr {

    public:
      explicit NetEEvent(NetEvent*);
      ~NetEEvent();

      const NetEvent* event() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEEvent* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;

    private:
      NetEvent*event_;
};

/*
 * This class is a special (and magical) expression node type that
 * represents enumeration types. These can only be found as parameters
 * to NetSTask objects.
 */
class NetENetenum  : public NetExpr {

    public:
      explicit NetENetenum(const netenum_t*);
      ~NetENetenum();

      const netenum_t* netenum() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetENetenum* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;

    private:
      const netenum_t*netenum_;
};

class NetENew : public NetExpr {
    public:
	// Make class object
      explicit NetENew(ivl_type_t);
	// dynamic array of objects.
      explicit NetENew(ivl_type_t, NetExpr*size, NetExpr* init_val=0);
      ~NetENew();

      inline ivl_type_t get_type() const { return obj_type_; }
      inline const NetExpr*size_expr() const { return size_; }
      inline const NetExpr*init_expr() const { return init_val_; }

      virtual ivl_variable_type_t expr_type() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetENew* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;

    private:
      ivl_type_t obj_type_;
      NetExpr*size_;
      NetExpr*init_val_;
};

/*
 * The NetENull node represents the SystemVerilog (null)
 * expression. This is always a null class handle.
 */
class NetENull : public NetExpr {

    public:
      NetENull();
      ~NetENull();

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetENull* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;
};

/*
 * The NetEProperty represents a SystemVerilog property select of a
 * class object. In SV, the expression would look like "a.b", where
 * the "a" is the signal (the NetNet) and "b" is the property name.
 *
 * The canon_index is an optional expression to address an element for
 * parameters that are arrays.
 */
class NetEProperty : public NetExpr {
    public:
      NetEProperty(NetNet*n, size_t pidx_, NetExpr*canon_index =0);
      ~NetEProperty();

      inline const NetNet* get_sig() const { return net_; }
      inline size_t property_idx() const { return pidx_; }
      inline const NetExpr*get_index() const { return index_; }

    public: // Overridden methods
      ivl_variable_type_t expr_type() const;
      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEProperty* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;

    private:
      NetNet*net_;
      size_t pidx_;
      NetExpr*index_;
};

/*
 * This class is a special (and magical) expression node type that
 * represents scope names. These can only be found as parameters to
 * NetSTask objects.
 */
class NetEScope  : public NetExpr {

    public:
      explicit NetEScope(NetScope*);
      ~NetEScope();

      const NetScope* scope() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEScope* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;

    private:
      NetScope*scope_;
};

/*
 * This node represents a system function call in an expression. The
 * object contains the name of the system function, which the backend
 * uses to do VPI matching.
 */
class NetESFunc  : public NetExpr {

    public:
      NetESFunc(const char*name, ivl_variable_type_t t,
		unsigned width, unsigned nprms, bool is_overridden =false);
      NetESFunc(const char*name, ivl_type_t rtype, unsigned nprms);
      ~NetESFunc();

      const char* name() const;

      unsigned nparms() const;
      void parm(unsigned idx, NetExpr*expr);
      NetExpr* parm(unsigned idx);
      const NetExpr* parm(unsigned idx) const;

      virtual NetExpr* eval_tree();
      virtual NetExpr* evaluate_function(const LineInfo&loc,
					 std::map<perm_string,LocalVar>&ctx) const;

      virtual ivl_variable_type_t expr_type() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual const netenum_t* enumeration() const;
      virtual void dump(std::ostream&) const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetESFunc*dup_expr() const;
      virtual NetNet*synthesize(Design*, NetScope*scope, NetExpr*root);

    private:
	/* Use the 32 bit ID as follows:
	 *   The lower sixteen bits are used to identify the individual
	 *   functions.
	 *
	 *   The top sixteen bits are used to indicate the number of
	 *   arguments the function can take by bit position. If more
	 *   than one bit is set the argument can take a different number
	 *   of arguments. This varies from 0 to 14 with the MSB indicating
	 *   fifteen or more (an unbounded value). For example all bit set
	 *   except for the LSB indicate 1 or more arguments are allowed.
	 */
      enum ID { NOT_BUILT_IN = 0x0,
                  /* Available in all version of Verilog/SystemVerilog. */
                ITOR   = 0x00020001,  /* $itor takes one argument. */
                RTOI   = 0x00020002,  /* $rtoi takes one argument. */
                  /* Available in Verilog 2005 and later. */
                ACOS   = 0x00020003,  /* $acos takes one argument. */
                ACOSH  = 0x00020004,  /* $acosh takes one argument. */
                ASIN   = 0x00020005,  /* $asin takes one argument. */
                ASINH  = 0x00020006,  /* $asinh takes one argument. */
                ATAN   = 0x00020007,  /* $atan takes one argument. */
                ATANH  = 0x00020008,  /* $atanh takes one argument. */
                ATAN2  = 0x00040009,  /* $atan2 takes two argument. */
                CEIL   = 0x0002000a,  /* $ceil takes one argument. */
                CLOG2  = 0x0002000b,  /* $clog2 takes one argument. */
                COS    = 0x0002000c,  /* $cos takes one argument. */
                COSH   = 0x0002000d,  /* $cosh takes one argument. */
                EXP    = 0x0002000e,  /* $exp takes one argument. */
                FLOOR  = 0x0002000f,  /* $floor takes one argument. */
                HYPOT  = 0x00040010,  /* $hypot takes two argument. */
                LN     = 0x00020011,  /* $ln takes one argument. */
                LOG10  = 0x00020012,  /* $log10 takes one argument. */
                POW    = 0x00040013,  /* $pow takes two argument. */
                SIN    = 0x00020014,  /* $sin takes one argument. */
                SINH   = 0x00020015,  /* $sinh takes one argument. */
                SQRT   = 0x00020016,  /* $sqrt takes one argument. */
                TAN    = 0x00020017,  /* $tan takes one argument. */
                TANH   = 0x00020018,  /* $tanh takes one argument. */
                  /* Added in SystemVerilog 2005 and later. */
                DIMS   = 0x00020019,  /* $dimensions takes one argument. */
                HIGH   = 0x0006001a,  /* $high takes one or two arguments. */
                INCR   = 0x0006001b,  /* $increment takes one or two arguments. */
                LEFT   = 0x0006001c,  /* $left takes one or two arguments. */
                LOW    = 0x0006001d,  /* $low takes one or two arguments. */
                RIGHT  = 0x0006001e,  /* $right takes one or two arguments. */
                SIZE   = 0x0006001f,  /* $size takes one or two arguments. */
                UPDIMS = 0x00020020,  /* $unpacked_dimensions takes one argument. */
                ISUNKN = 0x00020021,  /* $isunknown takes one argument. */
                ONEHT  = 0x00020022,  /* $onehot takes one argument. */
                ONEHT0 = 0x00020023,  /* $onehot0 takes one argument. */
                  /* Added in SystemVerilog 2009 and later. */
                CTONES = 0x00020024,  /* $countones takes one argument. */
                  /* Added in SystemVerilog 2012 and later. */
                CTBITS = 0xfffc0025,  /* $countbits takes two or more arguments. */
                  /* Added as Icarus extensions to Verilog-A. */
                ABS    = 0x00020026,  /* $abs takes one argument. */
                MAX    = 0x00040027,  /* $max takes two argument. */
                MIN    = 0x00040028,  /* $min takes two argument. */
                  /* A dummy value to properly close the enum. */
		DUMMY  = 0xffffffff };

      bool takes_nargs_(ID func, unsigned nargs) {
	    if (nargs > 15) nargs = 15;
	    return func & (1U << (nargs + 16));
      }

      const char* name_;
      ivl_variable_type_t type_;
      const netenum_t*enum_type_;
      std::vector<NetExpr*>parms_;
      bool is_overridden_;

      ID built_in_id_() const;

      NetExpr* evaluate_one_arg_(ID id, const NetExpr*arg) const;
      NetExpr* evaluate_two_arg_(ID id, const NetExpr*arg0,
					const NetExpr*arg1) const;

      NetEConst* evaluate_rtoi_(const NetExpr*arg) const;
      NetECReal* evaluate_itor_(const NetExpr*arg) const;

      NetEConst* evaluate_clog2_(const NetExpr*arg) const;

      NetECReal* evaluate_math_one_arg_(ID id, const NetExpr*arg) const;
      NetECReal* evaluate_math_two_arg_(ID id, const NetExpr*arg0,
					       const NetExpr*arg1) const;

      NetExpr* evaluate_abs_(const NetExpr*arg) const;
      NetExpr* evaluate_min_max_(ID id, const NetExpr*arg0,
					const NetExpr*arg1) const;

	/* Constant SystemVerilog functions. */
      NetEConst* evaluate_countones_(const NetExpr*arg) const;
      NetEConst* evaluate_dimensions_(const NetExpr*arg) const;
      NetEConst* evaluate_isunknown_(const NetExpr*arg) const;
      NetEConst* evaluate_onehot_(const NetExpr*arg) const;
      NetEConst* evaluate_onehot0_(const NetExpr*arg) const;
      NetEConst* evaluate_unpacked_dimensions_(const NetExpr*arg) const;

	/* This value is used as a default when the array functions are
	 * called with a single argument. */
      static const NetEConst*const_one_;

      NetEConst* evaluate_array_funcs_(ID id,
                                       const NetExpr*arg0,
                                       const NetExpr*arg1) const;
      NetEConst* evaluate_countbits_(void) const;

    public:
      bool is_built_in() const { return built_in_id_() != NOT_BUILT_IN; };

    private: // not implemented
      NetESFunc(const NetESFunc&);
      NetESFunc& operator= (const NetESFunc&);
};

class NetEShallowCopy : public NetExpr {
    public:
	// Make a shallow copy from arg2 into arg1.
      explicit NetEShallowCopy(NetExpr*arg1, NetExpr*arg2);
      ~NetEShallowCopy();

      virtual ivl_variable_type_t expr_type() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual NetEShallowCopy* dup_expr() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;

      virtual void dump(std::ostream&os) const;

      void expr_scan_oper1(struct expr_scan_t*) const;
      void expr_scan_oper2(struct expr_scan_t*) const;

    private:
      NetExpr*arg1_;
      NetExpr*arg2_;
};

/*
 * This class represents the ternary (?:) operator. It has 3
 * expressions, one of which is a condition used to select which of
 * the other two expressions is the result.
 */
class NetETernary  : public NetExpr {

    public:
      NetETernary(NetExpr*c, NetExpr*t, NetExpr*f, unsigned wid, bool signed_flag);
      ~NetETernary();

      const netenum_t* enumeration() const;

      const NetExpr*cond_expr() const;
      const NetExpr*true_expr() const;
      const NetExpr*false_expr() const;

      virtual NetETernary* dup_expr() const;
      virtual NetExpr* eval_tree();
      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;
      virtual ivl_variable_type_t expr_type() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;
      virtual NetNet*synthesize(Design*, NetScope*scope, NetExpr*root);

    public:
      static bool test_operand_compat(ivl_variable_type_t tru, ivl_variable_type_t fal);

    private:
      NetExpr* blended_arguments_(const NetExpr*t, const NetExpr*f) const;

      NetExpr*cond_;
      NetExpr*true_val_;
      NetExpr*false_val_;
};

/*
 * This class represents a unary operator, with the single operand
 * and a single character for the operator. The operator values are:
 *
 *   ~  -- Bit-wise negation
 *   !  -- Logical negation
 *   &  -- Reduction AND
 *   |  -- Reduction OR
 *   ^  -- Reduction XOR
 *   +  --
 *   -  --
 *   A  -- Reduction NAND (~&)
 *   N  -- Reduction NOR (~|)
 *   X  -- Reduction NXOR (~^ or ^~)
 *   m  -- abs(x)  (i.e. "magnitude")
 *   v  -- Cast from real to integer (vector)
 *   2  -- Cast from real or logic (vector) to bool (vector)
 *   r  -- Cast from integer (vector) to real
 *   i  -- post-increment
 *   I  -- pre-increment
 *   d  -- post-decrement
 *   D  -- pre-decrement
 */
class NetEUnary  : public NetExpr {

    public:
      NetEUnary(char op, NetExpr*ex, unsigned wid, bool signed_flag);
      ~NetEUnary();

      char op() const { return op_; }
      const NetExpr* expr() const { return expr_; }

      virtual NetEUnary* dup_expr() const;
      virtual NetExpr* eval_tree();
      virtual NetExpr* evaluate_function(const LineInfo&loc,
					 std::map<perm_string,LocalVar>&ctx) const;
      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

      virtual ivl_variable_type_t expr_type() const;
      virtual NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                                  bool nested_func = false) const;
      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

    protected:
      char op_;
      NetExpr* expr_;

    private:
      virtual NetExpr* eval_arguments_(const NetExpr*ex) const;
      virtual NetExpr* eval_tree_real_(const NetExpr*ex) const;
};

class NetEUBits : public NetEUnary {

    public:
      NetEUBits(char op, NetExpr*ex, unsigned wid, bool signed_flag);
      ~NetEUBits();

      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);

      virtual NetEUBits* dup_expr() const;
      virtual ivl_variable_type_t expr_type() const;
};

class NetEUReduce : public NetEUnary {

    public:
      NetEUReduce(char op, NetExpr*ex);
      ~NetEUReduce();

      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);
      virtual NetEUReduce* dup_expr() const;
      virtual ivl_variable_type_t expr_type() const;

    private:
      virtual NetEConst* eval_arguments_(const NetExpr*ex) const;
      virtual NetEConst* eval_tree_real_(const NetExpr*ex) const;
};

class NetECast : public NetEUnary {

    public:
      NetECast(char op, NetExpr*ex, unsigned wid, bool signed_flag);
      ~NetECast();

      virtual NetNet* synthesize(Design*, NetScope*scope, NetExpr*root);
      virtual NetECast* dup_expr() const;
      virtual ivl_variable_type_t expr_type() const;
      virtual void dump(std::ostream&) const;

    private:
      virtual NetExpr* eval_arguments_(const NetExpr*ex) const;
};

/*
 * When a signal shows up in an expression, this type represents
 * it. From this the expression can get any kind of access to the
 * structural signal, including arrays.
 *
 * The NetESignal may refer to an array, if the word_index is
 * included. This expression calculates the index of the word in the
 * array. It may only be nil if the expression refers to the whole
 * array, and that is legal only in limited situation.
 */
class NetESignal  : public NetExpr {

    public:
      explicit NetESignal(NetNet*n);
      NetESignal(NetNet*n, NetExpr*word_index);
      ~NetESignal();

      perm_string name() const;

      virtual NetESignal* dup_expr() const;
      NetNet* synthesize(Design*des, NetScope*scope, NetExpr*root);
      NexusSet* nex_input(bool rem_out = true, bool always_sens = false,
                          bool nested_func = false) const;
      NexusSet* nex_input_base(bool rem_out, bool always_sens, bool nested_func,
                               unsigned base, unsigned width) const;
      const netenum_t*enumeration() const;

      virtual NetExpr*evaluate_function(const LineInfo&loc,
					std::map<perm_string,LocalVar>&ctx) const;

	// This is the expression for selecting an array word, if this
	// signal refers to an array.
      const NetExpr* word_index() const;

	// This is the width of the vector that this signal refers to.
      unsigned vector_width() const;
	// Point back to the signal that this expression node references.
      const NetNet* sig() const;
      NetNet* sig();
	// Declared vector dimensions for the signal.
      long msi() const;
      long lsi() const;

      virtual ivl_variable_type_t expr_type() const;

      virtual void expr_scan(struct expr_scan_t*) const;
      virtual void dump(std::ostream&) const;

    private:
      NetNet*net_;
      const netenum_t*enum_type_;
	// Expression to select a word from the net.
      NetExpr*word_;
};

/*
 * The Design object keeps a list of work items for processing
 * elaboration. This is the type of those work items.
 */
struct elaborator_work_item_t {
      explicit elaborator_work_item_t(Design*d)
      : des(d) { }
      virtual ~elaborator_work_item_t() { }
      virtual void elaborate_runrun() =0;
    protected:
      Design*des;
};

/*
 * This class contains an entire design. It includes processes and a
 * netlist, and can be passed around from function to function.
 */
class Design {

    public:
      Design();
      ~Design();

	/* We need to pass the tool delay selection for $sdf_annotate. */
      enum delay_sel_t { MIN, TYP, MAX };
      void set_delay_sel(delay_sel_t sel);
      const char* get_delay_sel() const;

	/* The flags are a generic way of accepting command line
	   parameters/flags and passing them to the processing steps
	   that deal with the design. The compilation driver sets the
	   entire flags map after elaboration is done. Subsequent
	   steps can then use the get_flag() function to get the value
	   of an interesting key. */

      void set_flags(const std::map<std::string,const char*>&f) { flags_ = f; }

      const char* get_flag(const std::string&key) const;

      NetScope* make_root_scope(perm_string name, NetScope*unit_scope,
				bool program_block, bool is_interface);
      NetScope* find_root_scope();
      std::list<NetScope*> find_root_scopes() const;

      NetScope* make_package_scope(perm_string name, NetScope*unit_scope,
				   bool is_unit);
      std::list<NetScope*> find_package_scopes() const;

	/* Attempt to set the precision to the specified value. If the
	   precision is already more precise, the keep the precise
	   setting. This is intended to hold the simulation precision
	   for use throughout the entire design. */

      void set_precision(int val);
      int  get_precision() const;

	/* This function takes a delay value and a scope, and returns
	   the delay value scaled to the precision of the design. */
      uint64_t scale_to_precision(uint64_t, const NetScope*)const;

	/* Look up a scope. If no starting scope is passed, then the
	   path is taken as an absolute scope name. Otherwise, the
	   scope is located starting at the passed scope and working
	   up if needed. */
      NetScope* find_scope(const hname_t&path) const;
      NetScope* find_scope(NetScope*, const hname_t&name,
                           NetScope::TYPE type = NetScope::MODULE) const;

      NetScope* find_package(perm_string name) const;

	// Note: Try to remove these versions of find_scope. Avoid
	// using these in new code, use the above forms (or
	// symbol_search) instead.
      NetScope* find_scope(const std::list<hname_t>&path) const;
      NetScope* find_scope(NetScope*, const std::list<hname_t>&path,
                           NetScope::TYPE type = NetScope::MODULE) const;

	/* These members help manage elaboration of scopes. When we
	   get to a point in scope elaboration where we want to put
	   off a scope elaboration, an object of scope_elaboration_t
	   is pushed onto the scope_elaborations list. The scope
	   elaborator will go through this list elaborating scopes
	   until the list is empty. */
      std::list<elaborator_work_item_t*>elaboration_work_list;
      void run_elaboration_work(void);

      std::set<NetScope*> defparams_later;

	// PARAMETERS

      void run_defparams();
      void evaluate_parameters();
	// Look for defparams that never matched, and print warnings.
      void residual_defparams();

	/* This method locates a signal, starting at a given
	   scope. The name parameter may be partially hierarchical, so
	   this method, unlike the NetScope::find_signal method,
	   handles global name binding. */

      NetNet*find_signal(NetScope*scope, pform_name_t path);

	// Functions
      NetFuncDef* find_function(NetScope*scope, const pform_name_t&key);

	// Tasks
      NetScope* find_task(NetScope*scope, const pform_name_t&name);

	// NODES
      void add_node(NetNode*);
      void del_node(NetNode*);

	// BRANCHES
      void add_branch(NetBranch*);

	// PROCESSES
      void add_process(NetProcTop*);
      void add_process(NetAnalogTop*);
      void delete_process(NetProcTop*);
      bool check_proc_delay() const;
      bool check_proc_synth() const;

      NetNet* find_discipline_reference(ivl_discipline_t dis, NetScope*scope);

	// Iterate over the design...
      void dump(std::ostream&) const;
      void functor(struct functor_t*);
      void join_islands(void);
      int emit(struct target_t*) const;

	// This is incremented by elaboration when an error is
	// detected. It prevents code being emitted.
      unsigned errors;

    private:
      NetScope* find_scope_(NetScope*, const hname_t&name,
                            NetScope::TYPE type = NetScope::MODULE) const;

      NetScope* find_scope_(NetScope*, const std::list<hname_t>&path,
                            NetScope::TYPE type = NetScope::MODULE) const;

	// Keep a tree of scopes. The NetScope class handles the wide
	// tree and per-hop searches for me.
      std::list<NetScope*>root_scopes_;

	// Keep a map of all the elaborated packages. Note that
	// packages do not nest.
      std::map<perm_string,NetScope*>packages_;

	// List the nodes in the design.
      NetNode*nodes_;
	// These are in support of the node functor iterator.
      NetNode*nodes_functor_cur_;
      NetNode*nodes_functor_nxt_;

	// List the branches in the design.
      NetBranch*branches_;

	// List the processes in the design.
      NetProcTop*procs_;
      NetProcTop*procs_idx_;

	// List the ANALOG processes in the design.
      NetAnalogTop*aprocs_;

	// Map of discipline take to NetNet for the reference node.
      std::map<perm_string,NetNet*>discipline_references_;

	// Map the design arguments to values.
      std::map<std::string,const char*> flags_;

      int des_precision_;
      delay_sel_t des_delay_sel_;

    private: // not implemented
      Design(const Design&);
      Design& operator= (const Design&);
};


/* =======
 */

inline bool operator == (const Link&l, const Link&r)
{ return l.is_equal(r); }

inline bool operator != (const Link&l, const Link&r)
{ return ! l.is_equal(r); }

/* Connect the pins of two nodes together. Either may already be
   connected to other things, connect is transitive. */
extern void connect(Link&, Link&);

/* Return true if l and r are connected. */
inline bool connected(const Link&l, const Link&r)
{ return l.is_linked(r); }

/* Return the number of signals in the nexus. */
extern unsigned count_signals(const Link&pin);

/* Find the next link that is an output into the nexus. */
extern Link* find_next_output(Link*lnk);

/* Find the signal connected to the given node pin. There should
   always be exactly one signal. The bidx parameter gets filled with
   the signal index of the Net, in case it is a vector. */
const NetNet* find_link_signal(const NetObj*net, unsigned pin,
			       unsigned&bidx);

inline std::ostream& operator << (std::ostream&o, const NetExpr&exp)
{ exp.dump(o); return o; }

extern std::ostream& operator << (std::ostream&, NetNet::Type);

/*
 * Manipulator to dump a scope complete path to the output. The
 * manipulator is "scope_path" and works like this:
 *
 *   out << .... << scope_path(sc) << ... ;
 */
struct __ScopePathManip { const NetScope*scope; };
inline __ScopePathManip scope_path(const NetScope*scope)
{ __ScopePathManip tmp; tmp.scope = scope; return tmp; }

extern std::ostream& operator << (std::ostream&o, __ScopePathManip);

struct __ObjectPathManip { const NetObj*obj; };
inline __ObjectPathManip scope_path(const NetObj*obj)
{ __ObjectPathManip tmp; tmp.obj = obj; return tmp; }

extern std::ostream& operator << (std::ostream&o, __ObjectPathManip);

/*
 * If this link has a nexus_ pointer, then it is the last Link in the
 * list. next_nlink() returns 0 for the last Link.
 */
inline Link* Link::next_nlink()
{
      if (nexus_) return 0;
      else return next_;
}

inline const Link* Link::next_nlink() const
{
      if (nexus_) return 0;
      else return next_;
}

inline NetPins*Link::get_obj()
{
      if (pin_zero_)
	    return node_;
      Link*tmp = this - pin_;
      assert(tmp->pin_zero_);
      return tmp->node_;
}

inline const NetPins*Link::get_obj() const
{
      if (pin_zero_)
	    return node_;
      const Link*tmp = this - pin_;
      assert(tmp->pin_zero_);
      return tmp->node_;
}

inline unsigned Link::get_pin() const
{
      if (pin_zero_)
	    return 0;
      else
	    return pin_;
}

#undef ENUM_UNSIGNED_INT
#endif /* IVL_netlist_H */