forked from OSVVM/OSVVM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicVectorGenericPkg.vhd
More file actions
1670 lines (1500 loc) · 60.5 KB
/
Copy pathDynamicVectorGenericPkg.vhd
File metadata and controls
1670 lines (1500 loc) · 60.5 KB
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
--
-- File Name: DynamicVectorGenericPkg.vhd
-- Design Unit Name: DynamicVectorGenericPkg
-- Revision: STANDARD VERSION
--
-- Maintainer: Jim Lewis email: jim@synthworks.com
-- Contributor(s):
-- Jim Lewis SynthWorks
--
--
-- Package Defines
-- Data structure for name.
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Revision History:
-- Version Description
-- 2026.05 Initial revision.
--
--
-- This file is part of OSVVM.
--
-- Copyright (c) 2026 by SynthWorks Design Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.numeric_std.all ;
use ieee.math_real.all ;
use std.textio.all ;
use work.IfElsePkg.all ;
use work.OsvvmScriptSettingsPkg.all ;
use work.OsvvmSettingsPkg.all ;
use work.TextUtilPkg.all ;
use work.ResolutionPkg.all ;
use work.TranscriptBasePkg.all ;
use work.AlertLogPkg.all ;
use work.NameStorePkg.all ;
use work.LanguageSupport2019Pkg.all ;
use work.IdFifoPtPkg.all ;
package DynamicVectorGenericPkg is
generic (type VectorType is array (type is range <>) of type is private ) ;
constant SUPPORTS_2019_GENERICS : boolean := TRUE ;
-- Package local definitions
subtype ElementType is VectorType'element ;
subtype IndexType is VectorType'index ;
type InternalVectorType is array (natural range <>) of ElementType ;
constant FIRST_INDEX : natural := 0 ;
constant NO_INDEX : integer := -1 ;
constant NO_NATURAL : integer := -1 ;
------------------------------------------------------------
-- DynamicVectorIDType
-- ID Type for Dynamic Arrays
type DynamicVectorIDType is record
IdNum : integer_max ; -- A unique list
CopyNum : integer_max ; -- A unique iterator
end record DynamicVectorIDType ;
constant EMPTY_DYNAMIC_ARRAY_ID : DynamicVectorIDType := (IdNum => 0, CopyNum => 0) ;
type DynamicVectorIDArrayType is array (integer range <>) of DynamicVectorIDType ;
------------------------------------------------------------
-- IsInitialized
-- True if singleton has been constructed
impure function IsInitialized (ID : DynamicVectorIDType) return boolean ; -- ID Valid
------------------------------------------------------------
-- NewID
-- Construct a new dynamic array
impure function NewID (
Name : String ;
Capacity : natural ;
ParentID : AlertLogIDType := OSVVM_DYNAMICVECTOR_ALERTLOG_ID ;
ReportMode : AlertLogReportModeType := USE_PARENT_ID ;
Search : NameSearchType := PRIVATE_NAME ;
PrintParent : AlertLogPrintParentType := PRINT_NAME_AND_PARENT
) return DynamicVectorIDType ;
------------------------------------------------------------
-- CopyID
-- Create a shallow copy of the data structure
--
impure function CopyID ( SiblingID : DynamicVectorIDType ) return DynamicVectorIDType ;
------------------------------------------------------------
-- Append
-- Add element(s) to the end of the list
procedure Append (
ID : DynamicVectorIDType ;
iValue : ElementType
) ;
procedure Append (
ID : DynamicVectorIDType ;
iValue : VectorType
) ;
------------------------------------------------------------
-- Get
-- Return the element(s) at the index
impure function Get (
ID : DynamicVectorIDType ;
Index : natural
) return ElementType ;
impure function Get (
ID : DynamicVectorIDType ;
Index : natural ;
NumValues : natural
) return VectorType ;
------------------------------------------------------------
-- Set
-- Set the element(s) at the index
procedure Set (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) ;
procedure Set (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : VectorType
) ;
------------------------------------------------------------
-- Insert
-- Insert element(s) to the list at Index
-- O(n) operation since array is shifted
procedure Insert (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) ;
procedure Insert (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : VectorType
) ;
------------------------------------------------------------
-- Prepend
-- Prepend element(s) to the list at start of list
-- O(n) operation since array is shifted
procedure Prepend (
ID : DynamicVectorIDType ;
iValue : ElementType
) ;
procedure Prepend (
ID : DynamicVectorIDType ;
iValue : VectorType
) ;
------------------------------------------------------------
-- Delete
-- Remove element(s) from the list at Index
-- O(n) operation since array is shifted
procedure Delete (
ID : DynamicVectorIDType ;
Index : natural
) ;
procedure Delete (
ID : DynamicVectorIDType ;
Index : natural ;
NumValues : natural
) ;
------------------------------------------------------------
-- Find
-- Search for value starting at StartingIndex and return index if found otherwise NO_INDEX
impure function Find (
ID : DynamicVectorIDType ;
StartingIndex : natural ;
iValue : ElementType
) return integer ;
impure function Find (
ID : DynamicVectorIDType ;
StartingIndex : natural ;
iValue : VectorType
) return integer ;
------------------------------------------------------------
-- Find
-- Search for value starting at Index 0 and return index if found otherwise NO_INDEX
impure function Find (
ID : DynamicVectorIDType ;
iValue : ElementType
) return integer ;
impure function Find (
ID : DynamicVectorIDType ;
iValue : VectorType
) return integer ;
------------------------------------------------------------
-- Match
-- Return true if value at StartingIndex matches iValue
impure function Match (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) return boolean ;
impure function Match (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : VectorType
) return boolean ;
------------------------------------------------------------
-- Each Iterator / Copy maintains an internal index to the list
-- The following provide means to manipulate that index
------------------------------------------------------------
-- GetIndex
-- Return the current value of the internal index
impure function GetIndex (ID : DynamicVectorIDType) return integer ;
------------------------------------------------------------
-- SetIndex
-- Set the current value of the internal index
procedure SetIndex (ID : DynamicVectorIDType ; Index : natural := FIRST_INDEX) ;
------------------------------------------------------------
-- GetFirstIndex
-- Return the first index in the list
impure function GetFirstIndex (ID : DynamicVectorIDType) return integer ;
------------------------------------------------------------
-- GetLastIndex
-- Return the last index in the list
-- With NumValues = 0, LastIndex is a reference to the next empty index
impure function GetLastIndex (ID : DynamicVectorIDType; NumValues : natural := 0) return integer ;
------------------------------------------------------------
-- IndexNext
-- Return the current index and then increment index by NumValues
impure function IndexNext (ID : DynamicVectorIDType; NumValues : natural := 1) return integer ;
------------------------------------------------------------
-- HasNext
-- If the index is incremented by NumValues, will the index be within the list
impure function HasNext (ID : DynamicVectorIDType; NumValues : natural := 1) return boolean ;
------------------------------------------------------------
-- IndexPrevious
-- Decrement index by NumValues and return the index value
impure function IndexPrevious (ID : DynamicVectorIDType; NumValues : natural := 1) return integer ;
------------------------------------------------------------
-- HasPrevious
-- If the index is decremented by NumValues, will the index be within the list
impure function HasPrevious (ID : DynamicVectorIDType; NumValues : natural := 1) return boolean ;
------------------------------------------------------------
-- GetNext
-- Get value at index and then increment index (index++)
impure function GetNext (
ID : DynamicVectorIDType
) return ElementType ;
impure function GetNext (
ID : DynamicVectorIDType ;
NumValues : natural
) return VectorType ;
------------------------------------------------------------
-- SetNext
-- Set value at index and then increment index (index++)
procedure SetNext (
ID : DynamicVectorIDType ;
iValue : ElementType
) ;
procedure SetNext (
ID : DynamicVectorIDType ;
iValue : VectorType
) ;
------------------------------------------------------------
-- FindNext
-- Search for value starting at iterator index and return index if found otherwise NO_INDEX
impure function FindNext (
ID : DynamicVectorIDType ;
iValue : ElementType
) return integer ;
impure function FindNext (
ID : DynamicVectorIDType ;
iValue : VectorType
) return integer ;
------------------------------------------------------------
-- GetPrevious
-- Decrement index by NumValues and then get value at index (--index)
impure function GetPrevious (
ID : DynamicVectorIDType
) return ElementType ;
impure function GetPrevious (
ID : DynamicVectorIDType ;
NumValues : natural
) return VectorType ;
------------------------------------------------------------
-- SetPrevious
-- Decrement index and then set value at index (--index)
procedure SetPrevious (
ID : DynamicVectorIDType ;
iValue : ElementType
) ;
procedure SetPrevious (
ID : DynamicVectorIDType ;
iValue : VectorType
) ;
------------------------------------------------------------
-- FindPrevious
-- Search for value starting at iterator index and return index if found otherwise NO_INDEX
impure function FindPrevious (
ID : DynamicVectorIDType ;
iValue : ElementType
) return integer ;
impure function FindPrevious (
ID : DynamicVectorIDType ;
iValue : VectorType
) return integer ;
------------------------------------------------------------
-- IsEmpty
-- Does the list have any elements in it
impure function IsEmpty (ID : DynamicVectorIDType) return boolean ; -- Does ID have storage
------------------------------------------------------------
-- Deallocate
-- Deallocate the current copy.
-- If no copies remain free up the list.
impure function Deallocate (ID : DynamicVectorIDType) return DynamicVectorIDType;
------------------------------------------------------------
-- GetSize
-- Return the number of elements in the list.
impure function GetSize (ID : DynamicVectorIDType) return integer ;
------------------------------------------------------------
-- GetCapacity
-- Return the maximum number of elements the list can hold.
impure function GetCapacity (ID : DynamicVectorIDType) return integer ;
------------------------------------------------------------
-- MakeEmpty
-- Set the size of the list to 0 for all copies of the list
procedure MakeEmpty (ID : DynamicVectorIDType) ;
------------------------------------------------------------
-- GetAlertLogID
-- Return the AlertLogID that is used internally and set during the call to NewID
impure function GetAlertLogID (ID : DynamicVectorIDType) return AlertLogIDType ;
end package DynamicVectorGenericPkg ;
--- ///////////////////////////////////////////////////////////////////////////
--- ///////////////////////////////////////////////////////////////////////////
--- ///////////////////////////////////////////////////////////////////////////
package body DynamicVectorGenericPkg is
constant ITERATOR_LENGTH_INIT : natural := 3 ;
constant ITERATOR_LENGTH_GROW : natural := 3 ;
constant INITIAL_ARRAY_SIZE : natural := 16 ;
------------------------------------------------------------
-- Package Local
function GetElementTypeDefault return ElementType is
variable DefaultValue : ElementType;
begin
return DefaultValue ;
end function GetElementTypeDefault;
------------------------------------------------------------
-- Package Local
procedure FailureIdNotInitialized(ID : DynamicVectorIDType ; Name : string) is
begin
if ID.IdNum /= integer'left then
Alert("DynamicVector: " & Name & ", invalid ID. IdNum: " & to_string(ID.IdNum) & " CopyNum: " & to_string(ID.CopyNum), FAILURE) ;
else
Alert("DynamicVector: " & Name & ", ID not Initialized. If ID is a signal, be sure to do a ""wait for 0 ns"" after NewID.", FAILURE) ;
end if ;
end procedure FailureIdNotInitialized ;
type DynamicVectorPType is protected
------------------------------------------------------------
impure function IsInitialized (ID : DynamicVectorIDType) return boolean ; -- ID Valid
------------------------------------------------------------
impure function NewID (
Name : String ;
Capacity : natural ;
ParentID : AlertLogIDType ;
ReportMode : AlertLogReportModeType ; -- These use the ParentAlertID rather than creating their own AlertLogID
Search : NameSearchType ; -- These are always private and cloned to hand off
PrintParent : AlertLogPrintParentType
) return DynamicVectorIDType ;
------------------------------------------------------------
impure function CopyID ( SiblingID : DynamicVectorIDType ) return DynamicVectorIDType ;
------------------------------------------------------------
procedure Append (
ID : DynamicVectorIDType ;
iValue : ElementType
) ;
procedure Append (
ID : DynamicVectorIDType ;
iValue : InternalVectorType
) ;
------------------------------------------------------------
impure function Get (
ID : DynamicVectorIDType ;
Index : natural
) return ElementType ;
impure function Get (
ID : DynamicVectorIDType ;
Index : natural ;
NumValues : natural
) return InternalVectorType ;
------------------------------------------------------------
procedure Set (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) ;
procedure Set (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : InternalVectorType
) ;
------------------------------------------------------------
procedure Insert (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) ;
procedure Insert (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : InternalVectorType
) ;
------------------------------------------------------------
procedure Delete (
ID : DynamicVectorIDType ;
Index : natural
) ;
procedure Delete (
ID : DynamicVectorIDType ;
Index : natural ;
NumValues : natural
) ;
------------------------------------------------------------
impure function GetIndex (ID : DynamicVectorIDType) return integer ;
procedure SetIndex (ID : DynamicVectorIDType ; Index : natural := FIRST_INDEX) ;
impure function GetFirstIndex (ID : DynamicVectorIDType) return integer ;
impure function GetLastIndex (ID : DynamicVectorIDType; NumValues : natural := 0) return integer ;
impure function IndexNext (ID : DynamicVectorIDType; NumValues : natural := 1) return integer ;
impure function HasNext (ID : DynamicVectorIDType; NumValues : natural := 1) return boolean ;
impure function IndexPrevious (ID : DynamicVectorIDType; NumValues : natural := 1) return integer ;
impure function HasPrevious (ID : DynamicVectorIDType; NumValues : natural := 1) return boolean ;
------------------------------------------------------------
impure function IsEmpty (ID : DynamicVectorIDType) return boolean ; -- Does ID have storage
impure function Deallocate (ID : DynamicVectorIDType) return DynamicVectorIDType ;
------------------------------------------------------------
impure function GetSize (ID : DynamicVectorIDType) return integer ;
impure function GetCapacity (ID : DynamicVectorIDType) return integer ;
procedure MakeEmpty (ID : DynamicVectorIDType) ;
------------------------------------------------------------
impure function GetAlertLogID (ID : DynamicVectorIDType) return AlertLogIDType ;
end protected DynamicVectorPType ;
type DynamicVectorPType is protected body
type IteratorType is record
HeadIndex : natural ;
InUse : boolean ;
end record IteratorType ;
type IteratorArrayType is array (natural range <>) of IteratorType ;
type IteratorArrayPtrType is access IteratorArrayType ;
type ArrayPtrType is access InternalVectorType ;
type DynamicVectorRecType is record
ArrayPtr : ArrayPtrType ;
IteratorPtr : IteratorArrayPtrType ;
TailIndex : natural ;
Capacity : natural ;
MaxCopyNum : natural ;
ActiveClones : natural ;
AlertLogID : AlertLogIDType ;
end record DynamicVectorRecType ;
type DynamicVectorRecPtrType is access DynamicVectorRecType ;
type SingletonArrayType is array (natural range <>) of DynamicVectorRecPtrType ;
type SingletonArrayPtrType is access SingletonArrayType ;
variable SingletonArrayPtr : SingletonArrayPtrType ;
variable NumItems : natural := 0 ;
variable MaxItems : natural := 0 ;
constant MIN_NUM_ITEMS : natural := 32 ; -- Min amount to resize array
variable IdFifo : IdFifoPType ;
------------------------------------------------------------
impure function IsInitialized (ID : DynamicVectorIDType) return boolean is
constant IdNum : integer := ID.IdNum ;
begin
if IdNum >= 1 and IdNum <= MaxItems then
if SingletonArrayPtr(IdNum) /= NULL then
if SingletonArrayPtr(IdNum).IteratorPtr /= NULL and SingletonArrayPtr(IdNum).ArrayPtr /= NULL then
if SingletonArrayPtr(IdNum).IteratorPtr(ID.CopyNum).InUse then
return TRUE ; -- Initialized
end if ;
end if ;
end if ;
end if ;
return FALSE ; -- Not Initialized
end function IsInitialized ;
------------------------------------------------------------
-- Package Local
impure function GetNextIdNumber return natural is
variable oldItemArrayPtr : SingletonArrayPtrType ;
begin
if not IdFifo.IsEmpty then
NumItems := NumItems + 1 ;
return IdFifo.Pop ;
elsif SingletonArrayPtr = NULL then
MaxItems := MIN_NUM_ITEMS ;
SingletonArrayPtr := new SingletonArrayType(1 to MaxItems) ;
NumItems := 1 ;
else
AlertIfNotEqual(NumItems, SingletonArrayPtr'length, "GetNextIdNumber: NumItems /= SingletonArrayPtr'length") ;
MaxItems := MaxItems + 32 ;
OldItemArrayPtr := SingletonArrayPtr ;
SingletonArrayPtr := new SingletonArrayType(1 to MaxItems) ;
SingletonArrayPtr.all(1 to NumItems) := oldItemArrayPtr.all(1 to NumItems) ;
deallocate(oldItemArrayPtr) ;
NumItems := NumItems + 1 ;
end if ;
for i in NumItems + 1 to MaxItems loop
IdFifo.push(i) ;
end loop ;
return NumItems ;
end function GetNextIdNumber ;
------------------------------------------------------------
impure function NewID (
Name : String ;
Capacity : natural ;
ParentID : AlertLogIDType ;
ReportMode : AlertLogReportModeType ; -- These use the ParentAlertID rather than creating their own AlertLogID
Search : NameSearchType ; -- These are always private and cloned to hand off
PrintParent : AlertLogPrintParentType
) return DynamicVectorIDType is
variable ID : DynamicVectorIDType ;
variable ResolvedCapacity : natural ;
variable IdNum : natural ;
begin
ResolvedCapacity := Maximum(Capacity, INITIAL_ARRAY_SIZE) ;
IdNum := GetNextIdNumber ;
SingletonArrayPtr(IdNum) := new DynamicVectorRecType ;
SingletonArrayPtr(IdNum).IteratorPtr := new IteratorArrayType'(1 to ITERATOR_LENGTH_INIT => (FIRST_INDEX, FALSE)) ;
SingletonArrayPtr(IdNum).IteratorPtr(1).InUse := TRUE ;
SingletonArrayPtr(IdNum).TailIndex := FIRST_INDEX ;
SingletonArrayPtr(IdNum).ActiveClones := 1 ;
SingletonArrayPtr(IdNum).MaxCopyNum := 1 ;
SingletonArrayPtr(IdNum).AlertLogID := NewID(Name, ParentID, ReportMode, PrintParent, CreateHierarchy => FALSE) ;
SingletonArrayPtr(IdNum).Capacity := ResolvedCapacity ;
SingletonArrayPtr(IdNum).ArrayPtr := new InternalVectorType(FIRST_INDEX to FIRST_INDEX - 1 + ResolvedCapacity ) ;
if Search /= PRIVATE_NAME then
Alert(SingletonArrayPtr(IdNum).AlertLogID, "DynamicVector, NewID: Search mode ignored. " &
"Search not currently supported. " &
"Please submit use model to GitHub issues site.", WARNING) ;
end if ;
ID.IdNum := IdNum ;
ID.CopyNum := 1 ;
return ID ;
end function NewID ;
------------------------------------------------------------
impure function CopyID ( SiblingID : DynamicVectorIDType ) return DynamicVectorIDType is
variable ID : DynamicVectorIDType ;
variable IdNum, vCopyNum : natural ;
variable OrigIteratorLength : natural ;
variable OldIteratorPtr, IteratorPtr : IteratorArrayPtrType ;
begin
IdNum := SiblingID.IdNum ;
ID.IdNum := IdNum ;
vCopyNum := SingletonArrayPtr(IdNum).MaxCopyNum + 1 ;
ID.CopyNum := vCopyNum ;
SingletonArrayPtr(IdNum).MaxCopyNum := vCopyNum ;
SingletonArrayPtr(IdNum).ActiveClones := SingletonArrayPtr(IdNum).ActiveClones + 1 ;
OrigIteratorLength := SingletonArrayPtr(IdNum).IteratorPtr'length ;
if vCopyNum > OrigIteratorLength then
OldIteratorPtr := SingletonArrayPtr(IdNum).IteratorPtr ;
IteratorPtr := new IteratorArrayType'(1 to OrigIteratorLength + ITERATOR_LENGTH_GROW => (FIRST_INDEX, FALSE)) ;
IteratorPtr.all(1 to OrigIteratorLength) := OldIteratorPtr.all(1 to OrigIteratorLength) ;
deallocate(OldIteratorPtr) ;
SingletonArrayPtr(IdNum).IteratorPtr := IteratorPtr ;
end if ;
SingletonArrayPtr(IdNum).IteratorPtr(vCopyNum).InUse := TRUE ;
return ID ;
end function CopyID ;
------------------------------------------------------------
-- PT Local
procedure IncreaseArrayCapacity (
IdNum : natural ;
NewSize : natural
) is
variable OldArrayPtr : ArrayPtrType ;
variable OldCapacity, NewCapacity : natural ;
begin
OldCapacity := SingletonArrayPtr(IdNum).Capacity ;
NewCapacity := OldCapacity ;
while NewCapacity < NewSize loop
NewCapacity := NewCapacity * 2 ;
end loop ;
OldArrayPtr := SingletonArrayPtr(IdNum).ArrayPtr ;
SingletonArrayPtr(IdNum).ArrayPtr := new InternalVectorType(FIRST_INDEX to FIRST_INDEX - 1 + NewCapacity) ;
SingletonArrayPtr(IdNum).Capacity := NewCapacity ;
SingletonArrayPtr(IdNum).ArrayPtr.all(FIRST_INDEX to FIRST_INDEX - 1 + OldCapacity) := OldArrayPtr.all(FIRST_INDEX to FIRST_INDEX - 1 + OldCapacity) ;
deallocate(OldArrayPtr) ;
end procedure IncreaseArrayCapacity ;
------------------------------------------------------------
-- PT Local
procedure SetArrayValue (
ID : DynamicVectorIDType ;
StartingIndex : natural ;
EndingIndex : natural ;
iValue : InternalVectorType
) is
alias revValue : InternalVectorType (EndingIndex downto StartingIndex) is iValue ;
begin
-- SingletonArrayPtr(ID.IdNum).ArrayPtr(StartingIndex to EndingIndex) := iValue ;
for i in StartingIndex to EndingIndex loop
SingletonArrayPtr(ID.IdNum).ArrayPtr(i) := revValue(i) ;
end loop ;
end procedure SetArrayValue ;
------------------------------------------------------------
-- PT Local
impure function GetArrayValue (
ID : DynamicVectorIDType ;
StartingIndex : natural ;
EndingIndex : natural
) return InternalVectorType is
variable Result : InternalVectorType(EndingIndex downto StartingIndex) ;
begin
for i in StartingIndex to EndingIndex loop
Result(i) := SingletonArrayPtr(ID.IdNum).ArrayPtr(i) ;
end loop ;
-- return SingletonArrayPtr(ID.IdNum).ArrayPtr(StartingIndex to EndingIndex) ;
return Result ;
end function GetArrayValue ;
------------------------------------------------------------
procedure Append (
ID : DynamicVectorIDType ;
iValue : ElementType
) is
variable EndingIndex, NewSize : natural ;
variable IdNum : natural ;
begin
IdNum := ID.IdNum ;
EndingIndex := SingletonArrayPtr(IdNum).TailIndex ;
NewSize := EndingIndex + 1 ;
if SingletonArrayPtr(IdNum).Capacity < NewSize then
IncreaseArrayCapacity(IdNum, NewSize) ;
end if ;
SingletonArrayPtr(IdNum).TailIndex := NewSize ;
SingletonArrayPtr(IdNum).ArrayPtr(EndingIndex) := iValue ;
end procedure Append ;
------------------------------------------------------------
procedure Append (
ID : DynamicVectorIDType ;
iValue : InternalVectorType
) is
variable StartingIndex : natural ;
variable NewSize : natural ;
variable EndingIndex : natural ;
constant ARRAY_SIZE : natural := iValue'length ;
variable IdNum : natural ;
begin
IdNum := ID.IdNum ;
StartingIndex := SingletonArrayPtr(IdNum).TailIndex ;
NewSize := SingletonArrayPtr(IdNum).TailIndex + ARRAY_SIZE ;
EndingIndex := NewSize - 1 ;
if SingletonArrayPtr(IdNum).Capacity < NewSize then
IncreaseArrayCapacity(IdNum, NewSize) ;
end if ;
SingletonArrayPtr(IdNum).TailIndex := NewSize ;
SetArrayValue(ID, StartingIndex, EndingIndex, iValue) ;
end procedure Append ;
------------------------------------------------------------
impure function Get (
ID : DynamicVectorIDType ;
Index : natural
) return ElementType is
variable StartingIndex, TailIndex : natural ;
begin
StartingIndex := Index ;
TailIndex := SingletonArrayPtr(ID.IdNum).TailIndex ;
if StartingIndex >= TailIndex then
Alert(SingletonArrayPtr(ID.IdNum).AlertLogID,
"DynamicVector: Get Index: " & to_string(Index) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(TailIndex-1), FAILURE) ;
return GetElementTypeDefault ;
end if ;
return SingletonArrayPtr(ID.IdNum).ArrayPtr(StartingIndex) ;
end function Get ;
------------------------------------------------------------
impure function Get (
ID : DynamicVectorIDType ;
Index : natural ;
NumValues : natural
) return InternalVectorType is
variable StartingIndex, EndingIndex, TailIndex : natural ;
begin
StartingIndex := Index ;
EndingIndex := StartingIndex + NumValues - 1 ;
TailIndex := SingletonArrayPtr(ID.IdNum).TailIndex ;
if EndingIndex >= TailIndex then
Alert(SingletonArrayPtr(ID.IdNum).AlertLogID,
"DynamicVector: Get Range: " & to_string(Index) & " to " & to_string(EndingIndex) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(TailIndex-1), FAILURE) ;
return InternalVectorType'(1 to NumValues => GetElementTypeDefault) ;
end if ;
return GetArrayValue(ID, StartingIndex, EndingIndex) ;
end function Get ;
------------------------------------------------------------
procedure Set (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) is
variable StartingIndex, TailIndex : natural ;
begin
StartingIndex := Index ;
TailIndex := SingletonArrayPtr(ID.IdNum).TailIndex ;
if StartingIndex >= TailIndex then
Alert(SingletonArrayPtr(ID.IdNum).AlertLogID,
"DynamicVector: Set Index: " & to_string(Index) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(TailIndex-1), FAILURE) ;
return ;
end if ;
SingletonArrayPtr(ID.IdNum).ArrayPtr(StartingIndex) := iValue ;
end procedure Set ;
------------------------------------------------------------
procedure Set (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : InternalVectorType
) is
variable StartingIndex, EndingIndex, TailIndex : natural ;
begin
StartingIndex := Index ;
EndingIndex := StartingIndex + iValue'length - 1 ;
TailIndex := SingletonArrayPtr(ID.IdNum).TailIndex ;
if EndingIndex >= TailIndex then
Alert(SingletonArrayPtr(ID.IdNum).AlertLogID,
"DynamicVector: Set Range: " & to_string(Index) & " to " & to_string(EndingIndex) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(TailIndex-1), FAILURE) ;
return ;
end if ;
SetArrayValue(ID, StartingIndex, EndingIndex, iValue) ;
end procedure Set ;
------------------------------------------------------------
procedure Insert (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : ElementType
) is
variable OldTailIndex, NewSize : natural ;
variable IdNum : natural ;
begin
IdNum := ID.IdNum ;
OldTailIndex := SingletonArrayPtr(IdNum).TailIndex ;
NewSize := OldTailIndex + 1 ;
if Index > OldTailIndex then
Alert(SingletonArrayPtr(IdNum).AlertLogID,
"DynamicVector: Insert Index: " & to_string(Index) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(OldTailIndex-1), FAILURE) ;
return ;
end if ;
if SingletonArrayPtr(IdNum).Capacity < NewSize then
IncreaseArrayCapacity(IdNum, NewSize) ;
end if ;
if Index /= OldTailIndex then
-- Move the current values over
SingletonArrayPtr(IdNum).ArrayPtr(Index+1 to OldTailIndex) :=
SingletonArrayPtr(IdNum).ArrayPtr(Index to OldTailIndex-1) ;
end if ;
SingletonArrayPtr(IdNum).TailIndex := NewSize ;
SingletonArrayPtr(IdNum).ArrayPtr(Index) := iValue ;
end procedure Insert ;
------------------------------------------------------------
procedure Insert (
ID : DynamicVectorIDType ;
Index : natural ;
iValue : InternalVectorType
) is
variable OldTailIndex : natural ;
variable NewSize : natural ;
constant ARRAY_SIZE : natural := iValue'length ;
variable IdNum : natural ;
begin
IdNum := ID.IdNum ;
OldTailIndex := SingletonArrayPtr(IdNum).TailIndex ;
NewSize := SingletonArrayPtr(IdNum).TailIndex + ARRAY_SIZE ;
if Index > OldTailIndex then
Alert(SingletonArrayPtr(IdNum).AlertLogID,
"DynamicVector: Insert Index: " & to_string(Index) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(OldTailIndex-1), FAILURE) ;
return ;
end if ;
if SingletonArrayPtr(IdNum).Capacity < NewSize then
IncreaseArrayCapacity(IdNum, NewSize) ;
end if ;
if Index /= OldTailIndex then
-- Move the current values over
SingletonArrayPtr(IdNum).ArrayPtr(Index + ARRAY_SIZE to NewSize - 1) :=
SingletonArrayPtr(IdNum).ArrayPtr(Index to OldTailIndex - 1) ;
end if ;
SingletonArrayPtr(IdNum).TailIndex := NewSize ;
SetArrayValue(ID, Index, Index + ARRAY_SIZE - 1, iValue) ;
end procedure Insert ;
------------------------------------------------------------
procedure Delete (
ID : DynamicVectorIDType ;
Index : natural
) is
variable OldTailIndex : natural ;
variable IdNum : natural ;
begin
IdNum := ID.IdNum ;
OldTailIndex := SingletonArrayPtr(IdNum).TailIndex ;
if Index >= OldTailIndex then
Alert(SingletonArrayPtr(IdNum).AlertLogID,
"DynamicVector: Delete Index: " & to_string(Index) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(OldTailIndex-1), FAILURE) ;
return ;
end if ;
-- Move the current values over
SingletonArrayPtr(IdNum).ArrayPtr(Index to OldTailIndex-2) :=
SingletonArrayPtr(IdNum).ArrayPtr(Index+1 to OldTailIndex-1) ;
SingletonArrayPtr(IdNum).TailIndex := OldTailIndex-1 ;
end procedure Delete ;
------------------------------------------------------------
procedure Delete (
ID : DynamicVectorIDType ;
Index : natural ;
NumValues : natural
) is
variable OldTailIndex : natural ;
variable IdNum : natural ;
begin
IdNum := ID.IdNum ;
OldTailIndex := SingletonArrayPtr(IdNum).TailIndex ;
if Index >= OldTailIndex then
Alert(SingletonArrayPtr(IdNum).AlertLogID,
"DynamicVector: Delete Index: " & to_string(Index) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(OldTailIndex-1), FAILURE) ;
return ;
end if ;
-- Move the current values over
SingletonArrayPtr(IdNum).ArrayPtr(Index to OldTailIndex-NumValues-1) :=
SingletonArrayPtr(IdNum).ArrayPtr(Index+NumValues to OldTailIndex-1) ;
SingletonArrayPtr(IdNum).TailIndex := OldTailIndex-NumValues ;
end procedure Delete ;
------------------------------------------------------------
impure function GetIndex (ID : DynamicVectorIDType) return integer is
begin
return SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex ;
end function GetIndex ;
------------------------------------------------------------
procedure SetIndex (ID : DynamicVectorIDType ; Index : natural := FIRST_INDEX) is
begin
SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex := Index ;
end procedure SetIndex ;
------------------------------------------------------------
impure function GetFirstIndex (ID : DynamicVectorIDType) return integer is
begin
return FIRST_INDEX ;
end function GetFirstIndex ;
------------------------------------------------------------
impure function GetLastIndex (ID : DynamicVectorIDType; NumValues : natural := 0) return integer is
-- With NumValues = 0, LastIndex is a reference to the next empty index
begin
return SingletonArrayPtr(ID.IdNum).TailIndex - NumValues ;
end function GetLastIndex ;
------------------------------------------------------------
impure function IndexNext (ID : DynamicVectorIDType; NumValues : natural := 1) return integer is
variable CurIndex, NextIndex, LastIndex : natural ;
begin
CurIndex := SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex ;
NextIndex := CurIndex + NumValues ;
LastIndex := SingletonArrayPtr(ID.IdNum).TailIndex ;
if NextIndex <= LastIndex then
SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex := NextIndex ;
else
Alert(SingletonArrayPtr(ID.IdNum).AlertLogID,
"DynamicVector: IndexNext Index: " & to_string(CurIndex) &
" outside of DyanmicArray range: " & to_string(FIRST_INDEX) &
" to " & to_string(LastIndex-1), FAILURE) ;
return NO_INDEX ;
end if ;
return CurIndex ;
end function IndexNext ;
------------------------------------------------------------
impure function HasNext (ID : DynamicVectorIDType; NumValues : natural := 1) return boolean is
begin
return SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex + NumValues <= SingletonArrayPtr(ID.IdNum).TailIndex ;
end function HasNext ;
------------------------------------------------------------
impure function IndexPrevious (ID : DynamicVectorIDType; NumValues : natural := 1) return integer is
variable PreviousIndex : integer ;
begin
PreviousIndex := SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex - NumValues ;
if PreviousIndex >= FIRST_INDEX then
SingletonArrayPtr(ID.IdNum).IteratorPtr(ID.CopyNum).HeadIndex := PreviousIndex ;
else