Codebase list gtkwave / 457be729-5368-47f5-83d0-c4fdf3c09209/main src / vcd_recoder.c
457be729-5368-47f5-83d0-c4fdf3c09209/main

Tree @457be729-5368-47f5-83d0-c4fdf3c09209/main (Download .tar.gz)

vcd_recoder.c @457be729-5368-47f5-83d0-c4fdf3c09209/mainraw · history · blame

   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
/*
 * Copyright (c) Tony Bybell 1999-2017.
 *
 * This program is free software; you can redistribute it and/or
 * modify it 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.
 */


/*
 * vcd.c 			23jan99ajb
 * evcd parts 			29jun99ajb
 * profiler optimizations 	15jul99ajb
 * more profiler optimizations	25jan00ajb
 * finsim parameter fix		26jan00ajb
 * vector rechaining code	03apr00ajb
 * multiple var section code	06apr00ajb
 * fix for duplicate nets	19dec00ajb
 * support for alt hier seps	23dec00ajb
 * fix for rcs identifiers	16jan01ajb
 * coredump fix for bad VCD	04apr02ajb
 * min/maxid speedup            27feb03ajb
 * bugfix on min/maxid speedup  06jul03ajb
 * escaped hier modification    20feb06ajb
 * added real_parameter vartype 04aug06ajb
 * recoder using vlists         17aug06ajb
 * code cleanup                 04sep06ajb
 * added in/out port vartype    31jan07ajb
 * use gperf for port vartypes  19feb07ajb
 * MTI SV implicit-var fix      05apr07ajb
 * MTI SV len=0 is real var     05apr07ajb
 * VCD fastloading		05mar09ajb
 * Backtracking fix             16oct18ajb
 */
#include <config.h>
#include "globals.h"
#include "vcd.h"
#include "vlist.h"
#include "lx2.h"
#include "hierpack.h"

/**/

static void malform_eof_fix(void)
{
if(feof(GLOBALS->vcd_handle_vcd_recoder_c_2))
	{
        memset(GLOBALS->vcdbuf_vcd_recoder_c_3, ' ', VCD_BSIZ);
        GLOBALS->vst_vcd_recoder_c_3=GLOBALS->vend_vcd_recoder_c_3;
        }
}

/**/

static void vlist_packer_emit_uv64(struct vlist_packer_t **vl, guint64 v)
{
guint64 nxt;

while((nxt = v>>7))
        {
	vlist_packer_alloc(*vl, v&0x7f);
        v = nxt;
        }

vlist_packer_alloc(*vl, (v&0x7f) | 0x80);
}


static void vlist_packer_emit_utt(struct vlist_packer_t **vl, UTimeType v)
{
UTimeType nxt;

while((nxt = v>>7))
        {
	vlist_packer_alloc(*vl, v&0x7f);
        v = nxt;
        }

vlist_packer_alloc(*vl, (v&0x7f) | 0x80);
}


static void vlist_packer_emit_uv32(struct vlist_packer_t **vl, unsigned int v)
{
unsigned int nxt;

while((nxt = v>>7))
        {
	vlist_packer_alloc(*vl, v&0x7f);
        v = nxt;
        }

vlist_packer_alloc(*vl, (v&0x7f) | 0x80);
}


static void vlist_packer_emit_string(struct vlist_packer_t **vl, char *s)
{
while(*s)
	{
	vlist_packer_alloc(*vl, *s);
	s++;
	}
vlist_packer_alloc(*vl, 0);
}

static void vlist_packer_emit_mvl9_string(struct vlist_packer_t **vl, char *s)
{
unsigned int recoded_bit;
unsigned char which = 0;
unsigned char accum = 0;

while(*s)
	{
	switch(*s)
	        {
	        case '0':		recoded_bit = AN_0; break;
	        case '1':		recoded_bit = AN_1; break;
	        case 'x': case 'X':	recoded_bit = AN_X; break;
	        case 'z': case 'Z':	recoded_bit = AN_Z; break;
	        case 'h': case 'H':	recoded_bit = AN_H; break;
	        case 'u': case 'U':	recoded_bit = AN_U; break;
	        case 'w': case 'W':     recoded_bit = AN_W; break;
	        case 'l': case 'L':	recoded_bit = AN_L; break;
		default:		recoded_bit = AN_DASH; break;
		}

	if(!which)
		{
		accum = (recoded_bit << 4);
		which = 1;
		}
		else
		{
		accum |= recoded_bit;
		vlist_packer_alloc(*vl, accum);
		which = accum = 0;
		}
	s++;
	}

recoded_bit = AN_MSK; /* XXX : this is assumed it is going to remain a 4 bit max quantity! */
if(!which)
	{
        accum = (recoded_bit << 4);
        }
        else
        {
        accum |= recoded_bit;
        }

vlist_packer_alloc(*vl, accum);
}

/**/

static void vlist_emit_uv32(struct vlist_t **vl, unsigned int v)
{
unsigned int nxt;
char *pnt;

if(GLOBALS->vlist_prepack) { vlist_packer_emit_uv32((struct vlist_packer_t **)vl, v); return; }

while((nxt = v>>7))
        {
	pnt = vlist_alloc(vl, 1);
        *pnt = (v&0x7f);
        v = nxt;
        }

pnt = vlist_alloc(vl, 1);
*pnt = (v&0x7f) | 0x80;
}


static void vlist_emit_string(struct vlist_t **vl, char *s)
{
char *pnt;

if(GLOBALS->vlist_prepack) { vlist_packer_emit_string((struct vlist_packer_t **)vl, s); return; }

while(*s)
	{
	pnt = vlist_alloc(vl, 1);
	*pnt = *s;
	s++;
	}
pnt = vlist_alloc(vl, 1);
*pnt = 0;
}

static void vlist_emit_mvl9_string(struct vlist_t **vl, char *s)
{
char *pnt;
unsigned int recoded_bit;
unsigned char which;
unsigned char accum;

if(GLOBALS->vlist_prepack) { vlist_packer_emit_mvl9_string((struct vlist_packer_t **)vl, s); return; }

which = accum = 0;

while(*s)
	{
	switch(*s)
	        {
	        case '0':		recoded_bit = AN_0; break;
	        case '1':		recoded_bit = AN_1; break;
	        case 'x': case 'X':	recoded_bit = AN_X; break;
	        case 'z': case 'Z':	recoded_bit = AN_Z; break;
	        case 'h': case 'H':	recoded_bit = AN_H; break;
	        case 'u': case 'U':	recoded_bit = AN_U; break;
	        case 'w': case 'W':     recoded_bit = AN_W; break;
	        case 'l': case 'L':	recoded_bit = AN_L; break;
		default:		recoded_bit = AN_DASH; break;
		}

	if(!which)
		{
		accum = (recoded_bit << 4);
		which = 1;
		}
		else
		{
		accum |= recoded_bit;
		pnt = vlist_alloc(vl, 1);
		*pnt = accum;
		which = accum = 0;
		}
	s++;
	}

recoded_bit = AN_MSK; /* XXX : this is assumed it is going to remain a 4 bit max quantity! */
if(!which)
	{
        accum = (recoded_bit << 4);
        }
        else
        {
        accum |= recoded_bit;
        }

pnt = vlist_alloc(vl, 1);
*pnt = accum;
}

/**/

static void write_fastload_time_section(void)
{
struct vlist_t *vlist;
struct vlist_packer_t *vlist_p;

/* emit blackout regions */
if(GLOBALS->blackout_regions)
	{
	struct blackout_region_t *bt = GLOBALS->blackout_regions;
	unsigned int bcnt = 0;
	while(bt)
		{
		bcnt++;
		bt = bt->next;
		}

	vlist_packer_emit_uv32((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, bcnt);

	bt = GLOBALS->blackout_regions;
	while(bt)
		{
		vlist_packer_emit_utt((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, bt->bstart);
		vlist_packer_emit_utt((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, bt->bend);
		bt = bt->next;
		}
	}
	else
	{
	vlist_packer_emit_uv32((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, 0);
	}

vlist_p = (struct vlist_packer_t *)GLOBALS->time_vlist_vcd_recoder_write;
vlist_packer_finalize(vlist_p);
vlist = vlist_p->v;
free_2(vlist_p);
GLOBALS->time_vlist_vcd_recoder_write = vlist;
vlist_freeze(&GLOBALS->time_vlist_vcd_recoder_write);
}

#ifdef HAVE_SYS_STAT_H
static void write_fastload_header(struct stat *mystat, unsigned int finalize_cnt)
#else
static void write_fastload_header(unsigned int finalize_cnt)
#endif
{
/*
write out the trailer information for vcd fastload...

vcd file size
vcd last modification time
number of finalize values
number of variable-length integer values in the time table (GLOBALS->time_vlist_count_vcd_recoder_c_1)
GLOBALS->time_vlist_vcd_recoder_write value
deltas from GLOBALS->time_vlist_vcd_recoder_write and on though stepping through list generated by vlist_emit_finalize()
*/

struct vlist_packer_t *vlist_p = vlist_packer_create();
struct vlist_t *vlist_summary_index;

struct vcdsymbol *v = GLOBALS->vcdsymroot_vcd_recoder_c_3;
guint64 val = (guint64)(uintptr_t)GLOBALS->time_vlist_vcd_recoder_write;
guint64 nval;
char buf[33];
char *pnt;

memset(buf, 0, sizeof(buf)); /* scan-build */

#ifdef HAVE_SYS_STAT_H
vlist_packer_emit_uv64(&vlist_p, (guint64)mystat->st_size);
vlist_packer_emit_uv64(&vlist_p, (guint64)mystat->st_mtime);
#else
vlist_packer_emit_uv64(&vlist_p, (guint64)0);
vlist_packer_emit_uv64(&vlist_p, (guint64)0);
#endif

vlist_packer_emit_uv32(&vlist_p, finalize_cnt);
vlist_packer_emit_uv64(&vlist_p, GLOBALS->time_vlist_count_vcd_recoder_c_1);

vlist_packer_emit_uv64(&vlist_p, val);
val = 0;
while(v)
	{
	nptr n = v->narray[0];
	nval = (guint64)(uintptr_t)n->mv.mvlfac_vlist;

	vlist_packer_emit_uv64(&vlist_p, nval - val);
	val = nval;

	v = v->next;
	}

vlist_packer_finalize(vlist_p);
vlist_summary_index = vlist_p->v;
free_2(vlist_p);
GLOBALS->time_vlist_vcd_recoder_write = vlist_summary_index;
vlist_freeze(&vlist_summary_index);

pnt = buf;
val = (guint64)(uintptr_t)vlist_summary_index;
while((nval = val>>7))
	{
	*(pnt++) = (val&0x7f);
	val = nval;
	}
*(pnt++) = ((val&0x7f) | 0x80);
do
	{
	pnt--;
	fputc((unsigned char)*pnt, GLOBALS->vlist_handle);
	} while(pnt != buf);

fflush(GLOBALS->vlist_handle);
}


static int read_fastload_body(void)
{
char *depacked = GLOBALS->fastload_depacked;
char *pnt = GLOBALS->fastload_current;
int rc = 0;
guint64 v = 0, vprev = 0;
int shamt = 0;
/* unsigned int num_finalize; */ /* scan-build */
unsigned int num_in_time_table, num_blackout_regions;
guint64 time_vlist_vcd_recoder_write;
struct vcdsymbol *vs;
struct vlist_t *vl;
unsigned int list_size;
unsigned int i;
struct blackout_region_t *bt_head = NULL, *bt_curr = NULL;

v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
/* num_finalize = v; */ /* scan-build */

v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
GLOBALS->time_vlist_count_vcd_recoder_c_1 = num_in_time_table = v;

v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
time_vlist_vcd_recoder_write = v;

vs=GLOBALS->vcdsymroot_vcd_recoder_c_3;
while(vs)
        {
        nptr n = vs->narray[0];

	v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
	v += vprev;
	vprev = v;

        n->mv.mvlfac_vlist = (struct vlist_t *)(intptr_t)(v);
	vs = vs->next;
	}

vlist_packer_decompress_destroy((char *)depacked);
GLOBALS->fastload_depacked = NULL;
GLOBALS->fastload_current = NULL;

/* now create the time table */
vl = (struct vlist_t *)(intptr_t)time_vlist_vcd_recoder_write;
vlist_uncompress(&vl);
depacked = pnt = (char *)vlist_packer_decompress(vl, &list_size);
vlist_destroy(vl);

vprev = 0;
for(i=0;i<num_in_time_table;i++)
	{
	TimeType tim;
	TimeType *tt;

	v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));

	v += vprev;
	vprev = v;

	tt = vlist_alloc(&GLOBALS->time_vlist_vcd_recoder_c_1, 0);
        *tt = tim = (TimeType)v;

	if(!i)
		{
		GLOBALS->start_time_vcd_recoder_c_3=tim;
		}

	GLOBALS->current_time_vcd_recoder_c_3=GLOBALS->end_time_vcd_recoder_c_3=tim;
	}

/* now process blackout regions */
v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
num_blackout_regions = v;

if(num_blackout_regions)
	{
	for(i=0;i<num_blackout_regions;i++)
		{
		struct blackout_region_t *bt = calloc_2(1, sizeof(struct blackout_region_t));
		TimeType tim;

		if(!bt_head)
			{
			bt_head = bt_curr = bt;
			}
			else
			{
			bt_curr->next = bt;
			bt_curr = bt;
			}

		v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
		tim = v;
		bt->bstart = tim;

		v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));
		tim = v;
		bt->bend = tim;
		}

	GLOBALS->blackout_regions = bt_head;
	}

vlist_packer_decompress_destroy((char *)depacked);

return(rc);
}

