-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathOsvvmScriptsFileCreate.tcl
235 lines (209 loc) · 9.53 KB
/
OsvvmScriptsFileCreate.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
# File Name: OsvvmScriptsFileCreate.tcl
# Purpose: Scripts for running simulations
# Revision: OSVVM MODELS STANDARD VERSION
#
# Maintainer: Jim Lewis email: jim@synthworks.com
# Contributor(s):
# Jim Lewis email: jim@synthworks.com
# Markus Ferringer Patterns for error handling and callbacks, ...
#
# Description
# Tcl procedures to Autogenerate Files
#
# 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
# 1/2025 2025.01 Initial
#
#
# This file is part of OSVVM.
#
# Copyright (c) 2025 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.
#
package require fileutil
namespace eval ::osvvm {
# -------------------------------------------------
# FindOsvvmSettingsDirectory
#
proc FindOsvvmSettingsDirectory {} {
if {[info exists ::env(OSVVM_SETTINGS_DIR)]} {
# if OSVVM_SETTINGS_DIR has an absolute path, CurrentSimulationDirectory/OsvvmHomeDirectory is ignored
if {$::osvvm::SettingsAreRelativeToSimulationDirectory} {
set SettingsDirectory [file join ${::osvvm::CurrentSimulationDirectory} $::env(OSVVM_SETTINGS_DIR) ${::osvvm::OsvvmSettingsSubDirectory}]
} else {
set SettingsDirectory [file join ${::osvvm::OsvvmHomeDirectory} $::env(OSVVM_SETTINGS_DIR) ${::osvvm::OsvvmSettingsSubDirectory}]
}
} else {
if {$::osvvm::SettingsAreRelativeToSimulationDirectory} {
set SettingsDirectory [file join ${::osvvm::CurrentSimulationDirectory} ${::osvvm::OsvvmSettingsSubDirectory}]
} else {
set SettingsDirectory [file join ${::osvvm::OsvvmHomeDirectory} "osvvm" ${::osvvm::OsvvmSettingsSubDirectory}]
}
}
CreateDirectory $SettingsDirectory
# set RelativeSettingsDirectory [::fileutil::relative [pwd] $SettingsDirectory]
# return $RelativeSettingsDirectory
# Needs to be a normalized path
return $SettingsDirectory
}
# -------------------------------------------------
# CreateOsvvmScriptSettingsPkg
#
proc CreateOsvvmScriptSettingsPkg {SettingsDirectory} {
set OsvvmScriptSettingsPkgFile [file join ${SettingsDirectory} "OsvvmScriptSettingsPkg_generated.vhd"]
set NewFileName [file join ${SettingsDirectory} "OsvvmScriptSettingsPkg_new.vhd"]
set WriteCode [catch {set FileHandle [open $NewFileName w]} WriteErrMsg]
if {$WriteCode} {
puts "Not able to open OsvvmScriptSettingsPkg_generated.vhd. Using defaults instead"
return ""
}
puts $FileHandle "-- This file is autogenerated by CreateOsvvmScriptSettingsPkg"
puts $FileHandle "package body OsvvmScriptSettingsPkg is"
puts $FileHandle " constant OSVVM_HOME_DIRECTORY : string := \"[file normalize ${::osvvm::OsvvmHomeDirectory}]\" ;"
if {${::osvvm::OsvvmTemporaryOutputDirectory} eq ""} {
puts $FileHandle " constant OSVVM_RAW_OUTPUT_DIRECTORY : string := \"\" ;"
} else {
puts $FileHandle " constant OSVVM_RAW_OUTPUT_DIRECTORY : string := \"${::osvvm::OsvvmTemporaryOutputDirectory}/\" ;"
}
if {${::osvvm::OutputBaseDirectory} eq ""} {
puts $FileHandle " constant OSVVM_BASE_OUTPUT_DIRECTORY : string := \"\" ;"
} else {
puts $FileHandle " constant OSVVM_BASE_OUTPUT_DIRECTORY : string := \"${::osvvm::OutputBaseDirectory}/\" ;"
}
puts $FileHandle " constant OSVVM_BUILD_YAML_FILE : string := \"${::osvvm::OsvvmBuildYamlFile}\" ;"
puts $FileHandle " constant OSVVM_TRANSCRIPT_YAML_FILE : string := \"${::osvvm::TranscriptYamlFile}\" ;"
puts $FileHandle " constant OSVVM_REVISION : string := \"${::osvvm::OsvvmVersion}\" ;"
puts $FileHandle " constant OSVVM_SETTINGS_REVISION : string := \"${::osvvm::OsvvmVersionCompatibility}\" ;"
puts $FileHandle "end package body OsvvmScriptSettingsPkg ;"
close $FileHandle
if {[FileDiff $OsvvmScriptSettingsPkgFile $NewFileName]} {
file rename -force $NewFileName $OsvvmScriptSettingsPkgFile
} else {
file delete -force $NewFileName
}
return $OsvvmScriptSettingsPkgFile
}
# -------------------------------------------------
# CreatePathPkg
#
proc CreatePathPkg {BaseName {SettingsDirectory ""}} {
if {$SettingsDirectory eq ""} {set SettingsDirectory $::osvvm::OsvvmUserSettingsDirectory}
set TestSettingsPkgFile [file join ${SettingsDirectory} "${BaseName}PathPkg_generated.vhd"]
set NewFileName [file join ${SettingsDirectory} "${BaseName}PathPkg_new.vhd"]
set DefaultSettingsPkgFile [file join ${SettingsDirectory} "${BaseName}PathPkg_default.vhd"]
set WriteCode [catch {set FileHandle [open $NewFileName w]} WriteErrMsg]
if {$WriteCode} {
puts "Not able to open ${NewFileName}. Using defaults instead"
analyze ${BaseName}SettingsPkg_default.vhd
return ""
}
set LocalScriptDir "[::fileutil::relative ${::osvvm::CurrentSimulationDirectory} [file normalize ${::osvvm::CurrentWorkingDirectory}]]"
puts $FileHandle "-- This file is autogenerated by CreatePathPkg"
puts $FileHandle "package ${BaseName}SettingsPkg is"
puts $FileHandle " constant TEST_PATH_DIR : string := \"${LocalScriptDir}\" ;"
puts $FileHandle " constant TEST_PATH_SET : boolean := TRUE ;"
puts $FileHandle "end package ${BaseName}SettingsPkg ;"
close $FileHandle
if {[FileDiff $TestSettingsPkgFile $NewFileName]} {
file rename -force $NewFileName $TestSettingsPkgFile
} else {
file delete -force $NewFileName
}
analyze $TestSettingsPkgFile
return $TestSettingsPkgFile
}
# -------------------------------------------------
# CreateAndAnalyzeBuildSettingsPkg
#
proc CreateBuildSettingsPkg {BaseName {SettingsDirectory ""}} {
if {$SettingsDirectory eq ""} {set SettingsDirectory $::osvvm::OsvvmUserSettingsDirectory}
set TestSettingsPkgFile [file join ${SettingsDirectory} "${BaseName}SettingsPkg_generated.vhd"]
set NewFileName [file join ${SettingsDirectory} "${BaseName}SettingsPkg_new.vhd"]
set DefaultSettingsPkgFile [file join ${SettingsDirectory} "${BaseName}SettingsPkg_default.vhd"]
set WriteCode [catch {set FileHandle [open $NewFileName w]} WriteErrMsg]
if {$WriteCode} {
puts "Not able to open ${NewFileName}. Using defaults instead"
analyze ${BaseName}SettingsPkg_default.vhd
return ""
}
set LocalScriptDir "[::fileutil::relative ${::osvvm::CurrentSimulationDirectory} [file normalize ${::osvvm::CurrentWorkingDirectory}]]"
puts $FileHandle "-- This file is autogenerated by CreateBuildSettingsPkg"
puts $FileHandle "package ${BaseName}SettingsPkg is"
puts $FileHandle " constant LOCAL_SCRIPT_DIR : string := \"${LocalScriptDir}\" ;"
puts $FileHandle " constant TEST_SUITE_NAME : string := \"${::osvvm::TestSuiteName}\" ;"
# Should be in top level OsvvmSettings
puts $FileHandle " constant RESULTS_DIR : string := \"${::osvvm::ResultsDirectory}\" ;"
if {$::osvvm::Debug} {
puts $FileHandle " constant MIRROR_ENABLE : boolean := TRUE ;"
} else {
puts $FileHandle " constant MIRROR_ENABLE : boolean := FALSE ;"
}
puts $FileHandle "end package ${BaseName}SettingsPkg ;"
close $FileHandle
if {[FileDiff $TestSettingsPkgFile $NewFileName]} {
file rename -force $NewFileName $TestSettingsPkgFile
} else {
file delete -force $NewFileName
}
analyze $TestSettingsPkgFile
return $TestSettingsPkgFile
}
# AutoGenerateFile
# Extract from FileName everything up to and including the pattern in the string
# Write Extracted contents to NewFileName
# Example call: set ErrorCode [catch {AutoGenerateFile $FileName $NewFileName "--!! Autogenerated:"} errmsg]
proc AutoGenerateFile {FileName NewFileName AutoGenerateMarker} {
set ReadCode [catch {set ReadFile [open $FileName r]} ReadErrMsg]
if {$ReadCode} { return }
set LinesOfFile [split [read $ReadFile] \n]
close $ReadFile
set WriteCode [catch {set WriteFile [open $NewFileName w]} WriteErrMsg]
if {$WriteCode} { return }
foreach OneLine $LinesOfFile {
puts $WriteFile $OneLine
if { [regexp ${AutoGenerateMarker} $OneLine] } {
break
}
}
close $WriteFile
}
proc FileDiff {File1 File2} {
set ReadFile1Code [catch {set FileHandle1 [open $File1 r]} ReadErrMsg]
if {$ReadFile1Code} {return "true"}
set LinesOfFile1 [split [read $FileHandle1] \n]
close $FileHandle1
set LengthOfFile1 [llength $$LinesOfFile1]
set ReadFile2Code [catch {set FileHandle2 [open $File2 r]} ReadErrMsg]
if {$ReadFile2Code} {return "true"}
set LinesOfFile2 [split [read $FileHandle2] \n]
close $FileHandle2
set LengthOfFile2 [llength $$LinesOfFile2]
if {$LengthOfFile1 != $LengthOfFile2} {return "true"}
for {set i 0} {$i < $LengthOfFile1} {incr i} {
if {[lindex $LinesOfFile1 $i] ne [lindex $LinesOfFile2 $i]} {return "true"}
}
return "false"
}
# Don't export the following due to conflicts with Tcl built-ins
# map
namespace export CreateOsvvmScriptSettingsPkg FindOsvvmSettingsDirectory CreateAndAnalyzeTestSettingsPkg
# end namespace ::osvvm
}