-
Notifications
You must be signed in to change notification settings - Fork 15
/
OsvvmScriptsCore.tcl
2254 lines (1929 loc) · 73.4 KB
/
OsvvmScriptsCore.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File Name: OsvvmScriptsCore.tcl
# Purpose: Scripts for running simulations
# Revision: OSVVM MODELS STANDARD VERSION
#
# Maintainer: Jim Lewis email: [email protected]
# Contributor(s):
# Jim Lewis email: [email protected]
# Markus Ferringer Patterns for error handling and callbacks, ...
#
# Description
# Tcl procedures with the intent of making running
# compiling and simulations tool independent
#
# Developed by:
# SynthWorks Design Inc.
# VHDL Training Classes
# OSVVM Methodology and Model Library
# 11898 SW 128th Ave. Tigard, Or 97223
# http://www.SynthWorks.com
#
# Revision History:
# Date Version Description
# 7/2024 2024.07 Updated LocalInclude to better restore state if it fails
# Fixed settings in SetLogSignals.
# 5/2024 2024.05 Updated for refactor of Simulate2Html. Renamed in prep for breaking file into smaller chunks.
# 3/2024 2024.03 Updated CreateOsvvmScriptSettingsPkg and added FindOsvvmSettingsDirectory
# 9/2023 2023.09 Updated messaging for file not found by build/include
# Made UnsetLibraryVars visible
# 7/2023 2023.07 Added calls to MergeRequirements and Requirements2Html
# 1/2023 2023.01 Added options for CoSim
# 12/2022 2022.12 Minor update to StartUp
# 09/2022 2022.09 Added RemoveLibrary, RemoveLibraryDirectory, OsvvmLibraryPath
# Added SetVhdlAnalyzeOptions, SetExtendedAnalyzeOptions, SetExtendedSimulateOptions
# Added (for GHDL) SetSaveWaves, SetExtendedElaborateOptions, SetExtendedRunOptions
# Added SetInteractiveMode, SetDebugMode, SetLogSignals
# 08/2022 2022.08 Added handling for Analyze with Verilog Libraries.
# Added SetSecondSimulationTopLevel, GetSecondSimulationTopLevel
# 06/2022 2022.06 Generic handling. Fixed spaces in library path.
# 05/2022 2022.05 Refactored to move variable settings to OsvvmDefaultSettings
# Added Error Handling
# 02/2022 2022.02 Added Analyze and Simulate Coverage and Extended Options
# Added support to run code coverage
# 01/2022 2022.01 Library directory to lower case. Added OptionalCommands to Verilog analyze.
# Writing of FC summary now in VHDL. Added DirectoryExists
# 12/2021 2021.12 Refactored for library handling. Changed to relative paths.
# 10/2021 2021.10 Added calls to Report2Html, Report2JUnit, and Simulate2Html
# 3/2021 2021.03 Updated printing of start/finish times
# 2/2021 2021.02 Updated initialization of libraries
# Analyze allows ".vhdl" extensions as well as ".vhd"
# Include/Build signal error if nothing to run
# Added SetVHDLVersion / GetVHDLVersion to support 2019 work
# Added SetSimulatorResolution / GetSimulatorResolution to support GHDL
# Added beta of LinkLibrary to support linking in project libraries
# Added beta of SetLibraryDirectory / GetLibraryDirectory
# Added beta of ResetRunLibrary
# 7/2020 2020.07 Refactored tool execution for simpler vendor customization
# 1/2020 2020.01 Updated Licenses to Apache
# 2/2019 Beta Project descriptors in .pro which execute
# as TCL scripts in conjunction with the library
# procedures
# 11/2018 Alpha Project descriptors in .files and .dirs files
#
#
# This file is part of OSVVM.
#
# Copyright (c) 2018 - 2024 by SynthWorks Design Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -------------------------------------------------
# StartUp
# re-run the startup scripts, this program included
#
proc StartUp {} {
puts "source $::osvvm::OsvvmScriptDirectory/StartUpShared.tcl"
eval "source $::osvvm::OsvvmScriptDirectory/StartUpShared.tcl"
}
namespace eval ::osvvm {
# -------------------------------------------------
# IterateFile
# do an operation on a list of items
#
proc IterateFile {FileWithNames ActionForName} {
# puts "$FileWithNames"
set FileHandle [open $FileWithNames]
set ListOfNames [split [read $FileHandle] \n]
close $FileHandle
foreach OneName $ListOfNames {
# skip blank lines
if {[string length $OneName] > 0} {
# use # as comment character
if {[string index $OneName 0] ne "#"} {
puts "$ActionForName ${OneName}"
# will break $OneName into individual pieces for handling
eval $ActionForName ${OneName}
# leaves $OneName as a single string
# $ActionForName ${OneName}
} else {
# handle other file formats
if {[lindex $OneName 1] eq "library"} {
eval library [lindex $OneName 2]
}
}
}
}
}
proc PrintWithPrefix {Prefix RawMessageList} {
foreach Message [split $RawMessageList \n] {
# Remove Prefix if already exists
# set NoPrefixMessage [regsub -nocase "^$Prefix " $Message ""]
# puts "$Prefix $NoPrefixMessage"
if {[regexp -nocase "$Prefix" $Message]} {
puts "$Message"
} else {
puts "$Prefix $Message"
}
}
}
# -------------------------------------------------
# FindIncludeFile
# finds an include file using directory, file base name, or file with extension to locate the file
#
proc FindIncludeFile {Path_Or_File} {
set JoinName [file join ${::osvvm::CurrentWorkingDirectory} ${Path_Or_File}]
set NormName [ReducePath $JoinName]
# Normalize to handle ".." and "."
set NameToHandle [file tail [file normalize $NormName]]
if {[file isfile $NormName]} {
return $NormName
} else {
if {[file isdirectory $NormName]} {
# Path_Or_File is directory name
set FileBaseName ${NormName}/[file rootname ${NameToHandle}]
} else {
# Path_Or_File is file name without an extension
set FileBaseName ${NormName}
}
# Determine which if any project files exist
set FileProName ${FileBaseName}.pro
set BuildProName [file join $NormName build.pro]
set FileTclName ${FileBaseName}.tcl
set FileDoName ${FileBaseName}.do
set FileDirsName ${FileBaseName}.dirs
set FileFilesName ${FileBaseName}.files
if {[file isfile ${FileProName}]} {
return ${FileProName}
} elseif {[file isfile ${BuildProName}]} {
return ${BuildProName}
} elseif {[file isfile ${FileTclName}]} {
return ${FileTclName}
} elseif {[file isfile ${FileDoName}]} {
return ${FileDoName}
} elseif {[file isfile ${FileDirsName}]} {
return ${FileDirsName}
} elseif {[file isfile ${FileFilesName}]} {
return ${FileFilesName}
} else {
error $Path_Or_File
}
}
}
# -------------------------------------------------
# include
# finds and sources a project file
#
proc include {Path_Or_File args} {
variable CurrentWorkingDirectory
CallbackBefore_Include $Path_Or_File
puts "include $Path_Or_File $args" ; # EchoOsvvmCmd
set FindFileErrorCode [catch {set IncludeFile [FindIncludeFile $Path_Or_File]} FindErrMsg]
if {$FindFileErrorCode != 0} {
CallbackOnError_FindIncludeFile $Path_Or_File include
} else {
LocalInclude $IncludeFile {*}$args
}
CallbackAfter_Include $Path_Or_File
}
proc LocalInclude {PathAndFile args} {
variable CurrentWorkingDirectory
# probably remove. Redundant with analyze and simulate
# If a library does not exist, then create the default
CheckLibraryExists
# Save CurrentWorkingDirectory, $::argv0, $::argv, $::argc
set SaveCurrentWorkingDirectory ${CurrentWorkingDirectory}
if {[info exists ::argv]} {
set SaveArgv0 $::argv0
set SaveArgv $::argv
set SaveArgc $::argc
} else {
set SaveArgv0 0
set SaveArgv 0
set SaveArgc 0
}
set ::argv0 [file tail $PathAndFile]
set ::argv $args
set ::argc [llength $args]
set ::ARGC $::argc
set ::ARGV(0) $::argv0
set index 1
foreach arg $::argv {set ::ARGV($index) $arg ; incr index 1}
set IncludeErrorCode [catch {LocalRunInclude $PathAndFile {*}$args} IncludeErrMsg]
set IncludeErrorInfo $::errorInfo
# Restore CurrentWorkingDirectory, $::argv0, $::argv, $::argc
set CurrentWorkingDirectory ${SaveCurrentWorkingDirectory}
set ::argv0 $SaveArgv0
set ::argv $SaveArgv
set ::argc $SaveArgc
set ::ARGC $::argc
set ::ARGV(0) $::argv0
set index 1
foreach arg $::argv {set ::ARGV($index) $arg ; incr index 1}
# Re-signal error after restoring CurrentWorkingDirectory and argv ...
if {$IncludeErrorCode != 0} {
error $IncludeErrMsg $IncludeErrorInfo
}
}
proc LocalRunInclude {PathAndFile args} {
variable CurrentWorkingDirectory
# Use the RootDir of PathAndFile as the CurrentWorkingDirectory
set RootDir [file dirname $PathAndFile]
puts "set CurrentWorkingDirectory ${RootDir}"
set CurrentWorkingDirectory ${RootDir}
# Handle the file based on its extension
set FileExtension [file extension $PathAndFile]
if {$FileExtension eq ".pro" || $FileExtension eq ".tcl"} {
puts "source ${PathAndFile}"
source ${PathAndFile}
} elseif {$FileExtension eq ".do"} {
# Do files can be simulator specific and require the simulator "do" to run them
puts "do ${PathAndFile}"
do ${PathAndFile}
} elseif {$FileExtension eq ".dirs"} {
# Path_Or_File is <name>.dirs
puts "IterateFile ${PathAndFile} include"
IterateFile ${PathAndFile} "include"
} else {
# was elseif {$FileExtension eq ".files"}
# Path_Or_File is <name>.files or other extension
puts "IterateFile ${PathAndFile} analyze"
IterateFile ${PathAndFile} "analyze"
}
}
# -------------------------------------------------
# BeforeBuildCleanUp
#
proc BeforeBuildCleanUp {} {
variable RanSimulationWithCoverage "false"
variable vendor_simulate_started
variable TestCaseName
variable TestSuiteName
variable TranscriptYamlFile
variable AnalyzeErrorCount 0
variable ConsecutiveAnalyzeErrors 0
variable SimulateErrorCount 0
variable ConsecutiveSimulateErrors 0
variable ScriptErrorCount 0
# Close any previous build information
if {[info exists TestCaseName]} {
unset TestCaseName
}
if {[info exists TestSuiteName]} {
unset TestSuiteName
}
# If Files Open, then Close them
# CloseAllFiles ; # oddly Questa has a number of files open already
# End simulation if one was started - only set by simulate - closes any open files
if {[info exists vendor_simulate_started]} {
puts "Ending Previous Simulation"
EndSimulation
unset vendor_simulate_started
}
# Remove old files if they were left lying around
if {[file exists ${TranscriptYamlFile}]} {
file delete -force -- ${TranscriptYamlFile}
}
set ::osvvm::CurrentWorkingDirectory ""
}
# -------------------------------------------------
proc SetBuildName {Path_Or_File} {
# Create the Log File Name
# Normalize to elaborate names, especially when Path_Or_File is "."
set NormPathOrFile [file normalize ${Path_Or_File}]
set NormDir [file dirname $NormPathOrFile]
set NormDirName [file tail $NormDir]
set NormTail [file tail $NormPathOrFile]
set NormTailRoot [file rootname $NormTail]
if {$NormDirName eq $NormTailRoot} {
# <Parent Dir>_<Script Name>.log
# set BuildName [file tail [file dirname $NormDir]]_${NormTailRoot}
# <Script Name>.log
set BuildName ${NormTailRoot}
} else {
# <Dir Name>_<Script Name>.log
set BuildName ${NormDirName}_${NormTailRoot}
}
return $BuildName
}
# -------------------------------------------------
# build
#
proc build {{Path_Or_File "."} args} {
variable AnalyzeErrorCount
variable SimulateErrorCount
variable ScriptErrorCount
variable BuildErrorInfo
variable Log2ErrorInfo
variable BuildStarted
variable BuildName
variable BuildErrorCode 0
if {$BuildStarted} {
include $Path_Or_File $args
} else {
set FindFileErrorCode [catch {set IncludeFile [FindIncludeFile $Path_Or_File]} FindErrMsg]
if {$FindFileErrorCode != 0} {
# With error handling here, directories do not get created if cannot find Path_Or_File
CallbackOnError_FindIncludeFile $Path_Or_File Build
} else {
BeforeBuildCleanUp
set BuildStarted "true"
# set BuildName [SetBuildName $Path_Or_File]
set BuildName [SetBuildName $IncludeFile]
set ::osvvm::LastBuildName $BuildName
StartTranscript ${BuildName}
# Catch any errors from the build and handle them below
set BuildErrorCode [catch {LocalBuild $BuildName $IncludeFile {*}$args} BuildErrMsg]
set LocalBuildErrorInfo $::errorInfo
set ReportYamlErrorCode [catch {FinishBuildYaml $BuildName} BuildYamlErrMsg]
set LocalBuildYamlErrorInfo $::errorInfo
set BuildStarted "false"
# Try to create reports, even if the build failed
set ReportErrorCode [catch {AfterBuildReports $BuildName} ReportsErrMsg]
set LocalReportErrorInfo $::errorInfo
StopTranscript ${BuildName}
set BuildName ""
# Cannot generate html log files until transcript is closed - previous step
set Log2ErrorCode [catch {Log2Osvvm $::osvvm::TranscriptFileName} ReportsErrMsg]
set Log2ErrorInfo $::errorInfo
# Run Callbacks on Error after trying to produce all reports
if {$BuildErrorCode != 0 || $AnalyzeErrorCount > 0 || $SimulateErrorCount > 0} {
CallbackOnError_Build $Path_Or_File $BuildErrMsg $LocalBuildErrorInfo
}
if {($ReportErrorCode != 0) || ($ScriptErrorCount != 0)} {
CallbackOnError_AfterBuildReports $LocalReportErrorInfo
}
# Fail on Test Case Errors
if {($::osvvm::BuildStatus eq "FAILED") && ($::osvvm::FailOnTestCaseErrors)} {
error "Test finished with Test Case Errors"
}
# Fail on Report / Script Errors?
if {($ReportYamlErrorCode != 0) || ($ReportErrorCode != 0) || ($Log2ErrorCode != 0) || ($ScriptErrorCount != 0)} {
# End Simulation with errors
if {$::osvvm::FailOnReportErrors} {
error "Test finished with either Report or Script (wave.do) errors."
}
}
}
}
}
proc LocalBuild {BuildName Path_Or_File args} {
variable TestSuiteStartTimeMs
variable RanSimulationWithCoverage
variable TestSuiteName
variable OutputBaseDirectory
puts "" ; # ensure that the next print is at the start of a line
puts "build $Path_Or_File" ; # EchoOsvvmCmd
CopyHtmlThemeFiles ${::osvvm::OsvvmScriptDirectory} ${::osvvm::OutputBaseDirectory} $::osvvm::HtmlThemeSubdirectory
StartBuildYaml $BuildName
CallbackBefore_Build ${Path_Or_File}
LocalInclude ${Path_Or_File} {*}$args
CallbackAfter_Build ${Path_Or_File}
if {[info exists TestSuiteName]} {
# Finalize Test Suite
set RequirementsSourceDir [file join ${::osvvm::ReportsDirectory} ${TestSuiteName}]
set RequirementsResultsFile [file join ${::osvvm::ReportsDirectory} ${BuildName} ${TestSuiteName}_req.yml]
MergeRequirements $RequirementsSourceDir $RequirementsResultsFile
Requirements2Html $RequirementsResultsFile "../"
FinalizeTestSuite $TestSuiteName
FinishTestSuiteBuildYaml
unset TestSuiteName
}
# Finalize Build
set RequirementsSourceDir [file join ${::osvvm::ReportsDirectory} ${BuildName}]
set RequirementsResultsFile [file join ${::osvvm::ReportsDirectory} ${BuildName}_req.yml]
MergeRequirements $RequirementsSourceDir $RequirementsResultsFile
Requirements2Html $RequirementsResultsFile
Requirements2Csv $RequirementsResultsFile
if {$RanSimulationWithCoverage eq "true"} {
vendor_MergeCodeCoverage $BuildName $::osvvm::CoverageDirectory ""
vendor_ReportCodeCoverage $BuildName $::osvvm::CoverageDirectory
}
}
proc AfterBuildReports {BuildName} {
# short sleep to allow the file to close
after 1000
set BuildYamlFile [file join ${::osvvm::OutputBaseDirectory} ${BuildName}.yml]
file rename -force ${::osvvm::OsvvmBuildYamlFile} ${BuildYamlFile}
CreateBuildReports ${BuildYamlFile}
# ReportBuildYaml2Dict ${BuildYamlFile}
# ReportBuildDict2Html
# ReportBuildDict2Junit
if {($::osvvm::SimulateInteractive) && ($::osvvm::OpenBuildHtmlFile)} {
OpenBuildHtml ${BuildName}
}
ReportBuildStatus
}
proc OpenBuildHtml {{BuildName ""}} {
if {$BuildName eq ""} {
set BuildName $::osvvm::LastBuildName
}
set BuildHtmlFile [file join ${::osvvm::OutputBaseDirectory} ${BuildName}.html]
if {![catch {info body vendor_OpenBuildHtml} err]} {
vendor_OpenBuildHtml $BuildHtmlFile $BuildName
} else {
DefaultVendor_OpenBuildHtml $BuildHtmlFile
}
}
proc DefaultVendor_OpenBuildHtml {BuildHtmlFile} {
if {[regexp {[Ww]indows} $::env(OS)]} {
exec {*}[auto_execok start] "$BuildHtmlFile"
}
}
# -------------------------------------------------
# CreateDirectory - Create directory if does not exist
#
proc CreateDirectory {Directory} {
if {![file isdirectory $Directory]} {
puts "creating directory $Directory"
file mkdir $Directory
}
}
# -------------------------------------------------
# CheckWorkingDir
# Used by library, analyze, and simulate
#
proc CheckWorkingDir {} {
variable CurrentSimulationDirectory
variable VhdlLibraryParentDirectory
variable VhdlWorkingLibrary
variable LibraryList
variable LibraryDirectoryList
set CurrentDir [pwd]
if {$CurrentSimulationDirectory ne $CurrentDir } {
if {$VhdlLibraryParentDirectory eq $CurrentSimulationDirectory} {
# Simulation Directory Moved, Set Library to current directory
SetLibraryDirectory $CurrentDir
if {[info exists VhdlWorkingLibrary]} {
unset VhdlWorkingLibrary
}
if {[info exists LibraryList]} {
unset LibraryList
unset LibraryDirectoryList
}
}
puts "set CurrentSimulationDirectory $CurrentDir"
set CurrentSimulationDirectory $CurrentDir
if {${::osvvm::OutputBaseDirectory} ne ""} {
CreateDirectory ${::osvvm::OutputBaseDirectory}
}
}
}
# -------------------------------------------------
# CheckLibraryInit
# Used by library
#
proc CheckLibraryInit {} {
variable VhdlLibraryParentDirectory
variable VhdlLibraryFullPath
if { [file tail ${VhdlLibraryParentDirectory}] eq $::osvvm::InvalidLibraryDirectory} {
set VhdlLibraryParentDirectory [pwd]
}
if { ${VhdlLibraryParentDirectory} eq [pwd]} {
# Local Library Directory - use OutputBaseDirectory
set VhdlLibraryFullPath [file join ${VhdlLibraryParentDirectory} ${::osvvm::OutputBaseDirectory} ${::osvvm::VhdlLibraryDirectory} ${::osvvm::VhdlLibrarySubdirectory}]
} else {
# Global Library Directory - do not use OutputBaseDirectory
set VhdlLibraryFullPath [file join ${VhdlLibraryParentDirectory} ${::osvvm::VhdlLibraryDirectory} ${::osvvm::VhdlLibrarySubdirectory}]
}
}
# -------------------------------------------------
# CheckLibraryExists
# Used by analyze, and simulate
#
proc CheckLibraryExists {} {
variable VhdlWorkingLibrary
if {![info exists VhdlWorkingLibrary]} {
library $::osvvm::DefaultLibraryName
}
}
# -------------------------------------------------
# CheckSimulationDirs
# Used by simulate
#
proc CheckSimulationDirs {} {
variable CurrentSimulationDirectory
CreateDirectory [file join ${CurrentSimulationDirectory} ${::osvvm::ResultsDirectory}]
CreateDirectory [file join ${CurrentSimulationDirectory} ${::osvvm::ReportsDirectory}]
CreateDirectory [file join ${CurrentSimulationDirectory} ${::osvvm::ReportsDirectory} ${::osvvm::BuildName}]
CreateDirectory [file join ${CurrentSimulationDirectory} ${::osvvm::OsvvmTemporaryOutputDirectory}]
if {$::osvvm::CoverageEnable && $::osvvm::CoverageSimulateEnable} {
CreateDirectory [file join $CurrentSimulationDirectory $::osvvm::CoverageDirectory $::osvvm::TestSuiteName]
}
}
# -------------------------------------------------
# ReducePath
# Remove "." and ".." from path
#
proc ReducePath {PathIn} {
set CharCount 0
set NewPath {}
foreach item [file split $PathIn] {
if {$item ne ".."} {
if {$item ne "."} {
lappend NewPath $item
incr CharCount 1
}
} else {
if {$CharCount >= 1} {
set NewPath [lreplace $NewPath end end]
incr CharCount -1
} else {
lappend NewPath $item
}
}
}
if {$NewPath eq ""} {
set NewPath "."
}
return [eval file join $NewPath]
}
# -------------------------------------------------
# StartTranscript
# Used by build
#
proc StartTranscript {FileBaseName} {
CheckWorkingDir
set TempTranscriptName [file join ${::osvvm::CurrentSimulationDirectory} ${::osvvm::OsvvmBuildLogFile}]
if {![catch {info body vendor_StartTranscript} err]} {
vendor_StartTranscript $TempTranscriptName
} else {
DefaultVendor_StartTranscript $TempTranscriptName
}
}
proc DefaultVendor_StartTranscript {FileName} {
if {$::osvvm::GotTee} {
set LogFile [open ${FileName} w]
tee channel stderr $LogFile
tee channel stdout $LogFile
} else {
set LogFile [open ${FileName} w]
puts $LogFile "Log files do not currently work in these tools"
close $LogFile
}
}
# -------------------------------------------------
# StopTranscript
# Used by build
#
proc StopTranscript {{FileBaseName ""}} {
variable TranscriptFileName
flush stdout
set FullPathLogDirectory [file join ${::osvvm::CurrentSimulationDirectory} ${::osvvm::OutputBaseDirectory} ${::osvvm::LogSubdirectory}]
CreateDirectory $FullPathLogDirectory
set TempTranscriptName [file join ${::osvvm::CurrentSimulationDirectory} ${::osvvm::OsvvmBuildLogFile}]
set TranscriptFileName [file join ${FullPathLogDirectory} ${FileBaseName}.log]
if {![catch {info body vendor_StopTranscript} err]} {
vendor_StopTranscript $TempTranscriptName
file rename -force ${TempTranscriptName} ${TranscriptFileName}
} else {
DefaultVendor_StopTranscript $TempTranscriptName
if {$::osvvm::GotTee} {
file rename -force ${TempTranscriptName} ${TranscriptFileName}
} else {
file copy -force ${TempTranscriptName} ${TranscriptFileName}
}
}
}
proc DefaultVendor_StopTranscript {{FileBaseName ""}} {
if {$::osvvm::GotTee} {
# Restore stdout
chan pop stdout
chan pop stderr
}
}
# -------------------------------------------------
# CloseAllFiles
# Used by build
#
proc CloseAllFiles {} {
foreach channel [file channels "file*"] {
close $channel
}
}
# -------------------------------------------------
# EndSimulation
# Used by build
#
proc EndSimulation {} {
vendor_end_previous_simulation
}
# -------------------------------------------------
# Library Commands
#
# -------------------------------------------------
proc OsvvmLibraryPath {PathToLib} {
# Make sure $PathToLib ends with VhdlLibraryDirectory/VhdlLibrarySubdirectory
# If it does not, fix it so it does.
set AddPathSuffix ""
set TailPathToLib [file tail $PathToLib]
if {$TailPathToLib ne $::osvvm::VhdlLibrarySubdirectory} {
set AddPathSuffix $::osvvm::VhdlLibrarySubdirectory
} else {
set $TailPathToLib [file tail [file dirname $PathToLib]
}
if {$TailPathToLib ne $::osvvm::VhdlLibraryDirectory} {
set AddPathSuffix [file join $::osvvm::VhdlLibraryDirectory $AddPathSuffix]
}
set ResolvedPathToLib [file normalize [file join $PathToLib $AddPathSuffix]]
return $ResolvedPathToLib
}
proc CreateLibraryPath {PathToLib} {
variable VhdlLibraryFullPath
set ResolvedPathToLib ""
if {$PathToLib eq ""} {
# Use existing library directory
set ResolvedPathToLib ${VhdlLibraryFullPath}
} else {
# Use specified path directly
# User can call library LibName [OsvvmLibraryPath LibPath]
set ResolvedPathToLib [file normalize $PathToLib]
# set ResolvedPathToLib [OsvvmLibraryPath $PathToLib]
}
return $ResolvedPathToLib
}
proc FindLibraryPath {PathToLib} {
variable VhdlLibraryFullPath
set ResolvedPathToLib ""
if {$PathToLib eq ""} {
# Use existing library directory
set ResolvedPathToLib ${VhdlLibraryFullPath}
} else {
set FullName [file join $PathToLib ${::osvvm::VhdlLibraryDirectory} ${::osvvm::VhdlLibrarySubdirectory}]
set LibsName [file join $PathToLib ${::osvvm::VhdlLibrarySubdirectory}]
if {[file isdirectory $FullName]} {
set ResolvedPathToLib [file normalize $FullName]
} elseif {[file isdirectory $LibsName]} {
set ResolvedPathToLib [file normalize $LibsName]
} elseif {[file isdirectory $PathToLib]} {
set ResolvedPathToLib [file normalize $PathToLib]
} else {
set ResolvedPathToLib [file normalize $FullName]
}
}
return $ResolvedPathToLib
}
proc FindExistingLibraryPath {PathToLib} {
variable VhdlLibraryFullPath
variable LibraryDirectoryList
if {$PathToLib eq ""} {
# Use existing library directory
return ${VhdlLibraryFullPath}
} elseif {[info exists LibraryDirectoryList]} {
# Sorting so shorter paths are first
set SortedLibraryDirectoryList [lsort -increasing $LibraryDirectoryList]
set NormalizedPathToLib [file normalize $PathToLib]
foreach LibraryDir $SortedLibraryDirectoryList {
if {[regexp $NormalizedPathToLib $LibraryDir]} {
return $LibraryDir
}
}
return ""
}
}
proc FindLibraryPathByName {LibraryName} {
variable LibraryList
set PathToLib ""
if {[info exists LibraryList]} {
# Find Library in list
set found [lsearch $LibraryList "[string tolower $LibraryName] *"]
if {$found >= 0} {
# Lookup Existing Library Directory
set item [lindex $LibraryList $found]
set PathToLib [lreplace $item 0 0]
}
}
return $PathToLib
}
# -------------------------------------------------
proc IsLibraryInList {LibraryName} {
variable LibraryList
variable LibraryDirectoryList
if {![info exists LibraryList]} {
# Create Initial empty list
set LibraryList ""
set LibraryDirectoryList ""
}
# set LowerLibraryName [string tolower $LibraryName]
set found [lsearch $LibraryList "${LibraryName} *"]
return $found
}
proc AddLibraryToList {LibraryName PathToLib} {
variable LibraryList
variable LibraryDirectoryList
if {![info exists LibraryList]} {
# Create Initial empty list
set LibraryList ""
set LibraryDirectoryList ""
}
# set LowerLibraryName [string tolower $LibraryName]
set found [lsearch $LibraryList "${LibraryName} *"]
if {$found < 0} {
lappend LibraryList "$LibraryName $PathToLib"
if {[lsearch $LibraryDirectoryList "${PathToLib}"] < 0} {
lappend LibraryDirectoryList "$PathToLib"
}
}
return $found
}
# -------------------------------------------------
proc ListLibraries {} {
variable LibraryList
if {[info exists LibraryList]} {
foreach LibraryName $LibraryList {
puts $LibraryName
}
}
}
# -------------------------------------------------
# Library
#
proc library {LibraryName {PathToLib ""}} {
variable VhdlWorkingLibrary
variable LibraryList
variable VhdlLibraryFullPath
CheckWorkingDir
CheckLibraryInit
# Now created after ResolvedPathToLib is set
# CreateDirectory $VhdlLibraryFullPath ; # Create library directory if it does not exist
set ResolvedPathToLib [CreateLibraryPath $PathToLib]
set LowerLibraryName [string tolower $LibraryName]
# Create library directory if it does not exist
CreateDirectory $ResolvedPathToLib
# Needs to be here to activate library (ActiveHDL)
# set found [AddLibraryToList $LowerLibraryName $ResolvedPathToLib]
set found [IsLibraryInList $LowerLibraryName]
# Policy: If library is already in library list, then use that directory
if {$found >= 0} {
# Lookup Existing Library Directory
set item [lindex $LibraryList $found]
set ResolvedPathToLib [lreplace $item 0 0]
}
puts "library $LibraryName $ResolvedPathToLib" ; # EchoOsvvmCmd
CallbackBefore_Library ${LibraryName} ${PathToLib}
if {[catch {vendor_library $LowerLibraryName $ResolvedPathToLib} LibraryErrMsg]} {
CallbackOnError_Library $LibraryErrMsg ${LibraryName} ${ResolvedPathToLib} vendor_library
} else {
CallbackAfter_Library ${LibraryName} ${PathToLib}
}
if {$found < 0} {
set found [AddLibraryToList $LowerLibraryName $ResolvedPathToLib]
# Could check found here or remove the return value from AddLibraryToList
}
set VhdlWorkingLibrary $LibraryName
}
# -------------------------------------------------
# LinkLibrary - aka map in some vendor tools
#
proc LocalLinkLibrary {LibraryName {PathToLib ""}} {
variable VhdlWorkingLibrary
variable VhdlLibraryFullPath
variable LibraryList
CheckWorkingDir
CheckLibraryInit
# CreateDirectory $VhdlLibraryFullPath ; # Make library directory if it does not exist
set ResolvedPathToLib [FindLibraryPath $PathToLib]
set LowerLibraryName [string tolower $LibraryName]
if {[file isdirectory $ResolvedPathToLib]} {
# set found [AddLibraryToList $LowerLibraryName $ResolvedPathToLib]
set found [IsLibraryInList $LowerLibraryName]
# Policy: If library is already in library list, then use that directory
if {$found >= 0} {
# Lookup Existing Library Directory
set item [lindex $LibraryList $found]
set ResolvedPathToLib [lreplace $item 0 0]
}
if {[catch {vendor_LinkLibrary $LowerLibraryName $ResolvedPathToLib} LibraryErrMsg]} {
CallbackOnError_LinkLibrary "${LibraryName} ${PathToLib} failed in call to vendor_LinkLibrary"
}
if {$found < 0} {
set found [AddLibraryToList $LowerLibraryName $ResolvedPathToLib]
# Could check found here or remove the return value from AddLibraryToList
}
} else {
CallbackOnError_LinkLibrary "${LibraryName} ${PathToLib} failed. $ResolvedPathToLib is not a directory."
}
}
proc LinkLibrary {LibraryName {PathToLib ""}} {
puts "LinkLibrary $LibraryName $PathToLib" ; # EchoOsvvmCmd
LocalLinkLibrary $LibraryName $PathToLib
}
# -------------------------------------------------
# LinkLibraryDirectory
#
proc LinkLibraryDirectory {{LibraryDirectory ""}} {
variable CurrentSimulationDirectory
variable ToolNameVersion
CheckWorkingDir
CheckLibraryInit
set ResolvedLibraryDirectory [FindLibraryPath $LibraryDirectory]
if {[file isdirectory $ResolvedLibraryDirectory]} {
foreach item [glob -nocomplain -directory $ResolvedLibraryDirectory *] {
if {[file isdirectory $item]} {
set LibraryName [file rootname [file tail $item]]
LocalLinkLibrary $LibraryName $ResolvedLibraryDirectory
}
}
} else {
if {[string tolower $::osvvm::OsvvmInitialized] eq "true"} {
puts "LinkLibraryDirectory $LibraryDirectory : $ResolvedLibraryDirectory does not exist"
}
}
}
# -------------------------------------------------
# LinkCurrentLibraries
# EDA tools are centric to the current directory
# If you change directory, they loose all of their library information
# LinkCurrentLibraries reestablishes the library information
#
proc LinkCurrentLibraries {} {
variable LibraryList
set OldLibraryList $LibraryList
# If directory changed, update CurrentSimulationDirectory, LibraryList
CheckWorkingDir
foreach item $OldLibraryList {
set LibraryName [lindex $item 0]
set PathToLib [lreplace $item 0 0] ; # handles spaces in path
LinkLibrary ${LibraryName} ${PathToLib}
}
}
# -------------------------------------------------
# analyze
#
proc analyze {FileName args} {
variable AnalyzeErrorCount
variable AnalyzeErrorStopCount
variable ConsecutiveAnalyzeErrors
if {[catch {LocalAnalyze $FileName {*}$args} errmsg]} {
set ::osvvm::LastAnalyzeHasError TRUE
CallbackOnError_Analyze $errmsg [concat $FileName $args]
} else {
set ::osvvm::LastAnalyzeHasError FALSE