#ifdef HAVE_SYS_STAT_H
static int read_fastload_header(struct stat *st)
#else
static int read_fastload_header(void)
#endif
{
int rc = 0;
int fs_rc = fseeko(GLOBALS->vlist_handle, 0, SEEK_END);
off_t ftlen = ftello(GLOBALS->vlist_handle);
guint64 v = 0;
int ch;
int shamt = 0;
unsigned char *depacked = NULL;
struct vlist_t *vl;
unsigned int list_size;
unsigned char *pnt;
#ifdef HAVE_SYS_STAT_H
struct stat mystat;
int stat_rc = stat(GLOBALS->loaded_file_name, &mystat);
#endif

if((fs_rc<0)||(!ftlen))
	{
	goto bail;
	}

do	{
	ftlen--;
	fseeko(GLOBALS->vlist_handle, ftlen, SEEK_SET);
	ch = fgetc(GLOBALS->vlist_handle);
	if(ch == EOF) { errno = 0; goto bail; }
	v |= ((guint64)(ch & 0x7f)) << shamt;
	shamt += 7;
	} while(!(ch & 0x80));

vl = (struct vlist_t *)(intptr_t)v;
vlist_uncompress(&vl);
depacked = vlist_packer_decompress(vl, &list_size);
vlist_destroy(vl);

pnt = depacked;
v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));

#ifdef HAVE_SYS_STAT_H
if((stat_rc)||(v != (guint64)mystat.st_size))
	{
	goto bail;
	}
#endif

v = 0; shamt = 0; do { v |= ((guint64)(*pnt & 0x7f)) << shamt; shamt += 7; } while(!(*(pnt++) & 0x80));

#ifdef HAVE_SYS_STAT_H
if(v != (guint64)st->st_mtime)
	{
	goto bail;
	}
#endif

rc = 1;
GLOBALS->fastload_depacked = (char *)depacked;
GLOBALS->fastload_current = (char *)pnt;

bail:
if(!rc) vlist_packer_decompress_destroy((char *)depacked);
return(rc);
}

/**/

#undef VCD_BSEARCH_IS_PERFECT		/* bsearch is imperfect under linux, but OK under AIX */

static void add_histent(TimeType time, struct Node *n, char ch, int regadd, char *vector);
static void vcd_build_symbols(void);
static void vcd_cleanup(void);
static void evcd_strcpy(char *dst, char *src);

/******************************************************************/

enum Tokens   { T_VAR, T_END, T_SCOPE, T_UPSCOPE,
		T_COMMENT, T_DATE, T_DUMPALL, T_DUMPOFF, T_DUMPON,
		T_DUMPVARS, T_ENDDEFINITIONS,
		T_DUMPPORTS, T_DUMPPORTSOFF, T_DUMPPORTSON, T_DUMPPORTSALL,
		T_TIMESCALE, T_VERSION, T_VCDCLOSE, T_TIMEZERO,
		T_EOF, T_STRING, T_UNKNOWN_KEY };

static char *tokens[]={ "var", "end", "scope", "upscope",
                 "comment", "date", "dumpall", "dumpoff", "dumpon",
                 "dumpvars", "enddefinitions",
                 "dumpports", "dumpportsoff", "dumpportson", "dumpportsall",
                 "timescale", "version", "vcdclose", "timezero",
                 "", "", "" };

#define NUM_TOKENS 19


#define T_GET tok=get_token();if((tok==T_END)||(tok==T_EOF))break;

/******************************************************************/

static unsigned int vcdid_hash(char *s, int len)
{
unsigned int val=0;
int i;

s+=(len-1);

for(i=0;i<len;i++)
        {
        val *= 94;
        val += (((unsigned char)*s) - 32);
        s--;
        }

return(val);
}

/******************************************************************/

/*
 * bsearch compare
 */
static int vcdsymbsearchcompare(const void *s1, const void *s2)
{
char *v1;
struct vcdsymbol *v2;

v1=(char *)s1;
v2=*((struct vcdsymbol **)s2);

return(strcmp(v1, v2->id));
}


/*
 * actual bsearch
 */
static struct vcdsymbol *bsearch_vcd(char *key, int len)
{
struct vcdsymbol **v;
struct vcdsymbol *t;

if(GLOBALS->indexed_vcd_recoder_c_3)
        {
        unsigned int hsh = vcdid_hash(key, len);
        if((hsh>=GLOBALS->vcd_minid_vcd_recoder_c_3)&&(hsh<=GLOBALS->vcd_maxid_vcd_recoder_c_3))
                {
                return(GLOBALS->indexed_vcd_recoder_c_3[hsh-GLOBALS->vcd_minid_vcd_recoder_c_3]);
                }

	return(NULL);
        }

if(GLOBALS->sorted_vcd_recoder_c_3)
	{
	v=(struct vcdsymbol **)bsearch(key, GLOBALS->sorted_vcd_recoder_c_3, GLOBALS->numsyms_vcd_recoder_c_3,
		sizeof(struct vcdsymbol *), vcdsymbsearchcompare);

	if(v)
		{
		#ifndef VCD_BSEARCH_IS_PERFECT
			for(;;)
				{
				t=*v;

				if((v==GLOBALS->sorted_vcd_recoder_c_3)||(strcmp((*(--v))->id, key)))
					{
					return(t);
					}
				}
		#else
			return(*v);
		#endif
		}
		else
		{
		return(NULL);
		}
	}
	else
	{
	if(!GLOBALS->err_vcd_recoder_c_3)
		{
		fprintf(stderr, "Near byte %d, VCD search table NULL..is this a VCD file?\n", (int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)));
		GLOBALS->err_vcd_recoder_c_3=1;
		}
	return(NULL);
	}
}


/*
 * sort on vcdsymbol pointers
 */
static int vcdsymcompare(const void *s1, const void *s2)
{
struct vcdsymbol *v1, *v2;

v1=*((struct vcdsymbol **)s1);
v2=*((struct vcdsymbol **)s2);

return(strcmp(v1->id, v2->id));
}


/*
 * create sorted (by id) table
 */
static void create_sorted_table(void)
{
struct vcdsymbol *v;
struct vcdsymbol **pnt;
unsigned int vcd_distance;

if(GLOBALS->sorted_vcd_recoder_c_3)
	{
	free_2(GLOBALS->sorted_vcd_recoder_c_3);	/* this means we saw a 2nd enddefinition chunk! */
	GLOBALS->sorted_vcd_recoder_c_3=NULL;
	}

if(GLOBALS->indexed_vcd_recoder_c_3)
	{
	free_2(GLOBALS->indexed_vcd_recoder_c_3);
	GLOBALS->indexed_vcd_recoder_c_3=NULL;
	}

if(GLOBALS->numsyms_vcd_recoder_c_3)
	{
        vcd_distance = GLOBALS->vcd_maxid_vcd_recoder_c_3 - GLOBALS->vcd_minid_vcd_recoder_c_3 + 1;

        if((vcd_distance <= VCD_INDEXSIZ)||(!GLOBALS->vcd_hash_kill))
                {
                GLOBALS->indexed_vcd_recoder_c_3 = (struct vcdsymbol **)calloc_2(vcd_distance, sizeof(struct vcdsymbol *));

		/* printf("%d symbols span ID range of %d, using indexing... hash_kill = %d\n", GLOBALS->numsyms_vcd_recoder_c_3, vcd_distance, GLOBALS->vcd_hash_kill);  */

                v=GLOBALS->vcdsymroot_vcd_recoder_c_3;
                while(v)
                        {
                        if(!GLOBALS->indexed_vcd_recoder_c_3[v->nid - GLOBALS->vcd_minid_vcd_recoder_c_3]) GLOBALS->indexed_vcd_recoder_c_3[v->nid - GLOBALS->vcd_minid_vcd_recoder_c_3] = v;
                        v=v->next;
                        }
                }
                else
		{
		pnt=GLOBALS->sorted_vcd_recoder_c_3=(struct vcdsymbol **)calloc_2(GLOBALS->numsyms_vcd_recoder_c_3, sizeof(struct vcdsymbol *));
		v=GLOBALS->vcdsymroot_vcd_recoder_c_3;
		while(v)
			{
			*(pnt++)=v;
			v=v->next;
			}

		qsort(GLOBALS->sorted_vcd_recoder_c_3, GLOBALS->numsyms_vcd_recoder_c_3, sizeof(struct vcdsymbol *), vcdsymcompare);
		}
	}
}

/******************************************************************/

static unsigned int vlist_emit_finalize(void)
{
struct vcdsymbol *v /* , *vprime */; /* scan-build */
struct vlist_t *vlist;
char vlist_prepack = GLOBALS->vlist_prepack;
int cnt = 0;

v=GLOBALS->vcdsymroot_vcd_recoder_c_3;
while(v)
	{
	nptr n = v->narray[0];

	set_vcd_vartype(v, n);

	if(n->mv.mvlfac_vlist)
		{
		if(vlist_prepack)
			{
	                vlist_packer_finalize(n->mv.mvlfac_packer_vlist);
	                vlist = n->mv.mvlfac_packer_vlist->v;
	                free_2(n->mv.mvlfac_packer_vlist);
	                n->mv.mvlfac_vlist = vlist;
	                vlist_freeze(&n->mv.mvlfac_vlist);
			}
			else
			{
			vlist_freeze(&n->mv.mvlfac_vlist);
			}
		}
		else
		{
		n->mv.mvlfac_vlist = vlist_prepack ? ((struct vlist_t *)vlist_packer_create()) : vlist_create(sizeof(char));

		if((/* vprime= */ bsearch_vcd(v->id, strlen(v->id)))==v) /* hash mish means dup net */ /* scan-build */
			{
			switch(v->vartype)
				{
				case V_REAL:
		                          	vlist_emit_uv32(&n->mv.mvlfac_vlist, 'R');
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->vartype);
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->size);
						vlist_emit_uv32(&n->mv.mvlfac_vlist, 0);
						vlist_emit_string(&n->mv.mvlfac_vlist, "NaN");
						break;

				case V_STRINGTYPE:
						vlist_emit_uv32(&n->mv.mvlfac_vlist, 'S');
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->vartype);
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->size);
						vlist_emit_uv32(&n->mv.mvlfac_vlist, 0);
						vlist_emit_string(&n->mv.mvlfac_vlist, "UNDEF");
						break;

				default:
					if(v->size==1)
						{
	                                        vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)'0');
	                                        vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->vartype);
						vlist_emit_uv32(&n->mv.mvlfac_vlist, RCV_X);
						}
						else
						{
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, 'B');
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->vartype);
		                                vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->size);
						vlist_emit_uv32(&n->mv.mvlfac_vlist, 0);
						vlist_emit_mvl9_string(&n->mv.mvlfac_vlist, "x");
						}
					break;
				}
			}

		if(vlist_prepack)
			{
	                vlist_packer_finalize(n->mv.mvlfac_packer_vlist);
	                vlist = n->mv.mvlfac_packer_vlist->v;
	                free_2(n->mv.mvlfac_packer_vlist);
	                n->mv.mvlfac_vlist = vlist;
	                vlist_freeze(&n->mv.mvlfac_vlist);
			}
			else
			{
			vlist_freeze(&n->mv.mvlfac_vlist);
			}
		}
	v=v->next;
	cnt++;
	}

return(cnt);
}

/******************************************************************/

/*
 * single char get inlined/optimized
 */
static void getch_alloc(void)
{
GLOBALS->vend_vcd_recoder_c_3=GLOBALS->vst_vcd_recoder_c_3=GLOBALS->vcdbuf_vcd_recoder_c_3=(char *)calloc_2(1,VCD_BSIZ);
}

static void getch_free(void)
{
free_2(GLOBALS->vcdbuf_vcd_recoder_c_3);
GLOBALS->vcdbuf_vcd_recoder_c_3=GLOBALS->vst_vcd_recoder_c_3=GLOBALS->vend_vcd_recoder_c_3=NULL;
}



static int getch_fetch(void)
{
size_t rd;

errno = 0;
if(feof(GLOBALS->vcd_handle_vcd_recoder_c_2)) return(-1);

GLOBALS->vcdbyteno_vcd_recoder_c_3+=(GLOBALS->vend_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3);
rd=fread(GLOBALS->vcdbuf_vcd_recoder_c_3, sizeof(char), VCD_BSIZ, GLOBALS->vcd_handle_vcd_recoder_c_2);
GLOBALS->vend_vcd_recoder_c_3=(GLOBALS->vst_vcd_recoder_c_3=GLOBALS->vcdbuf_vcd_recoder_c_3)+rd;

if((!rd)||(errno)) return(-1);

if(GLOBALS->vcd_fsiz_vcd_recoder_c_2)
	{
	splash_sync(GLOBALS->vcdbyteno_vcd_recoder_c_3, GLOBALS->vcd_fsiz_vcd_recoder_c_2); /* gnome 2.18 seems to set errno so splash moved here... */
	}

return((int)(*GLOBALS->vst_vcd_recoder_c_3));
}

static inline signed char getch(void) {
  signed char ch = (GLOBALS->vst_vcd_recoder_c_3!=GLOBALS->vend_vcd_recoder_c_3)?((int)(*GLOBALS->vst_vcd_recoder_c_3)):(getch_fetch());
  GLOBALS->vst_vcd_recoder_c_3++;
  return(ch);
}

static inline signed char getch_peek(void) {
  signed char ch = (GLOBALS->vst_vcd_recoder_c_3!=GLOBALS->vend_vcd_recoder_c_3)?((int)(*GLOBALS->vst_vcd_recoder_c_3)):(getch_fetch());
  /* no increment */
  return(ch);
}

static int getch_patched(void)
{
char ch;

ch=*GLOBALS->vsplitcurr_vcd_recoder_c_3;
if(!ch)
	{
	return(-1);
	}
	else
	{
	GLOBALS->vsplitcurr_vcd_recoder_c_3++;
	return((int)ch);
	}
}

/*
 * simple tokenizer
 */
static int get_token(void)
{
int ch;
int i, len=0;
int is_string=0;
char *yyshadow;

for(;;)
	{
	ch=getch();
	if(ch<0) return(T_EOF);
	if(ch<=' ') continue;	/* val<=' ' is a quick whitespace check      */
	break;			/* (take advantage of fact that vcd is text) */
	}
if(ch=='$')
	{
	GLOBALS->yytext_vcd_recoder_c_3[len++]=ch;
	for(;;)
		{
		ch=getch();
		if(ch<0) return(T_EOF);
		if(ch<=' ') continue;
		break;
		}
	}
	else
	{
	is_string=1;
	}

for(GLOBALS->yytext_vcd_recoder_c_3[len++]=ch;;GLOBALS->yytext_vcd_recoder_c_3[len++]=ch)
	{
	if(len==GLOBALS->T_MAX_STR_vcd_recoder_c_3)
		{
		GLOBALS->yytext_vcd_recoder_c_3=(char *)realloc_2(GLOBALS->yytext_vcd_recoder_c_3, (GLOBALS->T_MAX_STR_vcd_recoder_c_3=GLOBALS->T_MAX_STR_vcd_recoder_c_3*2)+1);
		}
	ch=getch();
	if(ch<=' ') break;
	}
GLOBALS->yytext_vcd_recoder_c_3[len]=0;	/* terminator */

if(is_string)
	{
	GLOBALS->yylen_vcd_recoder_c_3=len;
	return(T_STRING);
	}

yyshadow=GLOBALS->yytext_vcd_recoder_c_3;
do
{
yyshadow++;
for(i=0;i<NUM_TOKENS;i++)
	{
	if(!strcmp(yyshadow,tokens[i]))
		{
		return(i);
		}
	}

} while(*yyshadow=='$'); /* fix for RCS ids in version strings */

return(T_UNKNOWN_KEY);
}


