-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathOsvvmScriptsFileCreate.tcl
151 lines (132 loc) · 5.61 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
# File Name: OsvvmScriptsFileCreate.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 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.
#
namespace eval ::osvvm {
# -------------------------------------------------
# CreateOsvvmScriptSettingsPkg
# do an operation on a list of items
#
proc FindOsvvmSettingsDirectory {} {
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
}
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
}
# 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
# end namespace ::osvvm
}