FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OSVVM-Scripts/OsvvmScriptsFileCreate.tcl at main · PLC2/OSVVM-Scripts · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PLC2
/
OSVVM-Scripts
Public
forked from
OSVVM/OSVVM-Scripts
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OSVVM-Scripts
/
OsvvmScriptsFileCreate.tcl
Copy path
More file actions
More file actions
Latest commit
History
History
History
375 lines (335 loc) · 16.4 KB
Breadcrumbs
OSVVM-Scripts
/
OsvvmScriptsFileCreate.tcl
Copy path
File metadata and controls
375 lines (335 loc) · 16.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
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
{{OsvvmSubdirectory
"
osvvm
"
}} {
#
When StartUpShared.tcl calls this to determine the value of ::osvvm::OsvvmUserSettingsDirectory,
#
OsvvmSettingsLocal.tcl has not been run yet, as a result,
#
* OsvvmSettingsSubdirectory will have its default value of "" and
#
* SettingsAreRelativeToSimulationDirectory will have its default value of false.
#
For OsvvmSettingsSubdirectory, this is ok as it is only needed to differentiate the VHDL code and not the settings.
#
SettingsAreRelativeToSimulationDirectory this is not ok and it usage has been deprecated.
#
This was used to differentiate VHDL sources for different simulators - use OsvvmSettingsSubdirectory instead
#
set
SettingsRootDirectory
${::osvvm::OsvvmHomeDirectory}
if
{
$::osvvm::SettingsAreRelativeToSimulationDirectory
} {
puts
"
WARNING: SettingsAreRelativeToSimulationDirectory is deprecated. Usage will generate an error in the future
"
set
SettingsRootDirectory [
file
normalize
${::osvvm::CurrentSimulationDirectory}
]
}
if
{[
info
exists ::env(OSVVM_SETTINGS_DIR)]} {
#
Note that OSVVM_SETTINGS_DIR may be either an absolute or relative path
#
For relative paths, use OsvvmHomeDirectory (location of OsvvmLibraries) as the base
set
SettingsDirectory
$::env(OSVVM_SETTINGS_DIR)
}
elseif
{[
file
isdirectory
${SettingsRootDirectory}
/../OsvvmSettings]} {
set
SettingsDirectory ../OsvvmSettings
}
else
{
puts
"
Note: Putting setting in directory OsvvmLibraries/
${OsvvmSubdirectory}
"
set
SettingsDirectory
${OsvvmSubdirectory}
}
set
SettingsDirectoryFullPath [
file
normalize [
file
join
${SettingsRootDirectory}
${SettingsDirectory}
${::osvvm::OsvvmSettingsSubdirectory}
]]
CreateDirectory
$SettingsDirectoryFullPath
#
set RelativeSettingsDirectory [::fileutil::relative [pwd] $SettingsDirectoryFullPath]
#
return $RelativeSettingsDirectory
#
Needs to be a normalized path
return
$SettingsDirectoryFullPath
}
#
-------------------------------------------------
#
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::OsvvmTempOutputDirectory}
eq
"
"
} {
puts
$FileHandle
"
constant OSVVM_TEMP_OUTPUT_DIRECTORY : string :=
\"\"
;
"
}
else
{
puts
$FileHandle
"
constant OSVVM_TEMP_OUTPUT_DIRECTORY : string :=
\"
${::osvvm::OsvvmTempOutputDirectory}
/
\"
;
"
}
if
{
${::osvvm::OutputBaseDirectory}
eq
"
"
} {
puts
$FileHandle
"
constant OSVVM_BASE_DIRECTORY : string :=
\"\"
;
"
}
else
{
puts
$FileHandle
"
constant OSVVM_BASE_DIRECTORY : string :=
\"
${::osvvm::OutputBaseDirectory}
/
\"
;
"
}
puts
$FileHandle
"
constant OSVVM_BUILD_YAML_FILE : string :=
\"
${::osvvm::OsvvmTempYamlFile}
\"
;
"
puts
$FileHandle
"
constant OSVVM_TRANSCRIPT_YAML_FILE : string :=
\"
${::osvvm::TempTranscriptYamlFile}
\"
;
"
puts
$FileHandle
"
constant OSVVM_REVISION : string :=
\"
${::osvvm::OsvvmVersion}
\"
;
"
puts
$FileHandle
"
constant OSVVM_SETTINGS_REVISION : string :=
\"
${::osvvm::OsvvmVersionCompatibility}
\"
; -- For Settings
"
puts
$FileHandle
"
constant ALERT_YAML_VERSION : string :=
\"
${::osvvm::OsvvmAlertYamlVersion}
\"
;
"
puts
$FileHandle
"
constant SCOREBOARD_YAML_VERSION : string :=
\"
${::osvvm::OsvvmScoreboardYamlVersion}
\"
;
"
puts
$FileHandle
"
constant COVERAGE_YAML_VERSION : string :=
\"
${::osvvm::OsvvmCoverageYamlVersion}
\"
;
"
puts
$FileHandle
"
constant REQUIREMENTS_YAML_VERSION : string :=
\"
${::osvvm::OsvvmRequirementsYamlVersion}
\"
;
"
puts
$FileHandle
"
end package body OsvvmScriptSettingsPkg ;
"
close
$FileHandle
if
{[FileDiff
$OsvvmScriptSettingsPkgFile
$NewFileName
]} {
file
rename -force
$NewFileName
$OsvvmScriptSettingsPkgFile
}
else
{
file
delete -force
$NewFileName
}
return
$OsvvmScriptSettingsPkgFile
}
#
-------------------------------------------------
#
FindOsvvmScriptSettingsPkg
#
proc
FindOsvvmScriptSettingsPkg
{ } {
set
SettingsDirectory [FindOsvvmSettingsDirectory]
if
{[FileExists
$SettingsDirectory
/OsvvmScriptSettingsPkg_local.vhd]} {
return
$SettingsDirectory
/OsvvmScriptSettingsPkg_local.vhd
#
If SettingsDirectory is in a subdirectory for a tool and/or vendor it may be appropriate to look above to find a local "default one"
#
elsif {[FileExists $SettingsDirectory/../OsvvmScriptSettingsPkg_local.vhd]} { analyze $SettingsDirectory/../OsvvmScriptSettingsPkg_local.vhd }
}
else
{
#
Generate the file if possible
set
GeneratedPkg [CreateOsvvmScriptSettingsPkg
$SettingsDirectory
]
puts
"
GeneratedPkg =
$GeneratedPkg
"
if
{[FileExists
$GeneratedPkg
]} {
return
$GeneratedPkg
}
else
{
return
OsvvmScriptSettingsPkg_default.vhd
}
}
}
#
-------------------------------------------------
#
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
}
#
-------------------------------------------------
#
CreateTestCaseCommonPkg
#
proc
CreateTestCaseCommonPkg
{ {PackageName
"
TestCaseCommonPkg
"
} {ValidatedResults
"
../ValidatedResults
"
} } {
#
set CurrentDir ""
set
CurrentDir [
file
normalize
${::osvvm::CurrentWorkingDirectory}
]
set
NewFileName [
file
join
${CurrentDir}
"
NewCreateTestCaseCommonPkg.vhd
"
]
if
{
${::osvvm::OutputBaseDirectory}
eq
"
"
} {
set
FileBaseName
"
"
}
else
{
set
FileBaseName
"
_
[
RemoveFilePathChars
${::osvvm::OutputBaseDirectory}
]
"
}
if
{
$::osvvm::Supports2019FilePath
&&
$::osvvm::VhdlVersion
>= 2019} {
set
TestCaseCommonPkgFile [
file
join
${CurrentDir}
"
${PackageName}${FileBaseName}
.vhd
"
]
}
else
{
CreateDirectory [
file
join
${CurrentDir}
deprecated]
set
TestCaseCommonPkgFile [
file
join
${CurrentDir}
"
deprecated
"
"
${PackageName}${FileBaseName}
_c.vhd
"
]
}
if
{![
info
exists ::osvvm::TestSuiteName]} {
error
"
Call TestSuite before calling CreateTestCaseCommonPkg
"
return
}
set
WriteCode [
catch
{
set
FileHandle [
open
$NewFileName
w]} WriteErrMsg]
if
{
$WriteCode
} {
puts
"
ScriptError: Not able to create
${TestCaseCommonPkgFile}
"
}
else
{
puts
$FileHandle
"
-- This file is autogenerated by CreateTestCaseCommonPkg
"
puts
$FileHandle
"
library osvvm ;
"
puts
$FileHandle
"
context osvvm.OsvvmContext ;
"
puts
$FileHandle
"
package
${PackageName}
is
"
if
{
$::osvvm::Supports2019FilePath
&&
$::osvvm::VhdlVersion
>= 2019} {
puts
$FileHandle
"
constant PATH_TO_TEST_SRC : string := RemoveEndingSeparator(ChangeSeparator(FILE_PATH)) &
\"
/
\"
; -- only valid with VHDL-2019
"
}
else
{
puts
$FileHandle
"
constant PATH_TO_TEST_SRC : string :=
\"
[
file
normalize [
file
join
$::osvvm::CurrentWorkingDirectory
]
]/
\"
;
"
}
puts
$FileHandle
"
constant PATH_TO_VALIDATED_RESULTS : string := PATH_TO_TEST_SRC &
\"
${ValidatedResults}
/
\"
;
"
puts
$FileHandle
"
constant CHECK_TRANSCRIPT : boolean := PATH_TO_TEST_SRC'length > 0 ; -- TRUE if all went well
"
puts
$FileHandle
"
"
puts
$FileHandle
"
-- PATH_TO_RESULTS is for test case generated output other than TranscriptOpen. If used you must create it
"
puts
$FileHandle
"
constant BUILD_NAME : string :=
\"
${::osvvm::BuildName}
\"
;
"
puts
$FileHandle
"
constant TEST_SUITE_NAME : string :=
\"
${::osvvm::TestSuiteName}
\"
;
"
puts
$FileHandle
"
constant PATH_TO_RESULTS : string := OSVVM_BASE_DIRECTORY & BUILD_NAME &
\"
/results/
\"
& TEST_SUITE_NAME &
\"
/
\"
;
"
puts
$FileHandle
"
"
puts
$FileHandle
"
-- Deprecated. Provided for backward compatibility
"
puts
$FileHandle
"
constant RESULTS_DIR : string := PATH_TO_RESULTS ;
"
puts
$FileHandle
"
constant VALIDATED_RESULTS_DIR : string := PATH_TO_VALIDATED_RESULTS ;
"
puts
$FileHandle
"
end package
${PackageName}
;
"
close
$FileHandle
if
{[FileDiff
$TestCaseCommonPkgFile
$NewFileName
]} {
puts
"
Creating
$TestCaseCommonPkgFile
"
file
rename -force
$NewFileName
$TestCaseCommonPkgFile
}
else
{
puts
"
Files
$NewFileName
$TestCaseCommonPkgFile
match. No updates
"
file
delete -force
$NewFileName
}
}
return
$TestCaseCommonPkgFile
}
#
-------------------------------------------------
#
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
}
#
-------------------------------------------------
#
FileDiff
#
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
"
}
#
-------------------------------------------------
#
ReadFrom - Open File and read it into the stream
#
proc
ReadFrom
{
filename
} {
set
f [
open
$filename
];
return
[
read
$f
][
close
$f
]}
#
-------------------------------------------------
#
PrintTo - Direct a stream of information into a file
#
proc
PrintTo
{
filename
str} {
set
f [
open
$filename
w];
puts
$f
$str
;
close
$f
}
#
-------------------------------------------------
#
MakeVti - Replace FileName with FileNameVti
#
proc
MakeVti
{FileName FilePrefix} {
PrintTo [
file
join
$FilePrefix
Vti
${FileName}
Vti_a.vhd] [
regsub
-all
${FileName}
[
ReadFrom [
file
join
$FilePrefix
${FileName}
_a.vhd
]
]
${FileName}
Vti]
}
#
-------------------------------------------------
#
Make2008 - For VHDL-2008 version remove the comment "--%%UncommentFor2008 " from the file
#
proc
Make2008
{FileName FilePrefix} {
PrintTo [
file
join
$FilePrefix
deprecated
${FileName}
_a.vhd] [
regsub
-all --
"--%%UncommentFor2008 "
[
ReadFrom [
file
join
$FilePrefix
${FileName}
_a.vhd
]
]
"
"
]
}
#
-------------------------------------------------
#
MakeArch - Create Vti, 2008 and Vti/2008 architectures
#
proc
MakeArch
{FileName} {
variable
CurrentWorkingDirectory
MakeVti
$FileName
$CurrentWorkingDirectory
Make2008
$FileName
$CurrentWorkingDirectory
Make2008
${FileName}
Vti [
file
join
$CurrentWorkingDirectory
Vti]
}
#
Don't export the following due to conflicts with Tcl built-ins
#
map
namespace
export CreateOsvvmScriptSettingsPkg FindOsvvmSettingsDirectory CreateAndAnalyzeTestSettingsPkg
namespace
export CreateTestCaseCommonPkg
#
end namespace ::osvvm
}
Back
|
FazBrowse Home
|
New Git URL