static int get_vartoken_patched(int match_kw)
{
int ch;
int len=0;

if(!GLOBALS->var_prevch_vcd_recoder_c_3)
	{
	for(;;)
		{
		ch=getch_patched();
		if(ch<0) { free_2(GLOBALS->varsplit_vcd_recoder_c_3); GLOBALS->varsplit_vcd_recoder_c_3=NULL; return(V_END); }
		if((ch==' ')||(ch=='\t')||(ch=='\n')||(ch=='\r')) continue;
		break;
		}
	}
	else
	{
	ch=GLOBALS->var_prevch_vcd_recoder_c_3;
	GLOBALS->var_prevch_vcd_recoder_c_3=0;
	}

if(ch=='[') return(V_LB);
if(ch==':') return(V_COLON);
if(ch==']') return(V_RB);

for(GLOBALS->yytext_vcd_recoder_c_3[len++]=ch;;GLOBALS->yytext_vcd_recoder_c_3[len++]=ch)
	{
	if(len==GLOBALS->T_MAX_STR_vcd_recoder_c_3)
		{
		GLOBALS->yytext_vcd_recoder_c_3=(char *)realloc_2(GLOBALS->yytext_vcd_recoder_c_3, (GLOBALS->T_MAX_STR_vcd_recoder_c_3=GLOBALS->T_MAX_STR_vcd_recoder_c_3*2)+1);
		}
	ch=getch_patched();
	if(ch<0) { free_2(GLOBALS->varsplit_vcd_recoder_c_3); GLOBALS->varsplit_vcd_recoder_c_3=NULL; break; }
	if((ch==':')||(ch==']'))
		{
		GLOBALS->var_prevch_vcd_recoder_c_3=ch;
		break;
		}
	}
GLOBALS->yytext_vcd_recoder_c_3[len]=0;	/* terminator */

if(match_kw)
	{
	int vr = vcd_keyword_code(GLOBALS->yytext_vcd_recoder_c_3, len);
	if(vr != V_STRING)
		{
		if(ch<0) { free_2(GLOBALS->varsplit_vcd_recoder_c_3); GLOBALS->varsplit_vcd_recoder_c_3=NULL; }
		return(vr);
		}
	}

GLOBALS->yylen_vcd_recoder_c_3=len;
if(ch<0) { free_2(GLOBALS->varsplit_vcd_recoder_c_3); GLOBALS->varsplit_vcd_recoder_c_3=NULL; }
return(V_STRING);
}

static int get_vartoken(int match_kw)
{
int ch;
int len=0;

if(GLOBALS->varsplit_vcd_recoder_c_3)
	{
	int rc=get_vartoken_patched(match_kw);
	if(rc!=V_END) return(rc);
	GLOBALS->var_prevch_vcd_recoder_c_3=0;
	}

if(!GLOBALS->var_prevch_vcd_recoder_c_3)
	{
	for(;;)
		{
		ch=getch();
		if(ch<0) return(V_END);
		if((ch==' ')||(ch=='\t')||(ch=='\n')||(ch=='\r')) continue;
		break;
		}
	}
	else
	{
	ch=GLOBALS->var_prevch_vcd_recoder_c_3;
	GLOBALS->var_prevch_vcd_recoder_c_3=0;
	}

if(ch=='[') return(V_LB);
if(ch==':') return(V_COLON);
if(ch==']') return(V_RB);

if(ch=='#')	/* for MTI System Verilog '$var reg 64 >w #implicit-var###VarElem:ram_di[0.0] [63:0] $end' style declarations */
	{	/* debussy simply escapes until the space */
	GLOBALS->yytext_vcd_recoder_c_3[len++]= '\\';
	}

for(GLOBALS->yytext_vcd_recoder_c_3[len++]=ch;;GLOBALS->yytext_vcd_recoder_c_3[len++]=ch)
	{
	if(len==GLOBALS->T_MAX_STR_vcd_recoder_c_3)
		{
		GLOBALS->yytext_vcd_recoder_c_3=(char *)realloc_2(GLOBALS->yytext_vcd_recoder_c_3, (GLOBALS->T_MAX_STR_vcd_recoder_c_3=GLOBALS->T_MAX_STR_vcd_recoder_c_3*2)+1);
		}

	ch=getch();
	if(ch==' ')
		{
		if(match_kw) break;
		if(getch_peek() == '[')
			{
			ch = getch();
			GLOBALS->varsplit_vcd_recoder_c_3=GLOBALS->yytext_vcd_recoder_c_3+len;	/* keep looping so we get the *last* one */
			continue;
			}
		}

	if((ch==' ')||(ch=='\t')||(ch=='\n')||(ch=='\r')||(ch<0)) break;
	if((ch=='[')&&(GLOBALS->yytext_vcd_recoder_c_3[0]!='\\'))
		{
		GLOBALS->varsplit_vcd_recoder_c_3=GLOBALS->yytext_vcd_recoder_c_3+len;		/* keep looping so we get the *last* one */
		}
	else
	if(((ch==':')||(ch==']'))&&(!GLOBALS->varsplit_vcd_recoder_c_3)&&(GLOBALS->yytext_vcd_recoder_c_3[0]!='\\'))
		{
		GLOBALS->var_prevch_vcd_recoder_c_3=ch;
		break;
		}
	}

GLOBALS->yytext_vcd_recoder_c_3[len]=0;	/* absolute terminator */
if((GLOBALS->varsplit_vcd_recoder_c_3)&&(GLOBALS->yytext_vcd_recoder_c_3[len-1]==']'))
	{
	char *vst;
	vst=malloc_2(strlen(GLOBALS->varsplit_vcd_recoder_c_3)+1);
	strcpy(vst, GLOBALS->varsplit_vcd_recoder_c_3);

	*GLOBALS->varsplit_vcd_recoder_c_3=0x00;		/* zero out var name at the left bracket */
	len=GLOBALS->varsplit_vcd_recoder_c_3-GLOBALS->yytext_vcd_recoder_c_3;

	GLOBALS->varsplit_vcd_recoder_c_3=GLOBALS->vsplitcurr_vcd_recoder_c_3=vst;
	GLOBALS->var_prevch_vcd_recoder_c_3=0;
	}
	else
	{
	GLOBALS->varsplit_vcd_recoder_c_3=NULL;
	}

if(match_kw)
	{
        int vr = vcd_keyword_code(GLOBALS->yytext_vcd_recoder_c_3, len);
        if(vr != V_STRING)
		{
		return(vr);
		}
	}

GLOBALS->yylen_vcd_recoder_c_3=len;
return(V_STRING);
}

static int get_strtoken(void)
{
int ch;
int len=0;

if(!GLOBALS->var_prevch_vcd_recoder_c_3)
      {
      for(;;)
              {
              ch=getch();
              if(ch<0) return(V_END);
              if((ch==' ')||(ch=='\t')||(ch=='\n')||(ch=='\r')) continue;
              break;
              }
      }
      else
      {
      ch=GLOBALS->var_prevch_vcd_recoder_c_3;
      GLOBALS->var_prevch_vcd_recoder_c_3=0;
      }

for(GLOBALS->yytext_vcd_recoder_c_3[len++]=ch;;GLOBALS->yytext_vcd_recoder_c_3[len++]=ch)
      {
	if(len==GLOBALS->T_MAX_STR_vcd_recoder_c_3)
		{
		GLOBALS->yytext_vcd_recoder_c_3=(char *)realloc_2(GLOBALS->yytext_vcd_recoder_c_3, (GLOBALS->T_MAX_STR_vcd_recoder_c_3=GLOBALS->T_MAX_STR_vcd_recoder_c_3*2)+1);
		}
      ch=getch();
      if((ch==' ')||(ch=='\t')||(ch=='\n')||(ch=='\r')||(ch<0)) break;
      }
GLOBALS->yytext_vcd_recoder_c_3[len]=0;        /* terminator */

GLOBALS->yylen_vcd_recoder_c_3=len;
return(V_STRING);
}

static void sync_end(char *hdr)
{
int tok;

if(hdr) { DEBUG(fprintf(stderr,"%s",hdr)); }
for(;;)
	{
	tok=get_token();
	if((tok==T_END)||(tok==T_EOF)) break;
	if(hdr) { DEBUG(fprintf(stderr," %s",GLOBALS->yytext_vcd_recoder_c_3)); }
	}
if(hdr) { DEBUG(fprintf(stderr,"\n")); }
}

static int version_sync_end(char *hdr)
{
int tok;
int rc = 0;

if(hdr) { DEBUG(fprintf(stderr,"%s",hdr)); }
for(;;)
	{
	tok=get_token();
	if((tok==T_END)||(tok==T_EOF)) break;
	if(hdr) { DEBUG(fprintf(stderr," %s",GLOBALS->yytext_vcd_recoder_c_3)); }
	if(strstr(GLOBALS->yytext_vcd_recoder_c_3, "Icarus"))	/* turn off autocoalesce for Icarus */
		{
		GLOBALS->autocoalesce = 0;
		rc = 1;
		}
	}
if(hdr) { DEBUG(fprintf(stderr,"\n")); }
return(rc);
}

static void parse_valuechange(void)
{
struct vcdsymbol *v;
char *vector;
int vlen;
unsigned char typ;

switch((typ = GLOBALS->yytext_vcd_recoder_c_3[0]))
	{
	/* encode bits as (time delta<<4) + (enum AnalyzerBits value) */
        case '0':
        case '1':
        case 'x': case 'X':
        case 'z': case 'Z':
        case 'h': case 'H':
        case 'u': case 'U':
        case 'w': case 'W':
        case 'l': case 'L':
        case '-':
                if(GLOBALS->yylen_vcd_recoder_c_3>1)
                        {
                        v=bsearch_vcd(GLOBALS->yytext_vcd_recoder_c_3+1, GLOBALS->yylen_vcd_recoder_c_3-1);
                        if(!v)
                                {
                                fprintf(stderr,"Near byte %d, Unknown VCD identifier: '%s'\n",(int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)),GLOBALS->yytext_vcd_recoder_c_3+1);
				malform_eof_fix();
                                }
                                else
                                {
				nptr n = v->narray[0];
				unsigned int time_delta;
				unsigned int rcv;

				if(!n->mv.mvlfac_vlist) /* overloaded for vlist, numhist = last position used */
					{
					n->mv.mvlfac_vlist = (GLOBALS->vlist_prepack) ? ((struct vlist_t *)vlist_packer_create()) : vlist_create(sizeof(char));
					vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)'0'); /* represents single bit routine for decompression */
					vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->vartype);
					}

				time_delta = GLOBALS->time_vlist_count_vcd_recoder_c_1 - (unsigned int)n->numhist;
				n->numhist = GLOBALS->time_vlist_count_vcd_recoder_c_1;

				switch(GLOBALS->yytext_vcd_recoder_c_3[0])
				        {
				        case '0':
				        case '1':		rcv = ((GLOBALS->yytext_vcd_recoder_c_3[0]&1)<<1) | (time_delta<<2);
								break; /* pack more delta bits in for 0/1 vchs */

				        case 'x': case 'X':	rcv = RCV_X | (time_delta<<4); break;
				        case 'z': case 'Z':	rcv = RCV_Z | (time_delta<<4); break;
				        case 'h': case 'H':	rcv = RCV_H | (time_delta<<4); break;
				        case 'u': case 'U':	rcv = RCV_U | (time_delta<<4); break;
				        case 'w': case 'W':     rcv = RCV_W | (time_delta<<4); break;
				        case 'l': case 'L':	rcv = RCV_L | (time_delta<<4); break;
					default:		rcv = RCV_D | (time_delta<<4); break;
					}

				vlist_emit_uv32(&n->mv.mvlfac_vlist, rcv);
                                }
                        }
                        else
                        {
                        fprintf(stderr,"Near byte %d, Malformed VCD identifier\n", (int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)));
			malform_eof_fix();
                        }
                break;

	/* encode everything else literally as a time delta + a string */
#ifndef STRICT_VCD_ONLY
        case 's':
        case 'S':
                vector=wave_alloca(GLOBALS->yylen_cache_vcd_recoder_c_3=GLOBALS->yylen_vcd_recoder_c_3);
		vlen = fstUtilityEscToBin((unsigned char *)vector, (unsigned char *)(GLOBALS->yytext_vcd_recoder_c_3+1), GLOBALS->yylen_vcd_recoder_c_3-1);
		vector[vlen] = 0;

                get_strtoken();
		goto process_binary;
#endif
        case 'b':
        case 'B':
        case 'r':
        case 'R':
                vector=wave_alloca(GLOBALS->yylen_cache_vcd_recoder_c_3=GLOBALS->yylen_vcd_recoder_c_3);
                strcpy(vector,GLOBALS->yytext_vcd_recoder_c_3+1);
                vlen=GLOBALS->yylen_vcd_recoder_c_3-1;

                get_strtoken();
