点击查看代码
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

# =============================================================================
# SystemVerilog/Verilog Snippets - Organized by Category
# Author: Auto-generated
# Description: Comprehensive SystemVerilog, Verilog and UVM snippets
# =============================================================================

# =============================================================================
# COMMONLY USED SNIPPETS (Top Priority)
# =============================================================================

snippet sv_header
//==============================================================================
// File : ${1:`expand('%:t')`}
// Project : ${2:Project Name}
// Module : ${3:`expand('%:t:r')`}
// Author : ${4:$USER}
// Created : ${5:`strftime("%Y-%m-%d")`}
// Modified : ${6:`strftime("%Y-%m-%d")`}
//==============================================================================
// Description:
// ${7:Brief description}
//==============================================================================

${0}


snippet tb
\`timescale 1ns/1ps

module ${1:`expand('%:t:r')`};

localparam int PERIOD = ${2:10};

logic ${3:clk};
logic ${4:rst_n};
${5}

// Clock generation
initial begin
$3 = 0;
forever #(PERIOD/2) $3 = ~$3;
end

// Reset generation
initial begin
$4 = 0;
repeat(2) @(posedge $3);
$4 = 1;
end

// DUT instantiation
${6:dut} u_dut (
.clk($3),
.rst_n($4)${7}
);

// Test stimulus
initial begin
@(posedge $4);
${0}
#1000;
\$finish;
end

// Waveform dump
initial begin
\$dumpfile("${8:`expand('%:t:r')`}\.vcd");
\$dumpvars(0, $1);
end

endmodule: $1


snippet always_ff
always_ff @(posedge ${1:clk} or negedge ${2:rst_n}) begin
if (!$2)
${3}
else
${4}
end

snippet class
class ${1:`expand('%:t:r')`};
${2}

function new(string name = "$1");
${3}
endfunction: new

endclass: $1

snippet sequence_item
class ${1:`expand('%:t:r')`} extends uvm_sequence_item;
\`uvm_object_utils($1)

// Transaction fields
rand bit [${2:7}:0] ${3:addr};
rand bit [${4:31}:0] ${5:data};
${6}

// Constraints
constraint ${7:valid}_c {
${8}
}

extern function new(string name = "$1");
extern function void do_copy(uvm_object rhs);
extern function bit do_compare(uvm_object rhs, uvm_comparer comparer);
extern function void do_print(uvm_printer printer);
extern function string convert2string();

endclass: $1

function $1::new(string name = "$1");
super.new(name);
endfunction: new

function void $1::do_copy(uvm_object rhs);
$1 rhs_;
if (!\$cast(rhs_, rhs))
\`uvm_fatal(get_type_name(), "Cast failed in do_copy")
super.do_copy(rhs);
this.$3 = rhs_.$3;
this.$5 = rhs_.$5;
endfunction: do_copy

function bit $1::do_compare(uvm_object rhs, uvm_comparer comparer);
$1 rhs_;
if (!\$cast(rhs_, rhs))
return 0;
return (super.do_compare(rhs, comparer) &&
(this.$3 == rhs_.$3) &&
(this.$5 == rhs_.$5));
endfunction: do_compare

function void $1::do_print(uvm_printer printer);
super.do_print(printer);
printer.print_field("$3", this.$3, $2+1);
printer.print_field("$5", this.$5, $4+1);
endfunction: do_print

function string $1::convert2string();
return $sformatf("$3=0x%0h, $5=0x%0h", $3, $5);
endfunction: convert2string

# moved: assert to COMMONLY USED SNIPPETS
assert (${1:condition}) else \$error("${2:Assertion failed}");

# moved: property to COMMONLY USED SNIPPETS
property ${1:`expand('%:t:r')`};
@(posedge ${2:clk}) ${3:condition};
endproperty: $1

# moved: sequence to COMMONLY USED SNIPPETS
sequence ${1:`expand('%:t:r')`};
${2}
endsequence: $1

# moved: implication to COMMONLY USED SNIPPETS
${1:antecedent} |-> ${2:consequent}

snippet uvm_agent
class ${1:`expand('%:t:r')`} extends uvm_agent;
\`uvm_component_utils($1)

${2:`substitute(expand('%:t:r'), '_agent$', '', '')`}_sequencer sqr;
$2_driver drv;
$2_monitor mon;

uvm_active_passive_enum is_active = UVM_ACTIVE;

extern function new(string name = "$1", uvm_component parent = null);
extern virtual function void build_phase(uvm_phase phase);
extern virtual function void connect_phase(uvm_phase phase);

endclass: $1

function $1::new(string name = "$1", uvm_component parent = null);
super.new(name, parent);
endfunction: new

function void $1::build_phase(uvm_phase phase);
super.build_phase(phase);

// Get configuration
if (!uvm_config_db#(uvm_active_passive_enum)::get(this, "", "is_active", is_active))
\`uvm_info(get_name(), "is_active not configured, using default UVM_ACTIVE", UVM_MEDIUM)

// Always create monitor
mon = $2_monitor::type_id::create("mon", this);

// Create driver and sequencer only in active mode
if (is_active == UVM_ACTIVE) begin
sqr = $2_sequencer::type_id::create("sqr", this);
drv = $2_driver::type_id::create("drv", this);
end
endfunction: build_phase

function void $1::connect_phase(uvm_phase phase);
super.connect_phase(phase);
if (is_active == UVM_ACTIVE) begin
drv.seq_item_port.connect(sqr.seq_item_export);
end
endfunction: connect_phase

snippet uvm_driver
class ${1:`expand('%:t:r')`} extends uvm_driver #(${2:`substitute(expand('%:t:r'), '_driver$', '_item', '')`});
\`uvm_component_utils($1)

virtual ${3:`substitute(expand('%:t:r'), '_driver$', '_if', '')`} vif;

extern function new(string name = "$1", uvm_component parent = null);
extern virtual function void build_phase(uvm_phase phase);
extern virtual task run_phase(uvm_phase phase);
extern virtual task drive_item($2 item);

endclass: $1

function $1::new(string name = "$1", uvm_component parent = null);
super.new(name, parent);
endfunction: new

function void $1::build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual $3)::get(this, "", "vif", vif))
\`uvm_fatal(get_name(), "Virtual interface not found!")
endfunction: build_phase

task $1::run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
drive_item(req);
seq_item_port.item_done();
end
endtask: run_phase

task $1::drive_item($2 item);
// TODO: Implement protocol-specific driving
// Example:
// @(posedge vif.clk);
// vif.data <= item.data;
${0}
endtask: drive_item

snippet uvm_monitor
class ${1:`expand('%:t:r')`} extends uvm_monitor;
\`uvm_component_utils($1)

uvm_analysis_port #(${2:`substitute(expand('%:t:r'), '_monitor$', '_item', '')`}) ap;
virtual ${3:`substitute(expand('%:t:r'), '_monitor$', '_if', '')`} vif;

extern function new(string name = "$1", uvm_component parent = null);
extern virtual function void build_phase(uvm_phase phase);
extern virtual task run_phase(uvm_phase phase);
extern virtual task collect_transaction(output $2 item);

endclass: $1

function $1::new(string name = "$1", uvm_component parent = null);
super.new(name, parent);
endfunction: new

function void $1::build_phase(uvm_phase phase);
super.build_phase(phase);
ap = new("ap", this);
if (!uvm_config_db#(virtual $3)::get(this, "", "vif", vif))
\`uvm_fatal(get_name(), "Virtual interface not found!")
endfunction: build_phase

task $1::run_phase(uvm_phase phase);
forever begin
$2 item;
collect_transaction(item);
\`uvm_info(get_name(), item.convert2string(), UVM_HIGH)
ap.write(item);
end
endtask: run_phase

task $1::collect_transaction(output $2 item);
item = $2::type_id::create("item");
// TODO: Implement protocol-specific monitoring
// Example:
// @(posedge vif.clk);
// if (vif.valid && vif.ready) begin
// item.data = vif.data;
// end
${0}
endtask: collect_transaction

snippet uvm_sequencer
class ${1:`expand('%:t:r')`} extends uvm_sequencer #(${2:`substitute(expand('%:t:r'), '_sequencer$', '_item', '')`});
\`uvm_component_utils($1)

extern function new(string name = "$1", uvm_component parent = null);

endclass: $1

function $1::new(string name = "$1", uvm_component parent = null);
super.new(name, parent);
endfunction: new

snippet uvm_sequence
class ${1:`expand('%:t:r')`} extends uvm_sequence #(${2:`substitute(expand('%:t:r'), '_\(seq\|sequence\)$', '_item', '')`});
\`uvm_object_utils($1)

// Sequence properties
rand int unsigned num_trans = ${3:10};

extern function new(string name = "$1");
extern virtual task body();
extern virtual task pre_body();
extern virtual task post_body();

endclass: $1

function $1::new(string name = "$1");
super.new(name);
endfunction: new

task $1::pre_body();
// Setup before sequence execution
\`uvm_info(get_type_name(), $sformatf("Starting sequence with %0d transactions", num_trans), UVM_MEDIUM)
endtask: pre_body

task $1::body();
repeat (num_trans) begin
\`uvm_do(req)
end
endtask: body

task $1::post_body();
// Cleanup after sequence execution
\`uvm_info(get_type_name(), "Sequence completed", UVM_MEDIUM)
endtask: post_body

# moved: sequence_item to COMMONLY USED SNIPPETS
// ============================================================================
// UVM SEQUENCE ITEM - Transaction Object (UVM Cookbook 5.2)
// ============================================================================
class ${1:`expand('%:t:r')`} extends uvm_sequence_item;
\`uvm_object_utils($1)

// Transaction fields
rand bit [${2:7}:0] ${3:addr};
rand bit [${4:31}:0] ${5:data};
${6}

// Constraints
constraint ${7:valid}_c {
${8}
}

extern function new(string name = "$1");
extern function void do_copy(uvm_object rhs);
extern function bit do_compare(uvm_object rhs, uvm_comparer comparer);
extern function void do_print(uvm_printer printer);
extern function string convert2string();

endclass: $1

function $1::new(string name = "$1");
super.new(name);
endfunction: new

function void $1::do_copy(uvm_object rhs);
$1 rhs_;
if (!\$cast(rhs_, rhs))
\`uvm_fatal(get_type_name(), "Cast failed in do_copy")
super.do_copy(rhs);
this.$3 = rhs_.$3;
this.$5 = rhs_.$5;
endfunction: do_copy

function bit $1::do_compare(uvm_object rhs, uvm_comparer comparer);
$1 rhs_;
if (!\$cast(rhs_, rhs))
return 0;
return (super.do_compare(rhs, comparer) &&
(this.$3 == rhs_.$3) &&
(this.$5 == rhs_.$5));
endfunction: do_compare

function void $1::do_print(uvm_printer printer);
super.do_print(printer);
printer.print_field("$3", this.$3, $2+1);
printer.print_field("$5", this.$5, $4+1);
endfunction: do_print

function string $1::convert2string();
return $sformatf("$3=0x%0h, $5=0x%0h", $3, $5);
endfunction: convert2string

snippet assert
assert (${1:condition}) else \$error("${2:Assertion failed}");

snippet property
property ${1:`expand('%:t:r')`};
@(posedge ${2:clk}) ${3:condition};
endproperty: $1

snippet sequence
sequence ${1:`expand('%:t:r')`};
${2}
endsequence: $1

snippet implication
${1:antecedent} |-> ${2:consequent}

# =============================================================================
# FILE TEMPLATES AND HEADERS
# =============================================================================

snippet sv_header
//==============================================================================
// File : ${1:`expand('%:t')`}
// Project : ${2:Project Name}
// Module : ${3:`expand('%:t:r')`}
// Author : ${4:$USER}
// Created : ${5:`strftime("%Y-%m-%d")`}
// Modified : ${6:`strftime("%Y-%m-%d")`}
//==============================================================================
// Description:
// ${7:Brief description}
//==============================================================================

${0}

snippet header_guard
\`ifndef ${1:`toupper(substitute(expand('%:t:r'), '[^A-Z0-9]', '_', 'g'))`}_SVH
\`define $1_SVH

${0}

\`endif // $1_SVH

snippet tb
\`timescale 1ns/1ps

module ${1:`expand('%:t:r')`};

localparam int PERIOD = ${2:10};

logic ${3:clk};
logic ${4:rst_n};
${5}

// Clock generation
initial begin
$3 = 0;
forever #(PERIOD/2) $3 = ~$3;
end

// Reset generation
initial begin
$4 = 0;
repeat(2) @(posedge $3);
$4 = 1;
end

// DUT instantiation
${6:dut} u_dut (
.clk($3),
.rst_n($4)${7}
);

// Test stimulus
initial begin
@(posedge $4);
${0}
#1000;
\$finish;
end

// Waveform dump
initial begin
\$dumpfile("${8:`expand('%:t:r')`}.vcd");
\$dumpvars(0, $1);
end

endmodule: $1

# =============================================================================
# MODULE AND INTERFACE DEFINITIONS
# =============================================================================

snippet module
module ${1:`expand('%:t:r')`} #(
parameter int ${2:WIDTH} = ${3:8}
) (
input logic ${4:clk},
input logic ${5:rst_n},
${6}
);
${0}
endmodule: $1

snippet interface
interface ${1:`expand('%:t:r')`} (
input logic clk,
input logic rst_n
);
${2}
endinterface: $1

snippet modport
modport ${1:`expand('%:t:r')`}_mp (
${2:input clk}
);

snippet package
package ${1:`expand('%:t:r')`}_pkg;
${2}
endpackage: $1_pkg

snippet program
program ${1:`expand('%:t:r')`};
${2}
endprogram: $1

# =============================================================================
# DATA TYPES
# =============================================================================

snippet logic
logic ${1:[7:0]} ${2:signal}${3: = ${4:0}};

snippet wire
wire ${1:[7:0]} ${2:signal};

snippet reg
reg ${1:[7:0]} ${2:signal}${3: = ${4:0}};

snippet bit
bit ${1:[7:0]} ${2:signal};

snippet byte
byte ${1:variable};

snippet int
int ${1:variable};

snippet parameter
parameter ${1:int} ${2:`toupper(expand('%:t:r'))`} = ${3:value};

snippet localparam
localparam ${1:int} ${2:`toupper(expand('%:t:r'))`} = ${3:value};

snippet typedef_struct
typedef struct packed {
${2}
} ${1:`expand('%:t:r')`}_s;

snippet typedef_enum
typedef enum logic ${1:[1:0]} {
${2:IDLE} = ${3:2'b00},
${4:ACTIVE} = ${5:2'b01}
} ${6:`expand('%:t:r')`}_e;

snippet typedef_union
typedef union packed {
${2}
} ${1:`expand('%:t:r')`}_u;

snippet enum
typedef enum ${1:logic} {
${2:IDLE},
${3:ACTIVE}
} ${4:`expand('%:t:r')`}_e;

# =============================================================================
# ARRAYS
# =============================================================================

snippet dynamic_array
${1:type} ${2:array}[];

snippet associative_array
${1:type} ${2:array}[${3:key_type}];

snippet queue
${1:type} ${2:queue}[$];

snippet packed_array
${1:type} [${2:msb}:${3:lsb}] ${4:array};

snippet unpacked_array
${1:type} ${2:array}[${3:size}];

snippet memory
reg [${1:7}:0] ${2:memory} [0:${3:255}];

# =============================================================================
# PROCEDURAL BLOCKS
# =============================================================================

snippet initial
initial begin
${1}
end

snippet always
always @(${1:posedge clk}) begin
${2}
end

snippet always_ff
always_ff @(posedge ${1:clk} or negedge ${2:rst_n}) begin
if (!$2)
${3}
else
${4}
end

snippet always_comb
always_comb begin
${1}
end

snippet always_latch
always_latch begin
${1}
end

snippet final
final begin
${1}
end

# =============================================================================
# CONTROL STRUCTURES
# =============================================================================

snippet if
if (${1:condition}) begin
${2}
end

snippet ife
if (${1:condition}) begin
${2}
end else begin
${3}
end

snippet case
case (${1:expression})
${2:value1}: begin
${3}
end
default: begin
${4}
end
endcase

snippet casex
casex (${1:expression})
${2:value1}: ${3}
default: ${4}
endcase

snippet casez
casez (${1:expression})
${2:value1}: ${3}
default: ${4}
endcase

snippet unique
unique case (${1:expression})
${2:value}: ${3}
default: ${4}
endcase

snippet priority
priority case (${1:expression})
${2:value}: ${3}
default: ${4}
endcase

snippet ternary
${1:condition} ? ${2:true} : ${3:false}

# =============================================================================
# LOOPS
# =============================================================================

snippet for
for (${1:int i = 0}; ${2:i < n}; ${3:i++}) begin
${4}
end

snippet foreach
foreach (${1:array}[${2:i}]) begin
${3}
end

snippet while
while (${1:condition}) begin
${2}
end

snippet do
do begin
${2}
end while (${1:condition});

snippet repeat
repeat (${1:count}) begin
${2}
end

snippet forever
forever begin
${1}
end

# =============================================================================
# FUNCTIONS AND TASKS
# =============================================================================

snippet function
function ${1:void} ${2:`expand('%:t:r')`}(${3});
${4}
endfunction: $2

snippet task
task ${1:`expand('%:t:r')`}(${2});
${3}
endtask: $1

snippet extern_function
extern function ${1:return_type} ${2:`expand('%:t:r')`}(${3});

snippet extern_task
extern task ${1:`expand('%:t:r')`}(${2});

# =============================================================================
# CLASSES
# =============================================================================

snippet class
class ${1:`expand('%:t:r')`};
${2}

function new(string name = "$1");
${3}
endfunction: new

endclass: $1

snippet class_param
class ${1:`expand('%:t:r')`} #(
parameter int ${2:WIDTH} = ${3:8}
);
${4}

function new(string name = "$1");
${5}
endfunction: new

endclass: $1

snippet virtual_class
virtual class ${1:`expand('%:t:r')`};
${2}
pure virtual function ${3:void} ${4:method}();
endclass: $1

snippet extends
extends ${1:base_class}

snippet static
static ${1:type} ${2:name};

snippet protected
protected ${1:type} ${2:name};

snippet local
local ${1:type} ${2:name};

# =============================================================================
# CONCURRENCY
# =============================================================================

snippet fork
fork
begin
${1}
end
begin
${2}
end
join

snippet fork_join_any
fork
begin
${1}
end
join_any

snippet fork_join_none
fork
begin
${1}
end
join_none

snippet wait
wait (${1:condition});

snippet event
event ${1:event_name};

snippet trigger
-> ${1:event_name};

snippet mailbox
mailbox #(${1:type}) ${2:mbx} = new(${3:bound});

snippet semaphore
semaphore ${1:sem} = new(${2:count});

# =============================================================================
# RANDOMIZATION AND CONSTRAINTS
# =============================================================================

snippet randomize
assert (${1:object}.randomize() with {
${2:constraints}
});

snippet constraint
constraint ${1:name}_c {
${2}
}

snippet dist
${1:variable} dist {
${2:value1} := ${3:weight1},
${4:value2} := ${5:weight2}
};

snippet solve_before
solve ${1:var1} before ${2:var2};

snippet soft
soft ${1:variable} == ${2:value};

snippet inside
${1:variable} inside {${2:range}};

snippet randcase
randcase
${1:weight1}: ${2:stmt1};
${3:weight2}: ${4:stmt2};
endcase

# =============================================================================
# COVERAGE
# =============================================================================

snippet covergroup
covergroup ${1:`expand('%:t:r')`}_cg @(${2:posedge clk});
option.per_instance = 1;
${3}
endgroup: $1_cg

snippet coverpoint
${1:signal}_cp: coverpoint ${2:signal} {
bins low = {[0:${3:127}]};
bins high = {[${4:128}:255]};
}

snippet cross
${1:name}_cross: cross ${2:cp1}, ${3:cp2};

snippet bins
bins ${1:name} = {${2:values}};

snippet ignore_bins
ignore_bins ${1:name} = {${2:values}};

snippet illegal_bins
illegal_bins ${1:name} = {${2:values}};

# =============================================================================
# ASSERTIONS
# =============================================================================

snippet assert
assert (${1:condition}) else \$error("${2:Assertion failed}");

snippet property
property ${1:`expand('%:t:r')};
@(posedge ${2:clk}) ${3:condition};
endproperty: $1

