-
Notifications
You must be signed in to change notification settings - Fork 16
/
easier_uvm_gen.pl
6281 lines (5393 loc) · 270 KB
/
easier_uvm_gen.pl
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
#!/usr/bin/perl
##
##----------------------------------------------------------------------
## Copyright (c) 2013-2016 by Doulos Ltd.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ----------------------------------------------------------------------
## Based on the juvb11.pl script v1.09 by Jim McGrath, Cadence which was uploaded as UVMWorld contribution on 16 September 2011
## 19/02/2014 Author Christoph Suehnel, Doulos
## 24/02/2014 David Long, Doulos - DUT port list, auto instantiation in top
## 12/03/2014 David Long, Doulos - Support for multiple IFs/register sub-blocks
## 04/04/2014 David Long, Doulos - Naming conventions and use of config_db updated
## 11/04/2014 David Long, Doulos - Constraints added to seq_item
## 20/05/2014 David Long, Doulos - Support for multiple agents within envs. Simplified directory structure,
## 05/06/2014 David Long, Doulos - Revised template file format and options. Preliminary version for public release
## 01/09/2014 David Long, Doulos - DUT now in test harness module. Removed unnecessary child environments. Improvements to code formatting
## 21/09/2014 David Long, Doulos - trans_var allows typedef. item replaced by req. Added checks/coverage_enable.
## 08/10/2014 David Long, Doulos - fixed some naming conventions. Check "is_active"
## 13/10/2014 David Long, Doulos - fixed bug with "uvm_seqr_class" switch in template file
## 13/10/2014 David Long, Doulos - default_sequence class now derived directly from uvm_sequence
## 17/10/2014 David Long, Doulos - removed unnecessary base class for test. Configuration for top env now set in TB module
## 22/10/2014 David Long, Doulos - Top-level sequence now started by env (default test run_phase does nothing). Removed unnecessary task wait_end_test.
## Added checking for critical warnings re include files (can be ignored by adding -c ("continue") flag to command line
## 06/11/2014 David Long, Doulos - Option to add common package for parameters, etc that can be accessed in all generated files (including test harness)
## 05/11/2014 David Long, Doulos - Generated packages now include files directly (removed .svh files). Removed unused *_common.sv files
## 07/11/2014 David Long, Doulos - Removed <test>_common_pkg include file - these items are now written to test common package directly.
## Test common package file is not regenerated if it has been modified since it was created (i.e. user changes are preserved).
## 07/11/2014 David Long, Doulos - Top-level sequence uses UVM 1.2 API to raise/drop objections in pre/post-start.
## 17/11/2014 David Long, Doulos - Corrected minor formatting issues.
## 16/12/2014 John Aynsley, Doulos - Tidied up positioning of blank lines.
## 19/12/2014 John Aynsley, Doulos - Add m_ prefix to member variables. Add some pretty-printing
## 05/01/2015 John Aynsley, Doulos - Fix bug with properties leaking between agents
## 16/01/2015 John Aynsley, Doulos - Tweak formatting
## 20/01/2015 John Aynsley, Doulos - Tweak formatting
## 28/01/2015 John Aynsley, Doulos - Add a parameter regmodel_file to reg.tpl to replace the hardwired "regmodel.sv"
## 28/01/2015 John Aynsley, Doulos - Allow regmodel_ as well as rm_ in reg.tpl file
## 29/01/2015 John Aynsley, Doulos - Call `uvm_error if randomize fails
## 04/02/2015 John Aynsley, Doulos - Fix bug so that common package gets included in agent interfaces, rationalize package imports
## 04/02/2015 John Aynsley, Doulos - Allow named constraints as trans_var = values
## 19/02/2015 John Aynsley, Doulos - Label coverpoints using field name rather than number
## 19/02/2015 John Aynsley, Doulos - Add new include files inside/after classes
## 07/04/2015 John Aynsley, Doulos - Add new include file inside th module
## 21/04/2015 John Aynsley, Doulos - Generate get/set_starting_phase methods for all sequences
## 05/05/2015 John Aynsley, Doulos - Add several new include files and independent flags to suppress the generation of default members and methods
## 06/05/2015 John Aynsley, Doulos - Add ability to inline all user-defined include files
## 11/05/2015 John Aynsley, Doulos - Restructure <top>_common_pkg as per common_pkg (not backward-compatible)
## 12/05/2015 John Aynsley, Doulos - Add _prepend_to_ and _append_to_ include files for build_phase, connect_phase, run_phase methods
## 12/05/2015 John Aynsley, Doulos - Don't generate end_of_elaboration_phase, start_of_simulation_phase, check_phase (allows it to be user-defined more conveniently)
## 12/05/2015 John Aynsley, Doulos - Don't generate empty run_phase for test (allows it to be user-defined more conveniently)
## 19/05/2015 John Aynsley, Doulos - Support multiple instances of each interface (with _N suffix in pinlist file)
## 20/05/2015 John Aynsley, Doulos - Refactor all the pretty-print code
## 26/05/2015 John Aynsley, Doulos - Generate comments showing possible include locations
## 30/05/2015 John Aynsley, Doulos - Permit trans_item name clashes across agents by distinguishing the filenames
## 05/06/2015 John Aynsley, Doulos - Add agent_copy_config_vars
## 16/06/2015 John Aynsley, Doulos - Add -m command line argument to specify path to common template file. Interface template files may have any name (not just *.tpl)
## 16/06/2015 John Aynsley, Doulos - Add prefix = setting to common template file as alternative to -p switch
## 17/06/2015 John Aynsley, Doulos - Refactor by adding warning_prompt
## 20/06/2015 John Aynsley, Doulos - Add reg_access_mode, reg_access_map, reg_access_block_type, reg_access_block_instance, top_reg_block_type, regmodel_file
## 20/06/2015 John Aynsley, Doulos - Make reg.tpl optional
## 21/06/2015 John Aynsley, Doulos - Add top_env_generate_end_of_elaboration (default yes)
## 21/06/2015 John Aynsley, Doulos - Revamp messages printed from script
## 21/06/2015 John Aynsley, Doulos - Fix bug in gen_env which was repeating additional agent declaration in number_of_instances loop
## 21/06/2015 John Aynsley, Doulos - Add compile/run script for Riviera
## 30/09/2015 John Aynsley, Doulos - Add command line flag -x to output dut_source_path, inc_path, and project without generating any code
## 01/10/2015 John Aynsley, Doulos - Adjust compile_vcs.do and compile_ius.do scripts to use built-in versions of UVM-1.2
## 01/10/2015 John Aynsley, Doulos - Replace factory with uvm_factory::get().
## 20/10/2015 John Aynsley, Doulos - Make the -r switch optional: instantiation of the register model will be forced in the presence of top_reg_block_type
## 20/10/2015 John Aynsley, Doulos - Extend command line flag -x to output regmodel_file without generating any code
## 22/10/2015 John Aynsley, Doulos - Make files.f optional. If absent, create a files.f that lists just the *.sv files in the DUT directory (alphabetical order)
## 23/10/2015 John Aynsley, Doulos - Allow dut_source_path to default to dut, inc_path to default to include, dut_pfile to default to pinlist
## 23/10/2015 John Aynsley, Doulos - Add common template setting uvm_cmdline = , and remove +UVM_VERBOSITY=FULL from sim scripts, using $uvm_cmdline instead
## 26/10/2015 John Aynsley, Doulos - With -x regmodel_file, force the script to read reg.tpl if the file exists
## 03/11/2015 John Aynsley, Doulos - Moved _N suffix to before standard suffix for consistency, e.g. changed m_${agent}_agent${suffix} to m_${agent}${suffix}_agent
## 09/11/2015 John Aynsley, Doulos - Call comparer.compare_field in overridden do_compare method of uvm_sequence_item (to keep Syosil scoreboard happy)
## 16/11/2015 John Aynsley, Doulos - Add top_default_seq_count in common template
## 17/11/2015 John Aynsley, Doulos - Rewrite the pretty-printing code
## 17/11/2015 John Aynsley, Doulos - Add support for the Syosil Versatile Scoreboard: syosil_scoreboard_src_path, ref_model_input, ref_model_output
## ref_model_compare_method, ref_model_inc_before/inside/after_class
## 26/11/2015 John Aynsley, Doulos - Generate pack and unpack methods in uvm_sequence_item class unless cmdline flag -nopack is present for backward compatibility
## 26/11/2015 John Aynsley, Doulos - Add trans_enum_var setting to distinguish enum variables in do_pack, do_unpack, and convert2string - mandatory for enums in pack!
## 26/11/2015 John Aynsley, Doulos - Add trans_meta setting to distinguish transaction metadata and thus exclude it from do_compare, do_pack, and do_unpack methods
## 26/11/2015 John Aynsley, Doulos - Add trans_enum_meta for metadata that happens to be of enum type
## 27/11/2015 John Aynsley, Doulos - Allow single unpacked array dimension in trans_var declaration
## 17/12/2015 John Aynsley, Doulos - Minor cosmetic surgery on the source code
## 18/12/2015 John Aynsley, Doulos - Eliminated the <agent>_env directory and the <agent>_env_pkg. There is now only an <agent>_pkg.
## Now only 1 pkg per UVC. Also scrapped subs gen_regmodel_pkg and gen_regmodel_env
## 19/12/2015 John Aynsley, Doulos - Made coverage object available to both coverage subscribers (agent and register), which also now contain a build_phase method
## 19/12/2015 John Aynsley, Doulos - Use coverage_enable to condition the calling of sample(), not the instantiation of a subscriber for an agent
## 19/12/2015 John Aynsley, Doulos - Move code executed after parsing control files to separate subs
## 20/12/2015 John Aynsley, Doulos - Removed the unused dut_inc_path and inc_file code
## 23/12/2015 John Aynsley, Doulos - Permit / in include filenames so that ./include can be structured into subdirectories
## 11/01/2016 John Aynsley, Doulos - Permit trans_var/trans_meta = // SystemVerilog comment
## 20/01/2016 John Aynsley, Doulos - Insert agent_copy_config_vars inc file only once if number_of_instances > 1, which can thus copy vars for multiple config objects
## 21/01/2016 John Aynsley, Doulos - Add dual_top and split_transactors to support acceleration/emulation-ready environments
## 01/02/2016 John Aynsley, Doulos - Add timeunit and timeprecision to interfaces (was previously only inserted in modules)
## 15/02/2016 John Aynsley, Doulos - Fix bug related to print_structure - %env_agents needs to store a copy of @additional_agents, not a \reference
## 15/02/2016 John Aynsley, Doulos - Add top_env_generate_run_phase (default yes)
## 15/02/2016 John Aynsley, Doulos - Add generate_file_header and file_header_inc
## 15/02/2016 John Aynsley, Doulos - Clean up auto-generated file header to only write out lines that are defined
## 17/02/2016 John Aynsley, Doulos - Add adapter_generate_methods_inside/after_class and adapter_inc_before/inside/after class
## 18/02/2016 John Aynsley, Doulos - Add nested_config_objects
## 18/02/2016 John Aynsley, Doulos - Add top_env_config_append_to_new
## 18/02/2016 John Aynsley, Doulos - Add top_env_config_generate_methods_inside/after_class
## 18/02/2016 John Aynsley, Doulos - Add agent_config_generate_methods_inside/after_class
## 18/02/2016 John Aynsley, Doulos - Add tb_generate_run_test
## 08/03/2016 John Aynsley, Doulos - Add -s command line switch to override syosil_scoreboard_src_path setting in common template
## 31/03/2016 John Aynsley, Doulos - Permit end-of-line comment with DEC in pinlist file
## 31/03/2016 John Aynsley, Doulos - Fix bug with trailing comments after last port connection in pinlist file
## 31/03/2016 John Aynsley, Doulos - Add calls to .set_item_context() before randomizing sequence objects to ensure random stability
## 05/04/2016 John Aynsley, Doulos - Replace -f with -F in Riviera script
## 06/04/2016 John Aynsley, Doulos - Modify compile_riviera.do script to compile everything UVM with a single call to alog
## 15/04/2016 John Aynsley, Doulos - Add tb_prepend_to_initial and tb_inc_before_run_test
## 15/04/2016 John Aynsley, Doulos - Add generate_interface_instance = no (interface instance not generated and vif not assigned)
## 15/04/2016 John Aynsley, Doulos - Add byo_interface
## 15/04/2016 John Aynsley, Doulos - Allow user-defined interface instance names in the pinlist file
## 15/04/2016 John Aynsley, Doulos - Changed "virtual interface is not set!" report from FATAL to WARNING - because might have a parameterized interface
## 12/05/2016 John Aynsley, Doulos - Allow multiple +uvm_cmdline settings to apply additively
## 27/05/2016 John Aynsley, Doulos - Don't generate empty build_phase method for monitor
## 27/05/2016 John Aynsley, Doulos - Modify compile_riviera.do script to use the UVM 1.2 library supplied with Riviera
## 11/08/2016 John Aynsley, Doulos - Fix serious bug - the default env sequence was not being started for an agent that accessed a register model
## 05/10/2016 John Aynsley, Doulos - Don't use the monitor's analysis port outside of the agent. Use the agent's analysis port instead.
## 07/10/2016 John Aynsley, Doulos - Move assignment to m_item in function <agent>_coverage::write
## 07/10/2016 John Aynsley, Doulos - Move lines around in generated code for top_default_sequence
## 07/10/2016 John Aynsley, Doulos - Add an m_config member to every ${agent_name}_env_default_seq register sequence and assign before start
## 10/10/2016 John Aynsley, Doulos - Add an m_config member to every ${agent_name}_default_seq and assign before start
## 10/10/2016 John Aynsley, Doulos - Add an m_config member to every driver and monitor and assign in agent::connect
## Easier UVM Generator
use strict;
use warnings;
require 5.8.0;
use File::Copy::Recursive qw(dircopy);
use File::Copy "cp";
use File::stat;
my $VERNUM = "2017-01-19";
# Subroutine prototypes:
sub parse_cmdline;
sub usage;
sub parse_common;
sub after_parse_common;
sub parse_reg_template;
sub parse_template;
sub after_parse_template;
sub check_file;
sub check_inc_file;
sub check_common_pkg;
sub check_common_env_pkg;
sub gen_bfm;
sub gen_if;
sub gen_seq_item;
sub gen_driver;
sub gen_monitor;
sub gen_sequencer;
sub gen_config;
sub gen_cov;
sub gen_agent;
sub gen_env;
sub gen_seq_lib;
sub gen_env_seq_lib;
sub gen_agent_pkg;
sub gen_top_pkg;
sub gen_dut_inst;
sub gen_top;
sub gen_port_converter;
sub gen_ref_model;
sub gen_top_env;
sub gen_top_config;
sub gen_top_seq_lib;
sub gen_top_test;
sub gen_regmodel_adapter;
sub gen_regmodel_coverage;
sub gen_regmodel_seq_lib;
sub gen_questa_script;
sub gen_vcs_script;
sub gen_ius_script;
sub gen_riviera_script;
sub gen_compile_file_list;
sub get_pkg_name;
sub write_file_header;
# Scalar Variables:
my $agent_has_env;
my $agent_if;
my $agent_item;
my $agent_name;
my $agent_reset;
my $agent_seqr_class;
my $aname;
my $argnum;
my $author;
my $backup;
my $common_pkg;
my $common_pkg_fname;
my $common_env_pkg;
my $common_env_pkg_fname;
my $common_tpl_fname;
my $company;
my $continue_on_warning;
my $copyright;
my $date;
my $dept;
my $dir1;
my $dir2;
my $dir;
my $dual_top;
my $dut_iname;
my $dut_path;
my $dut_pfile;
my $dut_tb_dir;
my $dut_tb_path;
my $dut_top;
my $ele;
my $email;
my $env_clock_list;
my $env_reset_list;
my $field;
my $file_header_inc;
my $flag_dut_source_path;
my $flag_inc_path;
my $flag_project;
my $flag_regmodel_file;
my $flag_x;
my $flag_nopack;
my $comments_at_include_locations;
my $generate_file_header;
my $nested_config_objects;
my $i;
my $inc_file;
my $inc_path;
my $incdir;
my $name;
my $pf;
my $port_decl;
my $project;
my $reg_template;
my $regmodel;
my $regmodel_file;
my $split_transactors;
my $syosil_scoreboard_src_path;
my $top_reg_block_type;
my $tbname;
my $tb_inc_before_run_test;
my $tb_inc_before_run_test_inline;
my $tb_inc_inside_module;
my $tb_inc_inside_inline;
my $tb_generate_run_test;
my $tb_module_name;
my $tb_prepend_to_initial;
my $tb_prepend_to_initial_inline;
my $th_module_name;
my $tel;
my $template_list;
my $template_name;
my $th_generate_clock_and_reset;
my $th_inc_inside_module;
my $th_inc_inside_inline;
my $timeunit;
my $timeprecision;
my $test_generate_methods_inside_class;
my $test_generate_methods_after_class;
my $test_inc_before_class;
my $test_inc_before_inline;
my $test_inc_inside_class;
my $test_inc_inside_inline;
my $test_inc_after_class;
my $test_inc_after_inline;
my $test_prepend_to_build_phase;
my $test_prepend_to_build_phase_inline;
my $test_append_to_build_phase;
my $test_append_to_build_phase_inline;
my $top_env_config_append_to_new;
my $top_env_config_append_to_new_inline;
my $top_env_config_generate_methods_inside_class;
my $top_env_config_generate_methods_after_class;
my $top_default_seq_count;
my $top_env_config_inc_before_class;
my $top_env_config_inc_before_inline;
my $top_env_config_inc_inside_class;
my $top_env_config_inc_inside_inline;
my $top_env_config_inc_after_class;
my $top_env_config_inc_after_inline;
my $top_env_generate_methods_inside_class;
my $top_env_generate_methods_after_class;
my $top_env_generate_end_of_elaboration;
my $top_env_generate_run_phase;
my $top_env_inc_before_class;
my $top_env_inc_before_inline;
my $top_env_inc_inside_class;
my $top_env_inc_inside_inline;
my $top_env_inc_after_class;
my $top_env_inc_after_inline;
my $top_env_prepend_to_build_phase;
my $top_env_prepend_to_build_phase_inline;
my $top_env_append_to_build_phase;
my $top_env_append_to_build_phase_inline;
my $top_env_append_to_connect_phase;
my $top_env_append_to_connect_phase_inline;
my $top_env_append_to_run_phase;
my $top_env_append_to_run_phase_inline;
my $top_seq_inc;
my $top_seq_inc_inline;
my $uvm_cmdline;
my $uvm_reg_addr;
my $uvm_reg_data;
my $uvm_reg_kind;
my $var_decl;
my $year;
my $version;
# Hash Variables
my %agent_adapter_generate_methods_inside_class;
my %agent_adapter_generate_methods_after_class;
my %agent_adapter_inc_before_class;
my %agent_adapter_inc_before_inline;
my %agent_adapter_inc_inside_class;
my %agent_adapter_inc_inside_inline;
my %agent_adapter_inc_after_class;
my %agent_adapter_inc_after_inline;
my %agent_append_to_build_phase;
my %agent_append_to_build_phase_inline;
my %agent_append_to_connect_phase;
my %agent_append_to_connect_phase_inline;
my %agent_checks_enable;
my %agent_config_generate_methods_inside_class;
my %agent_config_generate_methods_after_class;
my %agent_config_inc_before_class;
my %agent_config_inc_before_inline;
my %agent_config_inc_inside_class;
my %agent_config_inc_inside_inline;
my %agent_config_inc_after_class;
my %agent_config_inc_after_inline;
my %agent_copy_config_vars;
my %agent_copy_config_vars_inline;
my %agent_cover_generate_methods_inside_class;
my %agent_cover_generate_methods_after_class;
my %agent_cover_inc;
my %agent_cover_inc_inline;
my %agent_cover_inc_before_class;
my %agent_cover_inc_before_inline;
my %agent_cover_inc_inside_class;
my %agent_cover_inc_inside_inline;
my %agent_cover_inc_after_class;
my %agent_cover_inc_after_inline;
my %agent_coverage_enable;
my %agent_driv_inc;
my %agent_driv_inc_inline;
my %agent_driv_inc_before_class;
my %agent_driv_inc_before_inline;
my %agent_driv_inc_inside_class;
my %agent_driv_inc_inside_inline;
my %agent_driv_inc_after_class;
my %agent_driv_inc_after_inline;
my %agent_env_prepend_to_build_phase;
my %agent_env_prepend_to_build_phase_inline;
my %agent_env_append_to_build_phase;
my %agent_env_append_to_build_phase_inline;
my %agent_env_append_to_connect_phase;
my %agent_env_append_to_connect_phase_inline;
my %agent_env_generate_methods_inside_class;
my %agent_env_generate_methods_after_class;
my %agent_env_inc_before_class;
my %agent_env_inc_before_inline;
my %agent_env_inc_inside_class;
my %agent_env_inc_inside_inline;
my %agent_env_inc_after_class;
my %agent_env_inc_after_inline;
my %agent_env_seq_inc;
my %agent_env_seq_inc_inline;
my %agent_factory_set;
my %agent_generate_methods_inside_class;
my %agent_generate_methods_after_class;
my %agent_is_active;
my %agent_inc_before_class;
my %agent_inc_before_inline;
my %agent_inc_inside_class;
my %agent_inc_inside_inline;
my %agent_inc_after_class;
my %agent_inc_after_inline;
my %agent_inc_inside_bfm;
my %agent_inc_inside_bfm_inline;
my %agent_mon_inc;
my %agent_mon_inc_inline;
my %agent_mon_inc_before_class;
my %agent_mon_inc_before_inline;
my %agent_mon_inc_inside_class;
my %agent_mon_inc_inside_inline;
my %agent_mon_inc_after_class;
my %agent_mon_inc_after_inline;
my %agent_parent;
my %agent_prepend_to_build_phase;
my %agent_prepend_to_build_phase_inline;
my %agent_seq_inc;
my %agent_seq_inc_inline;
my %agent_seqr_inc_before_class;
my %agent_seqr_inc_before_inline;
my %agent_seqr_inc_inside_class;
my %agent_seqr_inc_inside_inline;
my %agent_seqr_inc_after_class;
my %agent_seqr_inc_after_inline;
my %agent_item_types;
my %agent_trans_generate_methods_inside_class;
my %agent_trans_generate_methods_after_class;
my %agent_trans_inc_before_class;
my %agent_trans_inc_before_inline;
my %agent_trans_inc_inside_class;
my %agent_trans_inc_inside_inline;
my %agent_trans_inc_after_class;
my %agent_trans_inc_after_inline;
my %agent_type_by_inst;
my %bus2reg_map;
my %byo_interface;
my %enum_var_types;
my %env_agents;
my %generate_interface_instance;
my %if_inc_inside_interface;
my %if_inc_inside_inline;
my %if_instance_names; # Used to identify instances in the dut_pfile (the pinlist)
my %number_of_instances; # Number of instances required of each agent/interface
my %reg_access_block_type; # Type of uvm_reg_block class containing registers
my %reg_access_instance; # Object path of uvm_reg_block class containing registers, appended to regmodel. Should be an empty string or start with a dot
my %reg_access_map; # Instance of map within uvm_reg_block
my %reg_access_mode; # Register access mode WR WO RO
my %reg_cover_generate_methods_inside_class;
my %reg_cover_generate_methods_after_class;
my %reg_cover_inc;
my %reg_cover_inc_inline;
my %reg_cover_inc_before_class;
my %reg_cover_inc_before_inline;
my %reg_cover_inc_inside_class;
my %reg_cover_inc_inside_inline;
my %reg_cover_inc_after_class;
my %reg_cover_inc_after_inline;
my %ref_model;
my %ref_model_inputs;
my %ref_model_outputs;
my %ref_model_compare_method;
my %ref_model_inc_before_class;
my %ref_model_inc_before_inline;
my %ref_model_inc_inside_class;
my %ref_model_inc_inside_inline;
my %ref_model_inc_after_class;
my %ref_model_inc_after_inline;
my %top_factory_set;
my %tpl_fname;
my %unpacked_bound;
# Array Variables
my @additional_agents;
my @agent_clock_array;
my @agent_instance_names;
my @agent_list; # Array of all agent names
my @agent_port_array;
my @agent_reset_array;
my @agent_var_array;
my @agent_enum_array;
my @agent_meta_array;
my @agent_var_cnstr_array;
my @all_agent_ifs; # Array of all interface names, including the _if suffix (not the interface instance names)
my @clist;
my @common_config_var_array;
my @config_var_array;
my @elist;
my @env_list;
my @fields;
my @inc_path_list;
my @list;
my @all_tx_vars;
my @non_local_tx_vars;
my @non_meta_tx_vars;
my @non_reg_env;
my @reg_env;
my @rlist;
my @stand_alone_agents;
my @top_env_agents;
open( LOGFILE, ">easier_uvm_gen.log" );
print LOGFILE "\nEasier UVM Code Generator version ${VERNUM}"
. " (Send feedback to info\@doulos.com)\n";
set_default_values();
parse_cmdline();
parse_common();
after_parse_common();
deal_with_deprecated_reg_template();
handle_minus_x_flag();
#Only print this message after calling handle_minus_x_flag() in case handle_minus_x_flag() prints out one of the paths and exits the script
print "Easier UVM Code Generator version ${VERNUM}\n";
check_common_pkg($common_pkg_fname) if $common_pkg_fname;
check_common_env_pkg($common_env_pkg_fname) if $common_env_pkg_fname;
create_directories_and_copy_files();
# Process the agent templates (@list created by parse_cmdline)
print LOGFILE "\nParsing Templates ...\n\n";
foreach my $i ( 0 .. @list - 1) {
if ( $list[$i] ne "" ) {
$template_name = $list[$i];
printf LOGFILE "Reading[$i]: $list[$i]\n";
parse_template();
after_parse_template();
# Make the per-agent directories
$dir = "${project}/tb/${agent_name}";
printf LOGFILE "dir: $dir\n";
mkdir( $dir, 0755 );
mkdir( $dir . "/sv", 0755 );
print LOGFILE "Writing code to files\n";
# Create the agent files
gen_if();
if ( $split_transactors eq "YES") {
gen_bfm();
}
gen_seq_item();
gen_config();
gen_driver();
gen_monitor();
gen_sequencer();
gen_cov();
gen_agent();
gen_seq_lib();
# Do not generate env or env_seq_lib if regmodel used or $agent_has_env = no
do {
gen_env();
gen_env_seq_lib();
} unless ( exists $reg_access_mode{$agent_name} ) or $agent_has_env eq "NO";
gen_agent_pkg();
}
}
if ( $regmodel eq 1 ) {
gen_regmodel_pkg();
foreach my $agent ( keys(%reg_access_mode) ) {
$agent_name = $agent;
gen_env();
gen_regmodel_adapter();
gen_regmodel_coverage();
gen_regmodel_seq_lib();
}
}
extra_checking_for_additional_agents();
print LOGFILE "top env agents = @top_env_agents\n";
print LOGFILE "Generating testbench in ${project}/tb\n";
print "Generating testbench in ${project}/tb\n";
gen_top_config();
gen_port_converter();
foreach my $ref_model_name ( keys(%ref_model) ) {
gen_ref_model($ref_model_name);
}
gen_top_env();
gen_top_seq_lib();
gen_top_pkg();
gen_top_test();
gen_top();
print "Generating simulator scripts in ${project}/sim\n";
print LOGFILE "Generating simulator scripts in ${project}/sim\n";
deal_with_files_f();
gen_questa_script();
gen_vcs_script();
gen_ius_script();
gen_riviera_script();
print_structure();
print LOGFILE "Code Generation complete\n";
# ---------- Subroutines -------------------------------------------------
sub set_default_values {
$date = localtime;
$project = "generated_tb";
$backup = "yes";
$version = "1.0";
$inc_path = "include";
$inc_file = "";
$dut_path = "dut";
$common_pkg = "";
$common_pkg_fname = "";
$common_env_pkg = "";
$common_env_pkg_fname = "";
$common_tpl_fname = "common.tpl";
$agent_name = "";
$agent_if = "";
$agent_item = "";
$dut_iname = "uut"; #instance name of dut in tb
$timeunit = "1ns";
$timeprecision = "1ps";
$regmodel = 0;
$dut_top = ""; #top level dut module
$dut_pfile = "pinlist"; #dut port list file
$uvm_cmdline = "";
$top_default_seq_count = undef;
$env_reset_list = "";
$env_clock_list = "";
$tbname = undef;
$regmodel_file = "regmodel.sv";
$top_reg_block_type = undef;
$syosil_scoreboard_src_path = undef;
$template_name = "example.tpl"; #default template name
$template_list = ""; #default template list
$reg_template = undef;
$dual_top = "NO";
$split_transactors = "NO";
}
sub parse_cmdline {
print LOGFILE "\nParsing cmdline ...\n\n";
print LOGFILE "num args is " . $#ARGV . "\n";
if ( $#ARGV == -1 ) { usage(); } ### no arguments, print help and exit
###if ($ARGV[$argnum] =~ m/\s*help/i)
if ( $ARGV[0] =~ m/\s*(-help|-hel|-he|-h)/i ) {
usage();
}
my $pnum_c = -2;
my $pnum_r = -2;
my $pnum_p = -2;
my $pnum_m = -2;
my $pnum_s = -2;
my $pnum_n = -2;
$continue_on_warning = 0;
# Searching for -x dut_source_path, -x inc_path, and -x project flag
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-x)/i ) {
if ( $ARGV[ $argnum + 1 ] eq "dut_source_path" ) {
$flag_x = 1;
$flag_dut_source_path = 1;
}
if ( $ARGV[ $argnum + 1 ] eq "inc_path" ) {
$flag_x = 1;
$flag_inc_path = 1;
}
if ( $ARGV[ $argnum + 1 ] eq "project" ) {
$flag_x = 1;
$flag_project = 1;
}
if ( $ARGV[ $argnum + 1 ] eq "regmodel_file" ) {
$flag_x = 1;
$flag_regmodel_file = 1;
}
}
}
# Searching for "continue on critical warnings" flag
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-c)/i ) {
$pnum_c = $argnum;
$continue_on_warning = 1;
printf LOGFILE "Code generation will continue if critical warnings are issued\n";
printf LOGFILE "pnum_c: $pnum_c\n";
}
}
# Searching for register flag
printf LOGFILE "Searching for regmodel flag\n";
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-r)/i ) {
$regmodel = 1;
$pnum_r = $argnum;
printf LOGFILE
"regmodel: $regmodel, Register layer will be included\n";
printf LOGFILE "pnum_r: $pnum_r\n";
}
}
# Searching for project name
printf LOGFILE "Searching for prefix\n";
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-p)/i ) {
$tbname = $ARGV[ $argnum + 1 ];
$pnum_p = $argnum;
printf LOGFILE "prefix: $tbname\n";
printf LOGFILE "pnum_p: $pnum_p\n";
}
}
# Searching for common template filename
printf LOGFILE "Searching for common template\n";
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-m)/i ) {
$common_tpl_fname = $ARGV[ $argnum + 1 ];
$pnum_m = $argnum;
printf LOGFILE "common_tpl_fname: $common_tpl_fname\n";
printf LOGFILE "pnum_m: $pnum_m\n";
}
}
# Searching for Syosil scoreboard path
printf LOGFILE "Searching for Syosil scoreboard path\n";
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-s)/i ) {
$syosil_scoreboard_src_path = $ARGV[ $argnum + 1 ];
$pnum_s = $argnum;
printf LOGFILE "syosil_scoreboard_src_path: $syosil_scoreboard_src_path\n";
printf LOGFILE "pnum_s: $pnum_s\n";
}
}
# Searching for -nopack flag
foreach $argnum ( 0 .. $#ARGV) {
if ( $ARGV[$argnum] =~ m/\s*(-nopack)/i ) {
$flag_nopack = 1;
$pnum_n = $argnum;
}
}
# searching for template (agent) names
printf LOGFILE "Searching for templates\n";
foreach $argnum ( 0 .. $#ARGV) {
if ( $argnum != $pnum_c &&
$argnum != $pnum_r &&
$argnum != $pnum_p && $argnum != $pnum_p + 1 &&
$argnum != $pnum_m && $argnum != $pnum_m + 1 &&
$argnum != $pnum_s && $argnum != $pnum_s + 1 &&
$argnum != $pnum_n ) {
#check for template name
if ( $ARGV[$argnum] =~
m/\s*(-template|-templat|-templa|-templ|-tem|-te|-t)/i )
{
print LOGFILE "template: $ARGV[$argnum]\n";
}
else {
if ( $ARGV[$argnum] ne "reg.tpl" ) {
$template_list = "$template_list $ARGV[$argnum]";
#print LOGFILE "T_List: $template_list\n";
}
else {
$reg_template = $ARGV[$argnum];
}
}
print LOGFILE "T_List: $template_list\n";
if ( $ARGV[$argnum] =~ m/\s*(-help|-hel|-he|-h)/i ) {
usage();
}
}
@list = split /\s+/, $template_list;
foreach $i ( 0 .. @list-1 ) {
if ( $list[$i] ne "" ) {
printf LOGFILE "List: $list[$i]\n";
}
}
}
@list or die "ERROR! You must specify at least 1 template file)\n";
}
sub usage {
print "\n";
print "USAGE: perl easier_uvm_gen.pl [-t] <filename> <filename> ... list of template file names\n";
print "\n";
print " -p <top> Prefix used to construct names associated with top-level env, default is top\n";
print " -m <filename> Path to common template file, default is common.tpl\n";
print " -s <path> Path to source files for Syosil scoreboard (overrides syosil_scoreboard_src_path in common template)\n";
print " -c The code generator will continue after warnings\n";
print " -r Causes a register model to be instantiated in the generated code (switch is no longer necessary}\n";
print " -x dut_source_path Returns the value of the dut_source_path setting\n";
print " -x inc_path Returns the value of the inc_path setting\n";
print " -x project Returns the value of the project setting\n";
print " -x regmodel_file Returns the value of the regmodel_file setting\n";
print " -nopack Suppresses generation of do_pack & do_unpack methods for backward compatibility\n";
print "\n";
exit;
} # end sub usage
sub parse_common {
my $template_name = $common_tpl_fname;
@common_config_var_array = ();
open( TH, $template_name )
|| die "Exiting due to Error: can't open template: ${template_name}\n";
print LOGFILE "Parsing common : $template_name ...\n\n";
for ( ; ; ) {
my $line;
undef $!;
unless ( defined( $line = <TH> ) ) {
die $! if $!;
last; # reached EOF
}
next if ( $line =~ m/^\s*#/ ); #comment line starts with "#"
next if ( $line =~ m/^\s+$/ ); #blank line
$line =~ s/(^.*?)#.*/$1/; #delete trailing comments
$line =~ /^\s*(\w+)\s*=\s*(.+?)\s*$/
or die "Exiting due to Error: bad entry in line $. of ${common_tpl_fname}: $line\n";
my $param_name = $1;
my $param_value = $2;
#check for dut path
if ( $param_name =~ /dut_source_path/i ) {
$dut_path = $param_value;
print LOGFILE "dut_path: $dut_path\n";
}
#check for include paths
if ( $param_name =~ /^\s*inc_path/i ) {
$inc_path = $param_value;
}
#check for project
if ( $param_name =~ /project/i ) {
$project = $param_value;
print LOGFILE "Project: $project\n";
}
#check for regmodel file
if ( $param_name =~ /regmodel_file/i) {
unless (defined($flag_x)) {
check_file($param_value);
}
$regmodel_file = $param_value;
print LOGFILE "regmodel_file: $regmodel_file\n";
}
#check for top-level regmodel type
if ( $param_name =~ /top_reg_block_type/i) {
$top_reg_block_type = $param_value;
print LOGFILE "top_reg_block_type: $top_reg_block_type\n";
}
# Don't parse the rest of the settings if called with the -x switch
unless (defined($flag_x)) {
if ( $param_name =~ /prefix/i ) {
unless ( defined $tbname ) {
$tbname = $param_value;
print LOGFILE "Prefix: $tbname\n";
}
}
if ( $param_name =~ /backup/i ) {
$backup = uc $param_value;
print LOGFILE "Backup: $backup\n";
}
if ( $param_name =~ /comments_at_include_locations/i ) {
$comments_at_include_locations = uc $param_value;
print LOGFILE "comments_at_include_locations = $comments_at_include_locations\n";
}
if ( $param_name =~ /copyright/i ) {
$copyright = $param_value;
print LOGFILE "$copyright\n";
}
if ( $param_name =~ /^\s*name/i ) {
$author = $param_value;
print LOGFILE "Name: $author\n";
}
if ( $param_name =~ /email/i ) {
$email = $param_value;
print LOGFILE "email: $email\n";
}
if ( $param_name =~ /tel/i ) {
$tel = $param_value;
print LOGFILE "Tel: $tel\n";
}
if ( $param_name =~ /dept/i ) {
$dept = $param_value;
print LOGFILE "dept: $dept\n";
}
if ( $param_name =~ /company/i ) {
$company = $param_value;
print LOGFILE "company: $dept\n";
}
if ( $param_name =~ /year/i ) {
$year = $param_value;
print LOGFILE "year: $year\n";
}
if ( $param_name =~ /version/i ) {
$version = $param_value;
print LOGFILE "version : $version\n";
}
if ( $param_name =~ /dut_top/i ) {
$dut_top = $param_value;
print LOGFILE "dut_top: $dut_top\n";
}
if ( $param_name =~ /dut_iname/i ) {
$dut_iname = $param_value;
print LOGFILE "dut instance name: $dut_iname\n";
}
if ( $param_name =~ /dut_pfile/i ) {
$dut_pfile = $param_value;
print LOGFILE "dut_pfile: $dut_pfile\n";
}
if ( $param_name =~ /timeunit/i ) {
$timeunit = $param_value;
print LOGFILE "timeunit: $timeunit\n";
}
if ( $param_name =~ /timeprecision/i ) {
$timeprecision = $param_value;
print LOGFILE "timeprecision: $timeprecision\n";
}
if ( $param_name =~ /uvm_cmdline/i ) {
$uvm_cmdline = $uvm_cmdline ? "$uvm_cmdline $param_value" : $param_value;
print LOGFILE "uvm_cmdline: $uvm_cmdline\n";
}
if ( $param_name =~ /nested_config_objects/i ) {
$nested_config_objects = uc $param_value;
print LOGFILE "nested_config_objects = $param_value\n";
}
if ( $param_name =~ /common_pkg/i ) {
$common_pkg_fname = $param_value;
print LOGFILE "common package file name: $common_pkg_fname\n";
}
if ( $param_name =~ /common_env_pkg/i ) {
$common_env_pkg_fname = $param_value;
print LOGFILE "common env package file name: $common_env_pkg_fname\n";
}
if ( $param_name =~ /tb_inc_inside_module/i ) {
$param_value =~ /\s*([\w\.\/]+)\s*(,|\s)?\s*(\w*)/
or die "Exiting due to Error: bad entry in line $. of ${template_name}: $line\n";
check_inc_file($1);
$tb_inc_inside_module = $1;
$tb_inc_inside_inline = $3 if ($3);
print LOGFILE "tb_inc_inside_module = $param_value\n";
}
if ( $param_name =~ /tb_inc_before_run_test/i ) {
$param_value =~ /\s*([\w\.\/]+)\s*(,|\s)?\s*(\w*)/
or die "Exiting due to Error: bad entry in line $. of ${template_name}: $line\n";
check_inc_file($1);
$tb_inc_before_run_test = $1;
$tb_inc_before_run_test_inline = $3 if ($3);
print LOGFILE "tb_inc_before_run_test = $param_value\n";
}
if ( $param_name =~ /tb_prepend_to_initial/i ) {
$param_value =~ /\s*([\w\.\/]+)\s*(,|\s)?\s*(\w*)/
or die "Exiting due to Error: bad entry in line $. of ${template_name}: $line\n";
check_inc_file($1);
$tb_prepend_to_initial = $1;
$tb_prepend_to_initial_inline = $3 if ($3);
print LOGFILE "tb_prepend_to_initial = $param_value\n";
}
if ( $param_name =~ /tb_generate_run_test/i ) {
$tb_generate_run_test = uc $param_value;
print LOGFILE "tb_generate_run_test = $param_value\n";