process_binary:
                v=bsearch_vcd(GLOBALS->yytext_vcd_recoder_c_3, GLOBALS->yylen_vcd_recoder_c_3);
                if(!v)
			{
                        fprintf(stderr,"Near byte %d, Unknown VCD identifier: '%s'\n",(int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)),GLOBALS->yytext_vcd_recoder_c_3+1);
			malform_eof_fix();
                        }
                        else
                        {
			nptr n = v->narray[0];
			unsigned int time_delta;

			if(!n->mv.mvlfac_vlist) /* overloaded for vlist, numhist = last position used */
				{
				unsigned char typ2 = toupper(typ);
				n->mv.mvlfac_vlist = (GLOBALS->vlist_prepack) ? ((struct vlist_t *)vlist_packer_create()) : vlist_create(sizeof(char));

				if((v->vartype!=V_REAL) && (v->vartype!=V_STRINGTYPE))
					{
                                        if((typ2=='R')||(typ2=='S'))
                                                {
                                                typ2 = 'B';     /* ok, typical case...fix as 'r' on bits variable causes recoder crash during trace extraction */
                                                }
					}
					else
					{
					if(typ2=='B')
						{
						typ2 = 'S';	/* should never be necessary...this is defensive */
						}
					}


				vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)toupper(typ2)); /* B/R/P/S for decompress */
				vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->vartype);
				vlist_emit_uv32(&n->mv.mvlfac_vlist, (unsigned int)v->size);
				}

			time_delta = GLOBALS->time_vlist_count_vcd_recoder_c_1 - (unsigned int)n->numhist;
			n->numhist = GLOBALS->time_vlist_count_vcd_recoder_c_1;

			vlist_emit_uv32(&n->mv.mvlfac_vlist, time_delta);

			if((typ=='b')||(typ=='B'))
				{
				if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE))
					{
					vlist_emit_mvl9_string(&n->mv.mvlfac_vlist, vector);
					}
					else
					{
					vlist_emit_string(&n->mv.mvlfac_vlist, vector);
					}
				}
				else
				{
				if((v->vartype == V_REAL)||(v->vartype == V_STRINGTYPE)||(typ=='s')||(typ=='S'))
					{
					vlist_emit_string(&n->mv.mvlfac_vlist, vector);
					}
					else
					{
					char *bits = wave_alloca(v->size + 1);
					int i, j, k=0;

					memset(bits, 0x0, v->size + 1);

					for(i=0;i<vlen;i++)
						{
						for(j=0;j<8;j++)
							{
							bits[k++] = ((vector[i] >> (7-j)) & 1) | '0';
							if(k >= v->size) goto bit_term;
							}
						}

					bit_term:
					vlist_emit_mvl9_string(&n->mv.mvlfac_vlist, bits);
					}
				}
                        }
		break;

	case 'p':
	case 'P':
		/* extract port dump value.. */
		vector=wave_alloca(GLOBALS->yylen_cache_vcd_recoder_c_3=GLOBALS->yylen_vcd_recoder_c_3);
		evcd_strcpy(vector,GLOBALS->yytext_vcd_recoder_c_3+1);	/* convert to regular vcd */
		vlen=GLOBALS->yylen_vcd_recoder_c_3-1;

		get_strtoken();	/* throw away 0_strength_component */
		get_strtoken(); /* throw away 0_strength_component */
		get_strtoken(); /* this is the id                  */

		typ = 'b';			/* convert to regular vcd */
		goto process_binary; /* store string literally */

	default:
		break;
	}
}


static void evcd_strcpy(char *dst, char *src)
{
static const char *evcd="DUNZduLHXTlh01?FAaBbCcf";
static const char  *vcd="01xz0101xz0101xzxxxxxxz";

char ch;
int i;

while((ch=*src))
	{
	for(i=0;i<23;i++)
		{
		if(evcd[i]==ch)
			{
			*dst=vcd[i];
			break;
			}
		}
	if(i==23) *dst='x';

	src++;
	dst++;
	}

*dst=0;	/* null terminate destination */
}


