diff --git a/inputs/specs/Readme.md b/inputs/specs/Readme.md new file mode 100644 index 0000000..e9e5913 --- /dev/null +++ b/inputs/specs/Readme.md @@ -0,0 +1,4 @@ +# Scalable Photonic Event-driven Circuit Simulator (SPECS) + +This test input was provided by the folks behind: +https://github.com/clement-z/specs diff --git a/inputs/specs/tracefile.vcd b/inputs/specs/tracefile.vcd new file mode 100644 index 0000000..9fb1ef0 --- /dev/null +++ b/inputs/specs/tracefile.vcd @@ -0,0 +1,850 @@ +$date + Feb 27, 2024 13:10:22 +$end + +$version + SystemC 2.3.4-Accellera --- Dec 21 2023 11:33:50 +$end + +$timescale + 1 fs +$end + +$scope module SystemC $end +$var real 1 aaaai abstol $end +$var real 1 aaaaj reltol $end +$var wire 32 aaaak resolution_multiplier [31:0] $end +$var wire 32 aaaal engine_timescale [31:0] $end +$var wire 32 aaaam simulation_mode [31:0] $end +$var wire 32 aaaan analysis_type [31:0] $end +$var wire 1 aaaao trace_all_optical_nets $end +$var wire 1 aaaap verbose_component_initialization $end +$scope module ROOT/PROBE1 $end +$var real 1 aaaaa power $end +$var real 1 aaaab abs $end +$var real 1 aaaac phase $end +$var real 1 aaaad wavelength $end +$upscope $end +$scope module ROOT/PROBE2 $end +$var real 1 aaaae power $end +$var real 1 aaaaf abs $end +$var real 1 aaaag phase $end +$var real 1 aaaah wavelength $end +$upscope $end +$upscope $end +$enddefinitions $end + +$comment +All initial values are dumped below at time 0 sec = 0 timescale units. +$end + +$dumpvars +r0 aaaaa +r0 aaaab +r0 aaaac +r0 aaaad +r0 aaaae +r0 aaaaf +r0 aaaag +r0 aaaah +r1e-08 aaaai +r0.0001 aaaaj +b1 aaaak +b11111111111111111111111111110001 aaaal +b1 aaaam +b10 aaaan +0aaaao +0aaaap +$end + +#500000 +r0.7500000000000001 aaaaa +r0.8660254037844387 aaaab +r1.55e-06 aaaad + +#513519 +r0.06107732630973817 aaaae +r0.2471382736642347 aaaaf +r-3.019982615386652 aaaag +r1.55e-06 aaaah + +#527038 +r0.43908726282771 aaaaa +r0.6626365993723181 aaaab +r-0.07697208321883701 aaaac + +#540557 +r0.1807824964681004 aaaae +r0.4251852495890473 aaaaf +r-2.917205356626333 aaaag + +#554076 +r0.2893867881121123 aaaaa +r0.5379468264727587 aaaab +r-0.2315419482812088 aaaac + +#567595 +r0.3030938779470622 aaaae +r0.5505396243205953 aaaaf +r-2.826817932895215 aaaag + +#581114 +r0.2322938300469538 aaaaa +r0.4819687023520861 aaaab +r-0.4261086193815833 aaaac + +#594633 +r0.4046470657398339 aaaae +r0.6361187512877088 aaaaf +r-2.748554678805672 aaaag + +#608152 +r0.225505047008062 aaaaa +r0.474873716905939 aaaab +r-0.5998171407223055 aaaac + +#621671 +r0.4790425346791882 aaaae +r0.6921289870242311 aaaaf +r-2.682012199966946 aaaag + +#635190 +r0.2433043754096753 aaaaa +r0.4932589334311901 aaaab +r-0.7201848502149577 aaaac + +#648709 +r0.5279793340766736 aaaae +r0.7266218645737779 aaaaf +r-2.626626897944953 aaaag + +#662228 +r0.2705493119359063 aaaaa +r0.5201435493552777 aaaab +r-0.7908220845629018 aaaac + +#675747 +r0.5563738530188335 aaaae +r0.7459047211399278 aaaaf +r-2.581658679896114 aaaag + +#689266 +r0.2988227585015811 aaaaa +r0.5466468316029839 aaaab +r-0.8270549399650127 aaaac + +#702785 +r0.5698038032367188 aaaae +r0.754853497863472 aaaaf +r-2.546188829201635 aaaag + +#716304 +r0.3239143711388023 aaaaa +r0.5691347565724679 aaaab +r-0.8422806071128653 aaaac + +#729823 +r0.5732928159525323 aaaae +r0.7571610237938377 aaaaf +r-2.519138632158556 aaaag + +#743342 +r0.344157058171879 aaaaa +r0.5866490076458657 aaaab +r-0.8455873520398153 aaaac + +#756861 +r0.570846325104414 aaaae +r0.7555437281219493 aaaaf +r-2.499311335969201 aaaag + +#770380 +r0.3593341188667259 aaaaa +r0.5994448422221397 aaaab +r-0.8426625762854761 aaaac + +#783899 +r0.5653861424841949 aaaae +r0.7519216332066759 aaaaf +r-2.485453995454335 aaaag + +#797418 +r0.3699755013073804 aaaaa +r0.6082561148951816 aaaab +r-0.836941935194452 aaaac + +#810937 +r0.5588755282928625 aaaae +r0.7475797805537965 aaaaf +r-2.476329755435503 aaaag + +#824456 +r0.3769208055588454 aaaaa +r0.6139387636880778 aaaab +r-0.830432465046374 aaaac + +#837975 +r0.5525155346241376 aaaae +r0.743313887011495 aaaaf +r-2.470787674611263 aaaag + +#851494 +r0.3810633315521118 aaaaa +r0.6173032735634179 aaaab +r-0.8242412022572203 aaaac + +#865013 +r0.5469481668762067 aaaae +r0.7395594410702947 aaaaf +r-2.467817943133139 aaaag + +#878532 +r0.3832140891098448 aaaaa +r0.6190428814790174 aaaab +r-0.8189106335582269 aaaac + +#892051 +r0.542435120599343 aaaae +r0.7365019488089241 aaaaf +r-2.466584877451274 aaaag + +#905570 +r0.3840422758805866 aaaaa +r0.6197114456588538 aaaab +r-0.8146354565677585 aaaac + +#919089 +r0.5390003425636926 aaaae +r0.7341664270202585 aaaaf +r-2.466436241625998 aaaag + +#932608 +r0.3840617441208002 aaaaa +r0.6197271529639476 aaaab +r-0.811405613754636 aaaac + +#946127 +r0.5365354456224452 aaaae +r0.7324857989220304 aaaaf +r-2.466892728236958 aaaag + +#959646 +r0.3836426993589259 aaaaa +r0.6193889725842121 aaaab +r-0.8091014540314083 aaaac + +#973165 +r0.534872353428934 aaaae +r0.7313496793114317 aaaaf +r-2.467624302689719 aaaag + +#986684 +r0.3830350651912226 aaaaa +r0.618898267238827 aaaab +r-0.8075561619571215 aaaac + +#1000203 +r0.5338296235742801 aaaae +r0.7306364510303877 aaaaf +r-2.468420451363118 aaaag + +#1013722 +r0.3823951454962045 aaaaa +r0.6183810681903227 aaaab +r-0.8065949733613343 aaaac + +#1027241 +r0.5332391124500654 aaaae +r0.7302322318619368 aaaaf +r-2.469160007418379 aaaag + +#1040760 +r0.3818108475293348 aaaaa +r0.6179084459119609 aaaab +r-0.80605779117055 aaaac + +#1054279 +r0.5329589115712128 aaaae +r0.7300403492761293 aaaaf +r-2.469784209139533 aaaag + +#1067798 +r0.3813231595475255 aaaaa +r0.6175136917895225 aaaab +r-0.8058101957344587 aaaac + +#1081317 +r0.5328773659617964 aaaae +r0.7299844970694901 aaaaf +r-2.470274752334376 aaaag + +#1094836 +r0.3809431121553057 aaaaa +r0.6172058912188911 aaaab +r-0.8057467543168472 aaaac + +#1108355 +r0.5329118084868358 aaaae +r0.7300080879598773 aaaaf +r-2.470637202011014 aaaag + +#1121874 +r0.3806643474437009 aaaaa +r0.6169800219161888 aaaab +r-0.8057896434615968 aaaac + +#1135393 +r0.5330045825668956 aaaae +r0.7300716283810074 aaaaf +r-2.470889286804971 aaaag + +#1148912 +r0.3804718767148849 aaaaa +r0.6168240241064584 aaaab +r-0.805884806420501 aaaac + +#1162431 +r0.5331180538759055 aaaae +r0.7301493366948336 aaaaf +r-2.471053207924353 aaaag + +#1175950 +r0.3803477811861909 aaaaa +r0.616723423575099 aaaab +r-0.8059971761613179 aaaac + +#1189469 +r0.533229644762427 aaaae +r0.7302257491779012 aaaaf +r-2.471151003538153 aaaag + +#1202988 +r0.3802746141410435 aaaaa +r0.616664101550466 aaaab +r-0.8061059259927235 aaaac + +#1216507 +r0.5333274465043649 aaaae +r0.7302927128928269 aaaaf +r-2.471202087777303 aaaag + +#1230026 +r0.3802371768425817 aaaaa +r0.6166337461107539 aaaab +r-0.8062002768821199 aaaac + +#1500000 +r0.3908905737610384 aaaaa +r0.6252124229100365 aaaab +r-2.349592049574162 aaaac + +#1513519 +r0.2864946135000446 aaaae +r0.5352519159237494 aaaaf +r-2.22798201137102 aaaag + +#1527038 +r0.2099798999366945 aaaaa +r0.4582356380037398 aaaab +r-2.106371973167878 aaaac + +#1540557 +r0.1539001304030359 aaaae +r0.3923010711214486 aaaaf +r-1.984761934964736 aaaag + +#1554076 +r0.1127977018048498 aaaaa +r0.3358536910692657 aaaab +r-1.863151896761594 aaaac + +#1567595 +r0.08267258448148024 aaaae +r0.2875284063905343 aaaaf +r-1.741541858558452 aaaag + +#1581114 +r0.06059304503093719 aaaaa +r0.2461565457812105 aaaab +r-1.61993182035531 aaaac + +#1594633 +r0.04441033420146252 aaaae +r0.2107375956052041 aaaaf +r-1.498321782152168 aaaag + +#1608152 +r0.03254957368256702 aaaaa +r0.180415004039484 aaaab +r-1.376711743949026 aaaac + +#1621671 +r0.02385649119663614 aaaae +r0.1544554667101043 aaaaf +r-1.255101705745884 aaaag + +#1635190 +r0.0174850883690681 aaaaa +r0.1322311928747075 aaaab +r-1.133491667542742 aaaac + +#1648709 +r0.01281530937446616 aaaae +r0.1132047232869113 aaaaf +r-1.0118816293396 aaaag + +#1662228 +r0.009392697989094196 aaaaa +r0.09691593258641323 aaaab +r-0.8902715911364585 aaaac + +#1675747 +r0.006884170560104735 aaaae +r0.08297090188797959 aaaaf +r-0.7686615529333166 aaaag + +#1689266 +r0.00504560078005692 aaaaa +r0.0710323924703154 aaaab +r-0.6470515147301747 aaaac + +#1702785 +r0.003698061663266471 aaaae +r0.06081169018590481 aaaaf +r-0.5254414765270328 aaaag + +#1716304 +r0.002710412627050312 aaaaa +r0.05206162336165011 aaaab +r-0.4038314383238908 aaaac + +#1729823 +r0.001986537077476639 aaaae +r0.04457058533917452 aaaaf +r-0.2822214001207489 aaaag + +#1743342 +r0.001455988479689212 aaaaa +r0.0381574170992903 aaaab +r-0.160611361917607 aaaac + +#1756861 +r0.001067134601726371 aaaae +r0.03266702621492154 aaaaf +r-0.03900132371446508 aaaag + +#1770380 +r0.0007821327394326487 aaaaa +r0.02796663618372165 aaaab +r0.08260871448867681 aaaac + +#1783899 +r0.0005732469185262877 aaaae +r0.02394257543637041 aaaaf +r0.2042187526918187 aaaag + +#1797418 +r0.0004201486691865837 aaaaa +r0.02049752836774677 aaaab +r0.3258287908949606 aaaac + +#1810937 +r0.0003079386883981344 aaaae +r0.01754818191147261 aaaaf +r0.4474388290981026 aaaag + +#1824456 +r0.0002256968610562277 aaaaa +r0.01502321074391981 aaaab +r0.5690488673012446 aaaac + +#1837975 +r0.0001654195299577783 aaaae +r0.01286155239299589 aaaaf +r0.6906589055043865 aaaag + +#1851494 +r0.0001212405913108168 aaaaa +r0.01101093053791626 aaaab +r0.8122689437075282 aaaac + +#1865013 +r8.88606138897164e-05 aaaae +r0.009426590788281647 aaaaf +r0.9338789819106701 aaaag + +#1878532 +r6.512842452751033e-05 aaaaa +r0.008070218369258067 aaaab +r1.055489020113812 aaaac + +#1892051 +r4.773444044287085e-05 aaaae +r0.006909011538771002 aaaaf +r1.177099058316954 aaaag + +#1905570 +r3.498590394170383e-05 aaaaa +r0.005914888328760217 aaaab +r1.298709096520096 aaaac + +#1919089 +r2.56421456554632e-05 aaaae +r0.005063807426775153 aaaaf +r1.420319134723238 aaaag + +#1932608 +r1.879384436976672e-05 aaaaa +r0.004335186774496195 aaaab +r1.54192917292638 aaaac + +#1946127 +r1.377453318224013e-05 aaaae +r0.003711405822897859 aaaaf +r1.663539211129521 aaaag + +#1959646 +r1.009573989523196e-05 aaaaa +r0.003177379406874785 aaaab +r1.785149249332663 aaaac + +#1973165 +r7.399449599031892e-06 aaaae +r0.002720192934155938 aaaaf +r1.906759287535805 aaaag + +#1986684 +r5.423263172070385e-06 aaaaa +r0.002328790066122403 aaaab +r2.028369325738947 aaaac + +#2000203 +r3.974860973089545e-06 aaaae +r0.001993705337578637 aaaaf +r2.149979363942089 aaaag + +#2013722 +r2.913286568270802e-06 aaaaa +r0.001706835249305217 aaaab +r2.271589402145231 aaaac + +#2027241 +r2.135229052368637e-06 aaaae +r0.001461242297625085 aaaaf +r2.393199440348373 aaaag + +#2040760 +r1.564968978930628e-06 aaaaa +r0.001250987201745337 aaaab +r2.514809478551514 aaaac + +#2054279 +r1.147009451889165e-06 aaaae +r0.001070985271555667 aaaaf +r2.636419516754656 aaaag + +#2067798 +r8.406752468806615e-07 aaaaa +r0.0009168834423636744 aaaab +r2.758029554957798 aaaac + +#2081317 +r6.161543564909984e-07 aaaae +r0.000784955002844748 aaaaf +r2.87963959316094 aaaag + +#2094836 +r4.515967282628094e-07 aaaaa +r0.0006720094703669059 aaaab +r3.001249631364082 aaaac + +#2108355 +r3.309878487902132e-07 aaaae +r0.0005753154341665216 aaaaf +r3.122859669567224 aaaag + +#2121874 +r2.425902341414176e-07 aaaaa +r0.0004925345004580061 aaaab +r-3.03871559940922 aaaac + +#2135393 +r1.778011546825338e-07 aaaae +r0.0004216647420434079 aaaaf +r-2.917105561206078 aaaag + +#2148912 +r1.303154297135202e-07 aaaaa +r0.0003609922848393303 aaaab +r-2.795495523002937 aaaac + +#2162431 +r9.551181628567705e-08 aaaae +r0.0003090498605171616 aaaaf +r-2.673885484799795 aaaag + +#2175950 +r7.000327643659275e-08 aaaaa +r0.0002645813229171567 aaaab +r-2.552275446596653 aaaac + +#2189469 +r5.130735549202296e-08 aaaae +r0.000226511270121429 aaaaf +r-2.430665408393511 aaaag + +#2202988 +r3.760459312171229e-08 aaaaa +r0.0001939190375432806 aaaab +r-2.309055370190369 aaaac + +#2216507 +r2.756145605807709e-08 aaaae +r0.0001660164330964772 aaaaf +r-2.187445331987227 aaaag + +#2230026 +r2.020056054276821e-08 aaaaa +r0.0001421286760044158 aaaab +r-2.065835293784085 aaaac + +#2243545 +r1.480555473492331e-08 aaaae +r0.0001216780782841483 aaaaf +r-1.944225255580943 aaaag + +#2257064 +r1.08514043728992e-08 aaaaa +r0.0001041700742675131 aaaab +r-1.822615217377801 aaaac + +#2270583 +r7.953297189629814e-09 aaaae +r8.918126030523349e-05 aaaaf +r-1.701005179174659 aaaag + +#2284102 +r5.829193532272127e-09 aaaaa +r7.634915541295874e-05 aaaab +r-1.579395140971518 aaaac + +#2297621 +r4.272378665918401e-09 aaaae +r6.536343523651738e-05 aaaaf +r-1.457785102768376 aaaag + +#2311140 +r3.131345590764744e-09 aaaaa +r5.595842734356233e-05 aaaab +r-1.336175064565234 aaaac + +#2324659 +r2.295050597228378e-09 aaaae +r4.790668635199452e-05 aaaaf +r-1.214565026362092 aaaag + +#2338178 +r1.682106650691325e-09 aaaaa +r4.101349351971038e-05 aaaab +r-1.09295498815895 aaaac + +#2351697 +r1.232862921504658e-09 aaaae +r3.511214777686859e-05 aaaaf +r-0.9713449499558081 aaaag + +#2365216 +r9.035996514230055e-10 aaaaa +r3.005993432166819e-05 aaaab +r-0.849734911752666 aaaac + +#2378735 +r6.62273409159943e-10 aaaae +r2.573467328644261e-05 aaaaf +r-0.7281248735495243 aaaag + +#2392254 +r4.853986694102951e-10 aaaaa +r2.203176500896592e-05 aaaab +r-0.6065148353463824 aaaac + +#2405773 +r3.557622350626238e-10 aaaae +r1.886166045348669e-05 aaaaf +r-0.4849047971432406 aaaag + +#2419292 +r2.607480734352198e-10 aaaaa +r1.614769560758499e-05 aaaab +r-0.3632947589400986 aaaac + +#2432811 +r1.911095419900619e-10 aaaae +r1.382423748313309e-05 aaaaf +r-0.2416847207369567 aaaag + +#2446330 +r1.400695182843794e-10 aaaaa +r1.183509688529753e-05 aaaab +r-0.1200746825338148 aaaac + +#2459849 +r1.026608600916345e-10 aaaae +r1.01321695648876e-05 aaaaf +r0.001535355669327037 aaaag + +#2473368 +r7.524301021266167e-11 aaaaa +r8.6742728924482e-06 aaaab +r0.1231453938724689 aaaac + +#2486887 +r5.514770264742838e-11 aaaae +r7.426149920882851e-06 aaaaf +r0.2447554320756108 aaaag + +#2500406 +r4.041929075795274e-11 aaaaa +r6.357616751421302e-06 aaaab +r0.3663654702787527 aaaac + +#2513925 +r2.962442652997997e-11 aaaae +r5.442832583313579e-06 aaaaf +r0.4879755084818946 aaaag + +#2527444 +r2.171256919092541e-11 aaaaa +r4.659674794545796e-06 aaaab +r0.6095855466850364 aaaac + +#2540963 +r1.591374808196303e-11 aaaae +r3.989203940883824e-06 aaaaf +r0.7311955848881785 aaaag + +#2554482 +r1.166363021295631e-11 aaaaa +r3.41520573508483e-06 aaaab +r0.8528056230913204 aaaac + +#2568001 +r8.548600181674247e-12 aaaae +r2.923798929761458e-06 aaaaf +r0.9744156612944621 aaaag + +#2581520 +r6.265507713451259e-12 aaaaa +r2.503099621159985e-06 aaaab +r1.096025699497604 aaaac + +#2595039 +r4.592165509327729e-12 aaaae +r2.142933855565245e-06 aaaaf +r1.217635737700746 aaaag + +#2608558 +r3.365726295378416e-12 aaaaa +r1.834591588168445e-06 aaaab +r1.339245775903888 aaaac + +#2622077 +r2.466834758545125e-12 aaaae +r1.570616044278526e-06 aaaaf +r1.46085581410703 aaaag + +#2635596 +r1.808012057998378e-12 aaaaa +r1.344623388907979e-06 aaaab +r1.582465852310172 aaaac + +#2649115 +r1.325142509259698e-12 aaaae +r1.151148343724517e-06 aaaaf +r1.704075890513313 aaaag + +#2662634 +r9.71233937339518e-13 aaaaa +r9.855120178564634e-07 aaaab +r1.825685928716455 aaaac + +#2676153 +r7.118444653677305e-13 aaaae +r8.437087562469235e-07 aaaaf +r1.947295966919597 aaaag + +#2689672 +r5.217306803165519e-13 aaaaa +r7.223092691614525e-07 aaaab +r2.068906005122739 aaaac + +#2703191 +r3.823909800899487e-13 aaaae +r6.183777001881203e-07 aaaaf +r2.190516043325881 aaaag + +#2716710 +r2.802650240262527e-13 aaaaa +r5.294006271494705e-07 aaaab +r2.312126081529023 aaaac + +#2730229 +r2.054140599078965e-13 aaaae +r4.532262789246631e-07 aaaaf +r2.433736119732165 aaaag + +#2743748 +r1.505536987872324e-13 aaaaa +r3.880124982358589e-07 aaaab +r2.555346157935307 aaaac + +#2757267 +r1.103450086555899e-13 aaaae +r3.321821919603607e-07 aaaaf +r2.676956196138448 aaaag + +#2770786 +r8.087493720370021e-14 aaaaa +r2.843851916040992e-07 aaaab +r2.79856623434159 aaaac + +#2784305 +r5.927549915843978e-14 aaaae +r2.434656015917645e-07 aaaaf +r2.920176272544732 aaaag + +#2797824 +r4.344466805127164e-14 aaaaa +r2.084338457431317e-07 aaaab +r3.041786310747874 aaaac + +#2811343 +r3.18418100038293e-14 aaaae +r1.784427359234029e-07 aaaaf +r-3.11978895822857 aaaag + +#2824862 +r2.333775143875881e-14 aaaaa +r1.527669841253627e-07 aaaab +r-2.998178920025429 aaaac + +#2838381 +r1.71048895195276e-14 aaaae +r1.307856625151534e-07 aaaaf +r-2.876568881822287 aaaag + +#2851900 +r1.253665102411449e-14 aaaaa +r1.119671872653524e-07 aaaab +r-2.754958843619145 aaaac + +#2865419 +r0 aaaae +r0 aaaaf +r0 aaaag + +#2878938 +r0 aaaaa +r0 aaaab +r0 aaaac + diff --git a/src/vcd.rs b/src/vcd.rs index 1ac6ca3..aa16034 100644 --- a/src/vcd.rs +++ b/src/vcd.rs @@ -42,14 +42,16 @@ pub fn read_with_options(filename: &str, options: LoadOptions) -> Result Result { - let (header_len, hierarchy) = read_hierarchy(&mut std::io::Cursor::new(&bytes), &options)?; - let wave_mem = read_values(&bytes[header_len..], &options, &hierarchy)?; + let (header_len, hierarchy, lookup) = + read_hierarchy(&mut std::io::Cursor::new(&bytes), &options)?; + let wave_mem = read_values(&bytes[header_len..], &options, &hierarchy, &lookup)?; Ok(Waveform::new(hierarchy, wave_mem)) } @@ -111,14 +113,48 @@ fn parse_attribute( } } +type IdLookup = Option, SignalRef>>; + fn read_hierarchy( input: &mut (impl BufRead + Seek), options: &LoadOptions, -) -> Result<(usize, Hierarchy)> { +) -> Result<(usize, Hierarchy, IdLookup)> { let start = input.stream_position().unwrap(); let mut h = HierarchyBuilder::new(FileFormat::Vcd); let mut attributes = Vec::new(); let mut path_names = HashMap::new(); + // this map is used to translate identifiers to signal references for cases where we detect ids that are too large + let mut id_map: HashMap, SignalRef> = HashMap::new(); + let mut use_id_map = false; + let mut var_count = 0u64; + + let mut id_to_signal_ref = |id: &[u8], var_count: u64| -> SignalRef { + // currently we only make a decision of whether to switch to a hash_map based lookup when we are at the first variable + if var_count == 0 { + if let Some(id_value) = id_to_int(id) { + if id_value < 1024 * 1024 { + return SignalRef::from_index(id_value as usize).unwrap(); + } else { + use_id_map = true; + } + } else { + use_id_map = true; + } + } + + if use_id_map { + match id_map.get(id) { + Some(signal_ref) => *signal_ref, + None => { + let signal_ref = SignalRef::from_index(id_map.len() + 1).unwrap(); + id_map.insert(id.to_vec(), signal_ref); + signal_ref + } + } + } else { + SignalRef::from_index(id_to_int(id).unwrap() as usize).unwrap() + } + }; let foo = |cmd: HeaderCmd| match cmd { HeaderCmd::Scope(tpe, name) => { @@ -153,10 +189,11 @@ fn read_hierarchy( VarDirection::vcd_default(), u32::from_str_radix(std::str::from_utf8(size).unwrap(), 10).unwrap(), index, - SignalRef::from_index(id_to_int(id).unwrap() as usize).unwrap(), + id_to_signal_ref(id, var_count), enum_type, type_name, ); + var_count += 1; Ok(()) } HeaderCmd::VectorVar(tpe, size, id, name, index) => { @@ -182,10 +219,11 @@ fn read_hierarchy( VarDirection::vcd_default(), length, index, - SignalRef::from_index(id_to_int(id).unwrap() as usize).unwrap(), + id_to_signal_ref(id, var_count), enum_type, type_name, ); + var_count += 1; Ok(()) } HeaderCmd::Date(value) => { @@ -217,7 +255,8 @@ fn read_hierarchy( read_header(input, foo).unwrap(); let end = input.stream_position().unwrap(); let hierarchy = h.finish(); - Ok(((end - start) as usize, hierarchy)) + let lookup = if use_id_map { Some(id_map) } else { None }; + Ok(((end - start) as usize, hierarchy, lookup)) } /// Tries to see if the name contains an index that is not white-space separated. @@ -706,6 +745,7 @@ fn read_values( input: &[u8], options: &LoadOptions, hierarchy: &Hierarchy, + lookup: &IdLookup, ) -> Result> { if options.multi_thread { let chunks = determine_thread_chunks(input.len()); @@ -727,6 +767,7 @@ fn read_values( is_first, starts_on_new_line, hierarchy, + lookup, ) }) .collect(); @@ -739,7 +780,8 @@ fn read_values( } Ok(Box::new(encoder.finish())) } else { - let encoder = read_single_stream_of_values(input, input.len() - 1, true, true, hierarchy); + let encoder = + read_single_stream_of_values(input, input.len() - 1, true, true, hierarchy, lookup); Ok(Box::new(encoder.finish())) } } @@ -750,6 +792,7 @@ fn read_single_stream_of_values<'a>( is_first: bool, starts_on_new_line: bool, hierarchy: &Hierarchy, + lookup: &IdLookup, ) -> crate::wavemem::Encoder { let mut encoder = crate::wavemem::Encoder::new(hierarchy); @@ -783,7 +826,11 @@ fn read_single_stream_of_values<'a>( found_first_time_step = true; } if found_first_time_step { - encoder.vcd_value_change(id_to_int(id).unwrap(), value); + let num_id = match lookup { + None => id_to_int(id).unwrap(), + Some(lookup) => lookup[id].index() as u64, + }; + encoder.vcd_value_change(num_id, value); } } }; diff --git a/tests/diff_tests.rs b/tests/diff_tests.rs index 7b82591..252eb2f 100644 --- a/tests/diff_tests.rs +++ b/tests/diff_tests.rs @@ -536,6 +536,12 @@ fn diff_riviera_pro_dump() { ); } +/// This VCD file contains very large signal references which cannot directly be converted to a SignalRef +#[test] +fn diff_specs_tracefile() { + run_diff_test_vcd_only("inputs/specs/tracefile.vcd"); +} + #[test] fn diff_surfer_counter() { run_diff_test("inputs/surfer/counter.vcd", "inputs/surfer/counter.vcd.fst");