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 | ###############################################################################
# Copyright (c) 2012-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform. As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
# @script
# Fill ZDB from CSV
###############################################################################
# -----------------------------------------------------------------------------
# createModule -
# -----------------------------------------------------------------------------
#
proc createModule {db name} {
set module [$db search module $name]
if {[$db oid isnull $module]} {
$db load module $name
set module [$db oid create [list module $name $name]]
}
return $module
}
# -----------------------------------------------------------------------------
# createPort -
# -----------------------------------------------------------------------------
#
proc createPort {db module name} {
set port [$db search port $module $name]
if {[$db oid isnull $port]} {
$db reloadModule [$db oid oname $module]
$db load port $name inout
}
}
# -----------------------------------------------------------------------------
# unitName -
# -----------------------------------------------------------------------------
#
proc unitName {name} {
if {[string match -nocase "jumper*" $name]} {
return $name
}
if {$name == ""} {
return ""
}
set prefix [string range $name 0 3]
if {[string compare -nocase $prefix "unit"] != 0} {
zmessage print ERR "Invalid name prefix: '$name' -> $prefix"
return ""
}
for {set i 4} {$i < [string length $name]} {incr i} {
set c [string index $name $i]
if {![string is integer $c]} {
break
}
append prefix $c
}
return $prefix
}
# -----------------------------------------------------------------------------
# portPrefix -
# -----------------------------------------------------------------------------
#
proc portPrefix {unit name} {
set prefix [string range $name [string length $unit] end]
return $prefix
}
# =============================================================================
# Parse - This is the main procedure that needs to be called twice with
# pass=1 and pass=2.
# =============================================================================
#
proc CSV:Parse {db pass} {
global CSV
##
# generate spos
#
set CSV(spos) 0
##
# Open the input file.
#
set in [open $CSV(fname) "r"]
##
# Add input file to spos database.
#
if {($pass == 1) && $CSV(spos)} {
$db spos addfile $CSV(fname)
}
##
# Initialize used variables.
#
set startPos 0
set endPos 0
set lineno 0
set size [file size $CSV(fname)]
array set moduleTable {}
##
# Loop over each line in the input file.
#
while {![eof $in]} {
set byte [gets $in line]
if {$byte < 0} {
break
}
##
# Calculate the end position of this line.
#
set endPos [expr {$startPos + $byte}]
##
# Add line information to spos database.
#
if {($pass == 1) && $CSV(spos)} {
$db spos addline $CSV(fname) [incr lineno] $endPos
}
##
# Update the progress bar.
#
if {[zprogress update "" $endPos $size]} {
break
}
##
# Split the line at the ',' character.
#
set lineList [split [string trim $line] ","]
if {[llength $lineList] != 6} {
zmessage print ERR $lineList
gui console print [llength $lineList]
continue
}
if {[lindex $lineList 0] == "DUPLICATE"} {
continue
}
if {[lindex $lineList 1] == "REF. DES"} {
continue
}
if {[lindex $lineList 3] == "REF. DES"} {
continue
}
if {[lindex $lineList 5] == "SIGNAL NAME"} {
continue
}
set inst1 [lindex $lineList 1]
if {$inst1 == {}} {
continue
}
set pin1 [lindex $lineList 2]
set inst2 [lindex $lineList 3]
set pin2 [lindex $lineList 4]
set signal [lindex $lineList 5]
if {$signal == ""} {
continue
}
if {$inst1 == ""} {
continue
}
if {$inst2 == ""} {
continue
}
set mod1 [unitName $inst1]
set mod2 [unitName $inst2]
if {$mod1 == ""} {
continue
}
if {$mod2 == ""} {
continue
}
set prefix1 [portPrefix $mod1 $inst1]
set prefix2 [portPrefix $mod2 $inst2]
set group1 $prefix1.$pin1
set group2 $prefix2.$pin2
if {$pass == 1} {
set module1 [createModule $db $mod1]
set module2 [createModule $db $mod2]
createPort $db $module1 $group1
createPort $db $module2 $group2
set moduleTable($mod2) 1
set moduleTable($mod1) 1
}
if {$pass == 2} {
$db reloadModule TOP
$db load net $signal -pin $mod1 $group1 -pin $mod2 $group2
}
##
# Set the new start position to the first character in the next line.
#
set startPos [expr {$endPos + 1}]
}
if {$pass == 1} {
$db load module TOP -top
foreach module [array names moduleTable] {
$db load inst [unitName $module] [unitName $module]
}
}
##
# Close the input file.
#
close $in
##
# Add end of file to spos database.
#
if {($pass == 1) && $CSV(spos)} {
$db spos addline $CSV(fname) end $size
}
}
##
# Get command line args of this Userware.
#
if {$argc != 1} {
error "Wrong # of args."
}
set CSV(fname) [lindex $argv 0]
set db [zdb new]
zprogress begin
##
# Read input file pass 1: create all modules and interfaces.
#
zprogress push "Read file [file tail $CSV(fname)]: Pass 1" 0.5
CSV:Parse $db 1
if {[zprogress pop]} {
return
}
##
# Read input file pass 2: create instances and connectivity.
#
zprogress push "Read file [file tail $CSV(fname)]: Pass 2" 1.0
CSV:Parse $db 2
if {[zprogress pop]} {
return
}
gui database changed $db
zprogress end
|