static void vcd_parse(void)
{
int tok;
unsigned char ttype;
int disable_autocoalesce = 0;

for(;;)
	{
	switch(get_token())
		{
		case T_COMMENT:
			sync_end("COMMENT:");
			break;
		case T_DATE:
			sync_end("DATE:");
			break;
		case T_VERSION:
			disable_autocoalesce = version_sync_end("VERSION:");
			break;
		case T_TIMEZERO:
			{
			int vtok=get_token();
			if((vtok==T_END)||(vtok==T_EOF)) break;
			GLOBALS->global_time_offset=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);

			DEBUG(fprintf(stderr,"TIMEZERO: "TTFormat"\n",GLOBALS->global_time_offset));
			sync_end(NULL);
			}
			break;
		case T_TIMESCALE:
			{
			int vtok;
			int i;
			char prefix=' ';

			vtok=get_token();
			if((vtok==T_END)||(vtok==T_EOF)) break;
			fractional_timescale_fix(GLOBALS->yytext_vcd_recoder_c_3);
			GLOBALS->time_scale=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
			if(!GLOBALS->time_scale) GLOBALS->time_scale=1;
			for(i=0;i<GLOBALS->yylen_vcd_recoder_c_3;i++)
				{
				if((GLOBALS->yytext_vcd_recoder_c_3[i]<'0')||(GLOBALS->yytext_vcd_recoder_c_3[i]>'9'))
					{
					prefix=GLOBALS->yytext_vcd_recoder_c_3[i];
					break;
					}
				}
			if(prefix==' ')
				{
				vtok=get_token();
				if((vtok==T_END)||(vtok==T_EOF)) break;
				prefix=GLOBALS->yytext_vcd_recoder_c_3[0];
				}
			switch(prefix)
				{
				case ' ':
				case 'm':
				case 'u':
				case 'n':
				case 'p':
				case 'f':
				case 'a':
				case 'z':
					GLOBALS->time_dimension=prefix;
					break;
				case 's':
					GLOBALS->time_dimension=' ';
					break;
				default:	/* unknown */
					GLOBALS->time_dimension='n';
					break;
				}

			DEBUG(fprintf(stderr,"TIMESCALE: "TTFormat" %cs\n",GLOBALS->time_scale, GLOBALS->time_dimension));
			sync_end(NULL);
			}
			break;
		case T_SCOPE:
			T_GET;
				{
				switch(GLOBALS->yytext_vcd_recoder_c_3[0])
					{
					case 'm':	ttype = TREE_VCD_ST_MODULE; break;
					case 't':	ttype = TREE_VCD_ST_TASK; break;
					case 'f':	ttype = (GLOBALS->yytext_vcd_recoder_c_3[1] == 'u') ? TREE_VCD_ST_FUNCTION : TREE_VCD_ST_FORK; break;
					case 'b':	ttype = TREE_VCD_ST_BEGIN; break;
					case 'g':       ttype = TREE_VCD_ST_GENERATE; break;
					case 's':       ttype = TREE_VCD_ST_STRUCT; break;
					case 'u':       ttype = TREE_VCD_ST_UNION; break;
					case 'c':       ttype = TREE_VCD_ST_CLASS; break;
					case 'i':       ttype = TREE_VCD_ST_INTERFACE; break;
					case 'p':       ttype = (GLOBALS->yytext_vcd_recoder_c_3[1] == 'r') ? TREE_VCD_ST_PROGRAM : TREE_VCD_ST_PACKAGE; break;

					case 'v':	{
							char *vht = GLOBALS->yytext_vcd_recoder_c_3;
				                       	if(!strncmp(vht, "vhdl_", 5))
                                				{
				                                switch(vht[5])
				                                        {
				                                        case 'a':       ttype = TREE_VHDL_ST_ARCHITECTURE; break;
				                                        case 'r':       ttype = TREE_VHDL_ST_RECORD; break;
				                                        case 'b':       ttype = TREE_VHDL_ST_BLOCK; break;
				                                        case 'g':       ttype = TREE_VHDL_ST_GENERATE; break;
				                                        case 'i':       ttype = TREE_VHDL_ST_GENIF; break;
				                                        case 'f':       ttype = (vht[6] == 'u') ? TREE_VHDL_ST_FUNCTION : TREE_VHDL_ST_GENFOR; break;
				                                        case 'p':       ttype = (!strncmp(vht+6, "roces", 5)) ? TREE_VHDL_ST_PROCESS: TREE_VHDL_ST_PROCEDURE; break;
				                                        default:        ttype = TREE_UNKNOWN; break;
				                                        }
								}
								else
								{
								ttype = TREE_UNKNOWN;
								}
                                			}
							break;

					default:	ttype = TREE_UNKNOWN;
							break;
					}
				}
			T_GET;
			if(tok==T_STRING)
				{
				struct slist *s;
				s=(struct slist *)calloc_2(1,sizeof(struct slist));
				s->len=GLOBALS->yylen_vcd_recoder_c_3;
				s->str=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+1);
				strcpy(s->str, GLOBALS->yytext_vcd_recoder_c_3);
				s->mod_tree_parent = GLOBALS->mod_tree_parent;

				allocate_and_decorate_module_tree_node(ttype, GLOBALS->yytext_vcd_recoder_c_3, NULL, GLOBALS->yylen_vcd_recoder_c_3, 0, 0, 0);

				if(GLOBALS->slistcurr)
					{
					GLOBALS->slistcurr->next=s;
					GLOBALS->slistcurr=s;
					}
					else
					{
					GLOBALS->slistcurr=GLOBALS->slistroot=s;
					}

				build_slisthier();
				DEBUG(fprintf(stderr, "SCOPE: %s\n",GLOBALS->slisthier));
				}
			sync_end(NULL);
			break;
		case T_UPSCOPE:
			if(GLOBALS->slistroot)
				{
				struct slist *s;

				GLOBALS->mod_tree_parent = GLOBALS->slistcurr->mod_tree_parent;
				s=GLOBALS->slistroot;
				if(!s->next)
					{
					free_2(s->str);
					free_2(s);
					GLOBALS->slistroot=GLOBALS->slistcurr=NULL;
					}
				else
				for(;;)
					{
					if(!s->next->next)
						{
						free_2(s->next->str);
						free_2(s->next);
						s->next=NULL;
						GLOBALS->slistcurr=s;
						break;
						}
					s=s->next;
					}
				build_slisthier();
				DEBUG(fprintf(stderr, "SCOPE: %s\n",GLOBALS->slisthier));
				}
				else
				{
				GLOBALS->mod_tree_parent = NULL;
				}
			sync_end(NULL);
			break;
		case T_VAR:
			if((GLOBALS->header_over_vcd_recoder_c_3)&&(0))
			{
			fprintf(stderr,"$VAR encountered after $ENDDEFINITIONS near byte %d.  VCD is malformed, exiting.\n",
				(int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)));
			vcd_exit(255);
			}
			else
			{
			int vtok;
			struct vcdsymbol *v=NULL;

			GLOBALS->var_prevch_vcd_recoder_c_3=0;
                        if(GLOBALS->varsplit_vcd_recoder_c_3)
                                {
                                free_2(GLOBALS->varsplit_vcd_recoder_c_3);
                                GLOBALS->varsplit_vcd_recoder_c_3=NULL;
                                }
			vtok=get_vartoken(1);
			if(vtok>V_STRINGTYPE) goto bail;

			v=(struct vcdsymbol *)calloc_2(1,sizeof(struct vcdsymbol));
			v->vartype=vtok;
			v->msi=v->lsi=GLOBALS->vcd_explicit_zero_subscripts; /* indicate [un]subscripted status */

			if(vtok==V_PORT)
				{
				vtok=get_vartoken(1);
				if(vtok==V_STRING)
					{
					v->size=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
					if(!v->size) v->size=1;
					}
					else
					if(vtok==V_LB)
					{
					vtok=get_vartoken(1);
					if(vtok==V_END) goto err;
					if(vtok!=V_STRING) goto err;
					v->msi=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
					vtok=get_vartoken(0);
					if(vtok==V_RB)
						{
						v->lsi=v->msi;
						v->size=1;
						}
						else
						{
						if(vtok!=V_COLON) goto err;
						vtok=get_vartoken(0);
						if(vtok!=V_STRING) goto err;
						v->lsi=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
						vtok=get_vartoken(0);
						if(vtok!=V_RB) goto err;

						if(v->msi>v->lsi)
							{
							v->size=v->msi-v->lsi+1;
							}
							else
							{
							v->size=v->lsi-v->msi+1;
							}
						}
					}
					else goto err;

				vtok=get_strtoken();
				if(vtok==V_END) goto err;
				v->id=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+1);
				strcpy(v->id, GLOBALS->yytext_vcd_recoder_c_3);
                                v->nid=vcdid_hash(GLOBALS->yytext_vcd_recoder_c_3,GLOBALS->yylen_vcd_recoder_c_3);

		                if(v->nid == (GLOBALS->vcd_hash_max+1))
                		        {
		                        GLOBALS->vcd_hash_max = v->nid;
		                        }
		                else
		                if((v->nid>0)&&(v->nid<=GLOBALS->vcd_hash_max))
		                        {
		                        /* general case with aliases */
		                        }
		                else
		                        {
		                        GLOBALS->vcd_hash_kill = 1;
		                        }

                                if(v->nid < GLOBALS->vcd_minid_vcd_recoder_c_3) GLOBALS->vcd_minid_vcd_recoder_c_3 = v->nid;
                                if(v->nid > GLOBALS->vcd_maxid_vcd_recoder_c_3) GLOBALS->vcd_maxid_vcd_recoder_c_3 = v->nid;

				vtok=get_vartoken(0);
				if(vtok!=V_STRING) goto err;
				if(GLOBALS->slisthier_len)
					{
					v->name=(char *)malloc_2(GLOBALS->slisthier_len+1+GLOBALS->yylen_vcd_recoder_c_3+1);
					strcpy(v->name,GLOBALS->slisthier);
					strcpy(v->name+GLOBALS->slisthier_len,GLOBALS->vcd_hier_delimeter);
					if(GLOBALS->alt_hier_delimeter)
						{
						strcpy_vcdalt(v->name+GLOBALS->slisthier_len+1,GLOBALS->yytext_vcd_recoder_c_3,GLOBALS->alt_hier_delimeter);
						}
						else
						{
						if((strcpy_delimfix(v->name+GLOBALS->slisthier_len+1,GLOBALS->yytext_vcd_recoder_c_3)) && (GLOBALS->yytext_vcd_recoder_c_3[0] != '\\'))
							{
							char *sd=(char *)malloc_2(GLOBALS->slisthier_len+1+GLOBALS->yylen_vcd_recoder_c_3+2);
							strcpy(sd,GLOBALS->slisthier);
							strcpy(sd+GLOBALS->slisthier_len,GLOBALS->vcd_hier_delimeter);
							sd[GLOBALS->slisthier_len+1] = '\\';
							strcpy(sd+GLOBALS->slisthier_len+2,v->name+GLOBALS->slisthier_len+1);
							free_2(v->name);
							v->name = sd;
							}
						}
					}
					else
					{
					v->name=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+1);
					if(GLOBALS->alt_hier_delimeter)
						{
						strcpy_vcdalt(v->name,GLOBALS->yytext_vcd_recoder_c_3,GLOBALS->alt_hier_delimeter);
						}
						else
						{
						if((strcpy_delimfix(v->name,GLOBALS->yytext_vcd_recoder_c_3)) && (GLOBALS->yytext_vcd_recoder_c_3[0] != '\\'))
							{
							char *sd=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+2);
							sd[0] = '\\';
							strcpy(sd+1,v->name);
							free_2(v->name);
							v->name = sd;
							}
						}
					}

                                if(GLOBALS->pv_vcd_recoder_c_3)
                                        {
                                        if(!strcmp(GLOBALS->prev_hier_uncompressed_name,v->name) && !disable_autocoalesce && (!strchr(v->name, '\\')))
                                                {
                                                GLOBALS->pv_vcd_recoder_c_3->chain=v;
                                                v->root=GLOBALS->rootv_vcd_recoder_c_3;
                                                if(GLOBALS->pv_vcd_recoder_c_3==GLOBALS->rootv_vcd_recoder_c_3) GLOBALS->pv_vcd_recoder_c_3->root=GLOBALS->rootv_vcd_recoder_c_3;
                                                }
                                                else
                                                {
                                                GLOBALS->rootv_vcd_recoder_c_3=v;
                                                }

					free_2(GLOBALS->prev_hier_uncompressed_name);
                                        }
					else
					{
					GLOBALS->rootv_vcd_recoder_c_3=v;
					}

                                GLOBALS->pv_vcd_recoder_c_3=v;
				GLOBALS->prev_hier_uncompressed_name = strdup_2(v->name);
				}
				else	/* regular vcd var, not an evcd port var */
				{
				vtok=get_vartoken(1);
				if(vtok==V_END) goto err;
				v->size=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
				vtok=get_strtoken();
				if(vtok==V_END) goto err;
				v->id=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+1);
				strcpy(v->id, GLOBALS->yytext_vcd_recoder_c_3);
                                v->nid=vcdid_hash(GLOBALS->yytext_vcd_recoder_c_3,GLOBALS->yylen_vcd_recoder_c_3);

                                if(v->nid == (GLOBALS->vcd_hash_max+1))
                                        {
                                        GLOBALS->vcd_hash_max = v->nid;
                                        }
                                else
                                if((v->nid>0)&&(v->nid<=GLOBALS->vcd_hash_max))
                                        {
                                        /* general case with aliases */
                                        }
                                else
                                        {
                                        GLOBALS->vcd_hash_kill = 1;
                                        }

                                if(v->nid < GLOBALS->vcd_minid_vcd_recoder_c_3) GLOBALS->vcd_minid_vcd_recoder_c_3 = v->nid;
                                if(v->nid > GLOBALS->vcd_maxid_vcd_recoder_c_3) GLOBALS->vcd_maxid_vcd_recoder_c_3 = v->nid;

				vtok=get_vartoken(0);
				if(vtok!=V_STRING) goto err;

				if(GLOBALS->slisthier_len)
					{
					v->name=(char *)malloc_2(GLOBALS->slisthier_len+1+GLOBALS->yylen_vcd_recoder_c_3+1);
					strcpy(v->name,GLOBALS->slisthier);
					strcpy(v->name+GLOBALS->slisthier_len,GLOBALS->vcd_hier_delimeter);
					if(GLOBALS->alt_hier_delimeter)
						{
						strcpy_vcdalt(v->name+GLOBALS->slisthier_len+1,GLOBALS->yytext_vcd_recoder_c_3,GLOBALS->alt_hier_delimeter);
						}
						else
						{
						if((strcpy_delimfix(v->name+GLOBALS->slisthier_len+1,GLOBALS->yytext_vcd_recoder_c_3)) && (GLOBALS->yytext_vcd_recoder_c_3[0] != '\\'))
							{
                                                        char *sd=(char *)malloc_2(GLOBALS->slisthier_len+1+GLOBALS->yylen_vcd_recoder_c_3+2);
                                                        strcpy(sd,GLOBALS->slisthier);
                                                        strcpy(sd+GLOBALS->slisthier_len,GLOBALS->vcd_hier_delimeter);
                                                        sd[GLOBALS->slisthier_len+1] = '\\';
                                                        strcpy(sd+GLOBALS->slisthier_len+2,v->name+GLOBALS->slisthier_len+1);
                                                        free_2(v->name);
                                                        v->name = sd;
							}
						}
					}
					else
					{
					v->name=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+1);
					if(GLOBALS->alt_hier_delimeter)
						{
						strcpy_vcdalt(v->name,GLOBALS->yytext_vcd_recoder_c_3,GLOBALS->alt_hier_delimeter);
						}
						else
						{
                                                if((strcpy_delimfix(v->name,GLOBALS->yytext_vcd_recoder_c_3)) && (GLOBALS->yytext_vcd_recoder_c_3[0] != '\\'))
                                                        {
                                                        char *sd=(char *)malloc_2(GLOBALS->yylen_vcd_recoder_c_3+2);
                                                        sd[0] = '\\';
                                                        strcpy(sd+1,v->name);
                                                        free_2(v->name);
                                                        v->name = sd;
                                                        }
						}
					}

                                if(GLOBALS->pv_vcd_recoder_c_3)
                                        {
                                        if(!strcmp(GLOBALS->prev_hier_uncompressed_name,v->name))
                                                {
                                                GLOBALS->pv_vcd_recoder_c_3->chain=v;
                                                v->root=GLOBALS->rootv_vcd_recoder_c_3;
                                                if(GLOBALS->pv_vcd_recoder_c_3==GLOBALS->rootv_vcd_recoder_c_3) GLOBALS->pv_vcd_recoder_c_3->root=GLOBALS->rootv_vcd_recoder_c_3;
                                                }
                                                else
                                                {
                                                GLOBALS->rootv_vcd_recoder_c_3=v;
                                                }

					free_2(GLOBALS->prev_hier_uncompressed_name);
                                        }
					else
					{
					GLOBALS->rootv_vcd_recoder_c_3=v;
					}
                                GLOBALS->pv_vcd_recoder_c_3=v;
				GLOBALS->prev_hier_uncompressed_name = strdup_2(v->name);

				vtok=get_vartoken(1);
				if(vtok==V_END) goto dumpv;
				if(vtok!=V_LB) goto err;
				vtok=get_vartoken(0);
				if(vtok!=V_STRING) goto err;
				v->msi=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
				vtok=get_vartoken(0);
				if(vtok==V_RB)
					{
					v->lsi=v->msi;
					goto dumpv;
					}
				if(vtok!=V_COLON) goto err;
				vtok=get_vartoken(0);
				if(vtok!=V_STRING) goto err;
				v->lsi=atoi_64(GLOBALS->yytext_vcd_recoder_c_3);
				vtok=get_vartoken(0);
				if(vtok!=V_RB) goto err;
				}

			dumpv:
			if(v->size == 0)
				{
				if(v->vartype != V_EVENT)
					{
					if(v->vartype != V_STRINGTYPE)
						{
						v->vartype = V_REAL;
						}
					}
					else
					{
					v->size = 1;
					}

				} /* MTI fix */


			if((v->vartype==V_REAL)||(v->vartype==V_STRINGTYPE))
				{
				v->size=1;		/* override any data we parsed in */
				v->msi=v->lsi=0;
				}
			else
			if((v->size>1)&&(v->msi<=0)&&(v->lsi<=0))
				{
				if(v->vartype==V_EVENT)
					{
					v->size=1;
					}
					else
					{
					/* any criteria for the direction here? */
					v->msi=v->size-1;
					v->lsi=0;
					}
				}
			else
			if((v->msi>v->lsi)&&((v->msi-v->lsi+1)!=v->size))
				{
				if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
					{
					if((v->msi-v->lsi+1) > v->size) /* if() is 2d add */
						{
						v->msi = v->size-1; v->lsi = 0;
						}
					/* all this formerly was goto err; */
					}
					else
					{
					v->size=v->msi-v->lsi+1;
					}
				}
			else
			if((v->lsi>=v->msi)&&((v->lsi-v->msi+1)!=v->size))
				{
				if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
					{
					if((v->lsi-v->msi+1) > v->size) /* if() is 2d add */
						{
						v->lsi = v->size-1; v->msi = 0;
						}
					/* all this formerly was goto err; */
					}
					else
					{
					v->size=v->lsi-v->msi+1;
					}
				}

			/* initial conditions */
			v->narray=(struct Node **)calloc_2(1,sizeof(struct Node *));
			v->narray[0]=(struct Node *)calloc_2(1,sizeof(struct Node));
			v->narray[0]->head.time=-1;
			v->narray[0]->head.v.h_val=AN_X;

			if(!GLOBALS->vcdsymroot_vcd_recoder_c_3)
				{
				GLOBALS->vcdsymroot_vcd_recoder_c_3=GLOBALS->vcdsymcurr_vcd_recoder_c_3=v;
				}
				else
				{
				GLOBALS->vcdsymcurr_vcd_recoder_c_3->next=v;
				GLOBALS->vcdsymcurr_vcd_recoder_c_3=v;
				}
			GLOBALS->numsyms_vcd_recoder_c_3++;

			if(GLOBALS->vcd_save_handle)
				{
				if(v->msi==v->lsi)
					{
					if((v->vartype==V_REAL)||(v->vartype==V_STRINGTYPE))
						{
						fprintf(GLOBALS->vcd_save_handle,"%s\n",v->name);
						}
						else
						{
						if(v->msi>=0)
							{
							if(!GLOBALS->vcd_explicit_zero_subscripts)
								fprintf(GLOBALS->vcd_save_handle,"%s%c%d\n",v->name,GLOBALS->hier_delimeter,v->msi);
								else
								fprintf(GLOBALS->vcd_save_handle,"%s[%d]\n",v->name,v->msi);
							}
							else
							{
							fprintf(GLOBALS->vcd_save_handle,"%s\n",v->name);
							}
						}
					}
					else
					{
					fprintf(GLOBALS->vcd_save_handle,"%s[%d:%d]\n",v->name,v->msi,v->lsi);
					}
				}

			goto bail;
			err:
			if(v)
				{
				GLOBALS->error_count_vcd_recoder_c_3++;
				if(v->name)
					{
					fprintf(stderr, "Near byte %d, $VAR parse error encountered with '%s'\n", (int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)), v->name);
					free_2(v->name);
					}
					else
					{
					fprintf(stderr, "Near byte %d, $VAR parse error encountered\n", (int)(GLOBALS->vcdbyteno_vcd_recoder_c_3+(GLOBALS->vst_vcd_recoder_c_3-GLOBALS->vcdbuf_vcd_recoder_c_3)));
					}
				if(v->id) free_2(v->id);
				free_2(v); v=NULL;
				GLOBALS->pv_vcd_recoder_c_3 = NULL;
				}

			bail:
			if(vtok!=V_END) sync_end(NULL);
			break;
			}
		case T_ENDDEFINITIONS:
			GLOBALS->header_over_vcd_recoder_c_3=1;	/* do symbol table management here */
			create_sorted_table();
			if((!GLOBALS->sorted_vcd_recoder_c_3)&&(!GLOBALS->indexed_vcd_recoder_c_3))
				{
				fprintf(stderr, "No symbols in VCD file..nothing to do!\n");
				vcd_exit(255);
				}
			if(GLOBALS->error_count_vcd_recoder_c_3)
				{
				fprintf(stderr, "\n%d VCD parse errors encountered, exiting.\n", GLOBALS->error_count_vcd_recoder_c_3);
				vcd_exit(255);
				}

			if(GLOBALS->use_fastload == VCD_FSL_READ)
				{
				read_fastload_body();
				fprintf(stderr, "VCDLOAD | Using fastload file.\n");
				return;
				}

			break;
		case T_STRING:
			if(!GLOBALS->header_over_vcd_recoder_c_3)
				{
				GLOBALS->header_over_vcd_recoder_c_3=1;	/* do symbol table management here */
				create_sorted_table();
				if((!GLOBALS->sorted_vcd_recoder_c_3)&&(!GLOBALS->indexed_vcd_recoder_c_3)) break;
				}
				{
				/* catchall for events when header over */
				if(GLOBALS->yytext_vcd_recoder_c_3[0]=='#')
					{
					TimeType tim;
					TimeType *tt;

					tim=atoi_64(GLOBALS->yytext_vcd_recoder_c_3+1);

					if(GLOBALS->start_time_vcd_recoder_c_3<0)
						{
						GLOBALS->start_time_vcd_recoder_c_3=tim;

						if(GLOBALS->time_vlist_vcd_recoder_write)
							{
							vlist_packer_emit_utt((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, tim);
							}
						}
						else
						{
/* backtracking fix */
						if(tim < GLOBALS->current_time_vcd_recoder_c_3)
							{
							if(!GLOBALS->vcd_already_backtracked)
								{
								GLOBALS->vcd_already_backtracked = 1;
								fprintf(stderr, "VCDLOAD | Time backtracking detected in VCD file!\n");
								}
							}
#if 0
						if(tim < GLOBALS->current_time_vcd_recoder_c_3) /* avoid backtracking time counts which can happen on malformed files */
							{
							tim = GLOBALS->current_time_vcd_recoder_c_3;
							}
#endif

						if(GLOBALS->time_vlist_vcd_recoder_write)
							{
							vlist_packer_emit_utt((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, tim - GLOBALS->current_time_vcd_recoder_c_3);
							}
						}

					GLOBALS->current_time_vcd_recoder_c_3=tim;
					if(GLOBALS->end_time_vcd_recoder_c_3<tim) GLOBALS->end_time_vcd_recoder_c_3=tim;	/* in case of malformed vcd files */
					DEBUG(fprintf(stderr,"#"TTFormat"\n",tim));

					tt = vlist_alloc(&GLOBALS->time_vlist_vcd_recoder_c_1, 0);
					*tt = tim;
					GLOBALS->time_vlist_count_vcd_recoder_c_1++;
					}
					else
					{
					if(GLOBALS->time_vlist_count_vcd_recoder_c_1)
						{
						/* OK, otherwise fix for System C which doesn't emit time zero... */
						}
						else
						{
						TimeType tim = LLDescriptor(0);
						TimeType *tt;

						GLOBALS->start_time_vcd_recoder_c_3=GLOBALS->current_time_vcd_recoder_c_3=GLOBALS->end_time_vcd_recoder_c_3=tim;

						if(GLOBALS->time_vlist_vcd_recoder_write)
							{
							vlist_packer_emit_utt((struct vlist_packer_t **)(void *)&GLOBALS->time_vlist_vcd_recoder_write, tim);
							}

						tt = vlist_alloc(&GLOBALS->time_vlist_vcd_recoder_c_1, 0);
						*tt = tim;
						GLOBALS->time_vlist_count_vcd_recoder_c_1=1;
						}
					parse_valuechange();
					}
				}
			break;
		case T_DUMPALL:	/* dump commands modify vals anyway so */
		case T_DUMPPORTSALL:
			break;	/* just loop through..                 */
		case T_DUMPOFF:
		case T_DUMPPORTSOFF:
			GLOBALS->dumping_off_vcd_recoder_c_3=1;
                        /* if((!GLOBALS->blackout_regions)||((GLOBALS->blackout_regions)&&(GLOBALS->blackout_regions->bstart<=GLOBALS->blackout_regions->bend))) : remove redundant condition */
                        if((!GLOBALS->blackout_regions)||(GLOBALS->blackout_regions->bstart<=GLOBALS->blackout_regions->bend))
				{
				struct blackout_region_t *bt = calloc_2(1, sizeof(struct blackout_region_t));

				bt->bstart = GLOBALS->current_time_vcd_recoder_c_3;
				bt->next = GLOBALS->blackout_regions;
				GLOBALS->blackout_regions = bt;
				}
			break;
		case T_DUMPON:
		case T_DUMPPORTSON:
			GLOBALS->dumping_off_vcd_recoder_c_3=0;
			if((GLOBALS->blackout_regions)&&(GLOBALS->blackout_regions->bstart>GLOBALS->blackout_regions->bend))
				{
				GLOBALS->blackout_regions->bend = GLOBALS->current_time_vcd_recoder_c_3;
				}
			break;
		case T_DUMPVARS:
		case T_DUMPPORTS:
			if(GLOBALS->current_time_vcd_recoder_c_3<0)
				{ GLOBALS->start_time_vcd_recoder_c_3=GLOBALS->current_time_vcd_recoder_c_3=GLOBALS->end_time_vcd_recoder_c_3=0; }
			break;
		case T_VCDCLOSE:
			sync_end("VCDCLOSE:");
			break;	/* next token will be '#' time related followed by $end */
		case T_END:	/* either closure for dump commands or */
			break;	/* it's spurious                       */
		case T_UNKNOWN_KEY:
			sync_end(NULL);	/* skip over unknown keywords */
			break;
		case T_EOF:
			if((GLOBALS->blackout_regions)&&(GLOBALS->blackout_regions->bstart>GLOBALS->blackout_regions->bend))
				{
				GLOBALS->blackout_regions->bend = GLOBALS->current_time_vcd_recoder_c_3;
				}

			GLOBALS->pv_vcd_recoder_c_3 = NULL;
			if(GLOBALS->prev_hier_uncompressed_name) { free_2(GLOBALS->prev_hier_uncompressed_name); GLOBALS->prev_hier_uncompressed_name = NULL; }

			return;
		default:
			DEBUG(fprintf(stderr,"UNKNOWN TOKEN\n"));
		}
	}
}


