-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeta_pkg.sv
More file actions
1480 lines (1121 loc) · 49.8 KB
/
meta_pkg.sv
File metadata and controls
1480 lines (1121 loc) · 49.8 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
// ===================================================================
//
// Name: meta_pkg.sv
//
// Description:
// Scroll down a little to see this file's live metadata.
// Ironically we can't create the metadata structure until _after_ it has been defined.
//
// Scroll down to the bottom to see templates you can copy and paste into your code.
// ===================================================================
`include "uvm_macros.svh"
`include "meta_macros.sv"
// ===================================================================
package meta_pkg;
// ===================================================================
import uvm_pkg::*;
// ===================================================================
(*_= "typedef struct metadata_t" *)
// ===================================================================
// This is the struct that holds the metadata for each element (class, block, file, task, or function).
// Each of the struct's fields is of type `string`, even if it holds a numeric value.
typedef struct {
string metatype = "";
// ------------------
// Indicates the metadata's type.
//
// Expected values are:
// * "CLASS_TYPE"
// * "BLOCK_TYPE"
// * "FILE_TYPE"
// * "TASK_TYPE"
// * "FUNCTION_TYPE"
//
// Knowing the metatype helps provide context for the other fields.
// For example if the metatype is “CLASS_TYPE” then the RCS keywords can be ignored.
//
// If no value is provided, this field is filled automatically.
string name = "";
// --------------
// The name of the element.
// This field is filled automatically by the metacatalog.
// For file metadata this should be the filename.
//
// If no value is provided, this field is filled automatically.
string description = "";
// ---------------------
// A brief one-line description of the element.
string details = "";
// -----------------
// Free-form text providing more details about the element.
// Generally longer than description.
// May contain simple formatting like linebreaks or Markdown.
string categories = "";
// --------------------
// A comma-separated list of categories the element belongs to.
// White space surrounding the commas is ignored.
// There are no preset categories so the definition of “category” is up to the user.
// The intent is that a category is something that the element is as opposed to something the element has.
// Elements can be “tagged” with a shared category to make it easier to filter and group them.
// For example memory tests might have categories “memory, test”.
//
// If the element is a class descended from uvm_object then this field is automatically appended with a list of all the UVM base classes in the element’s class hierarchy.
string attributes = "";
// --------------------
// A comma-separated list of attributes the element has.
// White space surrounding the commas is ignored.
// There are no preset attributes so the definition of “attribute” is up to the user.
// The intent is that an attribute is something that the element has as opposed to something the element is.
// Elements can be “tagged” with a shared attribute to make it easier to filter and group them.
// For example a random test sequence with an interrupt handler might have attributes “random, interrupt handler”.
string type_id = "";
// -----------------
// UVM objects have a `type_id` property which represents the class in the UVM factory.
// This metadata field contains the name of the type_id which generally is the same as the class name.
// It can be found with the function call `type_id::get().get_type_name()`.
//
// Only used for class metadata.
//
// If no value is provided, this field is filled automatically.
string hierarchical_name = "";
// ---------------------------
// The full hierarchical path to the metadata block.
//
// Used for block, task, and function metadata.
//
// If no value is provided, this field is filled automatically.
string file = "";
// --------------
// The full file pathname of the file in the local file system containing the element's source code.
// The pathname generally includes the user’s home directory information so the same file will have different file metadata depending on which user generates the metadata and where.
//
// If no value is provided, this field is filled automatically.
string line = "";
// --------------
// The line number in the `file` where the metadata is created, i.e. inside the element.
// It's a numeric value but the field type is still `string`.
//
// If no value is provided, this field is filled automatically.
// RCS keywords
// ============
// These fields are not filled automatically; you need to explicitly put the keywords in your metadata struct.
// However, Perforce will expand them automatically when you check in the file with one of the `+k` file types.
// See `icmp4 help filetypes` for more information.
string id = "";
// ------------
// RCS `$Id$` keyword.
// IC Manage/Perforce filename and revision number in depot syntax.
string header = "";
// ----------------
// RCS `$Header$` keyword.
// Synonymous with $Id$.
string author = "";
// ----------------
// RCS `$Author$` keyword.
// IC Manage/Perforce user submitting the file.
string date = "";
// --------------
// RCS `$Date$` keyword.
// Date of last submission in format "YYYY/MM/DD".
string date_time = "";
// -------------------
// RCS `$DateTime$` keyword.
// Date and time of last submission in format "YYYY/MM/DD hh:mm:ss".
string change = "";
// ----------------
// RCS `$Change$` keyword.
// IC Manage/Perforce changelist number under which file was submitted.
string depot_file = "";
// --------------------
// RCS `$File$` keyword.
// IC Manage/Perforce filename in depot syntax, without revision number.
string revision = "";
// ------------------
// RCS `$Revision$` keyword.
// IC Manage/Perforce revision number.
string metaoptions = "";
// ---------------------
// Comma-separated flags for controlling metadata operations.
// White space surrounding the commas is ignored.
// Currently these metaoptions are supported:
// * "disable_auto_base_class_listing" - If present, prevents the categories field from being auto-filled with a list of UVM base classes.
// Some classes cause execution to fail while determining base classes, so set this metaoption to bypass the failing operation.
// * "do_not_register" - If present, prevents the metadata from being added to the metacatalog.
// However the metadata is still added to the element itself.
} metadata_t;
// ===================================================================
(*_= "typedef enum metatype_t" *)
// ===================================================================
// Enum of possible metadata `metatype` values for internal use.
// Note that the `metatype` field in the `metadata_t` struct takes a string.
typedef enum {CLASS_TYPE, BLOCK_TYPE, FILE_TYPE, TASK_TYPE, FUNCTION_TYPE} metatype_t;
class \_metadata_$_meta_pkg.sv extends uvm_object;
`CLASS_METADATA('{
// ===================================================================
name: "meta_pkg.sv",
// ===================================================================
description:
"Utilities for adding and managing metadata in classes and blocks.",
details: {
"Metadata is structured information about SystemVerilog entities. ",
"Metadata may be added to sub-classes of `uvm_object` and to procedural `begin-end` blocks. ",
"These utilities add metadata that is accessible from within the simulation. ",
"Run test `print_meta_catalog` to output all the metadata to a YAML file which can be processed offline. ",
"Add metadata like this to classes and blocks almost anywhere in the design. ",
"At the bottom of this file, there are templates you can copy and paste into other files. ",
"Since metadata is part of the source code, it must be syntactically correct so it will compile. ",
"Pay careful attention to syntax, especially punctuation. ",
"This is the metadata for this file. ",
"That makes this meta-metadata. "
},
categories:
"file, package",
attributes:
"metadata, documentation",
// RCS keywords
id: "$Id$",
header: "$Header$",
author: "$Author$",
date: "$Date$",
date_time: "$DateTime$",
change: "$Change$",
depot_file: "$File$",
revision: "$Revision$",
metatype: "FILE_TYPE",
string:
"" // Required
})
// ===================================================================
`uvm_object_utils(\_metadata_$_meta_pkg.sv )
function new(string name = "\_metadata_$_meta_pkg.sv ");
super.new(name);
endfunction : new
endclass : \_metadata_$_meta_pkg.sv
`include "meta_utils.sv"
// ===================================================================
class _meta_component extends uvm_component;
// ===================================================================
`CLASS_METADATA('{
description:
"A component that has the ability to delete its own children.",
details: {
"UVM does not provide a way to remove components from the component tree. ",
"Function `list_uvm_clsses_of_object()` needs to instantiate components temporarily for quick analysis, then remove them. ",
"Otherwise the components would persist in the component tree and their phases would run, potentially causing problems. ",
"This `_meta_component` can serve as a parent for those temporary components that deletes them when done. ",
"Note that the `_meta_component` itself does persist in the main component tree, but its phases are empty so there should be no side-effects. ",
"This has a singleton-style static `get()` function that returns a single static instance of itself, located under `uvm_top`. ",
"Please use that `get()` function instead of creating your own `_meta_component` so there aren't more than one `_meta_component` in the tree. ",
""
},
attributes:
"metadata",
string: ""
})
// ===================================================================
local static _meta_component pseudo_singleton;
`uvm_component_utils(_meta_component)
function new(string name="", uvm_component parent=null);
super.new(name, parent);
endfunction : new
// ===================================================================
static function _meta_component get;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Return a handle to the singleton _meta_component object.",
details: {
"It's not really a singleton because `new()` is public so anyone can create a new one. ",
"The `uvm_component_utils` prevent us from making `new()` local. ",
"But there can only be one static instance. ",
"It's not enforceable, but it is _recommended_ to use this static `get()` function instead of creating your own instance. ",
""
},
attributes:
"metadata",
string: ""
})
// Parameters:
// None
// =================================================================//
if (pseudo_singleton == null) begin
// Create the `_meta_component` and add it to `uvm_top`.
pseudo_singleton = _meta_component::type_id::create("_meta_component", null);
end
return pseudo_singleton;
endfunction : get
// ===================================================================
virtual function void delete_children;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Delete all of this component's children.",
details: {
"This is the raison d'etre for this class. ",
"Remove all child components and release their handles. ",
"Without this, children would persist in the component tree forever. ",
""
},
string: ""
})
// Parameters;
// None
// ===================================================================
// In this UVM implementation child classes are stored in two protected associative arrays.
// Clean them both out.
// This is not a documented feature.
// This may change in different implementations.
foreach (m_children[i]) m_children[i] = null;
m_children.delete();
foreach (m_children_by_handle[i]) m_children_by_handle[i] = null;
m_children_by_handle.delete();
// Check the result using the documented interface.
// This will alert us if this undocumented method fails to work for some reason.
assert_zero_children : assert (get_num_children() == 0)
else begin
`uvm_error(get_name(), "Failed to delete components.")
end
endfunction : delete_children
endclass : _meta_component
// ===================================================================
class metacatalog;
// ===================================================================
static function void _metacatalog_metadata();
`FUNCTION_METADATA('{
// Ironically can't use CLASS_METADATA here because the metacatalog is not a uvm_object.
// So we use a dummy function to apply metadata to this class.
name:
"metacatalog",
description:
"Provides utilities for registering and retrieving metadata structures in the UVM resource database.",
details: {
"Implemented as a singleton. ",
"To retrieve its instance use the static function meta_pkg::metacatalog::get(). "
},
categories:
"class",
// Override `metatype` since we're not using the `CLASS_METADATA` macro.
metatype:
"CLASS_TYPE",
string:
"" // Required
})
// =================================================================//
endfunction : _metacatalog_metadata
local static metacatalog singleton;
// Some arcana for using the `uvm_resource_pool` lookup functions
static uvm_resource#(meta_pkg::metadata_t) metadata_type_template = new();
// ===================================================================
local function new(string name = "");
// ===================================================================
endfunction : new
// ===================================================================
static function metacatalog get;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Return a handle to the singleton metacatalog object.",
attributes:
"metadata",
string: ""
})
// Parameters:
// None
// ===================================================================
if (singleton == null) begin
singleton = new("metacatalog");
end
return singleton;
endfunction : get
// ===================================================================
virtual function metadata_t register_class_metadata;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Register the given class metadata in the metacatalog and return a new, completed metadata struct.",
details: {
"Takes user-supplied metadata, auto-fills several fields, and registers it in the metacatalog. ",
"Returns the auto-filled metadata so it can be stored as a static property of the class. ",
"Don't call this function directly. ",
"Instead use the `CLASS_METADATA()` macro. ",
"The macro fills in most of the arguments for you. ",
""
},
attributes:
"metadata",
string: ""
})
// Parameters:
input uvm_object_wrapper obj; // The component or object proxy for the class as returned by `uvm_object::get_type()`
input uvm_object_wrapper type_id; // The component or object proxy for the class as returned by `uvm_object::type_id::get()`
input metadata_t metadata; // The user-supplied metadata struct
input string file; // The filename for the metadata `file` field, typically `__FILE__
input int line; // The line number for the metadata `line` field, typically `__LINE__
// ===================================================================
metatype_t metatype = CLASS_TYPE;
string uvm_classes = "";
string options_q[$];
bit options_hash[string];
bit ok;
// Slurp all options into an associative array
ok = csv_to_list(options_q, metadata.metaoptions);
assert (ok) else `uvm_error("print", "Failed to parse metaoptions")
foreach (options_q[i]) begin
options_hash[options_q[i]] = 1;
end
// Auto-fill blank metadata
if (metadata.name == "") begin
if (obj.get_type_name() == "") begin
if (type_id.get_type_name() == "") begin
`uvm_warning("metacatalog", {"Class metadata at file ", file, " line ", $sformatf("%0d", line), " does not specify a value for `name`."})
end
else begin
metadata.name = type_id.get_type_name();
end
end
else begin
metadata.name = obj.get_type_name();
end
end
else `uvm_info("metacatalog", {"Class ", metadata.name, " metadata `name` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.metatype == "") metadata.metatype = metatype.name();
else `uvm_info("metacatalog", {"Class ", metadata.name, " metadata `metatype` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.type_id == "") metadata.type_id = type_id.get_type_name();
else `uvm_info("metacatalog", {"Class ", metadata.name, " metadata `type_id` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.file == "") metadata.file = file;
else `uvm_info("metacatalog", {"Class ", metadata.name, " metadata `file` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.line == "") begin
if (line > 0) begin
metadata.line.itoa(line);
end
end
else `uvm_info("metacatalog", {"Class ", metadata.name, " metadata `line` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (!options_hash.exists("disable_auto_base_class_listing")) begin
uvm_classes = list_uvm_classes_of_object(obj);
end
if (metadata.categories == "") begin
metadata.categories = uvm_classes;
end
else if (uvm_classes != "") begin
metadata.categories = {metadata.categories, ",", uvm_classes};
end
if (!options_hash.exists("do_not_register")) begin
uvm_resource_db#(metadata_t)::set("*", metadata.name, metadata);
`uvm_info("metacatalog", {"Registered ", metadata.metatype, " metadata ", metadata.name}, UVM_HIGH)
end
// Return the auto-filled metadata for storage in the class
return metadata;
endfunction : register_class_metadata
// ===================================================================
virtual function metadata_t register_block_metadata;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Register the given block metadata in the metacatalog and return a new, completed metadata struct.",
details: {
"Block metadata is typically used for modules and files. ",
"Takes user-supplied metadata, auto-fills several fields, and registers it in the metacatalog. ",
"Returns the auto-filled metadata so it can be stored as a variable in the block. ",
"Don't call this function directly. ",
"Instead use the `BLOCK_METADATA()` or `FILE_METADATA()` macro. ",
"The macros fill in most of the arguments for you. ",
""
},
attributes:
"metadata",
string: ""
})
// Parameters:
input metadata_t metadata; // The user-supplied metadata struct
input string hierarchical_name; // The hierarchical path name to the metadata block
input metatype_t metatype; // The type for the metadata `metatype` field, typically `BLOCK_TYPE` or `FILE_TYPE`
input string file; // The filename for the metadata `file` field, typically `__FILE__
input int line; // The line number for the metadata `line` field, typically `__LINE__
// ===================================================================
string options_q[$];
bit options_hash[string];
bit ok;
// Slurp all options into an associative array
ok = csv_to_list(options_q, metadata.metaoptions);
assert (ok) else `uvm_error("print", "Failed to parse metaoptions")
foreach (options_q[i]) begin
options_hash[options_q[i]] = 1;
end
// Auto-fill blank metadata
if (metadata.metatype == "") metadata.metatype = metatype.name();
else `uvm_info("metacatalog", {"Block ", metadata.name, " metadata `metatype` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.metatype == "FILE_TYPE") begin
if (metadata.name == "") begin : get_name_from_filename
string tokens[$];
string temp_name;
bit ok;
ok = split_string(tokens, metadata.file, "/");
assert (ok);
if (tokens.size() >= 1) begin
temp_name = tokens.pop_back();
end
metadata.name = temp_name;
end
end
else if (metadata.name == "") begin : get_name_from_block_hierarchical_name
string tokens[$];
string temp_name;
bit ok;
ok = split_string(tokens, metadata.hierarchical_name, ".");
assert (ok);
if (tokens.size() >= 1) begin
temp_name = tokens.pop_back();
if (temp_name == "_metadata_block") begin : if_leaf_block_is_the_metadata_block_go_up_one_more_level
if (tokens.size() >= 1) begin
temp_name = tokens.pop_back();
end
end
end
metadata.name = temp_name;
end
if (metadata.name == "")
`uvm_warning("metacatalog", {"Block metadata at file ", file, " line ", $sformatf("%0d", line), " does not specify a value for `name`."})
if (metadata.hierarchical_name == "") metadata.hierarchical_name = hierarchical_name;
else `uvm_info("metacatalog", {"Block ", metadata.name, " metadata `hierarchical_name` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.file == "") metadata.file = file;
else `uvm_info("metacatalog", {"Block ", metadata.name, " metadata `file` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.line == "") begin
if (line > 0) begin
metadata.line.itoa(line);
end
end
else `uvm_info("metacatalog", {"Block ", metadata.name, " metadata `line` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (!options_hash.exists("do_not_register")) begin
uvm_resource_db#(metadata_t)::set("*", metadata.name, metadata);
`uvm_info("metacatalog", {"Registered ", metadata.metatype, " metadata ", metadata.name, " for ", metadata.hierarchical_name}, UVM_HIGH)
end
// Return the auto-filled metadata for storage in the class
return metadata;
endfunction : register_block_metadata
// ===================================================================
virtual function metadata_t register_subroutine_metadata;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Register the given subroutine metadata in the metacatalog and return a new, completed metadata struct.",
details: {
"Subroutine metadata is typically used for tasks and functions. ",
"Takes user-supplied metadata, auto-fills several fields, and registers it in the metacatalog. ",
"Returns the auto-filled metadata so it can be stored as a static variable in the subroutine. ",
"Don't call this function directly. ",
"Instead use the `TASK_METADATA()` or `FUNCTION_METADATA()` macro. ",
"The macros fill in most of the arguments for you. ",
""
},
attributes:
"metadata",
string: ""
})
// Parameters:
input metadata_t metadata; // The user-supplied metadata struct
input string hierarchical_name; // The hierarchical path name to the metadata block
input metatype_t metatype; // The type for the metadata `metatype` field, typically `TASK_TYPE` or `FUNCTION_TYPE`
input string file; // The filename for the metadata `file` field, typically `__FILE__
input int line; // The line number for the metadata `line` field, typically `__LINE__
// ===================================================================
string options_q[$];
bit options_hash[string];
bit ok;
// Slurp all options into an associative array
ok = csv_to_list(options_q, metadata.metaoptions);
assert (ok) else `uvm_error("print", "Failed to parse metaoptions")
foreach (options_q[i]) begin
options_hash[options_q[i]] = 1;
end
// Auto-fill blank metadata
if (metadata.metatype == "") metadata.metatype = metatype.name();
else `uvm_info("metacatalog", {"Subroutine ", metadata.name, " metadata metatype field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.name == "") begin : get_name_from_hierarchical_name
string tokens[$];
string temp_name;
bit ok;
ok = split_string(tokens, hierarchical_name, ".");
assert (ok);
if (tokens.size() >= 1) begin
temp_name = tokens.pop_back();
end
metadata.name = temp_name;
end
if (metadata.name == "")
`uvm_warning("metacatalog", {"Subroutine metadata at file ", file, " line ", $sformatf("%0d", line), " does not specify a value for `name`."})
if (metadata.hierarchical_name == "") metadata.hierarchical_name = hierarchical_name;
else `uvm_info("metacatalog", {"Subroutine ", metadata.name, " metadata `hierarchical_name` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.file == "") metadata.file = file;
else `uvm_info("metacatalog", {"Subroutine ", metadata.name, " metadata `file` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (metadata.line == "") begin
if (line > 0) begin
metadata.line.itoa(line);
end
end
else `uvm_info("metacatalog", {"Subroutine ", metadata.name, " metadata `line` field has user-supplied value; it will not be auto-filled."}, UVM_HIGH)
if (!options_hash.exists("do_not_register")) begin
uvm_resource_db#(metadata_t)::set("*", metadata.name, metadata);
`uvm_info("metacatalog", {"Registered ", metadata.metatype, " metadata ", metadata.name, " for ", metadata.hierarchical_name}, UVM_HIGH)
end
// Return the auto-filled metadata for storage in the class
return metadata;
endfunction : register_subroutine_metadata
// ===================================================================
virtual function void rsrc_q_to_metadata_q;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Convert a UVM resource `rsrc_q_t` queue to a SystemVerilog queue of `metadata_t`.",
details: {
"UVM resource lookup functions return results in a parameterized queue of type `rsrc_q_t`. ",
"This function transfers metadata items in the resource queue to the supplied SystemVerilog queue of `metadata_t`, replacing its contents. ",
"Any non-metadata items in the incoming queue are ignored. ",
""
},
attributes:
"metadata",
string: ""
})
// Parameters:
ref metadata_t metadata_q[$]; // Outgoing metadata queue, extracted from the incoming resource queue
ref uvm_resource_types::rsrc_q_t rsrc_q; // Incoming resource queue received from a UVM resource lookup function
// ===================================================================
metadata_q.delete();
for (int i = 0; i < rsrc_q.size(); i++) begin
uvm_resource_base rsrc;
metadata_t metadata;
uvm_resource#(metadata_t) metadata_resource;
int success;
rsrc = rsrc_q.get(i);
success = $cast(metadata_resource, rsrc);
if (success) begin
// The payload must be "read" from the resource
metadata = metadata_resource.read();
metadata_q.push_back(metadata);
end
end
endfunction : rsrc_q_to_metadata_q
// ===================================================================
static function uvm_resource_base get_metadata_type_handle;
// ===================================================================
// Some arcana for using the `uvm_resource_pool` lookup functions
return metadata_type_template.get_type_handle();
endfunction : get_metadata_type_handle
// ===================================================================
virtual function void lookup_name;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Lookup metadata by name and return matches in the supplied queue.",
details: {
"Returns all metadata items that match the name.\n",
"Example:\n",
" metadata_t q[$];", "\n",
" meta_pkg::metacatalog::get().lookup_name(q, \"reset_block\");", "\n",
""
},
categories:
"",
attributes:
"metadata",
string:
"" // Required
})
// Parameters:
ref metadata_t metadata_q[$]; // Receives the returned metadata
input string name; // Name of the elements to match
// ===================================================================
uvm_resource_types::rsrc_q_t rsrc_q;
rsrc_q = uvm_resource_pool::get().lookup_name("", name, get_metadata_type_handle());
rsrc_q_to_metadata_q(metadata_q, rsrc_q);
endfunction : lookup_name
// ===================================================================
virtual function metadata_t get_by_name;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Lookup metadata by name.",
details: {
"Returns one metadata item, even if multiple items match the name.\n",
"Example:\n",
" metadata_t m = meta_pkg::metacatalog::get().get_by_name(\"meta_pkg.sv\");\n",
" $display(\"%p\", m);\n",
""
},
attributes:
"metadata",
string:
"" // Required
})
// Parameters:
input string name; // Name of the element
// ===================================================================
uvm_resource_base rsrc;
metadata_t metadata;
uvm_resource#(metadata_t) metadata_resource;
int success;
rsrc = uvm_resource_pool::get().get_by_name("", name, get_metadata_type_handle());
success = $cast(metadata_resource, rsrc);
assert (success);
metadata = metadata_resource.read();
return metadata;
endfunction : get_by_name
// ===================================================================
virtual function void lookup_metadata;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Lookup all metadata.",
details: {
"Fills the supplied queue of type `metadata_t` with all metadata items.\n",
"Example:\n",
" metadata_t q[$];\n",
" meta_pkg::metacatalog::get().lookup_metadata(q);\n",
" foreach (q[i]) $display(\"%p\", q[i]);\n",
""
},
categories:
"",
attributes:
"metadata",
string:
"" // Required
})
// Parameters:
ref metadata_t metadata_q[$]; // Receives the returned metadata
// ===================================================================
uvm_resource_types::rsrc_q_t rsrc_q;
rsrc_q = uvm_resource_pool::get().lookup_type("", get_metadata_type_handle());
rsrc_q_to_metadata_q(metadata_q, rsrc_q);
endfunction : lookup_metadata
// ===================================================================
virtual function void lookup_regex;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Lookup all metadata whose name matches regular expression.",
details: {
"Fills the supplied queue of type `metadata_t` with matching items. ",
"Regular expression for name is given in a string. ",
"If `re` is in /slashes/ then it's interpreted as a proper regular expression. ",
"Otherwise it's interpreted as a glob (i.e. wildcards `*` and `?`). ",
"Example:\n",
" metadata_t q[$];\n",
" // Regex matches metadata whose name starts with 'mem_'\n",
" meta_pkg::metacatalog::get().lookup_regex(q, \"/^mem_/\");\n",
" foreach (q[i]) $display(\"%p\", q[i]);\n",
"\n",
" // Glob matches metadata whose name starts with 'mem_'\n",
" meta_pkg::metacatalog::get().lookup_regex(q, \"mem_*\");\n",
" foreach (q[i]) $display(\"%p\", q[i]);\n",
""
},
categories:
"",
attributes:
"metadata",
string:
"" // Required
})
// Parameters:
ref metadata_t metadata_q[$]; // Receives the returned metadata
input string re; // Regular expression or glob for names
// ===================================================================
uvm_resource_types::rsrc_q_t rsrc_q;
rsrc_q = uvm_resource_pool::get().lookup_regex(re, "");
rsrc_q_to_metadata_q(metadata_q, rsrc_q);
endfunction : lookup_regex
// ===================================================================
virtual function void print;
// ===================================================================
`FUNCTION_METADATA('{
description:
"Print all metadata to the simulator output log file.",
details: {
"Output is lightly formatted for legibility. ",
"Empty metadata fields are omitted. "
},
attributes:
"metadata",
string: ""
})
// Parameters:
// None
// ===================================================================
metadata_t metadata_q[$];
lookup_metadata(metadata_q);
$display("Catalog");
$display("=======");
$display("```");
foreach (metadata_q[i]) begin
string categories[$];
string attributes[$];
bit ok;
metadata_t metadata;
metadata = metadata_q[i];
$display({"Metatype:\n\t", metadata.metatype});
$display({"Name:\n\t", metadata.name});
if (metadata.description != "") $display({"Description:\n\t", metadata.description});