snippet sequence
sequence ${1:`expand('%:t:r')};
${2}
endsequence: $1

snippet assume
assume property (${1:property_name});

snippet cover
cover property (${1:property_name});

snippet sva
property ${1:prop_name};
@(posedge ${2:clk}) disable iff (!${3:rst_n})
${4:sequence};
endproperty

assert_$1: assert property ($1)
else \$error("$1 failed at %0t", \$time);

snippet implication
${1:antecedent} |-> ${2:consequent}

snippet overlapping
${1:antecedent} |=> ${2:consequent}

# =============================================================================
# GENERATE
# =============================================================================

snippet generate
generate
for (genvar ${1:i} = 0; $1 < ${2:N}; $1++) begin : ${3:gen_block}
${4}
end
endgenerate

snippet generate_if
generate
if (${1:condition}) begin : ${2:gen_label}
${3}
end
endgenerate

snippet genvar
genvar ${1:i};

# =============================================================================
# INSTANTIATION
# =============================================================================

snippet inst
${1:module_name} #(
.${2:PARAM}(${3:VALUE})
) ${4:u_${1/([a-z]+).*/$1/}} (
.${5:clk}(${6:clk}),
.${7:rst_n}(${8:rst_n})${9}
);

snippet port
.${1:port}(${2:signal})${3:,}

snippet bind
bind ${1:instance} ${2:module} ${3:bind_inst} (${4});

# =============================================================================
# CLOCKING
# =============================================================================

snippet clocking
clocking ${1:`expand('%:t:r')`}_cb @(posedge ${2:clk});
default input #1step output #1ns;
${3}
endclocking: $1

# =============================================================================
# PREPROCESSOR DIRECTIVES
# =============================================================================

snippet define
\`define ${1:`toupper(expand('%:t:r'))`} ${2:value}

snippet ifdef
\`ifdef ${1:`toupper(expand('%:t:r'))`}
${2}
\`endif

snippet ifndef
\`ifndef ${1:`toupper(expand('%:t:r'))`}
${2}
\`endif

snippet include
\`include "${1:filename.svh}"

snippet timescale
\`timescale ${1:1ns}/${2:1ps}

# =============================================================================
# SYSTEM TASKS
# =============================================================================

snippet display
\$display("${1:message

snippet monitor
\$monitor("Time=%0t: ${1:signal}=%0d", \$time, ${2:signal});

snippet finish
\$finish;

snippet stop
\$stop;

snippet readmemh
\$readmemh("${1:file.hex}", ${2:memory});

snippet fopen
integer ${1:fh};
$1 = \$fopen("${2:file.txt}", "${3:w}");

snippet sformatf
\$sformatf("${1:format}", ${2:args})

snippet urandom
\$urandom()

snippet urandom_range
\$urandom_range(${1:max}, ${2:min})

snippet cast
\$cast(${1:dest}, ${2:source})

# =============================================================================
# FSM TEMPLATE
# =============================================================================

snippet fsm
typedef enum logic [${1:1}:0] {
${2:IDLE} = ${3:2'b00},
${4:ACTIVE} = ${5:2'b01},
${6:DONE} = ${7:2'b10}
} ${8:state}_t;

$8_t current_state, next_state;

always_ff @(posedge ${9:clk} or negedge ${10:rst_n}) begin
if (!$10)
current_state <= $2;
else
current_state <= next_state;
end

always_comb begin
next_state = current_state;
case (current_state)
$2: ${11}
$4: ${12}
$6: ${13}
default: next_state = $2;
endcase
end

# =============================================================================
# COMMON PATTERNS
# =============================================================================

snippet fifo
logic [${1:DEPTH_W}-1:0] wr_ptr, rd_ptr;
logic [${2:DATA_W}-1:0] mem [2**$1];
logic empty, full;

assign empty = (wr_ptr == rd_ptr);
assign full = (wr_ptr + 1 == rd_ptr);

snippet handshake
logic ${1:valid}, ${2:ready};

always_ff @(posedge ${3:clk} or negedge ${4:rst_n}) begin
if (!$4)
$1 <= 1'b0;
else if ($1 && $2)
$1 <= 1'b0;
else if (${5:condition})
$1 <= 1'b1;
end

snippet assign
assign ${1:target} = ${2:expression};

# =============================================================================
# UVM COMPONENTS
# =============================================================================

snippet component_param sequence
class ${1:`expand('%:t:r')`} #(
parameter int ${2:DATA_WIDTH} = ${3:32}
) extends uvm_sequence #(${4:`substitute(expand('%:t:r'), '_\(seq\|sequence\)$', '_item', '')`}#($2));
`uvm_object_param_utils($1#($2))

typedef $4#($2) item_t;
rand int unsigned num_trans = ${5:10};

extern function new(string name = "$1");
extern virtual task body();

endclass: $1

function $1#($2)::new(string name = "$1");
super.new(name);
endfunction: new

task $1#($2)::body();
repeat (num_trans) begin
`uvm_do(req)
end
endtask: body

snippet sequence_item
class ${1:`expand('%:t:r')`} extends uvm_sequence_item;
`uvm_object_utils($1)

// Transaction fields
rand bit [${2:7}:0] ${3:addr};
rand bit [${4:31}:0] ${5:data};
${6}

// Constraints
constraint ${7:valid}_c {
${8}
}

extern function new(string name = "$1");
extern function void do_copy(uvm_object rhs);
extern function bit do_compare(uvm_object rhs, uvm_comparer comparer);
extern function void do_print(uvm_printer printer);
extern function string convert2string();

endclass: $1

function $1::new(string name = "$1");
super.new(name);
endfunction: new

function void $1::do_copy(uvm_object rhs);
$1 rhs_;
if (!$cast(rhs_, rhs))
`uvm_fatal(get_type_name(), "Cast failed in do_copy")
super.do_copy(rhs);
this.$3 = rhs_.$3;
this.$5 = rhs_.$5;
endfunction: do_copy

function bit $1::do_compare(uvm_object rhs, uvm_comparer comparer);
$1 rhs_;
if (!$cast(rhs_, rhs))
return 0;
return (super.do_compare(rhs, comparer) &&
(this.$3 == rhs_.$3) &&
(this.$5 == rhs_.$5));
endfunction: do_compare

function void $1::do_print(uvm_printer printer);
super.do_print(printer);
printer.print_field("$3", this.$3, $2+1);
printer.print_field("$5", this.$5, $4+1);
endfunction: do_print

function string $1::convert2string();
return $sformatf("$3=0x%0h, $5=0x%0h", $3, $5);
endfunction: convert2string

# =============================================================================
# SYSTEMVERILOG ASSERTIONS (SVA) - COMPREHENSIVE
# =============================================================================

snippet sva_property
// ============================================================================
// SVA PROPERTY - Assertion Property (IEEE 1800-2017 Chapter 16)
// ============================================================================
// Purpose: Define temporal property for verification
//
// Property Structure:
// property name;
// @(posedge clk) disable iff (reset)
// antecedent |-> consequent;
// endproperty
//
// Implication Operators:
// |-> Overlapping (consequent checked same cycle)
// |=> Non-overlapping (consequent checked next cycle)
//
// Sequence Operators:
// ##n - Delay by n cycles
// ##[m:n] - Delay between m and n cycles
// [*n] - Repeat exactly n times
// [*m:n] - Repeat between m and n times
// [->n] - Goto repetition (non-consecutive)
// [=n] - Non-consecutive repetition
//
// Example:
// property req_ack;
// @(posedge clk) disable iff (rst)
// req |-> ##[1:3] ack;
// endproperty
// ============================================================================
property ${1:prop_name};
@(posedge ${2:clk}) disable iff (${3:!rst_n})
${4:antecedent} |-> ${5:consequent};
endproperty: $1

${6:assert_}$1: assert property ($1)
else `uvm_error("ASSERT", $sformatf("$1 failed at %0t", $time))

snippet sva_sequence
sequence ${1:seq_name};
${2:expression};
endsequence: $1

snippet sva_implication
property ${1:overlap_prop};
@(posedge ${2:clk}) disable iff (${3:!rst_n})
${4:req} |-> ${5:grant}; // If req this cycle, grant must be true this cycle
endproperty

property ${6:nonoverlap_prop};
@(posedge $2) disable iff ($3)
$4 |=> $5; // If req this cycle, grant must be true next cycle
endproperty

snippet sva_delay
// Fixed Delay: ##n
property ${1:fixed_delay};
@(posedge ${2:clk})
${3:req} |-> ##${4:2} ${5:ack}; // ack exactly 2 cycles after req
endproperty

// Range Delay: ##[m:n]
property ${6:range_delay};
@(posedge $2)
$3 |-> ##[${7:1}:${8:5}] $5; // ack within 1-5 cycles after req
endproperty

// Unbounded Delay: ##[1:$]
property ${9:unbounded_delay};
@(posedge $2)
$3 |-> ##[1:$] $5; // ack eventually after req
endproperty

snippet sva_repetition
// Consecutive Repetition: [*n]
property ${1:consecutive_rep};
@(posedge ${2:clk})
${3:busy}[*${4:3}] ##1 ${5:done}; // busy for exactly 3 cycles, then done
endproperty

// Range Repetition: [*m:n]
property ${6:range_rep};
@(posedge $2)
$3[*${7:2}:${8:5}] ##1 $5; // busy for 2-5 cycles, then done
endproperty

// Goto Repetition: [->n]
property ${9:goto_rep};
@(posedge $2)
${10:valid}[->3] ##1 ${11:complete}; // valid high 3 times (non-consecutive), then complete
endproperty

// Non-consecutive Repetition: [=n]
property ${12:noncons_rep};
@(posedge $2)
$10[=3]; // valid high 3 times (may be non-consecutive)
endproperty

snippet sva_throughout
property ${1:throughout_prop};
@(posedge ${2:clk})
${3:enable} throughout (${4:req} ##[1:5] ${5:ack});
// enable must remain high from req until ack
endproperty

snippet sva_advanced

// 1. Request-Acknowledge with Timeout
property ${1:req_ack_timeout};
@(posedge ${2:clk}) disable iff (${3:!rst_n})
${4:req} |-> ##[1:${5:10}] ${6:ack};
endproperty

// 2. Mutual Exclusion
property ${7:mutex};
@(posedge $2) disable iff ($3)
${8:sig_a} |-> !${9:sig_b};
endproperty

// 3. FIFO Full/Empty Relationship
property ${10:fifo_full_empty};
@(posedge $2) disable iff ($3)
!(${11:full} && ${12:empty});
endproperty

// 4. Handshake Protocol
property ${13:handshake};
@(posedge $2) disable iff ($3)
${14:valid} && ${15:ready} |=> !${16:valid} || ${17:new_data};
endproperty

// 5. One-Hot Encoding
property ${18:onehot};
@(posedge $2)
$onehot(${19:state});
endproperty

snippet sva_cover
property ${1:cover_prop};
@(posedge ${2:clk})
${3:condition};
endproperty

cover_$1: cover property ($1)
`uvm_info("COVER", $sformatf("$1 covered at %0t", $time), UVM_MEDIUM)

snippet sva_assume
property ${1:assume_prop};
@(posedge ${2:clk})
${3:input_constraint};
endproperty

assume_$1: assume property ($1);

snippet sva_concurrent
${1:assert_name}: assert property (
@(posedge ${2:clk}) disable iff (${3:!rst_n})
${4:property_expression}
) else `uvm_error("ASSERT", "$1 failed");

snippet sva_immediate
assert (${1:condition}) else `uvm_error("ASSERT", "${2:Assertion failed}");

snippet sva_system
// $rose - Detects 0->1 transition
property ${1:rose_detect};
@(posedge ${2:clk})
$rose(${3:signal}) |-> ${4:action};
endproperty

// $fell - Detects 1->0 transition
property ${5:fell_detect};
@(posedge $2)
$fell($3) |-> $4;
endproperty

// $stable - Signal unchanged
property ${6:stable_check};
@(posedge $2)
${7:hold} |-> $stable($3);
endproperty

// $past - Previous value
property ${8:past_check};
@(posedge $2)
${9:valid} |-> ${10:data} == $past(${11:prev_data});
endproperty

// $onehot - Exactly one bit high
property ${12:onehot_check};
@(posedge $2)
$onehot(${13:state_vector});
endproperty

// $onehot0 - At most one bit high
property ${14:onehot0_check};
@(posedge $2)
$onehot0($13);
endproperty

// $isunknown - Check for X/Z
property ${15:unknown_check};
@(posedge $2)
!$isunknown($3);
endproperty

snippet sva_fifo

// 1. No write when full
property ${1:no_write_when_full};
@(posedge ${2:clk}) disable iff (${3:!rst_n})
${4:full} |-> !${5:wr_en};
endproperty
assert_$1: assert property ($1);

// 2. No read when empty
property ${6:no_read_when_empty};
@(posedge $2) disable iff ($3)
${7:empty} |-> !${8:rd_en};
endproperty
assert_$6: assert property ($6);

// 3. Write increments count (when not full)
property ${9:write_inc_count};
@(posedge $2) disable iff ($3)
$5 && !$4 |=> ${10:count} == $past($10) + 1;
endproperty
assert_$9: assert property ($9);

// 4. Read decrements count (when not empty)
property ${11:read_dec_count};
@(posedge $2) disable iff ($3)
$8 && !$7 |=> $10 == $past($10) - 1;
endproperty
assert_$11: assert property ($11);

// 5. Full and empty are mutually exclusive
property ${12:full_empty_mutex};
@(posedge $2)
!($4 && $7);
endproperty
assert_$12: assert property ($12);

snippet sva_axi

// 1. Valid-Ready Handshake (AXI Rule)
property ${1:axi_valid_stable};
@(posedge ${2:clk}) disable iff (${3:!rst_n})
${4:valid} && !${5:ready} |=> $stable($4) && $stable(${6:data});
endproperty
assert_$1: assert property ($1)
else `uvm_error("AXI", "VALID/data must remain stable until READY");

// 2. BVALID follows WLAST and WREADY
property ${7:axi_bvalid_after_wlast};
@(posedge $2) disable iff ($3)
${8:wlast} && ${9:wready} |-> ##[1:${10:16}] ${11:bvalid};
endproperty
assert_$7: assert property ($7);

// 3. RVALID must not be dependent on RREADY
property ${12:axi_rvalid_independent};
@(posedge $2) disable iff ($3)
${13:rvalid} |-> ${13:rvalid} throughout (##[0:$] ${14:rready});
endproperty
assert_$12: assert property ($12);

# =============================================================================
# MACROS AND PREPROCESSOR (IEEE 1800-2012 Section 22)
# =============================================================================

snippet macro_define
\`define ${1:MACRO_NAME}(${2:args}) \\
${3:macro body}

snippet macro_stringify
\`define ${1:TO_STRING}(${2:x}) \`"${2}\`"

snippet macro_concat
\`define ${1:CONCAT}(${2:a}, ${3:b}) ${2}\`\`${3}

snippet macro_ifdef_block
\`ifdef ${1:MACRO_NAME}
${2:code when defined}
\`else
${3:code when not defined}
\`endif

snippet macro_ifndef_block
\`ifndef ${1:MACRO_NAME}
${2:code when not defined}
\`else
${3:code when defined}
\`endif

snippet macro_undef
\`undef ${1:MACRO_NAME}

snippet macro_line
\`line ${1:line_number} "${2:filename}" ${3:level}

snippet macro_default
\`default_nettype ${1:wire}

snippet macro_resetall
\`resetall

snippet macro_celldefine
\`celldefine
${1}
\`endcelldefine

snippet macro_pragma
\`pragma ${1:pragma_name} ${2:pragma_value}

snippet macro_begin_keywords
\`begin_keywords "${1:1800-2012}"
${2}
\`end_keywords

# =============================================================================
# COMMON UVM MACROS
# =============================================================================

snippet uvm_info_macro
\`uvm_info("${1:ID}", $sformatf("${2:Message: %s}", ${3:arg}), ${4:UVM_MEDIUM})

snippet uvm_warning_macro
\`uvm_warning("${1:ID}", $sformatf("${2:Message: %s}", ${3:arg}))

snippet uvm_error_macro
\`uvm_error("${1:ID}", $sformatf("${2:Message: %s}", ${3:arg}))

snippet uvm_fatal_macro
\`uvm_fatal("${1:ID}", $sformatf("${2:Message: %s}", ${3:arg}))

snippet uvm_do_macro
\`uvm_do(${1:sequence_item})

snippet uvm_do_with_macro
\`uvm_do_with(${1:sequence_item}, {
${2:constraints}
})

snippet uvm_create_macro
\`uvm_create(${1:sequence_item})

snippet uvm_send_macro
\`uvm_send(${1:sequence_item})

snippet uvm_rand_send_macro
\`uvm_rand_send(${1:sequence_item})

snippet uvm_rand_send_with_macro
\`uvm_rand_send_with(${1:sequence_item}, {
${2:constraints}
})

snippet uvm_field_int
\`uvm_field_int(${1:field_name}, ${2:UVM_DEFAULT})

snippet uvm_field_object
\`uvm_field_object(${1:field_name}, ${2:UVM_DEFAULT})

snippet uvm_field_string
\`uvm_field_string(${1:field_name}, ${2:UVM_DEFAULT})

snippet uvm_field_enum
\`uvm_field_enum(${1:enum_type}, ${2:field_name}, ${3:UVM_DEFAULT})

snippet uvm_field_array_int
\`uvm_field_array_int(${1:field_name}, ${2:UVM_DEFAULT})

snippet uvm_field_sarray_int
\`uvm_field_sarray_int(${1:field_name}, ${2:UVM_DEFAULT})

snippet uvm_field_queue
\`uvm_field_queue_${1:int}(${2:field_name}, ${3:UVM_DEFAULT})

snippet uvm_field_aa
\`uvm_field_aa_${1:int}_${2:string}(${3:field_name}, ${4:UVM_DEFAULT})

# =============================================================================
# COMMON UTILITY MACROS
# =============================================================================

snippet macro_min
\`define MIN(a, b) (((a) < (b)) ? (a) : (b))

snippet macro_max
\`define MAX(a, b) (((a) > (b)) ? (a) : (b))

snippet macro_abs
\`define ABS(x) (((x) < 0) ? -(x) : (x))

snippet macro_clamp
\`define CLAMP(x, min, max) (((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x)))

snippet macro_swap
\`define SWAP(a, b, tmp) \\
tmp = a; \\
a = b; \\
b = tmp;

snippet macro_bit_width
\`define BIT_WIDTH(x) ($clog2(x))

snippet macro_is_power_of_2
\`define IS_POWER_OF_2(x) (((x) != 0) && (((x) & ((x) - 1)) == 0))

snippet macro_align_up
\`define ALIGN_UP(x, align) ((((x) + (align) - 1) / (align)) * (align))

snippet macro_div_round_up
\`define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))

# =============================================================================
# VERIFICATION MACROS
# =============================================================================

snippet macro_check_fatal
\`define CHECK_FATAL(cond, msg) \\
if (!(cond)) begin \\
\$fatal(1, msg); \\
end

snippet macro_check_error
\`define CHECK_ERROR(cond, msg) \\
if (!(cond)) begin \\
\$error(msg); \\
end

snippet macro_check_warning
\`define CHECK_WARNING(cond, msg) \\
if (!(cond)) begin \\
\$warning(msg); \\
end

snippet macro_assert
\`define ASSERT(cond) \\
assert(cond) else \$error("Assertion failed: \`"cond\`" at %m")

snippet macro_cover
\`define COVER(name, cond) \\
cover property (@(posedge clk) cond) \\
\$display("Coverage: name hit at %t", \$time);

# =============================================================================
# DEBUG MACROS
# =============================================================================

snippet macro_debug
\`ifdef DEBUG
\`define DEBUG_PRINT(msg) \$display("[DEBUG] %t: msg", \$time)
\`else
\`define DEBUG_PRINT(msg)
\`endif

snippet macro_verbose
\`ifdef VERBOSE
\`define VERBOSE_PRINT(level, msg) \\
if (verbose_level >= level) \$display("[VERBOSE] msg")
\`else
\`define VERBOSE_PRINT(level, msg)
\`endif

snippet macro_trace
\`define TRACE(msg) \$display("[TRACE] %t %m: msg", \$time)

snippet macro_dump_vars
\`define DUMP_VARS(var) \\
\$display("[DUMP] %t %m: \`"var\`" = %0d", \$time, var)

# =============================================================================
# REGISTER ACCESS MACROS
# =============================================================================

snippet macro_reg_write
\`define REG_WRITE(addr, data) \\
@(posedge clk); \\
reg_addr = addr; \\
reg_wdata = data; \\
reg_wr_en = 1'b1; \\
@(posedge clk); \\
reg_wr_en = 1'b0;

snippet macro_reg_read
\`define REG_READ(addr, data) \\
@(posedge clk); \\
reg_addr = addr; \\
reg_rd_en = 1'b1; \\
@(posedge clk); \\
data = reg_rdata; \\
reg_rd_en = 1'b0;

snippet macro_reg_field
\`define REG_FIELD(reg, msb, lsb) reg[msb:lsb]

snippet macro_reg_bit
\`define REG_BIT(reg, bit) reg[bit]

# =============================================================================
# TIMING MACROS
# =============================================================================

snippet macro_wait_clks
\`define WAIT_CLKS(n) \\
repeat(n) @(posedge clk);

snippet macro_wait_ns
\`define WAIT_NS(ns) \\
#(ns * 1ns);

snippet macro_wait_until
\`define WAIT_UNTIL(cond) \\
wait(cond);

snippet macro_wait_clk_edge
\`define WAIT_CLK_EDGE \\
@(posedge clk);

# =============================================================================
# ARRAY/MEMORY MACROS
# =============================================================================

snippet macro_array_sum
\`define ARRAY_SUM(arr, size) \\
function int; \\
int sum = 0; \\
for (int i = 0; i < size; i++) \\
sum += arr[i]; \\
return sum; \\
endfunction

snippet macro_array_fill
\`define ARRAY_FILL(arr, size, val) \\
for (int i = 0; i < size; i++) \\
arr[i] = val;

snippet macro_array_copy
\`define ARRAY_COPY(dst, src, size) \\
for (int i = 0; i < size; i++) \\
dst[i] = src[i];

# =============================================================================
# CONDITIONAL COMPILATION MACROS
# =============================================================================

snippet macro_synthesis
\`ifdef SYNTHESIS
${1:// Synthesis code}
\`else
${2:// Simulation code}
\`endif

snippet macro_formal
\`ifdef FORMAL
${1:// Formal verification code}
\`endif

snippet macro_coverage
\`ifdef COVERAGE
${1:// Coverage code}
\`endif

snippet macro_simulation
\`ifndef SYNTHESIS
${1:// Simulation-only code}
\`endif

# =============================================================================
# PARAMETERIZED MACROS (Advanced)
# =============================================================================

snippet macro_gen_comparator
\`define GEN_COMPARATOR(name, width) \\
module name ( \\
input logic [width-1:0] a, \\
input logic [width-1:0] b, \\
output logic eq, \\
output logic gt, \\
output logic lt \\
); \\
assign eq = (a == b); \\
assign gt = (a > b); \\
assign lt = (a < b); \\
endmodule

snippet macro_gen_register
\`define GEN_REGISTER(name, width, reset_val) \\
always_ff @(posedge clk or negedge rst_n) begin \\
if (!rst_n) \\
name <= reset_val; \\
else if (name``_en) \\
name <= name``_next; \\
end

snippet macro_gen_fifo
\`define GEN_FIFO(name, width, depth) \\
logic [width-1:0] name``_mem [depth]; \\
logic [\$clog2(depth)-1:0] name``_wr_ptr, name``_rd_ptr; \\
logic name``_full, name``_empty;

# =============================================================================
# PROTOCOL-SPECIFIC MACROS
# =============================================================================

snippet macro_axi_handshake
\`define AXI_HANDSHAKE(valid, ready) \\
(valid && ready)

snippet macro_axi_wait
\`define AXI_WAIT_HANDSHAKE(valid, ready) \\
do begin \\
@(posedge clk); \\
end while (!(valid && ready));

snippet macro_apb_write
\`define APB_WRITE(addr, data) \\
@(posedge clk); \\
paddr = addr; \\
pwdata = data; \\
pwrite = 1'b1; \\
psel = 1'b1; \\
@(posedge clk); \\
penable = 1'b1; \\
@(posedge clk); \\
psel = 1'b0; \\
penable = 1'b0;

snippet macro_apb_read
\`define APB_READ(addr, data) \\
@(posedge clk); \\
paddr = addr; \\
pwrite = 1'b0; \\
psel = 1'b1; \\
@(posedge clk); \\
penable = 1'b1; \\
@(posedge clk); \\
data = prdata; \\
psel = 1'b0; \\
penable = 1'b0;

# =============================================================================
# STRING MANIPULATION MACROS
# =============================================================================

snippet macro_str_concat
\`define STR_CONCAT(a, b) {a, b}

snippet macro_str_format
\`define STR_FORMAT(fmt, args) \\
\$sformatf(fmt, args)

snippet macro_to_hex
\`define TO_HEX(val, width) \\
\$sformatf("0x%0h", val)

snippet macro_to_bin
\`define TO_BIN(val, width) \\
\$sformatf("%0b", val)

# =============================================================================
# FILE I/O MACROS
# =============================================================================

snippet macro_file_open
\`define FILE_OPEN(handle, filename, mode) \\
handle = \$fopen(filename, mode); \\
if (!handle) \\
\$fatal(1, "Failed to open file: filename");

snippet macro_file_write
\`define FILE_WRITE(handle, fmt, args) \\
\$fdisplay(handle, fmt, args);

snippet macro_file_close
\`define FILE_CLOSE(handle) \\
\$fclose(handle);

# =============================================================================
# RANDOM MACROS
# =============================================================================

snippet macro_rand_range
\`define RAND_RANGE(min, max) \\
(\$urandom_range(max, min))

snippet macro_rand_bool
\`define RAND_BOOL \\
(\$urandom() & 1)

snippet macro_rand_choice
\`define RAND_CHOICE(arr, size) \\
arr[\$urandom_range(size-1, 0)]

# =============================================================================
# PERFORMANCE MEASUREMENT MACROS
# =============================================================================

snippet macro_perf_start
\`define PERF_START(name) \\
realtime name``_start_time = \$realtime;

snippet macro_perf_end
\`define PERF_END(name) \\
\$display("[PERF] name: %.2f ns", \$realtime - name``_start_time);

snippet macro_cycle_count
\`define CYCLE_COUNT_START(name) \\
int name``_cycle_count = 0;

snippet macro_cycle_count_inc
\`define CYCLE_COUNT_INC(name) \\
name``_cycle_count++;

snippet macro_cycle_count_report
\`define CYCLE_COUNT_REPORT(name) \\
\$display("[CYCLES] name: %0d cycles", name``_cycle_count);

# =============================================================================
# ADDITIONAL SYSTEMVERILOG CONSTRUCTS (IEEE 1800-2012)
# =============================================================================

snippet checker
checker ${1:checker_name} (
${2:input logic clk},
${3:input logic rst_n}
);
${4:// Assertions}
${0}
endchecker: $1

snippet let
let ${1:name} = ${2:expression};

snippet expect
expect (${1:property_name}) else ${2:action};

snippet restrict
restrict property (${1:property_name});

snippet alias
alias ${1:new_name} = ${2:existing_name};

snippet nettype
nettype ${1:data_type} ${2:nettype_name} with ${3:resolution_function};

# =============================================================================
# INTERFACE AND MODPORT ADVANCED
# =============================================================================

snippet interface_class
interface class ${1:interface_name};
pure virtual function ${2:void} ${3:method}(${4});
endclass: $1

snippet implements
implements ${1:interface_class_name}

snippet modport_clocking
modport ${1:name} (
clocking ${2:cb},
${3:input reset}
);

snippet interface_param
interface ${1:`expand('%:t:r')`} #(
parameter int ${2:WIDTH} = ${3:8}
) (
input logic clk,
input logic rst_n
);
${4}
endinterface: $1

# =============================================================================
# ADVANCED CLASS FEATURES
# =============================================================================

snippet extern_class
extern class ${1:class_name};

snippet constraint_mode
${1:constraint_name}.constraint_mode(${2:0});

snippet rand_mode
${1:variable}.rand_mode(${2:0});

snippet this
this.${1:member}

snippet super
super.${1:method}(${2});

snippet new_array
${1:array} = new[${2:size}];

snippet new_copy
${1:object} = new ${2:original};

# =============================================================================
# PACKAGE IMPORT AND EXPORT
# =============================================================================

snippet import_pkg
import ${1:package_name}::${2:*};

snippet export_pkg
export ${1:package_name}::${2:*};

snippet import_item
import ${1:package_name}::${2:item_name};

# =============================================================================
# VIRTUAL INTERFACES
# =============================================================================

snippet virtual_interface
virtual ${1:interface_name} ${2:vif};

snippet virtual_interface_param
virtual ${1:interface_name}#(${2:params}) ${3:vif};

# =============================================================================
# DPI (Direct Programming Interface)
# =============================================================================

snippet dpi_import
import "DPI-C" function ${1:return_type} ${2:function_name}(${3:args});

snippet dpi_export
export "DPI-C" function ${1:function_name};

snippet dpi_context
import "DPI-C" context function ${1:return_type} ${2:function_name}(${3:args});

snippet dpi_pure
import "DPI-C" pure function ${1:return_type} ${2:function_name}(${3:args});

# =============================================================================
# PROGRAM BLOCKS (Advanced)
# =============================================================================

snippet program_clocking
program ${1:`expand('%:t:r')`} (
${2:interface_name}.${3:modport} ${4:port}
);
clocking ${5:cb} @(posedge ${4}.clk);
${6}
endclocking

initial begin
${0}
end
endprogram: $1

# =============================================================================
# CONFIG AND BIND
# =============================================================================

snippet config
config ${1:config_name};
design ${2:top_module};
${3}
endconfig: $1

snippet cell_config
cell ${1:instance_path} use ${2:library}.${3:cell};

snippet instance_config
instance ${1:instance_path} use ${2:configuration};

# =============================================================================
# SPECIFY BLOCKS (Timing)
# =============================================================================

snippet specify
specify
specparam ${1:tPD} = ${2:10};
(${3:input} => ${4:output}) = $1;
endspecify

snippet setuphold
\$setuphold(posedge ${1:clk}, ${2:data}, ${3:setup_time}, ${4:hold_time});

snippet width_check
\$width(posedge ${1:signal}, ${2:min_width});

snippet period_check
\$period(posedge ${1:clk}, ${2:min_period});

# =============================================================================
# UNIQUE, PRIORITY, UNIQUE0
# =============================================================================

snippet unique_if
unique if (${1:condition}) begin
${2}
end else if (${3:condition}) begin
${4}
end

snippet priority_if
priority if (${1:condition}) begin
${2}
end else if (${3:condition}) begin
${4}
end

snippet unique0_case
unique0 case (${1:expression})
${2:value}: ${3}
default: ${4}
endcase

# =============================================================================
# STREAMING OPERATORS
# =============================================================================

snippet stream_pack
{<<{${1:data}}}

snippet stream_unpack
{>>{${1:data}}}

snippet stream_slice
{<<${1:8}{${2:data}}}

# =============================================================================
# ARRAY METHODS
# =============================================================================

snippet array_size
${1:array}.size()

snippet array_delete
${1:array}.delete(${2:index});

snippet array_exists
${1:array}.exists(${2:index})

snippet array_first
${1:array}.first(${2:index})

snippet array_last
${1:array}.last(${2:index})

snippet array_next
${1:array}.next(${2:index})

snippet array_prev
${1:array}.prev(${2:index})

snippet array_find
${1:array}.find(${2:item}) with (${3:item} == ${4:value})

snippet array_find_index
${1:array}.find_index with (${2:item} == ${3:value})

snippet array_find_first
${1:array}.find_first with (${2:item} > ${3:value})

snippet array_min
${1:array}.min()

snippet array_max
${1:array}.max()

snippet array_sum
${1:array}.sum()

snippet array_product
${1:array}.product()

snippet array_and
${1:array}.and()

snippet array_or
${1:array}.or()

snippet array_xor
${1:array}.xor()

snippet array_unique
${1:array}.unique()

snippet array_sort
${1:array}.sort()

snippet array_rsort
${1:array}.rsort()

snippet array_reverse
${1:array}.reverse()

snippet array_shuffle
${1:array}.shuffle()

# =============================================================================
# STRING METHODS
# =============================================================================

snippet string_len
${1:str}.len()

snippet string_getc
${1:str}.getc(${2:index})

snippet string_putc
${1:str}.putc(${2:index}, ${3:char})

snippet string_toupper
${1:str}.toupper()

snippet string_tolower
${1:str}.tolower()

snippet string_compare
${1:str}.compare(${2:str2})

snippet string_icompare
${1:str}.icompare(${2:str2})

snippet string_substr
${1:str}.substr(${2:start}, ${3:end})

snippet string_atoi
${1:str}.atoi()

snippet string_atohex
${1:str}.atohex()

snippet string_atooct
${1:str}.atooct()

snippet string_atobin
${1:str}.atobin()

snippet string_atoreal
${1:str}.atoreal()

snippet string_itoa
${1:str}.itoa(${2:value})

snippet string_hextoa
${1:str}.hextoa(${2:value})

snippet string_octtoa
${1:str}.octtoa(${2:value})

snippet string_bintoa
${1:str}.bintoa(${2:value})

snippet string_realtoa
${1:str}.realtoa(${2:value})

# =============================================================================
# PROCESS CONTROL
# =============================================================================

snippet process_self
process::self()

snippet process_status
${1:proc}.status()

snippet process_kill
${1:proc}.kill()

snippet process_await
${1:proc}.await()

snippet process_suspend
${1:proc}.suspend()

snippet process_resume
${1:proc}.resume()

# =============================================================================
# REFINEMENT (IEEE 1800-2012)
# =============================================================================

snippet global_clocking
global clocking ${1:cb} @(posedge ${2:clk});
${3}
endclocking

snippet default_clocking
default clocking ${1:cb};

snippet default_disable
default disable iff ${1:reset};

# =============================================================================
# COVERAGE OPTIONS
# =============================================================================

snippet covergroup_option
option.name = "${1:name}";
option.weight = ${2:1};
option.goal = ${3:100};
option.comment = "${4:comment}";
option.at_least = ${5:1};
option.auto_bin_max = ${6:64};
option.per_instance = ${7:0};
option.get_inst_coverage = ${8:0};

snippet coverpoint_option
option.weight = ${1:1};
option.goal = ${2:100};
option.comment = "${3:comment}";
option.at_least = ${4:1};
option.auto_bin_max = ${5:64};

# =============================================================================
# WILDCARD BINS
# =============================================================================

snippet bins_wildcard
wildcard bins ${1:name} = {${2:4'b10??}};

snippet bins_transition
bins ${1:name} = (${2:val1} => ${3:val2} => ${4:val3});

snippet bins_sequence
bins ${1:name} = (${2:val1}[*${3:2}] => ${4:val2});

# =============================================================================
# RANDSEQUENCE
# =============================================================================

snippet randsequence
randsequence(${1:production})
${1}: ${2:item1} ${3:| item2};
$2: ${4:/* actions */};
$3: ${5:/* actions */};
endsequence

# =============================================================================
# SOFT CONSTRAINTS
# =============================================================================

snippet soft_constraint
constraint ${1:name}_c {
soft ${2:variable} == ${3:value};
}

# =============================================================================
# DIST CONSTRAINTS (Advanced)
# =============================================================================

snippet dist_weight
${1:variable} dist {
${2:value1} := ${3:weight1},
${4:value2} := ${5:weight2},
[${6:min}:${7:max}] := ${8:weight3}
};

snippet dist_equal
${1:variable} dist {
${2:value1}, ${3:value2}, ${4:value3}
};

# =============================================================================
# IMPLICATION CONSTRAINTS
# =============================================================================

snippet constraint_implication
constraint ${1:name}_c {
${2:condition} -> ${3:constraint};
}

snippet constraint_if
constraint ${1:name}_c {
if (${2:condition})
${3:constraint1}
else
${4:constraint2}
}

# =============================================================================
# FOREACH IN CONSTRAINTS
# =============================================================================

snippet constraint_foreach
constraint ${1:name}_c {
foreach (${2:array}[${3:i}])
${2}[$3] ${4:inside {[0:10]}};
}

# =============================================================================
# UNIQUE IN CONSTRAINTS
# =============================================================================

snippet constraint_unique
constraint ${1:name}_c {
unique {${2:var1}, ${3:var2}, ${4:var3}};
}

# =============================================================================
# INLINE RANDOMIZATION
# =============================================================================

snippet randomize_inline
std::randomize(${1:variable}) with {
$1 ${2:inside {[0:100]}};
};

# =============================================================================
# CROSS COVERAGE (Advanced)
# =============================================================================

snippet cross_binsof
${1:name}_cross: cross ${2:cp1}, ${3:cp2} {
ignore_bins ${4:ignore} = binsof(${2}) intersect {${5:values}};
}

snippet cross_iff
${1:name}_cross: cross ${2:cp1}, ${3:cp2} iff (${4:condition});

# =============================================================================
# SYSTEM FUNCTIONS (Additional)
# =============================================================================

snippet countones
\$countones(${1:expression})

snippet countbits
\$countbits(${1:expression}, ${2:'1})

snippet onehot
\$onehot(${1:expression})

snippet onehot0
\$onehot0(${1:expression})

snippet isunknown
\$isunknown(${1:expression})

snippet bits
\$bits(${1:expression})

snippet typename
\$typename(${1:expression})

snippet high
\$high(${1:array})

snippet low
\$low(${1:array})

snippet left
\$left(${1:array})

snippet right
\$right(${1:array})

snippet increment
\$increment(${1:array})

snippet size
\$size(${1:array}, ${2:dimension})

snippet dimensions
\$dimensions(${1:array})

snippet unpacked_dimensions
\$unpacked_dimensions(${1:array})

# =============================================================================
# SEVERITY SYSTEM TASKS
# =============================================================================

snippet fatal
\$fatal(${1:finish_number}, "${2:message}", ${3:args});

snippet error
\$error("${1:message}", ${2:args});

snippet warning
\$warning("${1:message}", ${2:args});

snippet info
\$info("${1:message}", ${2:args});

# =============================================================================
# UVM HDL ACCESS (uvm_hdl_read/force/deposit)
# =============================================================================

snippet uvm_hdl_read
uvm_hdl_read("${1:hdl_path}", ${2:value});

snippet uvm_hdl_force
uvm_hdl_force("${1:hdl_path}", ${2:value});

snippet uvm_hdl_release
uvm_hdl_release("${1:hdl_path}");

snippet uvm_hdl_deposit
uvm_hdl_deposit("${1:hdl_path}", ${2:value});

snippet uvm_hdl_check_path
uvm_hdl_check_path("${1:hdl_path}");

snippet uvm_hdl_read_string
uvm_hdl_read_string("${1:hdl_path}", ${2:str_value});

snippet uvm_hdl_force_string
uvm_hdl_force_string("${1:hdl_path}", "${2:str_value}");

snippet uvm_hdl_deposit_string
uvm_hdl_deposit_string("${1:hdl_path}", "${2:str_value}");

# =============================================================================
# UVM PHASE METHODS
# =============================================================================

snippet build_phase
function void build_phase(uvm_phase phase);
super.build_phase(phase);
${1}
endfunction: build_phase

snippet pre_build_phase
function void pre_build_phase(uvm_phase phase);
super.pre_build_phase(phase);
${1}
endfunction: pre_build_phase

snippet post_build_phase
function void post_build_phase(uvm_phase phase);
super.post_build_phase(phase);
${1}
endfunction: post_build_phase

snippet connect_phase
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
${1}
endfunction: connect_phase

snippet pre_connect_phase
function void pre_connect_phase(uvm_phase phase);
super.pre_connect_phase(phase);
${1}
endfunction: pre_connect_phase

snippet post_connect_phase
function void post_connect_phase(uvm_phase phase);
super.post_connect_phase(phase);
${1}
endfunction: post_connect_phase

snippet end_of_elaboration_phase
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
${1}
endfunction: end_of_elaboration_phase

snippet pre_end_of_elaboration_phase
function void pre_end_of_elaboration_phase(uvm_phase phase);
super.pre_end_of_elaboration_phase(phase);
${1}
endfunction: pre_end_of_elaboration_phase

snippet post_end_of_elaboration_phase
function void post_end_of_elaboration_phase(uvm_phase phase);
super.post_end_of_elaboration_phase(phase);
${1}
endfunction: post_end_of_elaboration_phase

snippet start_of_simulation_phase
function void start_of_simulation_phase(uvm_phase phase);
super.start_of_simulation_phase(phase);
${1}
endfunction: start_of_simulation_phase

snippet pre_start_of_simulation_phase
function void pre_start_of_simulation_phase(uvm_phase phase);
super.pre_start_of_simulation_phase(phase);
${1}
endfunction: pre_start_of_simulation_phase

snippet post_start_of_simulation_phase
function void post_start_of_simulation_phase(uvm_phase phase);
super.post_start_of_simulation_phase(phase);
${1}
endfunction: post_start_of_simulation_phase

snippet run_phase
task run_phase(uvm_phase phase);
super.run_phase(phase);
${1}
endtask: run_phase

snippet pre_run_phase
function void pre_run_phase(uvm_phase phase);
super.pre_run_phase(phase);
${1}
endfunction: pre_run_phase

snippet post_run_phase
function void post_run_phase(uvm_phase phase);
super.post_run_phase(phase);
${1}
endfunction: post_run_phase

snippet extract_phase
// Collect simulation data, statistics, etc.
function void extract_phase(uvm_phase phase);
super.extract_phase(phase);
${1}
endfunction: extract_phase

snippet check_phase
function void check_phase(uvm_phase phase);
super.check_phase(phase);
${1}
endfunction: check_phase


snippet report_phase
function void report_phase(uvm_phase phase);
super.report_phase(phase);
${1}
endfunction: report_phase

snippet final_phase
function void final_phase(uvm_phase phase);
super.final_phase(phase);
${1}
endfunction: final_phase
# Runtime Phases (12-phase triads)
snippet pre_reset_phase
task pre_reset_phase(uvm_phase phase);
super.pre_reset_phase(phase);
${1}
endtask: pre_reset_phase

snippet reset_phase
task reset_phase(uvm_phase phase);
super.reset_phase(phase);
${1}
endtask: reset_phase

snippet post_reset_phase
task post_reset_phase(uvm_phase phase);
super.post_reset_phase(phase);
${1}
endtask: post_reset_phase

snippet pre_configure_phase
task pre_configure_phase(uvm_phase phase);
super.pre_configure_phase(phase);
${1}
endtask: pre_configure_phase

snippet configure_phase
task configure_phase(uvm_phase phase);
super.configure_phase(phase);
${1}
endtask: configure_phase

snippet post_configure_phase
task post_configure_phase(uvm_phase phase);
super.post_configure_phase(phase);
${1}
endtask: post_configure_phase

snippet pre_main_phase
task pre_main_phase(uvm_phase phase);
super.pre_main_phase(phase);
${1}
endtask: pre_main_phase

snippet main_phase
task main_phase(uvm_phase phase);
super.main_phase(phase);
${1}
endtask: main_phase

snippet post_main_phase
task post_main_phase(uvm_phase phase);
super.post_main_phase(phase);
${1}
endtask: post_main_phase

snippet pre_shutdown_phase
task pre_shutdown_phase(uvm_phase phase);
super.pre_shutdown_phase(phase);
${1}
endtask: pre_shutdown_phase

snippet shutdown_phase
task shutdown_phase(uvm_phase phase);
super.shutdown_phase(phase);
${1}
endtask: shutdown_phase

snippet post_shutdown_phase
task post_shutdown_phase(uvm_phase phase);
super.post_shutdown_phase(phase);
${1}
endtask: post_shutdown_phase

# =============================================================================
# UVM PHASE METHODS (Optional Inline Completions)
# =============================================================================

snippet phase build_phase
function void `expand('%:t:r')`::build_phase(uvm_phase phase);
// Purpose: create/configure components; do NOT call super
// Example:
// sqr = my_sequencer::type_id::create("sqr", this);
// drv = my_driver::type_id::create("drv", this);
// mon = my_monitor::type_id::create("mon", this);
// if (!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))
// `uvm_fatal(get_name(), "Virtual interface not found")
// uvm_config_db#(uvm_object_wrapper)::set(this, "sqr.main_phase", "default_sequence", my_sequence::type_id::get());
${0}
endfunction: build_phase

snippet phase connect_phase
function void `expand('%:t:r')`::connect_phase(uvm_phase phase);
// Purpose: connect TLM ports/exports and analysis ports
// Example:
// drv.seq_item_port.connect(sqr.seq_item_export);
// mon.ap.connect(sb.analysis_export);
// if (is_active == UVM_ACTIVE) drv.seq_item_port.connect(sqr.seq_item_export);
super.connect_phase(phase);
${0}
endfunction: connect_phase



snippet phase end_of_elaboration_phase
function void `expand('%:t:r')`::end_of_elaboration_phase(uvm_phase phase);
// Purpose: validate topology, print configuration
// Example:
// uvm_root::get().print_topology();
// uvm_config_db#(type)::dump();
super.end_of_elaboration_phase(phase);
${0}
endfunction: end_of_elaboration_phase


snippet phase start_of_simulation_phase
function void `expand('%:t:r')`::start_of_simulation_phase(uvm_phase phase);
// Purpose: pre-sim setup/logging
// Example:
// `uvm_info(get_name(), "Start of simulation", UVM_LOW)
// uvm_report_server rs = uvm_report_server::get_server();
// rs.set_max_quit_count(0);
// uvm_root::get().set_timeout(1ms, 0);
// `uvm_info(get_name(), $sformatf("Seed=%0d", $get_initial_random_seed()), UVM_LOW)
super.start_of_simulation_phase(phase);
${0}
endfunction: start_of_simulation_phase

snippet phase run_phase
task `expand('%:t:r')`::run_phase(uvm_phase phase);
// Purpose: time-based behavior, objections, stimulus
// Example:
// phase.raise_objection(this);
// fork
// begin `uvm_do(req) end
// begin monitor.run(); end
// join
// phase.drop_objection(this);
// `uvm_info(get_name(), "Run phase active", UVM_LOW)
super.run_phase(phase);
${0}
endtask: run_phase




snippet phase extract_phase
function void `expand('%:t:r')`::extract_phase(uvm_phase phase);
// Purpose: collect data/statistics
// Example:
// sb.extract();
// void'($display("Extracting stats"));
// cov_db.sample();
super.extract_phase(phase);
${0}
endfunction: extract_phase


snippet phase check_phase
function void `expand('%:t:r')`::check_phase(uvm_phase phase);
// Purpose: validate results (scoreboards, assertions)
// Example:
// if (!sb.is_pass()) `uvm_error(get_name(), "Scoreboard failed")
// `uvm_info(get_name(), $sformatf("Coverage=%0.2f", cov.get_inst_coverage()), UVM_LOW)
super.check_phase(phase);
${0}
endfunction: check_phase


snippet phase report_phase
function void `expand('%:t:r')`::report_phase(uvm_phase phase);
// Purpose: emit reports/summaries
// Example:
// `uvm_info(get_name(), sb.format_results(), UVM_NONE)
// void'($display("Report: %s", get_full_name()));
// uvm_report_server::get_server().summarize();
super.report_phase(phase);
${0}
endfunction: report_phase



snippet phase final_phase
function void `expand('%:t:r')`::final_phase(uvm_phase phase);
// Purpose: cleanup resources, finalize logs
// Example:
// void'($display("Finalizing"));
// if ($test$plusargs("auto_finish")) $finish;
super.final_phase(phase);
${0}
endfunction: final_phase



# Runtime Inline (two-choice) snippets
snippet phase pre_reset_phase
task `expand('%:t:r')`::pre_reset_phase(uvm_phase phase);
// Purpose: prepare for reset (stop drivers, clear state)
// Example:
// drv.stop(); mon.clear(); sb.reset();
${0}
endtask: pre_reset_phase

snippet phase reset_phase
task `expand('%:t:r')`::reset_phase(uvm_phase phase);
// Purpose: apply and hold reset
// Example:
// vif.rst_n <= 0; repeat (5) @(posedge vif.clk); vif.rst_n <= 1;
${0}
endtask: reset_phase

snippet phase post_reset_phase
task `expand('%:t:r')`::post_reset_phase(uvm_phase phase);
// Purpose: resume after reset (re-enable components)
// Example:
// drv.start(); mon.enable();
${0}
endtask: post_reset_phase

snippet phase pre_configure_phase
task `expand('%:t:r')`::pre_configure_phase(uvm_phase phase);
// Purpose: set configuration knobs
// Example:
// uvm_config_db#(int)::set(this, "sqr", "burst_len", 16);
${0}
endtask: pre_configure_phase

snippet phase configure_phase
task `expand('%:t:r')`::configure_phase(uvm_phase phase);
// Purpose: program DUT registers/modes via sequences
// Example:
// cfg_seq seq = cfg_seq::type_id::create("cfg_seq");
// seq.start(sqr);
${0}
endtask: configure_phase

snippet phase post_configure_phase
task `expand('%:t:r')`::post_configure_phase(uvm_phase phase);
// Purpose: validate configuration completion
// Example:
// `uvm_info(get_name(), "Configuration completed", UVM_LOW)
${0}
endtask: post_configure_phase

snippet phase pre_main_phase
task `expand('%:t:r')`::pre_main_phase(uvm_phase phase);
// Purpose: prepare for main stimulus (seed, counters)
// Example:
// void'($urandom(seed));
${0}
endtask: pre_main_phase

snippet phase main_phase
task `expand('%:t:r')`::main_phase(uvm_phase phase);
// Purpose: primary stimulus with objections
// Example:
// phase.raise_objection(this);
// my_seq seq = my_seq::type_id::create("seq");
// seq.start(sqr);
// phase.drop_objection(this);
${0}
endtask: main_phase

snippet phase post_main_phase
task `expand('%:t:r')`::post_main_phase(uvm_phase phase);
// Purpose: cleanup after main stimulus
// Example:
// drv.flush(); sb.summarize();
${0}
endtask: post_main_phase

snippet phase pre_shutdown_phase
task `expand('%:t:r')`::pre_shutdown_phase(uvm_phase phase);
// Purpose: prepare for shutdown (stop new transactions)
// Example:
// drv.stop_issuance();
${0}
endtask: pre_shutdown_phase

snippet phase shutdown_phase
task `expand('%:t:r')`::shutdown_phase(uvm_phase phase);
// Purpose: drain pipelines and flush outstanding items
// Example:
// phase.raise_objection(this);
// wait_for_drain();
// phase.drop_objection(this);
${0}
endtask: shutdown_phase

snippet phase post_shutdown_phase
task `expand('%:t:r')`::post_shutdown_phase(uvm_phase phase);
// Purpose: finalize run (close files, release handles)
// Example:
// `uvm_info(get_name(), "Shutdown complete", UVM_LOW)
${0}
endtask: post_shutdown_phase


# =============================================================================
# UVM PHASE METHODS (Extern Completions)
# Usage per phase (declarations only; implement outside the class):
# - build_phase: extern function; implementation creates/configures components.
# - connect_phase: extern function; implementation connects TLM/analysis ports.
# - start_of_simulation_phase: extern function; implementation performs pre-sim setup.
# Examples:
# - Class declaration:
# class my_component extends uvm_component;
# extern function void build_phase(uvm_phase phase);
# extern function void connect_phase(uvm_phase phase);
# extern task run_phase(uvm_phase phase);
# endclass
# - Implementation outside class:
# function void my_component::build_phase(uvm_phase phase);
# mon = my_monitor::type_id::create("mon", this);
# endfunction
# function void my_component::connect_phase(uvm_phase phase);
# drv.seq_item_port.connect(sqr.seq_item_export);
# endfunction
# task my_component::run_phase(uvm_phase phase);
# phase.raise_objection(this);
# // stimulus
# phase.drop_objection(this);
# endtask
# - run_phase: extern task; implementation drives stimulus and objections.
# - extract/check/report/final: extern functions; implementations collect, check,
# report, and cleanup.
# =============================================================================

snippet extern build_phase
extern function void build_phase(uvm_phase phase);

snippet extern connect_phase
extern function void connect_phase(uvm_phase phase);

snippet extern end_of_elaboration_phase
extern function void end_of_elaboration_phase(uvm_phase phase);

snippet extern start_of_simulation_phase
extern function void start_of_simulation_phase(uvm_phase phase);

snippet extern run_phase
extern task run_phase(uvm_phase phase);

snippet extern extract_phase
extern function void extract_phase(uvm_phase phase);

snippet extern check_phase
extern function void check_phase(uvm_phase phase);

snippet extern report_phase
extern function void report_phase(uvm_phase phase);

snippet extern final_phase
extern function void final_phase(uvm_phase phase);


snippet extern pre_reset_phase
extern task pre_reset_phase(uvm_phase phase);

snippet extern reset_phase
extern task reset_phase(uvm_phase phase);

snippet extern post_reset_phase
extern task post_reset_phase(uvm_phase phase);

snippet extern pre_configure_phase
extern task pre_configure_phase(uvm_phase phase);

snippet extern configure_phase
extern task configure_phase(uvm_phase phase);

snippet extern post_configure_phase
extern task post_configure_phase(uvm_phase phase);

snippet extern pre_main_phase
extern task pre_main_phase(uvm_phase phase);

snippet extern main_phase
extern task main_phase(uvm_phase phase);

snippet extern post_main_phase
extern task post_main_phase(uvm_phase phase);

snippet extern pre_shutdown_phase
extern task pre_shutdown_phase(uvm_phase phase);

snippet extern shutdown_phase
extern task shutdown_phase(uvm_phase phase);

snippet extern post_shutdown_phase
extern task post_shutdown_phase(uvm_phase phase);



#######
snippet uvm_objection
phase.raise_objection(this);
\`uvm_info(${1:get_full_name()},"${2:main_phase} started, objection raised.", ${3:UVM_NONE})
$0
phase.drop_objection(this);
uvm_info($1, "$2 finished, objection dropped ", $3)
snippet objection
phase.raise_objection(this);
\`uvm_info(${1:get_full_name()},"${2:main_phase} started, objection raised.", ${3:UVM_NONE})
$0
phase.drop_objection(this);
uvm_info($1, "$2 finished, objection dropped ", $3)