/*******************************************************************************/

void add_histent(TimeType tim, struct Node *n, char ch, int regadd, char *vector)
{
struct HistEnt *he;
char heval;

if(!vector)
{
if(!n->curr)
	{
	he=histent_calloc();
        he->time=-1;
        he->v.h_val=AN_X;

	n->curr=he;
	n->head.next=he;

	add_histent(tim,n,ch,regadd, vector);
	}
	else
	{
	if(regadd) { tim*=(GLOBALS->time_scale); }

	if(ch=='0')              heval=AN_0; else
	if(ch=='1')              heval=AN_1; else
        if((ch=='x')||(ch=='X')) heval=AN_X; else
        if((ch=='z')||(ch=='Z')) heval=AN_Z; else
        if((ch=='h')||(ch=='H')) heval=AN_H; else
        if((ch=='u')||(ch=='U')) heval=AN_U; else
        if((ch=='w')||(ch=='W')) heval=AN_W; else
        if((ch=='l')||(ch=='L')) heval=AN_L; else
        /* if(ch=='-') */        heval=AN_DASH;		/* default */

	if((n->curr->v.h_val!=heval)||(tim==GLOBALS->start_time_vcd_recoder_c_3)||(n->vartype==ND_VCD_EVENT)||(GLOBALS->vcd_preserve_glitches)) /* same region == go skip */
        	{
		if(n->curr->time==tim)
			{
			DEBUG(printf("Warning: Glitch at time ["TTFormat"] Signal [%p], Value [%c->%c].\n",
				tim, n, AN_STR[n->curr->v.h_val], ch));
			n->curr->v.h_val=heval;		/* we have a glitch! */

			GLOBALS->num_glitches_vcd_recoder_c_4++;
			if(!(n->curr->flags&HIST_GLITCH))
				{
				n->curr->flags|=HIST_GLITCH;	/* set the glitch flag */
				GLOBALS->num_glitch_regions_vcd_recoder_c_4++;
				}
			}
			else
			{
                	he=histent_calloc();
                	he->time=tim;
                	he->v.h_val=heval;

                	n->curr->next=he;
			if(n->curr->v.h_val==heval)
				{
				n->curr->flags|=HIST_GLITCH;    /* set the glitch flag */
				GLOBALS->num_glitch_regions_vcd_recoder_c_4++;				
				}
			n->curr=he;
                	GLOBALS->regions+=regadd;
			}
                }
       }
}
else
{
switch(ch)
	{
	case 's': /* string */
	{
	if(!n->curr)
		{
		he=histent_calloc();
		he->flags=(HIST_STRING|HIST_REAL);
	        he->time=-1;
	        he->v.h_vector=NULL;

		n->curr=he;
		n->head.next=he;

		add_histent(tim,n,ch,regadd, vector);
		}
		else
		{
		if(regadd) { tim*=(GLOBALS->time_scale); }

			if(n->curr->time==tim)
				{
				DEBUG(printf("Warning: String Glitch at time ["TTFormat"] Signal [%p].\n",
					tim, n));
				if(n->curr->v.h_vector) free_2(n->curr->v.h_vector);
				n->curr->v.h_vector=vector;		/* we have a glitch! */

				GLOBALS->num_glitches_vcd_recoder_c_4++;
				if(!(n->curr->flags&HIST_GLITCH))
					{
					n->curr->flags|=HIST_GLITCH;	/* set the glitch flag */
					GLOBALS->num_glitch_regions_vcd_recoder_c_4++;
					}
				}
				else
				{
	                	he=histent_calloc();
				he->flags=(HIST_STRING|HIST_REAL);
	                	he->time=tim;
	                	he->v.h_vector=vector;

	                	n->curr->next=he;
				n->curr=he;
	                	GLOBALS->regions+=regadd;
				}
	       }
	break;
	}
	case 'g': /* real number */
	{
	if(!n->curr)
		{
		he=histent_calloc();
		he->flags=HIST_REAL;
	        he->time=-1;
#ifdef WAVE_HAS_H_DOUBLE
                he->v.h_double = strtod("NaN", NULL);
#else
	        he->v.h_vector=NULL;
#endif

		n->curr=he;
		n->head.next=he;

		add_histent(tim,n,ch,regadd, vector);
		}
		else
		{
		if(regadd) { tim*=(GLOBALS->time_scale); }

		if(
#ifdef WAVE_HAS_H_DOUBLE
                  (vector&&(n->curr->v.h_double!=*(double *)vector))
#else
		  (n->curr->v.h_vector&&vector&&(*(double *)n->curr->v.h_vector!=*(double *)vector))
#endif
			||(tim==GLOBALS->start_time_vcd_recoder_c_3)
#ifndef WAVE_HAS_H_DOUBLE
			||(!n->curr->v.h_vector)
#endif
			||(GLOBALS->vcd_preserve_glitches)||(GLOBALS->vcd_preserve_glitches_real)
			) /* same region == go skip */
	        	{
			if(n->curr->time==tim)
				{
				DEBUG(printf("Warning: Real number Glitch at time ["TTFormat"] Signal [%p].\n",
					tim, n));
#ifdef WAVE_HAS_H_DOUBLE
                                n->curr->v.h_double = *((double *)vector);
#else
				if(n->curr->v.h_vector) free_2(n->curr->v.h_vector);
				n->curr->v.h_vector=vector;		/* we have a glitch! */
#endif
				GLOBALS->num_glitches_vcd_recoder_c_4++;
				if(!(n->curr->flags&HIST_GLITCH))
					{
					n->curr->flags|=HIST_GLITCH;	/* set the glitch flag */
					GLOBALS->num_glitch_regions_vcd_recoder_c_4++;
					}
				}
				else
				{
	                	he=histent_calloc();
				he->flags=HIST_REAL;
	                	he->time=tim;
#ifdef WAVE_HAS_H_DOUBLE
				he->v.h_double = *((double *)vector);
#else
	                	he->v.h_vector=vector;
#endif
	                	n->curr->next=he;
				n->curr=he;
	                	GLOBALS->regions+=regadd;
				}
	                }
			else
			{
#ifndef WAVE_HAS_H_DOUBLE
			free_2(vector);
#endif
			}
#ifdef WAVE_HAS_H_DOUBLE
	        free_2(vector);
#endif
	       }
	break;
	}
	default:
	{
	if(!n->curr)
		{
		he=histent_calloc();
	        he->time=-1;
	        he->v.h_vector=NULL;

		n->curr=he;
		n->head.next=he;

		add_histent(tim,n,ch,regadd, vector);
		}
		else
		{
		if(regadd) { tim*=(GLOBALS->time_scale); }

		if(
		  (n->curr->v.h_vector&&vector&&(strcmp(n->curr->v.h_vector,vector)))
			||(tim==GLOBALS->start_time_vcd_recoder_c_3)
			||(!n->curr->v.h_vector)
			||(GLOBALS->vcd_preserve_glitches)
			) /* same region == go skip */
	        	{
			if(n->curr->time==tim)
				{
				DEBUG(printf("Warning: Glitch at time ["TTFormat"] Signal [%p], Value [%c->%c].\n",
					tim, n, AN_STR[n->curr->v.h_val], ch));
				if(n->curr->v.h_vector) free_2(n->curr->v.h_vector);
				n->curr->v.h_vector=vector;		/* we have a glitch! */

				GLOBALS->num_glitches_vcd_recoder_c_4++;
				if(!(n->curr->flags&HIST_GLITCH))
					{
					n->curr->flags|=HIST_GLITCH;	/* set the glitch flag */
					GLOBALS->num_glitch_regions_vcd_recoder_c_4++;
					}
				}
				else
				{
	                	he=histent_calloc();
	                	he->time=tim;
	                	he->v.h_vector=vector;

	                	n->curr->next=he;
				n->curr=he;
	                	GLOBALS->regions+=regadd;
				}
	                }
			else
			{
			free_2(vector);
			}
	       }
	break;
	}
	}
}

}

/*******************************************************************************/

static void vcd_build_symbols(void)
{
int j;
int max_slen=-1;
struct sym_chain *sym_chain=NULL, *sym_curr=NULL;
int duphier=0;
char hashdirty;
struct vcdsymbol *v, *vprime;
char *str = wave_alloca(1); /* quiet scan-build null pointer warning below */
#ifdef _WAVE_HAVE_JUDY
int ss_len, longest = 0;
#endif

v=GLOBALS->vcdsymroot_vcd_recoder_c_3;
while(v)
	{
	int msi;
	int delta;

		{
		int slen;
		int substnode;

		msi=v->msi;
		delta=((v->lsi-v->msi)<0)?-1:1;
		substnode=0;

		slen=strlen(v->name);
		str=(slen>max_slen)?(wave_alloca((max_slen=slen)+32)):(str); /* more than enough */
		strcpy(str,v->name);

		if((v->msi>=0)||(v->msi != v->lsi))
			{
			strcpy(str+slen,GLOBALS->vcd_hier_delimeter);
			slen++;
			}

		if((vprime=bsearch_vcd(v->id, strlen(v->id)))!=v) /* hash mish means dup net */
			{
			if(v->size!=vprime->size)
				{
				fprintf(stderr,"ERROR: Duplicate IDs with differing width: %s %s\n", v->name, vprime->name);
				}
				else
				{
				substnode=1;
				}
			}

		if((v->size==1)&&(v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE))
			{
			struct symbol *s = NULL;

			for(j=0;j<v->size;j++)
				{
				if(v->msi>=0)
					{
					if(!GLOBALS->vcd_explicit_zero_subscripts)
						sprintf(str+slen,"%d",msi);
						else
						sprintf(str+slen-1,"[%d]",msi);
					}

				hashdirty=0;
				if(symfind(str, NULL))
					{
					char *dupfix=(char *)malloc_2(max_slen+32);
#ifndef _WAVE_HAVE_JUDY
					hashdirty=1;
#endif
					DEBUG(fprintf(stderr,"Warning: %s is a duplicate net name.\n",str));

					do sprintf(dupfix, "$DUP%d%s%s", duphier++, GLOBALS->vcd_hier_delimeter, str);
						while(symfind(dupfix, NULL));

					strcpy(str, dupfix);
					free_2(dupfix);
					duphier=0; /* reset for next duplicate resolution */
					}
					/* fallthrough */
					{
					s=symadd(str,hashdirty?hash(str):GLOBALS->hashcache);
#ifdef _WAVE_HAVE_JUDY
					ss_len = strlen(str); if(ss_len >= longest) { longest = ss_len + 1; }
#endif
					s->n=v->narray[j];
					if(substnode)
						{
						struct Node *n, *n2;

						n=s->n;
						n2=vprime->narray[j];
						/* nname stays same */
						/* n->head=n2->head; */
						/* n->curr=n2->curr; */
						n->curr=(hptr)n2;
						/* harray calculated later */
						n->numhist=n2->numhist;
						}

#ifndef _WAVE_HAVE_JUDY
					s->n->nname=s->name;
#endif
					if(!GLOBALS->firstnode)
					        {
					        GLOBALS->firstnode=
					        GLOBALS->curnode=calloc_2(1, sizeof(struct symchain));
					        }
					        else
					        {
					        GLOBALS->curnode->next=calloc_2(1, sizeof(struct symchain));
					        GLOBALS->curnode=GLOBALS->curnode->next;
					        }
					GLOBALS->curnode->symbol=s;

					GLOBALS->numfacs++;
					DEBUG(fprintf(stderr,"Added: %s\n",str));
					}
				msi+=delta;
				}

			if((j==1)&&(v->root))
				{
				s->vec_root=(struct symbol *)v->root;		/* these will get patched over */
				s->vec_chain=(struct symbol *)v->chain;		/* these will get patched over */
				v->sym_chain=s;

				if(!sym_chain)
					{
					sym_curr=(struct sym_chain *)calloc_2(1,sizeof(struct sym_chain));
					sym_chain=sym_curr;
					}
					else
					{
					sym_curr->next=(struct sym_chain *)calloc_2(1,sizeof(struct sym_chain));
					sym_curr=sym_curr->next;
					}
				sym_curr->val=s;
				}
			}
			else	/* atomic vector */
			{
			if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)&&(v->vartype!=V_INTEGER)&&(v->vartype!=V_PARAMETER))
			/* if((v->vartype!=V_REAL)&&(v->vartype!=V_STRINGTYPE)) */
				{
				sprintf(str+slen-1,"[%d:%d]",v->msi,v->lsi);
				/* 2d add */
				if((v->msi>v->lsi)&&((v->msi-v->lsi+1)!=v->size))
					{
					if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
						{
						v->msi = v->size-1; v->lsi = 0;
						}
					}
				else	
				if((v->lsi>=v->msi)&&((v->lsi-v->msi+1)!=v->size))
					{
					if((v->vartype!=V_EVENT)&&(v->vartype!=V_PARAMETER))
						{
						v->lsi = v->size-1; v->msi = 0;
						}
					}
				}
				else
				{
				*(str+slen-1)=0;
				}


			hashdirty=0;
			if(symfind(str, NULL))
				{
				char *dupfix=(char *)malloc_2(max_slen+32);
#ifndef _WAVE_HAVE_JUDY
				hashdirty=1;
#endif
				DEBUG(fprintf(stderr,"Warning: %s is a duplicate net name.\n",str));

				do sprintf(dupfix, "$DUP%d%s%s", duphier++, GLOBALS->vcd_hier_delimeter, str);
					while(symfind(dupfix, NULL));

				strcpy(str, dupfix);
				free_2(dupfix);
				duphier=0; /* reset for next duplicate resolution */
				}
				/* fallthrough */
				{
				struct symbol *s;

				s=symadd(str,hashdirty?hash(str):GLOBALS->hashcache);	/* cut down on double lookups.. */
#ifdef _WAVE_HAVE_JUDY
                                ss_len = strlen(str); if(ss_len >= longest) { longest = ss_len + 1; }
#endif
				s->n=v->narray[0];
				if(substnode)
					{
					struct Node *n, *n2;

					n=s->n;
					n2=vprime->narray[0];
					/* nname stays same */
					/* n->head=n2->head; */
					/* n->curr=n2->curr; */
					n->curr=(hptr)n2;
					/* harray calculated later */
					n->numhist=n2->numhist;
					n->extvals=n2->extvals;
					n->msi=n2->msi;
					n->lsi=n2->lsi;
					}
					else
					{
					s->n->msi=v->msi;
					s->n->lsi=v->lsi;

					s->n->extvals=1;
					}

#ifndef _WAVE_HAVE_JUDY
				s->n->nname=s->name;
#endif
				if(!GLOBALS->firstnode)
				        {
				        GLOBALS->firstnode=
				        GLOBALS->curnode=calloc_2(1, sizeof(struct symchain));
				        }
				        else
				        {
				        GLOBALS->curnode->next=calloc_2(1, sizeof(struct symchain));
				        GLOBALS->curnode=GLOBALS->curnode->next;
				        }
				GLOBALS->curnode->symbol=s;

				GLOBALS->numfacs++;
				DEBUG(fprintf(stderr,"Added: %s\n",str));
				}
			}
		}

	v=v->next;
	}

#ifdef _WAVE_HAVE_JUDY
{
Pvoid_t  PJArray = GLOBALS->sym_judy;
PPvoid_t PPValue;
char *Index = calloc_2(1, longest);

for (PPValue  = JudySLFirst (PJArray, (uint8_t *)Index, PJE0);
         PPValue != (PPvoid_t) NULL;
         PPValue  = JudySLNext  (PJArray, (uint8_t *)Index, PJE0))
    {
	struct symbol *s = *(struct symbol **)PPValue;
	s->name = strdup_2(Index);
	s->n->nname = s->name;
    }

free_2(Index);
}
#endif

if(sym_chain)
	{
	sym_curr=sym_chain;
	while(sym_curr)
		{
		sym_curr->val->vec_root= ((struct vcdsymbol *)sym_curr->val->vec_root)->sym_chain;

		if ((struct vcdsymbol *)sym_curr->val->vec_chain)
			sym_curr->val->vec_chain=((struct vcdsymbol *)sym_curr->val->vec_chain)->sym_chain;

		DEBUG(printf("Link: ('%s') '%s' -> '%s'\n",sym_curr->val->vec_root->name, sym_curr->val->name, sym_curr->val->vec_chain?sym_curr->val->vec_chain->name:"(END)"));

		sym_chain=sym_curr;
		sym_curr=sym_curr->next;
		free_2(sym_chain);
		}
	}
}

/*******************************************************************************/

static void vcd_cleanup(void)
{
struct slist *s, *s2;
struct vcdsymbol *v, *vt;

if(GLOBALS->indexed_vcd_recoder_c_3)
	{
	free_2(GLOBALS->indexed_vcd_recoder_c_3); GLOBALS->indexed_vcd_recoder_c_3=NULL;
	}

if(GLOBALS->sorted_vcd_recoder_c_3)
	{
	free_2(GLOBALS->sorted_vcd_recoder_c_3); GLOBALS->sorted_vcd_recoder_c_3=NULL;
	}

v=GLOBALS->vcdsymroot_vcd_recoder_c_3;
while(v)
	{
	if(v->name) free_2(v->name);
	if(v->id) free_2(v->id);
	if(v->narray) free_2(v->narray);
	vt=v;
	v=v->next;
	free_2(vt);
	}
GLOBALS->vcdsymroot_vcd_recoder_c_3=GLOBALS->vcdsymcurr_vcd_recoder_c_3=NULL;

if(GLOBALS->slisthier) { free_2(GLOBALS->slisthier); GLOBALS->slisthier=NULL; }
s=GLOBALS->slistroot;
while(s)
	{
	s2=s->next;
	if(s->str)free_2(s->str);
	free_2(s);
	s=s2;
	}

GLOBALS->slistroot=GLOBALS->slistcurr=NULL; GLOBALS->slisthier_len=0;

if(GLOBALS->vcd_is_compressed_vcd_recoder_c_2)
	{
	pclose(GLOBALS->vcd_handle_vcd_recoder_c_2);
	GLOBALS->vcd_handle_vcd_recoder_c_2 = NULL;
	}
	else
	{
	fclose(GLOBALS->vcd_handle_vcd_recoder_c_2);
	GLOBALS->vcd_handle_vcd_recoder_c_2 = NULL;
	}

if(GLOBALS->yytext_vcd_recoder_c_3)
	{
	free_2(GLOBALS->yytext_vcd_recoder_c_3);
	GLOBALS->yytext_vcd_recoder_c_3=NULL;
	}
}

/*******************************************************************************/

TimeType vcd_recoder_main(char *fname)
{
unsigned int finalize_cnt = 0;
#ifdef HAVE_SYS_STAT_H
struct stat mystat;
int stat_rc = stat(fname, &mystat);
#endif

GLOBALS->pv_vcd_recoder_c_3=GLOBALS->rootv_vcd_recoder_c_3=NULL;
GLOBALS->vcd_hier_delimeter[0]=GLOBALS->hier_delimeter;

if(GLOBALS->use_fastload)
	{
        char *ffname = malloc_2(strlen(fname) + 4 + 1);
        sprintf(ffname, "%s.idx", fname);

        GLOBALS->vlist_handle = fopen(ffname, "rb");
	if(GLOBALS->vlist_handle)
		{
		GLOBALS->use_fastload = VCD_FSL_READ;

		/* need to do a sanity check looking for time of vcd file vs recoder file, etc. */
#ifdef HAVE_SYS_STAT_H
		if( (stat_rc) || (!read_fastload_header(&mystat)) )
#else
		if(!read_fastload_header())
#endif
			{
			GLOBALS->use_fastload = VCD_FSL_WRITE;
			fclose(GLOBALS->vlist_handle);
			GLOBALS->vlist_handle = NULL;
			}
		}
		else
		{
		GLOBALS->use_fastload = VCD_FSL_WRITE;
		}

        free_2(ffname);
        }

errno=0;	/* reset in case it's set for some reason */

GLOBALS->yytext_vcd_recoder_c_3=(char *)malloc_2(GLOBALS->T_MAX_STR_vcd_recoder_c_3+1);

if(!GLOBALS->hier_was_explicitly_set) /* set default hierarchy split char */
	{
	GLOBALS->hier_delimeter='.';
	}

if(suffix_check(fname, ".gz") || suffix_check(fname, ".zip"))
	{
	char *str;
	int dlen;
	dlen=strlen(WAVE_DECOMPRESSOR);
	str=wave_alloca(strlen(fname)+dlen+1);
	strcpy(str,WAVE_DECOMPRESSOR);
	strcpy(str+dlen,fname);
	GLOBALS->vcd_handle_vcd_recoder_c_2=popen(str,"r");
	GLOBALS->vcd_is_compressed_vcd_recoder_c_2=~0;
	}
	else
	{
	if(strcmp("-vcd",fname))
		{
		GLOBALS->vcd_handle_vcd_recoder_c_2=fopen(fname,"rb");

		if(GLOBALS->vcd_handle_vcd_recoder_c_2)
			{
			fseeko(GLOBALS->vcd_handle_vcd_recoder_c_2, 0, SEEK_END);	/* do status bar for vcd load */
			GLOBALS->vcd_fsiz_vcd_recoder_c_2 = ftello(GLOBALS->vcd_handle_vcd_recoder_c_2);
			fseeko(GLOBALS->vcd_handle_vcd_recoder_c_2, 0, SEEK_SET);
			}

		if(GLOBALS->vcd_warning_filesize < 0) GLOBALS->vcd_warning_filesize = VCD_SIZE_WARN;

		if(GLOBALS->vcd_warning_filesize)
		if(GLOBALS->vcd_fsiz_vcd_recoder_c_2 > (GLOBALS->vcd_warning_filesize * (1024 * 1024)))
			{
			if(!GLOBALS->vlist_prepack)
				{
				fprintf(stderr, "Warning! File size is %d MB.  This might fail in recoding.\n"
					"Consider converting it to the FST database format instead.  (See the\n"
					"vcd2fst(1) manpage for more information.)\n"
					"To disable this warning, set rc variable vcd_warning_filesize to zero.\n"
					"Alternatively, use the -o, --optimize command line option to convert to FST\n"
					"or the -g, --giga command line option to use dynamically compressed memory.\n\n",
						(int)(GLOBALS->vcd_fsiz_vcd_recoder_c_2/(1024*1024)));
				}
				else
				{
				fprintf(stderr, "VCDLOAD | File size is %d MB, using vlist prepacking%s.\n\n",
						(int)(GLOBALS->vcd_fsiz_vcd_recoder_c_2/(1024*1024)),
						GLOBALS->vlist_spill_to_disk ? " and spill file" : "");
				}
			}
		}
		else
		{
		GLOBALS->splash_disable = 1;
		GLOBALS->vcd_handle_vcd_recoder_c_2=stdin;
		}
	GLOBALS->vcd_is_compressed_vcd_recoder_c_2=0;
	}

if(!GLOBALS->vcd_handle_vcd_recoder_c_2)
	{
	fprintf(stderr, "Error opening %s .vcd file '%s'.\n",
		GLOBALS->vcd_is_compressed_vcd_recoder_c_2?"compressed":"", fname);
	perror("Why");
	vcd_exit(255);
	}

/* SPLASH */				splash_create();

sym_hash_initialize(GLOBALS);
getch_alloc();		/* alloc membuff for vcd getch buffer */

build_slisthier();

GLOBALS->time_vlist_vcd_recoder_c_1 = vlist_create(sizeof(TimeType));

if(GLOBALS->use_fastload == VCD_FSL_WRITE)
	{
	GLOBALS->time_vlist_vcd_recoder_write = ((struct vlist_t *)vlist_packer_create());
	}

if((GLOBALS->vlist_spill_to_disk) && (GLOBALS->use_fastload != VCD_FSL_READ))
	{
	vlist_init_spillfile();
	}

vcd_parse();
if(GLOBALS->varsplit_vcd_recoder_c_3)
	{
        free_2(GLOBALS->varsplit_vcd_recoder_c_3);
        GLOBALS->varsplit_vcd_recoder_c_3=NULL;
        }

if(GLOBALS->vlist_handle)
	{
	FILE *vh = GLOBALS->vlist_handle;
	GLOBALS->vlist_handle = NULL;
	vlist_freeze(&GLOBALS->time_vlist_vcd_recoder_c_1);
	GLOBALS->vlist_handle = vh;
	}
	else
	{
	vlist_freeze(&GLOBALS->time_vlist_vcd_recoder_c_1);
	}

if(GLOBALS->time_vlist_vcd_recoder_write)
	{
	write_fastload_time_section();
	}

if(GLOBALS->use_fastload != VCD_FSL_READ)
	{
	finalize_cnt = vlist_emit_finalize();
	}

if(GLOBALS->time_vlist_vcd_recoder_write)
	{
#ifdef HAVE_SYS_STAT_H
	write_fastload_header(&mystat, finalize_cnt);
#else
	write_fastload_header(finalize_cnt);
#endif
	}


if((!GLOBALS->sorted_vcd_recoder_c_3)&&(!GLOBALS->indexed_vcd_recoder_c_3))
	{
	fprintf(stderr, "No symbols in VCD file..is it malformed?  Exiting!\n");
	vcd_exit(255);
	}

if(GLOBALS->vcd_save_handle) { fclose(GLOBALS->vcd_save_handle); GLOBALS->vcd_save_handle = NULL; }

fprintf(stderr, "["TTFormat"] start time.\n["TTFormat"] end time.\n", GLOBALS->start_time_vcd_recoder_c_3*GLOBALS->time_scale, GLOBALS->end_time_vcd_recoder_c_3*GLOBALS->time_scale);

if(GLOBALS->vcd_fsiz_vcd_recoder_c_2)
        {
        splash_sync(GLOBALS->vcd_fsiz_vcd_recoder_c_2, GLOBALS->vcd_fsiz_vcd_recoder_c_2);
	GLOBALS->vcd_fsiz_vcd_recoder_c_2 = 0;
        }
else
if(GLOBALS->vcd_is_compressed_vcd_recoder_c_2)
	{
        splash_sync(1,1);
	GLOBALS->vcd_fsiz_vcd_recoder_c_2 = 0;
	}

GLOBALS->min_time=GLOBALS->start_time_vcd_recoder_c_3*GLOBALS->time_scale;
GLOBALS->max_time=GLOBALS->end_time_vcd_recoder_c_3*GLOBALS->time_scale;
GLOBALS->global_time_offset = GLOBALS->global_time_offset * GLOBALS->time_scale;

if((GLOBALS->min_time==GLOBALS->max_time)&&(GLOBALS->max_time==LLDescriptor(-1)))
        {
        fprintf(stderr, "VCD times range is equal to zero.  Exiting.\n");
        vcd_exit(255);
        }

vcd_build_symbols();
vcd_sortfacs();
vcd_cleanup();

getch_free();		/* free membuff for vcd getch buffer */


if(GLOBALS->blackout_regions)
	{
	struct blackout_region_t *bt = GLOBALS->blackout_regions;
	while(bt)
		{
		bt->bstart *= GLOBALS->time_scale;
		bt->bend *= GLOBALS->time_scale;
		bt = bt->next;
		}
	}

/* is_vcd=~0; */
GLOBALS->is_lx2 = LXT2_IS_VLIST;

/* SPLASH */                            splash_finalize();
return(GLOBALS->max_time);
}

/*******************************************************************************/

void vcd_import_masked(void)
{
/* nothing */
}

void vcd_set_fac_process_mask(nptr np)
{
if(np && np->mv.mvlfac_vlist)
	{
	import_vcd_trace(np);
	}
}


#define vlist_locate_import(x,y) ((GLOBALS->vlist_prepack) ? ((depacked) + (y)) : vlist_locate((x),(y)))

void import_vcd_trace(nptr np)
{
struct vlist_t *v = np->mv.mvlfac_vlist;
int len = 1;
unsigned int list_size;
unsigned char vlist_type;
/* unsigned int vartype = 0; */ /* scan-build */
unsigned int vlist_pos = 0;
unsigned char *chp;
unsigned int time_idx = 0;
TimeType *curtime_pnt;
unsigned char arr[5];
int arr_pos;
unsigned int accum;
unsigned char ch;
double *d;
unsigned char *depacked = NULL;

if(!v) return;
vlist_uncompress(&v);

if(GLOBALS->vlist_prepack)
	{
	depacked = vlist_packer_decompress(v, &list_size);
	vlist_destroy(v);
	}
	else
	{
	list_size=vlist_size(v);
	}

if(!list_size)
	{
	len = 1;
	vlist_type = '!'; /* possible alias */
	}
	else
	{
	chp = vlist_locate_import(v, vlist_pos++);
	if(chp)
		{
		switch((vlist_type = (*chp & 0x7f)))
			{
			case '0':
				len = 1;
				chp = vlist_locate_import(v, vlist_pos++);
				if(!chp)
					{
					fprintf(stderr, "Internal error file '%s' line %d, exiting.\n", __FILE__, __LINE__);
					exit(255);
					}
				/* vartype = (unsigned int)(*chp & 0x7f); */ /*scan-build */
				break;

			case 'B':
			case 'R':
			case 'S':
				chp = vlist_locate_import(v, vlist_pos++);
				if(!chp)
					{
					fprintf(stderr, "Internal error file '%s' line %d, exiting.\n", __FILE__, __LINE__);
					exit(255);
					}
				/* vartype = (unsigned int)(*chp & 0x7f); */ /* scan-build */

				arr_pos = accum = 0;

		                do      {
		                	chp = vlist_locate_import(v, vlist_pos++);
		                        if(!chp) break;
		                        ch = *chp;
					arr[arr_pos++] = ch;
		                        } while (!(ch & 0x80));

				for(--arr_pos; arr_pos>=0; arr_pos--)
					{
					ch = arr[arr_pos];
					accum <<= 7;
					accum |= (unsigned int)(ch & 0x7f);
					}

				len = accum;

				break;

			default:
				fprintf(stderr, "Unsupported vlist type '%c', exiting.", vlist_type);
				vcd_exit(255);
				break;
			}
		}
		else
		{
		len = 1;
		vlist_type = '!'; /* possible alias */
		}
	}


if(vlist_type == '0') /* single bit */
	{
	while(vlist_pos < list_size)
		{
		unsigned int delta, bitval;
		char ascval;

		arr_pos = accum = 0;

                do      {
                	chp = vlist_locate_import(v, vlist_pos++);
                        if(!chp) break;
                        ch = *chp;
			arr[arr_pos++] = ch;
                        } while (!(ch & 0x80));

		for(--arr_pos; arr_pos>=0; arr_pos--)
			{
			ch = arr[arr_pos];
			accum <<= 7;
			accum |= (unsigned int)(ch & 0x7f);
			}

		if(!(accum&1))
			{
			delta = accum >> 2;
			bitval = (accum >> 1) & 1;
			ascval = '0' + bitval;
			}
			else
			{
			delta = accum >> 4;
			bitval = (accum >> 1) & 7;
			ascval = RCV_STR[bitval];
			}
		time_idx += delta;

		curtime_pnt = vlist_locate(GLOBALS->time_vlist_vcd_recoder_c_1, time_idx ? time_idx-1 : 0);
		if(!curtime_pnt)
			{
			fprintf(stderr, "GTKWAVE | malformed bitwise signal data for '%s' after time_idx = %d\n",
				np->nname, time_idx - delta);
			exit(255);
			}

		add_histent(*curtime_pnt,np,ascval,1, NULL);
		}

	add_histent(MAX_HISTENT_TIME-1, np, 'x', 0, NULL);
	add_histent(MAX_HISTENT_TIME,   np, 'z', 0, NULL);
	}
else if(vlist_type == 'B') /* bit vector, port type was converted to bit vector already */
	{
	char *sbuf = malloc_2(len+1);
	int dst_len;
	char *vector;

	while(vlist_pos < list_size)
		{
		unsigned int delta;

		arr_pos = accum = 0;

                do      {
                	chp = vlist_locate_import(v, vlist_pos++);
                        if(!chp) break;
                        ch = *chp;
			arr[arr_pos++] = ch;
                        } while (!(ch & 0x80));

		for(--arr_pos; arr_pos>=0; arr_pos--)
			{
			ch = arr[arr_pos];
			accum <<= 7;
			accum |= (unsigned int)(ch & 0x7f);
			}

		delta = accum;
		time_idx += delta;

		curtime_pnt = vlist_locate(GLOBALS->time_vlist_vcd_recoder_c_1,  time_idx ? time_idx-1 : 0);
		if(!curtime_pnt)
			{
			fprintf(stderr, "GTKWAVE | malformed 'b' signal data for '%s' after time_idx = %d\n",
				np->nname, time_idx - delta);
			exit(255);
			}

		dst_len = 0;
		for(;;)
			{
			chp = vlist_locate_import(v, vlist_pos++);
			if(!chp) break;
			ch = *chp;
			if((ch >> 4) == AN_MSK) break;
			if(dst_len == len) { if(len != 1) memmove(sbuf, sbuf+1, dst_len - 1); dst_len--; }
			sbuf[dst_len++] = AN_STR[ch >> 4];
			if((ch & AN_MSK) == AN_MSK) break;
			if(dst_len == len) { if(len != 1) memmove(sbuf, sbuf+1, dst_len - 1); dst_len--; }
			sbuf[dst_len++] = AN_STR[ch & AN_MSK];
			}

		if(len == 1)
			{
			add_histent(*curtime_pnt, np,sbuf[0],1, NULL);
			}
			else
			{
			vector = malloc_2(len+1);
			if(dst_len < len)
				{
				unsigned char extend=(sbuf[0]=='1')?'0':sbuf[0];
				memset(vector, extend, len - dst_len);
				memcpy(vector + (len - dst_len), sbuf, dst_len);
				}
				else
				{
				memcpy(vector, sbuf, len);
				}

			vector[len] = 0;
			add_histent(*curtime_pnt, np,0,1,vector);
			}
		}

	if(len==1)
		{
		add_histent(MAX_HISTENT_TIME-1, np, 'x', 0, NULL);
		add_histent(MAX_HISTENT_TIME,   np, 'z', 0, NULL);
		}
		else
		{
		add_histent(MAX_HISTENT_TIME-1, np, 'x', 0, (char *)calloc_2(1,sizeof(char)));
		add_histent(MAX_HISTENT_TIME,   np, 'z', 0, (char *)calloc_2(1,sizeof(char)));
		}

	free_2(sbuf);
	}
else if(vlist_type == 'R') /* real */
	{
	char *sbuf = malloc_2(64);
	int dst_len;
	char *vector;

	while(vlist_pos < list_size)
		{
		unsigned int delta;

		arr_pos = accum = 0;

                do      {
                	chp = vlist_locate_import(v, vlist_pos++);
                        if(!chp) break;
                        ch = *chp;
			arr[arr_pos++] = ch;
                        } while (!(ch & 0x80));

		for(--arr_pos; arr_pos>=0; arr_pos--)
			{
			ch = arr[arr_pos];
			accum <<= 7;
			accum |= (unsigned int)(ch & 0x7f);
			}

		delta = accum;
		time_idx += delta;

		curtime_pnt = vlist_locate(GLOBALS->time_vlist_vcd_recoder_c_1,  time_idx ? time_idx-1 : 0);
		if(!curtime_pnt)
			{
			fprintf(stderr, "GTKWAVE | malformed 'r' signal data for '%s' after time_idx = %d\n",
				np->nname, time_idx - delta);
			exit(255);
			}

		dst_len = 0;
		do
			{
			chp = vlist_locate_import(v, vlist_pos++);
			if(!chp) break;
			ch = *chp;
			sbuf[dst_len++] = ch;
			} while(ch);

		vector=malloc_2(sizeof(double));
		sscanf(sbuf,"%lg",(double *)vector);
		add_histent(*curtime_pnt, np,'g',1,(char *)vector);
		}

	d=malloc_2(sizeof(double));
	*d=1.0;
	add_histent(MAX_HISTENT_TIME-1, np, 'g', 0, (char *)d);

	d=malloc_2(sizeof(double));
	*d=0.0;
	add_histent(MAX_HISTENT_TIME, np, 'g', 0, (char *)d);

	free_2(sbuf);
	}
else if(vlist_type == 'S') /* string */
	{
	char *sbuf = malloc_2(list_size); /* being conservative */
	int dst_len;
	char *vector;

	while(vlist_pos < list_size)
		{
		unsigned int delta;

		arr_pos = accum = 0;

                do      {
                	chp = vlist_locate_import(v, vlist_pos++);
                        if(!chp) break;
                        ch = *chp;
			arr[arr_pos++] = ch;
                        } while (!(ch & 0x80));

		for(--arr_pos; arr_pos>=0; arr_pos--)
			{
			ch = arr[arr_pos];
			accum <<= 7;
			accum |= (unsigned int)(ch & 0x7f);
			}

		delta = accum;
		time_idx += delta;

		curtime_pnt = vlist_locate(GLOBALS->time_vlist_vcd_recoder_c_1,  time_idx ? time_idx-1 : 0);
		if(!curtime_pnt)
			{
			fprintf(stderr, "GTKWAVE | malformed 's' signal data for '%s' after time_idx = %d\n",
				np->nname, time_idx - delta);
			exit(255);
			}

		dst_len = 0;
		do
			{
			chp = vlist_locate_import(v, vlist_pos++);
			if(!chp) break;
			ch = *chp;
			sbuf[dst_len++] = ch;
			} while(ch);

		vector=malloc_2(dst_len + 1);
		strcpy(vector, sbuf);
		add_histent(*curtime_pnt, np,'s',1,(char *)vector);
		}

	d=malloc_2(sizeof(double));
	*d=1.0;
	add_histent(MAX_HISTENT_TIME-1, np, 'g', 0, (char *)d);

	d=malloc_2(sizeof(double));
	*d=0.0;
	add_histent(MAX_HISTENT_TIME, np, 'g', 0, (char *)d);

	free_2(sbuf);
	}
else if(vlist_type == '!') /* error in loading */
	{
	nptr n2 = (nptr)np->curr;

	if((n2)&&(n2 != np))	/* keep out any possible infinite recursion from corrupt pointer bugs */
		{
		import_vcd_trace(n2);

		if(GLOBALS->vlist_prepack)
			{
			vlist_packer_decompress_destroy((char *)depacked);
			}
			else
			{
			vlist_destroy(v);
			}
		np->mv.mvlfac_vlist = NULL;

		np->head = n2->head;
		np->curr = n2->curr;
		return;
		}

	fprintf(stderr, "Error in decompressing vlist for '%s', exiting.\n", np->nname);
	vcd_exit(255);
	}

if(GLOBALS->vlist_prepack)
	{
	vlist_packer_decompress_destroy((char *)depacked);
	}
	else
	{
	vlist_destroy(v);
	}
np->mv.mvlfac_vlist = NULL;
}