1 |
22 |
sckoarn |
#! /usr/bin/env wish
|
2 |
|
|
##-------------------------------------------------------------------------------
|
3 |
|
|
##-- Copyright 2014 Ken Campbell
|
4 |
|
|
##-- All Rights Reserved
|
5 |
|
|
##----------------------------------------------------------------------------
|
6 |
|
|
## This file is an application that will generate some starting structure files.
|
7 |
|
|
## Output from this program is not covered by this license, you may apply your
|
8 |
|
|
## own copyright and license notices to generated files as you see fit.
|
9 |
|
|
##
|
10 |
|
|
## Redistribution and use in source and binary forms, with or without
|
11 |
|
|
## modification, are permitted provided that the following conditions are met:
|
12 |
|
|
##
|
13 |
|
|
## 1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
## this list of conditions and the following disclaimer.
|
15 |
|
|
##
|
16 |
|
|
## 2. Redistributions in binary form must reproduce the above copyright notice,
|
17 |
|
|
## this list of conditions and the following disclaimer in the documentation
|
18 |
|
|
## and/or other materials provided with the distribution.
|
19 |
|
|
##
|
20 |
|
|
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21 |
|
|
## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22 |
|
|
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23 |
|
|
## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
24 |
|
|
## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25 |
|
|
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26 |
|
|
## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27 |
|
|
## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28 |
|
|
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29 |
|
|
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
|
|
## POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
##-------------------------------------------------------------------------------
|
32 |
|
|
##-- $Author: $
|
33 |
|
|
##--
|
34 |
|
|
##-- Description :
|
35 |
|
|
##-- This application takes a text file containing the definition of a VHDL
|
36 |
|
|
## entity, parses that entity and generates the VHDL Test Bench starting
|
37 |
|
|
## file set. It is a rewrite of the previous ttb_gen_gui to include
|
38 |
|
|
## view of the file.
|
39 |
|
|
## This version has been updated to handle any entity definition
|
40 |
|
|
## as well as generating generics found on the target entity.
|
41 |
|
|
##--
|
42 |
|
|
##------------------------------------------------------------------------------
|
43 |
|
|
|
44 |
|
|
## package requires
|
45 |
|
|
package require Iwidgets 4.0
|
46 |
|
|
|
47 |
|
|
## set the current version info
|
48 |
|
|
set version "V 3.0"
|
49 |
|
|
## put up a title on the main window boarder
|
50 |
|
|
wm title . "TTB Gen $version"
|
51 |
|
|
|
52 |
|
|
## the location of the template by default
|
53 |
|
|
set template "../vhdl/template_tb_bhv.vhd"
|
54 |
|
|
|
55 |
|
|
set use_list 0
|
56 |
|
|
|
57 |
|
|
## Working Directory or vhdl directory
|
58 |
|
|
set workd [frame .wdf]
|
59 |
|
|
set ent_dir [iwidgets::entryfield $workd.cen1 -labeltext "Working Directory"]
|
60 |
|
|
button $workd.br0 -text "Browse" -command {fill_list}
|
61 |
|
|
pack $workd.br0 -side right
|
62 |
|
|
pack $ent_dir -fill x
|
63 |
|
|
pack $workd -fill x -pady 6
|
64 |
|
|
|
65 |
|
|
## Output directory
|
66 |
|
|
set tlist [frame .lstf]
|
67 |
|
|
set odir [iwidgets::entryfield $tlist.ent1 -labeltext "Output Directory"]
|
68 |
|
|
set lbut [button $tlist.br1 -text "Browse" -command {browsed_from_set $odir $odir}]
|
69 |
|
|
pack $lbut -side right
|
70 |
|
|
pack $odir -fill x
|
71 |
|
|
pack $tlist -fill x
|
72 |
|
|
|
73 |
|
|
## Template location
|
74 |
|
|
set tdirf [frame .tmpf]
|
75 |
|
|
set tdir [iwidgets::entryfield $tdirf.ent2 -width 60 -labeltext "Template Location"]
|
76 |
|
|
set tbut [button $tdirf.br2 -text "Browse" -command {browse_set_entry $tdir}]
|
77 |
|
|
pack $tbut -side right
|
78 |
|
|
pack $tdir -fill x
|
79 |
|
|
pack $tdirf -fill x -pady 6
|
80 |
|
|
$tdir delete 0 end
|
81 |
|
|
$tdir insert end $template
|
82 |
|
|
$tdir configure -state readonly
|
83 |
|
|
|
84 |
|
|
## type spec
|
85 |
|
|
set tsf [frame .tsfr]
|
86 |
|
|
set load_but [button $tsf.bt1 -text "Generate" -command ttb_gen]
|
87 |
|
|
set mo_sel [iwidgets::optionmenu $tsf.mode -labeltext "Mode"]
|
88 |
|
|
set gbatv 0
|
89 |
|
|
set gbat [checkbutton $tsf.chb1 -text "Gen Bat File" -variable gbatv]
|
90 |
|
|
set cpakv 0
|
91 |
|
|
set cpak [checkbutton $tsf.chb2 -text "Copy Package" -variable cpakv]
|
92 |
|
|
##$mo_sel insert end Work Recurse List
|
93 |
|
|
$mo_sel insert end "No bhv" "bhv"
|
94 |
|
|
set p_view [iwidgets::feedback $tsf.fb1 -labeltext "Generation Status" -barheight 10]
|
95 |
|
|
set statsVar ""
|
96 |
|
|
##set stat_txt [label $tsf.lb1 -textvariable statsVar]
|
97 |
|
|
set stat_txt [label .lb1 -textvariable statsVar]
|
98 |
|
|
|
99 |
|
|
pack $cpak -side left
|
100 |
|
|
pack $gbat -side left
|
101 |
|
|
pack $mo_sel -side left
|
102 |
|
|
pack $load_but -side left -padx 20
|
103 |
|
|
pack $p_view -side left
|
104 |
|
|
pack $tsf
|
105 |
|
|
pack $stat_txt -fill x
|
106 |
|
|
|
107 |
|
|
## create paned window
|
108 |
|
|
set win [iwidgets::panedwindow .pw -width 200 -height 300 ]
|
109 |
|
|
$win add top -margin 4 -minimum 100
|
110 |
|
|
$win add middle -margin 4 -minimum 100
|
111 |
|
|
$win configure -orient vertical
|
112 |
|
|
$win fraction 80 20
|
113 |
|
|
$win paneconfigure 1 -minimum 60
|
114 |
|
|
## create two locations for objects
|
115 |
|
|
set wtop [$win childsite 0]
|
116 |
|
|
set wbot [$win childsite 1]
|
117 |
|
|
pack $win -fill both -expand yes
|
118 |
|
|
## create two object boxes
|
119 |
|
|
set list_win [iwidgets::selectionbox $wtop.sb -margin 2 -itemscommand load_ent_file \
|
120 |
|
|
-itemslabel "VHDL Files" -selectionlabel "Selected VHDL File"]
|
121 |
|
|
set view_win [iwidgets::scrolledtext $wbot.rts -borderwidth 2 -wrap none]
|
122 |
|
|
pack $list_win -fill both -expand yes
|
123 |
|
|
pack $view_win -fill both -expand yes
|
124 |
|
|
|
125 |
|
|
set aboutb [button .abb1 -text "About" -command show_about]
|
126 |
|
|
pack $aboutb -anchor s
|
127 |
|
|
## some tags for the view window
|
128 |
|
|
##$view_win tag configure highlite -background #a0b7ce
|
129 |
|
|
$view_win tag configure highlite -background grey80
|
130 |
|
|
|
131 |
|
|
###########################################################################
|
132 |
|
|
## some debug and help procs
|
133 |
|
|
## Message Error, terminate
|
134 |
|
|
proc msg_error { msg } {
|
135 |
|
|
tk_messageBox -message $msg -type ok
|
136 |
|
|
exit
|
137 |
|
|
}
|
138 |
|
|
###########################################################################
|
139 |
|
|
## Message, continue
|
140 |
|
|
proc dbg_msg { msg } {
|
141 |
|
|
tk_messageBox -message $msg -type ok
|
142 |
|
|
}
|
143 |
|
|
#########################################################################
|
144 |
|
|
## browse and get directory
|
145 |
|
|
## Using extfileselectiondialog get a directory and update the
|
146 |
|
|
## field passed to it
|
147 |
|
|
proc browsed_from_set { src dest } {
|
148 |
|
|
set wdir [$src get]
|
149 |
|
|
if {$wdir == ""} {
|
150 |
|
|
iwidgets::extfileselectiondialog .dsb -modality application -fileson false
|
151 |
|
|
} else {
|
152 |
|
|
iwidgets::extfileselectiondialog .dsb -modality application -fileson false \
|
153 |
|
|
-directory $wdir
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
if {[.dsb activate]} {
|
157 |
|
|
set dchoice [.dsb get]
|
158 |
|
|
$dest configure -state normal
|
159 |
|
|
$dest delete 0 end
|
160 |
|
|
$dest insert 0 "$dchoice"
|
161 |
|
|
$dest configure -state readonly
|
162 |
|
|
}
|
163 |
|
|
destroy .dsb
|
164 |
|
|
}
|
165 |
|
|
#########################################################################
|
166 |
|
|
## browse and get file name
|
167 |
|
|
## Using extfileselectiondialog get a directory and update the
|
168 |
|
|
## field passed to it
|
169 |
|
|
proc browse_set_entry { dest } {
|
170 |
|
|
iwidgets::extfileselectiondialog .dsb -modality application
|
171 |
|
|
|
172 |
|
|
if {[.dsb activate]} {
|
173 |
|
|
set dchoice [.dsb get]
|
174 |
|
|
$dest configure -state normal
|
175 |
|
|
$dest delete 0 end
|
176 |
|
|
$dest insert 0 "$dchoice"
|
177 |
|
|
$dest configure -state readonly
|
178 |
|
|
}
|
179 |
|
|
destroy .dsb
|
180 |
|
|
}
|
181 |
|
|
##########################################################################
|
182 |
|
|
## proc pars_pindef
|
183 |
|
|
proc pars_pindef { pins } {
|
184 |
|
|
|
185 |
|
|
set pdef {}
|
186 |
|
|
|
187 |
|
|
foreach l $pins {
|
188 |
|
|
set mps {}
|
189 |
|
|
|
190 |
|
|
set pdirection ""
|
191 |
|
|
set spin [split $l ":"]
|
192 |
|
|
## if multi pin def
|
193 |
|
|
if {[string first "," [lindex $spin 0]] > 0} {
|
194 |
|
|
set mpins [split [lindex $spin 0] ","]
|
195 |
|
|
foreach p $mpins {
|
196 |
|
|
lappend mps [string trim $p]
|
197 |
|
|
}
|
198 |
|
|
} else {
|
199 |
|
|
set mps [string trim [lindex $spin 0]]
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
#puts $mps
|
203 |
|
|
set ptype_str {}
|
204 |
|
|
|
205 |
|
|
set pdirection_str [string trim [lindex $spin 1]]
|
206 |
|
|
#puts $pdirection_str
|
207 |
|
|
set p_valid 1
|
208 |
|
|
## parce out the direction, supporting only 3
|
209 |
|
|
if {[string first "inout" $pdirection_str] == 0} {
|
210 |
|
|
set pdirection "inout"
|
211 |
|
|
set ptype_str [string trim [string range $pdirection_str 5 end]]
|
212 |
|
|
#puts $ptype_str
|
213 |
|
|
} elseif {[string first "in" $pdirection_str] == 0} {
|
214 |
|
|
set pdirection "in"
|
215 |
|
|
set ptype_str [string trim [string range $pdirection_str 2 end]]
|
216 |
|
|
#puts $ptype_str
|
217 |
|
|
} elseif {[string first "out" $pdirection_str] == 0} {
|
218 |
|
|
set pdirection "out"
|
219 |
|
|
set ptype_str [string trim [string range $pdirection_str 3 end]]
|
220 |
|
|
#puts $ptype_str
|
221 |
|
|
} elseif {$pdirection == ""} {
|
222 |
|
|
set p_valid 0
|
223 |
|
|
set ptype_str {}
|
224 |
|
|
#puts $l
|
225 |
|
|
#dbg_msg "Unsuported Pin direction found. \n Suported are IN OUT and INOUT."
|
226 |
|
|
}
|
227 |
|
|
## check for and remove extra )'s
|
228 |
|
|
set len [string length $ptype_str]
|
229 |
|
|
#puts $len
|
230 |
|
|
set len [expr $len - 2]
|
231 |
|
|
#puts $len
|
232 |
|
|
set tb [string first "(" $ptype_str]
|
233 |
|
|
if {$tb >= 0} {
|
234 |
|
|
set tb [string first "))" $ptype_str]
|
235 |
|
|
if {$tb >= 0} {
|
236 |
|
|
set tmp_str [string range $ptype_str 0 $len]
|
237 |
|
|
set ptype_str $tmp_str
|
238 |
|
|
}
|
239 |
|
|
} else {
|
240 |
|
|
set tb [string first ")" $ptype_str]
|
241 |
|
|
if {$tb >= 0} {
|
242 |
|
|
set tmp_str [string range $ptype_str 0 $len]
|
243 |
|
|
set ptype_str $tmp_str
|
244 |
|
|
}
|
245 |
|
|
}
|
246 |
|
|
## if we have a valid pin def add one or more
|
247 |
|
|
if {$p_valid == 1} {
|
248 |
|
|
foreach p $mps {
|
249 |
|
|
set def {}
|
250 |
|
|
lappend def $p $pdirection $ptype_str
|
251 |
|
|
lappend pdef $def
|
252 |
|
|
}
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
#puts $pdef
|
256 |
|
|
# lappend pdef $pname $pdirection $ptype
|
257 |
|
|
return $pdef
|
258 |
|
|
}
|
259 |
|
|
## end pars_pindef
|
260 |
|
|
|
261 |
|
|
##########################################################################
|
262 |
|
|
## proc pars_gendef
|
263 |
|
|
proc pars_gendef { gens } {
|
264 |
|
|
|
265 |
|
|
set gdef {}
|
266 |
|
|
foreach l $gens {
|
267 |
|
|
set mgs {}
|
268 |
|
|
set sgen [split $l ":"]
|
269 |
|
|
## if multi gen def
|
270 |
|
|
if {[string first "," [lindex $sgen 0]] > 0} {
|
271 |
|
|
set mgens [split [lindex $sgen 0] ","]
|
272 |
|
|
foreach p $mgens {
|
273 |
|
|
lappend mgs [string trim $p]
|
274 |
|
|
}
|
275 |
|
|
} else {
|
276 |
|
|
set mgs [string trim [lindex $sgen 0]]
|
277 |
|
|
}
|
278 |
|
|
#puts $mgs
|
279 |
|
|
set gtype_str [string trim [lindex $sgen 1]]
|
280 |
|
|
foreach p $mgs {
|
281 |
|
|
set def {}
|
282 |
|
|
lappend def $p $gtype_str
|
283 |
|
|
lappend gdef $def
|
284 |
|
|
}
|
285 |
|
|
}
|
286 |
|
|
#puts $gdef
|
287 |
|
|
return $gdef
|
288 |
|
|
}
|
289 |
|
|
## end pars_gendef
|
290 |
|
|
|
291 |
|
|
##--------------------------------------------------------------------------------
|
292 |
|
|
## Write header to file passed
|
293 |
|
|
proc write_header { handle } {
|
294 |
|
|
global version
|
295 |
|
|
##global scan_date
|
296 |
|
|
set raw_date [clock scan now]
|
297 |
|
|
set scan_date [clock format $raw_date -format "%d %b %Y %T"]
|
298 |
|
|
|
299 |
|
|
## so CVS will not modify selections, they have to be chopped up
|
300 |
|
|
set auth "-- \$Auth"
|
301 |
|
|
append auth "or: \$"
|
302 |
|
|
set cvs_date "-- \$dat"
|
303 |
|
|
append cvs_date "e: \$"
|
304 |
|
|
set cvs_name "-- \$Nam"
|
305 |
|
|
append cvs_name "e: \$"
|
306 |
|
|
set cvs_id "-- \$I"
|
307 |
|
|
append cvs_id "d: \$"
|
308 |
|
|
set cvs_source "-- \$Sour"
|
309 |
|
|
append cvs_source "ce: \$"
|
310 |
|
|
set cvs_log "-- \$Lo"
|
311 |
|
|
append cvs_log "g: \$"
|
312 |
|
|
|
313 |
|
|
puts $handle "-------------------------------------------------------------------------------"
|
314 |
|
|
puts $handle "-- Copyright -----------------------------------"
|
315 |
|
|
puts $handle "-- All Rights Reserved"
|
316 |
|
|
puts $handle "-------------------------------------------------------------------------------"
|
317 |
|
|
puts $handle "$auth"
|
318 |
|
|
puts $handle "--"
|
319 |
|
|
puts $handle "$cvs_date"
|
320 |
|
|
puts $handle "--"
|
321 |
|
|
puts $handle "$cvs_id"
|
322 |
|
|
puts $handle "--"
|
323 |
|
|
puts $handle "$cvs_source"
|
324 |
|
|
puts $handle "--"
|
325 |
|
|
puts $handle "-- Description :"
|
326 |
|
|
puts $handle "-- This file was generated by TTB Gen Plus $version"
|
327 |
|
|
puts $handle "-- on $scan_date"
|
328 |
|
|
puts $handle "------------------------------------------------------------------------------"
|
329 |
|
|
puts $handle "-- This software contains concepts confidential to ----------------"
|
330 |
|
|
puts $handle "-- ---------. and is only made available within the terms of a written"
|
331 |
|
|
puts $handle "-- agreement."
|
332 |
|
|
puts $handle "-------------------------------------------------------------------------------"
|
333 |
|
|
puts $handle "-- Revision History:"
|
334 |
|
|
puts $handle "$cvs_log"
|
335 |
|
|
puts $handle "--"
|
336 |
|
|
puts $handle "-------------------------------------------------------------------------------"
|
337 |
|
|
puts $handle ""
|
338 |
|
|
}
|
339 |
|
|
|
340 |
|
|
##########################################################################
|
341 |
|
|
## write Library and use statements
|
342 |
|
|
proc write_lib_statements { handle } {
|
343 |
|
|
puts $handle "library IEEE;"
|
344 |
|
|
puts $handle "--library tb_pkg;"
|
345 |
|
|
puts $handle "--possible users libs;"
|
346 |
|
|
puts $handle "use IEEE.STD_LOGIC_1164.all;"
|
347 |
|
|
puts $handle "use IEEE.STD_LOGIC_ARITH.all;"
|
348 |
|
|
puts $handle "use std.textio.all;"
|
349 |
|
|
puts $handle "use work.tb_pkg.all;"
|
350 |
|
|
puts $handle "--possible users use statement;"
|
351 |
|
|
puts $handle "--library synthworks;"
|
352 |
|
|
puts $handle "-- use SynthWorks.RandomBasePkg.all; "
|
353 |
|
|
puts $handle "-- use SynthWorks.RandomPkg.all;"
|
354 |
|
|
puts $handle ""
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
#####################################################################
|
358 |
|
|
## A directory has been selected now fill the list win with VHDL files
|
359 |
|
|
proc fill_list {} {
|
360 |
|
|
global ent_dir odir
|
361 |
|
|
global tlist_ent use_list list_win ts_ent statsVar
|
362 |
|
|
global view_win mo_sel
|
363 |
|
|
|
364 |
|
|
## get the user selection
|
365 |
|
|
browsed_from_set $ent_dir $ent_dir
|
366 |
|
|
## as a default make output dir = input dir
|
367 |
|
|
set tmp_dir [$ent_dir get]
|
368 |
|
|
$odir delete 0 end
|
369 |
|
|
$odir insert end $tmp_dir
|
370 |
|
|
$odir configure -state readonly
|
371 |
|
|
|
372 |
|
|
## clear the list window and selection
|
373 |
|
|
$list_win clear items
|
374 |
|
|
$list_win clear selection
|
375 |
|
|
$view_win clear
|
376 |
|
|
## get the working directory
|
377 |
|
|
set dir [$ent_dir get]
|
378 |
|
|
## get the list of VHDL files in working directory
|
379 |
|
|
set ftype ".vhd*"
|
380 |
|
|
set file_lst ""
|
381 |
|
|
set file_lst [glob -directory $dir *$ftype]
|
382 |
|
|
|
383 |
|
|
##puts $file_lst
|
384 |
|
|
|
385 |
|
|
## for each of the files in the file_lst
|
386 |
|
|
foreach l $file_lst {
|
387 |
|
|
## creat string that is just the file name: no path
|
388 |
|
|
set testt $l
|
389 |
|
|
set nstart [string last "/" $l]
|
390 |
|
|
incr nstart
|
391 |
|
|
set name_str [string range $l $nstart end]
|
392 |
|
|
## insert item on list
|
393 |
|
|
$list_win insert items 1 $name_str
|
394 |
|
|
}
|
395 |
|
|
}
|
396 |
|
|
|
397 |
|
|
######################################################################
|
398 |
|
|
## load the vhdl file that has just been selected from list_win
|
399 |
|
|
proc load_ent_file {} {
|
400 |
|
|
global ent_dir list_win view_win statsVar
|
401 |
|
|
|
402 |
|
|
## update selection with selected item
|
403 |
|
|
$list_win selectitem
|
404 |
|
|
set sel_dx [$list_win curselection]
|
405 |
|
|
if {$sel_dx == ""} {
|
406 |
|
|
return
|
407 |
|
|
}
|
408 |
|
|
## recover the selected item
|
409 |
|
|
set ln [$list_win get]
|
410 |
|
|
## Get the working directory
|
411 |
|
|
#puts $ln
|
412 |
|
|
set lp [$ent_dir get]
|
413 |
|
|
## append the file name
|
414 |
|
|
append lp "/" $ln
|
415 |
|
|
## if the file does not exist return
|
416 |
|
|
set fexist [file exist $lp]
|
417 |
|
|
if {$fexist == 0} {
|
418 |
|
|
return
|
419 |
|
|
}
|
420 |
|
|
set ent_file [open $lp r]
|
421 |
|
|
## clear the view_win
|
422 |
|
|
$view_win clear
|
423 |
|
|
set file_list {}
|
424 |
|
|
## load file to memory
|
425 |
|
|
while {![eof $ent_file]} {
|
426 |
|
|
## Get a line
|
427 |
|
|
set rline [gets $ent_file]
|
428 |
|
|
lappend file_list $rline
|
429 |
|
|
}
|
430 |
|
|
close $ent_file
|
431 |
|
|
## put file in text window and highlite the entity part
|
432 |
|
|
set ent_found 0
|
433 |
|
|
set in_ent 0
|
434 |
|
|
set statsVar ""
|
435 |
|
|
foreach l $file_list {
|
436 |
|
|
if {$in_ent == 0} {
|
437 |
|
|
set ent_def [string first entity $l]
|
438 |
|
|
set ent_is [string first is $l]
|
439 |
|
|
if {$ent_def >= 0 && $ent_is >= 0} {
|
440 |
|
|
set ent_name [lindex $l 1]
|
441 |
|
|
set statsVar "Entity $ent_name found"
|
442 |
|
|
set ent_found 1
|
443 |
|
|
set in_ent 1
|
444 |
|
|
$view_win insert end "$l\n" highlite
|
445 |
|
|
} else {
|
446 |
|
|
$view_win insert end "$l\n"
|
447 |
|
|
}
|
448 |
|
|
} else {
|
449 |
|
|
set ent_def [string first "end $ent_name" $l]
|
450 |
|
|
set ent2_def [string first "end\;" $l]
|
451 |
|
|
if {$ent_def >= 0 || $ent2_def >= 0} {
|
452 |
|
|
set end_name [lindex $l 1]
|
453 |
|
|
set end_found 1
|
454 |
|
|
set in_ent 0
|
455 |
|
|
$view_win insert end "$l\n" highlite
|
456 |
|
|
} elseif {[string first "end entity $ent_name" $l] >= 0} {
|
457 |
|
|
set end_name [lindex $l 1]
|
458 |
|
|
set end_found 1
|
459 |
|
|
set in_ent 0
|
460 |
|
|
$view_win insert end "$l\n" highlite
|
461 |
|
|
} else {
|
462 |
|
|
$view_win insert end "$l\n" highlite
|
463 |
|
|
}
|
464 |
|
|
}
|
465 |
|
|
}
|
466 |
|
|
if {$ent_found == 0} {
|
467 |
|
|
set statsVar "No Entity found!!"
|
468 |
|
|
}
|
469 |
|
|
##$view_win import $lp
|
470 |
|
|
##$view_win yview moveto 1
|
471 |
|
|
##puts $lp
|
472 |
|
|
}
|
473 |
|
|
|
474 |
|
|
#########################################################################
|
475 |
|
|
proc ttb_gen {} {
|
476 |
|
|
global mo_sel template ent_dir list_win odir p_view tdir
|
477 |
|
|
global cpakv gbatv
|
478 |
|
|
|
479 |
|
|
set template [$tdir get]
|
480 |
|
|
|
481 |
|
|
$p_view configure -steps 7
|
482 |
|
|
$p_view reset
|
483 |
|
|
## recover the selected item
|
484 |
|
|
set ln [$list_win get]
|
485 |
|
|
## Get the working directory
|
486 |
|
|
#puts $ln
|
487 |
|
|
set lp [$ent_dir get]
|
488 |
|
|
## append the file name
|
489 |
|
|
append lp "/" $ln
|
490 |
|
|
|
491 |
|
|
set path_text $lp
|
492 |
|
|
set destin_text [$odir get]
|
493 |
|
|
set infile [open $path_text r]
|
494 |
|
|
set file_list list
|
495 |
|
|
|
496 |
|
|
set tmpcnt 0
|
497 |
|
|
|
498 |
|
|
##################################################################
|
499 |
|
|
## Read in the file and strip comments as we do
|
500 |
|
|
while {![eof $infile]} {
|
501 |
|
|
## Get a line
|
502 |
|
|
set rline [gets $infile]
|
503 |
|
|
## get rid of white space
|
504 |
|
|
set rline [string trim $rline]
|
505 |
|
|
## Find comment if there
|
506 |
|
|
set cindex [string first -- $rline]
|
507 |
|
|
## if a comment was found at the start of the line
|
508 |
|
|
if {$cindex == 0 || $rline == ""} {
|
509 |
|
|
set rline [string range $rline 0 [expr $cindex - 1]]
|
510 |
|
|
##dbg_msg $rline
|
511 |
|
|
if {[llength $rline] > 0} {
|
512 |
|
|
lappend file_list [string tolower $rline]
|
513 |
|
|
}
|
514 |
|
|
## else was not found so put line in list
|
515 |
|
|
} else {
|
516 |
|
|
if {$cindex > 0} {
|
517 |
|
|
# get rid of trailing comments and trim off spaces
|
518 |
|
|
set rline [string trim [string range $rline 0 $cindex-1]]
|
519 |
|
|
##puts $rline
|
520 |
|
|
}
|
521 |
|
|
lappend file_list [string tolower $rline]
|
522 |
|
|
}
|
523 |
|
|
incr tmpcnt
|
524 |
|
|
}
|
525 |
|
|
$p_view step
|
526 |
|
|
## collect the library statements
|
527 |
|
|
foreach l $file_list {
|
528 |
|
|
set libpos [string first library $l]
|
529 |
|
|
if {$libpos >= 0} {
|
530 |
|
|
lappend libs_list $l
|
531 |
|
|
}
|
532 |
|
|
}
|
533 |
|
|
## collect the use statements
|
534 |
|
|
foreach l $file_list {
|
535 |
|
|
set usepos [string first use $l]
|
536 |
|
|
if {$usepos >= 0} {
|
537 |
|
|
lappend use_list $l
|
538 |
|
|
}
|
539 |
|
|
}
|
540 |
|
|
## check for the entity def
|
541 |
|
|
set ent_found 0
|
542 |
|
|
foreach l $file_list {
|
543 |
|
|
set ent_def [string first entity $l]
|
544 |
|
|
if {$ent_def >= 0} {
|
545 |
|
|
set ent_name [lindex $l 1]
|
546 |
|
|
break
|
547 |
|
|
}
|
548 |
|
|
}
|
549 |
|
|
## if no ent die
|
550 |
|
|
if {$ent_def < 0} {
|
551 |
|
|
dbg_msg "An entity definition was not found in the file provided."
|
552 |
|
|
## exit
|
553 |
|
|
}
|
554 |
|
|
$p_view step
|
555 |
|
|
## check for end entity
|
556 |
|
|
foreach l $file_list {
|
557 |
|
|
lappend ent_list $l
|
558 |
|
|
set end_def [string first end $l]
|
559 |
|
|
if {$end_def >= 0} {
|
560 |
|
|
set end_ent [string first "end $ent_name" $l]
|
561 |
|
|
if {$end_ent >= 0} {
|
562 |
|
|
break
|
563 |
|
|
}
|
564 |
|
|
set end_ent [string first "end\;" $l]
|
565 |
|
|
if {$end_ent >= 0} {
|
566 |
|
|
break
|
567 |
|
|
}
|
568 |
|
|
set end_ent [string first "end entity $ent_name" $l]
|
569 |
|
|
if {$end_ent >= 0} {
|
570 |
|
|
break
|
571 |
|
|
}
|
572 |
|
|
}
|
573 |
|
|
}
|
574 |
|
|
## if no end die
|
575 |
|
|
if {$end_def < 0} {
|
576 |
|
|
dbg_msg "no end statement found for this entity"
|
577 |
|
|
## exit
|
578 |
|
|
}
|
579 |
|
|
|
580 |
|
|
####
|
581 |
|
|
## collect the generic if there is one.
|
582 |
|
|
set generic_list {}
|
583 |
|
|
set generic_found 0
|
584 |
|
|
foreach l $ent_list {
|
585 |
|
|
if {$generic_found == 0} {
|
586 |
|
|
set gfound [string first generic $l]
|
587 |
|
|
if {$gfound >= 0} {
|
588 |
|
|
set generic_found 1
|
589 |
|
|
set line_test [split $l "("]
|
590 |
|
|
if {[llength $line_test] > 1} {
|
591 |
|
|
set generic_list [lindex $line_test 1]
|
592 |
|
|
}
|
593 |
|
|
}
|
594 |
|
|
} elseif {[string first ");" $l]} {
|
595 |
|
|
set line_test [split $l ")"]
|
596 |
|
|
if {[llength $line_test] > 1} {
|
597 |
|
|
append generic_list [lindex $line_test 0]
|
598 |
|
|
}
|
599 |
|
|
break
|
600 |
|
|
} else {
|
601 |
|
|
append generic_list $l
|
602 |
|
|
}
|
603 |
|
|
}
|
604 |
|
|
## split into a list
|
605 |
|
|
if {$generic_found == 1} {
|
606 |
|
|
set generic_list [split $generic_list ";"]
|
607 |
|
|
}
|
608 |
|
|
##puts $generic_list
|
609 |
|
|
set gen_lst [pars_gendef $generic_list]
|
610 |
|
|
|
611 |
|
|
set port_found 0
|
612 |
|
|
####################################################################
|
613 |
|
|
## a few checks have been done, and non-relevant stuff stripped off.
|
614 |
|
|
## now create an arrry of just the pin names and related info
|
615 |
|
|
set port_list {}
|
616 |
|
|
foreach l $ent_list {
|
617 |
|
|
## look for the port statement
|
618 |
|
|
# get rid of comments and trim off spaces
|
619 |
|
|
##set cs [split $l "--"]
|
620 |
|
|
##set l [string trim [lindex $cs 0]]
|
621 |
|
|
if {$port_found == 0} {
|
622 |
|
|
set pfound [string first port $l]
|
623 |
|
|
## found one now check if there is a pin def in the same line
|
624 |
|
|
if {$pfound >= 0} {
|
625 |
|
|
set port_found 1
|
626 |
|
|
set efound [string first : $l]
|
627 |
|
|
if {$efound >= 0} {
|
628 |
|
|
set line_test [split $l "("]
|
629 |
|
|
if {[llength $line_test] > 1} {
|
630 |
|
|
## first port so set
|
631 |
|
|
set port_list [lindex $line_test 1]
|
632 |
|
|
}
|
633 |
|
|
}
|
634 |
|
|
}
|
635 |
|
|
} else {
|
636 |
|
|
append port_list $l
|
637 |
|
|
}
|
638 |
|
|
}
|
639 |
|
|
##puts $port_list
|
640 |
|
|
set port_list [split $port_list ";"]
|
641 |
|
|
##puts $port_list
|
642 |
|
|
## Change the port list into a pin info list
|
643 |
|
|
set split_pin [pars_pindef $port_list]
|
644 |
|
|
|
645 |
|
|
# dbg_msg $split_pin
|
646 |
|
|
## calculate the longest pin name in characters
|
647 |
|
|
set name_length 0
|
648 |
|
|
foreach l $split_pin {
|
649 |
|
|
set temp_length [string length [lindex $l 0]]
|
650 |
|
|
if {$temp_length > $name_length} {
|
651 |
|
|
set name_length $temp_length
|
652 |
|
|
}
|
653 |
|
|
}
|
654 |
|
|
#dbg_msg $name_length
|
655 |
|
|
## Make the name length one bigger
|
656 |
|
|
incr name_length
|
657 |
|
|
|
658 |
|
|
$p_view step
|
659 |
|
|
#########################################################################
|
660 |
|
|
## Generate the test bench entity.
|
661 |
|
|
## Create the file name
|
662 |
|
|
set file_type "_tb_ent.vhd"
|
663 |
|
|
set ent_file_name $destin_text
|
664 |
|
|
append ent_file_name "/" $ent_name $file_type
|
665 |
|
|
# dbg_msg $ent_file_name
|
666 |
|
|
## Create the tb entity name
|
667 |
|
|
set tb_ent_name $ent_name
|
668 |
|
|
set tb_sufix "_tb"
|
669 |
|
|
append tb_ent_name $tb_sufix
|
670 |
|
|
|
671 |
|
|
## open and write the header
|
672 |
|
|
set ent_file [open $ent_file_name w+]
|
673 |
|
|
write_header $ent_file
|
674 |
|
|
|
675 |
|
|
## write out Library and use statements
|
676 |
|
|
write_lib_statements $ent_file
|
677 |
|
|
|
678 |
|
|
puts $ent_file "entity $tb_ent_name is"
|
679 |
|
|
puts $ent_file " generic ("
|
680 |
|
|
puts $ent_file " stimulus_file: in string"
|
681 |
|
|
puts $ent_file " )\;"
|
682 |
|
|
puts $ent_file " port ("
|
683 |
|
|
|
684 |
|
|
##-----------------------------------------
|
685 |
|
|
# for each pin in the list output the TB ent pin
|
686 |
|
|
set plist_size [llength $split_pin]
|
687 |
|
|
#dbg_msg $plist_size
|
688 |
|
|
set i 1
|
689 |
|
|
foreach l $split_pin {
|
690 |
|
|
set pdirection [lindex $l 1]
|
691 |
|
|
# puts $pdirection
|
692 |
|
|
## switch on the source pin direction
|
693 |
|
|
switch -exact $pdirection {
|
694 |
|
|
"in" {set tb_ptype "buffer"}
|
695 |
|
|
"out" {set tb_ptype "in"}
|
696 |
|
|
"inout" {set tb_ptype "inout"}
|
697 |
|
|
default {
|
698 |
|
|
msg_error "Should have not got here .. pin direction in entity creation!!"
|
699 |
|
|
}
|
700 |
|
|
}
|
701 |
|
|
## creat some formats for appending
|
702 |
|
|
set new_pname [format " %-${name_length}s" [lindex $l 0]]
|
703 |
|
|
set new_ptype [format ": %-8s" $tb_ptype]
|
704 |
|
|
if {$i != $plist_size} {
|
705 |
|
|
append new_pname $new_ptype [lindex $l 2] ";"
|
706 |
|
|
} else {
|
707 |
|
|
append new_pname $new_ptype [lindex $l 2]
|
708 |
|
|
}
|
709 |
|
|
puts $ent_file $new_pname
|
710 |
|
|
incr i
|
711 |
|
|
}
|
712 |
|
|
|
713 |
|
|
puts $ent_file " )\;"
|
714 |
|
|
puts $ent_file "end $tb_ent_name;"
|
715 |
|
|
close $ent_file
|
716 |
|
|
|
717 |
|
|
$p_view step
|
718 |
|
|
##################################################################
|
719 |
|
|
## Generate the top level test bench entity
|
720 |
|
|
## Create the file name
|
721 |
|
|
set file_type "_ttb_ent.vhd"
|
722 |
|
|
set ent_file_name $destin_text
|
723 |
|
|
append ent_file_name "/" $ent_name $file_type
|
724 |
|
|
# dbg_msg $ent_file_name
|
725 |
|
|
## Create the tb entity name
|
726 |
|
|
set ttb_ent_name $ent_name
|
727 |
|
|
set ttb_sufix "_ttb"
|
728 |
|
|
append ttb_ent_name $ttb_sufix
|
729 |
|
|
|
730 |
|
|
## open and write the header
|
731 |
|
|
set ttb_ent_file [open $ent_file_name w+]
|
732 |
|
|
write_header $ttb_ent_file
|
733 |
|
|
|
734 |
|
|
puts $ttb_ent_file "library IEEE;"
|
735 |
|
|
puts $ttb_ent_file "--library dut_lib;"
|
736 |
|
|
puts $ttb_ent_file "use IEEE.STD_LOGIC_1164.all;"
|
737 |
|
|
puts $ttb_ent_file "--use dut_lib.all;"
|
738 |
|
|
puts $ttb_ent_file ""
|
739 |
|
|
puts $ttb_ent_file "entity $ttb_ent_name is"
|
740 |
|
|
puts $ttb_ent_file " generic ("
|
741 |
|
|
puts $ttb_ent_file " stimulus_file: string := \"stm/stimulus_file.stm\""
|
742 |
|
|
puts $ttb_ent_file " )\;"
|
743 |
|
|
puts $ttb_ent_file "end $ttb_ent_name\;"
|
744 |
|
|
|
745 |
|
|
close $ttb_ent_file
|
746 |
|
|
|
747 |
|
|
$p_view step
|
748 |
|
|
#################################################################
|
749 |
|
|
## Generate the top level structure
|
750 |
|
|
## Create the file name
|
751 |
|
|
set file_type "_ttb_str.vhd"
|
752 |
|
|
set str_file_name $destin_text
|
753 |
|
|
append str_file_name "/" $ent_name $file_type
|
754 |
|
|
# dbg_msg $ent_file_name
|
755 |
|
|
## Create the tb entity name
|
756 |
|
|
set ttb_ent_name $ent_name
|
757 |
|
|
set ttb_sufix "_ttb"
|
758 |
|
|
append ttb_ent_name $ttb_sufix
|
759 |
|
|
|
760 |
|
|
## open and write the header
|
761 |
|
|
set ttb_str_file [open $str_file_name w+]
|
762 |
|
|
write_header $ttb_str_file
|
763 |
|
|
|
764 |
|
|
puts $ttb_str_file ""
|
765 |
|
|
puts $ttb_str_file "architecture struct of $ttb_ent_name is"
|
766 |
|
|
puts $ttb_str_file ""
|
767 |
|
|
puts $ttb_str_file "component $ent_name"
|
768 |
|
|
## if there is generic parts to entity
|
769 |
|
|
if {$generic_found == 1} {
|
770 |
|
|
set len [llength $gen_lst]
|
771 |
|
|
set cnt 0
|
772 |
|
|
puts $ttb_str_file "-- generic ("
|
773 |
|
|
foreach g $gen_lst {
|
774 |
|
|
incr cnt
|
775 |
|
|
set gline "-- "
|
776 |
|
|
append gline [lindex $g 0] " : " [lindex $g 1]
|
777 |
|
|
if {$cnt != $len} {
|
778 |
|
|
append gline "\;"
|
779 |
|
|
}
|
780 |
|
|
puts $ttb_str_file $gline
|
781 |
|
|
}
|
782 |
|
|
puts $ttb_str_file "-- )\;"
|
783 |
|
|
}
|
784 |
|
|
|
785 |
|
|
puts $ttb_str_file " port ("
|
786 |
|
|
## put out the dut component def
|
787 |
|
|
###################################################
|
788 |
|
|
# for each pin in the list output the TB ent pin
|
789 |
|
|
set i 1
|
790 |
|
|
foreach l $split_pin {
|
791 |
|
|
## creat some formats for appending
|
792 |
|
|
set new_pname [format " %-${name_length}s" [lindex $l 0]]
|
793 |
|
|
set new_ptype [format ": %-8s" [lindex $l 1]]
|
794 |
|
|
if {$i != $plist_size} {
|
795 |
|
|
append new_pname $new_ptype [lindex $l 2] ";"
|
796 |
|
|
} else {
|
797 |
|
|
append new_pname $new_ptype [lindex $l 2]
|
798 |
|
|
}
|
799 |
|
|
puts $ttb_str_file $new_pname
|
800 |
|
|
incr i
|
801 |
|
|
}
|
802 |
|
|
puts $ttb_str_file " )\;"
|
803 |
|
|
puts $ttb_str_file "end component\;"
|
804 |
|
|
|
805 |
|
|
puts $ttb_str_file ""
|
806 |
|
|
puts $ttb_str_file "component $tb_ent_name"
|
807 |
|
|
puts $ttb_str_file " generic ("
|
808 |
|
|
puts $ttb_str_file " stimulus_file: in string"
|
809 |
|
|
puts $ttb_str_file " )\;"
|
810 |
|
|
puts $ttb_str_file " port ("
|
811 |
|
|
## put out the tb component def
|
812 |
|
|
####################################################
|
813 |
|
|
# for each pin in the list output the TB ent pin
|
814 |
|
|
set i 1
|
815 |
|
|
foreach l $split_pin {
|
816 |
|
|
set pdirection [lindex $l 1]
|
817 |
|
|
# dbg_msg $pdirection
|
818 |
|
|
## switch on the source pin direction
|
819 |
|
|
switch -exact $pdirection {
|
820 |
|
|
"in" {set tb_ptype "buffer"}
|
821 |
|
|
"out" {set tb_ptype "in"}
|
822 |
|
|
"inout" {set tb_ptype "inout"}
|
823 |
|
|
default {
|
824 |
|
|
msg_error "Should have not got here .. pin direction in entity creation!!"
|
825 |
|
|
}
|
826 |
|
|
}
|
827 |
|
|
## creat some formats for appending
|
828 |
|
|
set new_pname [format " %-${name_length}s" [lindex $l 0]]
|
829 |
|
|
set new_ptype [format ": %-8s" $tb_ptype]
|
830 |
|
|
if {$i != $plist_size} {
|
831 |
|
|
append new_pname $new_ptype [lindex $l 2] ";"
|
832 |
|
|
} else {
|
833 |
|
|
append new_pname $new_ptype [lindex $l 2]
|
834 |
|
|
}
|
835 |
|
|
puts $ttb_str_file $new_pname
|
836 |
|
|
incr i
|
837 |
|
|
}
|
838 |
|
|
puts $ttb_str_file " )\;"
|
839 |
|
|
puts $ttb_str_file "end component\;"
|
840 |
|
|
puts $ttb_str_file ""
|
841 |
|
|
|
842 |
|
|
puts $ttb_str_file "--for all: $ent_name use entity dut_lib.$ent_name\(str)\;"
|
843 |
|
|
puts $ttb_str_file "for all: $tb_ent_name use entity work.$tb_ent_name\(bhv)\;"
|
844 |
|
|
|
845 |
|
|
puts $ttb_str_file ""
|
846 |
|
|
#####################################################
|
847 |
|
|
# for each pin in the list output the TB ent pin
|
848 |
|
|
# generate a signal name
|
849 |
|
|
foreach l $split_pin {
|
850 |
|
|
## creat some formats for appending
|
851 |
|
|
set new_pname [format " signal temp_%-${name_length}s" [lindex $l 0]]
|
852 |
|
|
append new_pname ": " [lindex $l 2] ";"
|
853 |
|
|
puts $ttb_str_file $new_pname
|
854 |
|
|
}
|
855 |
|
|
|
856 |
|
|
puts $ttb_str_file ""
|
857 |
|
|
puts $ttb_str_file "begin"
|
858 |
|
|
puts $ttb_str_file ""
|
859 |
|
|
puts $ttb_str_file "dut: $ent_name"
|
860 |
|
|
## if there is generic parts to entity
|
861 |
|
|
if {$generic_found == 1} {
|
862 |
|
|
set len [llength $gen_lst]
|
863 |
|
|
set cnt 0
|
864 |
|
|
puts $ttb_str_file "-- generic map("
|
865 |
|
|
foreach g $gen_lst {
|
866 |
|
|
incr cnt
|
867 |
|
|
set gline "-- "
|
868 |
|
|
append gline [lindex $g 0] " => "
|
869 |
|
|
puts $ttb_str_file $gline
|
870 |
|
|
}
|
871 |
|
|
puts $ttb_str_file "-- )"
|
872 |
|
|
dbg_msg "A generic map was generated for\nthe DUT, but commented out \
|
873 |
|
|
\nThe user will have to complete\nthis section of the code in the\n \
|
874 |
|
|
ttb_str file."
|
875 |
|
|
}
|
876 |
|
|
|
877 |
|
|
puts $ttb_str_file " port map("
|
878 |
|
|
##-----------------------------------------
|
879 |
|
|
# for each pin in the list output the TB ent pin
|
880 |
|
|
# Generate port map for DUT
|
881 |
|
|
set i 1
|
882 |
|
|
foreach l $split_pin {
|
883 |
|
|
## creat some formats for appending
|
884 |
|
|
set new_pname [format " %-${name_length}s" [lindex $l 0]]
|
885 |
|
|
if {$i != $plist_size} {
|
886 |
|
|
append new_pname "=> temp_" [lindex $l 0] ","
|
887 |
|
|
} else {
|
888 |
|
|
append new_pname "=> temp_" [lindex $l 0]
|
889 |
|
|
}
|
890 |
|
|
puts $ttb_str_file $new_pname
|
891 |
|
|
incr i
|
892 |
|
|
}
|
893 |
|
|
|
894 |
|
|
puts $ttb_str_file " )\;"
|
895 |
|
|
puts $ttb_str_file ""
|
896 |
|
|
puts $ttb_str_file "tb: $tb_ent_name"
|
897 |
|
|
puts $ttb_str_file " generic map("
|
898 |
|
|
puts $ttb_str_file " stimulus_file => stimulus_file"
|
899 |
|
|
puts $ttb_str_file " )"
|
900 |
|
|
puts $ttb_str_file " port map("
|
901 |
|
|
##-----------------------------------------
|
902 |
|
|
# for each pin in the list output the TB ent pin
|
903 |
|
|
# Generate port map for DUT
|
904 |
|
|
set i 1
|
905 |
|
|
foreach l $split_pin {
|
906 |
|
|
## creat some formats for appending
|
907 |
|
|
set new_pname [format " %-${name_length}s" [lindex $l 0]]
|
908 |
|
|
if {$i != $plist_size} {
|
909 |
|
|
append new_pname "=> temp_" [lindex $l 0] ","
|
910 |
|
|
} else {
|
911 |
|
|
append new_pname "=> temp_" [lindex $l 0]
|
912 |
|
|
}
|
913 |
|
|
puts $ttb_str_file $new_pname
|
914 |
|
|
incr i
|
915 |
|
|
}
|
916 |
|
|
|
917 |
|
|
puts $ttb_str_file " )\;"
|
918 |
|
|
puts $ttb_str_file ""
|
919 |
|
|
puts $ttb_str_file "end struct\;"
|
920 |
|
|
close $ttb_str_file
|
921 |
|
|
|
922 |
|
|
######################################################################
|
923 |
|
|
## Now generate the bhv file from template
|
924 |
|
|
|
925 |
|
|
if {[$mo_sel get] == "bhv"} {
|
926 |
|
|
|
927 |
|
|
$p_view step
|
928 |
|
|
set infile [open "$template" r]
|
929 |
|
|
|
930 |
|
|
while {![eof $infile]} {
|
931 |
|
|
## Get a line
|
932 |
|
|
set rline [gets $infile]
|
933 |
|
|
lappend temp_file_list $rline
|
934 |
|
|
}
|
935 |
|
|
close $infile
|
936 |
|
|
|
937 |
|
|
## strip off the header
|
938 |
|
|
set end_header 0
|
939 |
|
|
foreach l $temp_file_list {
|
940 |
|
|
set comment [string first -- $l]
|
941 |
|
|
if {$comment < 0} {
|
942 |
|
|
set end_header 1
|
943 |
|
|
}
|
944 |
|
|
## if we found the end of the header
|
945 |
|
|
if {$end_header == 1} {
|
946 |
|
|
lappend template_list $l
|
947 |
|
|
}
|
948 |
|
|
}
|
949 |
|
|
|
950 |
|
|
## split the file into two peices, to the point of input initialization
|
951 |
|
|
set i 1
|
952 |
|
|
foreach l $template_list {
|
953 |
|
|
## check for parsing point
|
954 |
|
|
set mid_point [string first parse_tb1 $l]
|
955 |
|
|
if {$mid_point >= 0} {
|
956 |
|
|
break
|
957 |
|
|
}
|
958 |
|
|
|
959 |
|
|
if {$i > 2} {
|
960 |
|
|
lappend top_half $l
|
961 |
|
|
}
|
962 |
|
|
incr i
|
963 |
|
|
}
|
964 |
|
|
|
965 |
|
|
set found 0
|
966 |
|
|
foreach l $template_list {
|
967 |
|
|
if {$found == 1} {
|
968 |
|
|
lappend bottom_half $l
|
969 |
|
|
}
|
970 |
|
|
## check for parsing point
|
971 |
|
|
set mid_point [string first parse_tb1 $l]
|
972 |
|
|
if {$mid_point >= 0} {
|
973 |
|
|
set found 1
|
974 |
|
|
}
|
975 |
|
|
}
|
976 |
|
|
|
977 |
|
|
## Create the file name
|
978 |
|
|
set file_type "_tb_bhv.vhd"
|
979 |
|
|
set bhv_file_name $destin_text
|
980 |
|
|
append bhv_file_name "/" $ent_name $file_type
|
981 |
|
|
# dbg_msg $ent_file_name
|
982 |
|
|
|
983 |
|
|
## open and write the header
|
984 |
|
|
set bhv_file [open $bhv_file_name w+]
|
985 |
|
|
write_header $bhv_file
|
986 |
|
|
|
987 |
|
|
puts $bhv_file ""
|
988 |
|
|
puts $bhv_file "architecture bhv of $tb_ent_name is"
|
989 |
|
|
puts $bhv_file ""
|
990 |
|
|
foreach l $top_half {
|
991 |
|
|
puts $bhv_file $l
|
992 |
|
|
}
|
993 |
|
|
|
994 |
|
|
puts $bhv_file ""
|
995 |
|
|
## now generate and write out input initialization
|
996 |
|
|
foreach l $split_pin {
|
997 |
|
|
set temp_def [lindex $l 1]
|
998 |
|
|
set input_def [string first in $temp_def]
|
999 |
|
|
if {$input_def >= 0} {
|
1000 |
|
|
set vector [string first vector $l]
|
1001 |
|
|
set init_def [format " %-${name_length}s" [lindex $l 0]]
|
1002 |
|
|
if {$vector >= 0} {
|
1003 |
|
|
append init_def "<= (others => '0')\;"
|
1004 |
|
|
} else {
|
1005 |
|
|
append init_def "<= '0'\;"
|
1006 |
|
|
}
|
1007 |
|
|
puts $bhv_file $init_def
|
1008 |
|
|
}
|
1009 |
|
|
}
|
1010 |
|
|
puts $bhv_file ""
|
1011 |
|
|
## now write out the bottem half and termination
|
1012 |
|
|
foreach l $bottom_half {
|
1013 |
|
|
puts $bhv_file $l
|
1014 |
|
|
}
|
1015 |
|
|
|
1016 |
|
|
close $bhv_file
|
1017 |
|
|
}
|
1018 |
|
|
## generate the
|
1019 |
|
|
if {$gbatv == 1} {
|
1020 |
|
|
set fn $destin_text
|
1021 |
|
|
append fn "\\build_tb.bat"
|
1022 |
|
|
set batf [open $fn w+]
|
1023 |
|
|
|
1024 |
|
|
puts $batf "ECHO OFF"
|
1025 |
|
|
puts $batf ""
|
1026 |
|
|
puts $batf "vlib work"
|
1027 |
|
|
puts $batf "vcom -quiet tb_pkg_header.vhd tb_pkg_body.vhd"
|
1028 |
|
|
set str {}
|
1029 |
|
|
append str "vcom -2008 -quiet " $ent_name "_tb_ent.vhd " $ent_name "_tb_bhv.vhd"
|
1030 |
|
|
puts $batf $str
|
1031 |
|
|
set str {}
|
1032 |
|
|
append str "vcom -quiet " $ent_name "_ttb_ent.vhd " $ent_name "_ttb_str.vhd"
|
1033 |
|
|
puts $batf $str
|
1034 |
|
|
puts $batf ""
|
1035 |
|
|
|
1036 |
|
|
close $batf
|
1037 |
|
|
}
|
1038 |
|
|
|
1039 |
|
|
## put out a terminating message for the user
|
1040 |
|
|
dbg_msg "Test bench files were generated in directory:\n $destin_text"
|
1041 |
|
|
$p_view step
|
1042 |
|
|
|
1043 |
|
|
if {$cpakv == 1} {
|
1044 |
|
|
## set avail [file exists "../vhdl/tb_pkg_header.vhd"]
|
1045 |
|
|
set avail [file exists "../vhdl/tb_pkg_header.vhd"]
|
1046 |
|
|
if {$avail < 1} {
|
1047 |
|
|
dbg_msg "The package files are not located in the\n expected location. \nThey were not copied."
|
1048 |
|
|
}
|
1049 |
|
|
|
1050 |
|
|
set dest $destin_text
|
1051 |
|
|
append dest "/tb_pkg_header.vhd"
|
1052 |
|
|
if {[file exists $dest] == 0} {
|
1053 |
|
|
file copy "../vhdl/tb_pkg_header.vhd" $dest
|
1054 |
|
|
}
|
1055 |
|
|
set dest $destin_text
|
1056 |
|
|
append dest "/tb_pkg_body.vhd"
|
1057 |
|
|
if {[file exists $dest] == 0} {
|
1058 |
|
|
file copy "../vhdl/tb_pkg_body.vhd" $dest
|
1059 |
|
|
}
|
1060 |
|
|
}
|
1061 |
|
|
}
|
1062 |
|
|
## end ttb_gen
|
1063 |
|
|
|
1064 |
|
|
## show copy right and liability statement.
|
1065 |
|
|
proc show_about {} {
|
1066 |
|
|
global version
|
1067 |
|
|
dbg_msg "ttb_gen Aplication version $version\n
|
1068 |
|
|
Copyright 2014 Ken Campbell\n
|
1069 |
|
|
All Rights Reserved\n
|
1070 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS\n
|
1071 |
|
|
AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED\n
|
1072 |
|
|
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n
|
1073 |
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n
|
1074 |
|
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\n
|
1075 |
|
|
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY\n
|
1076 |
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n
|
1077 |
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n
|
1078 |
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\n
|
1079 |
|
|
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n
|
1080 |
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER\n
|
1081 |
|
|
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n
|
1082 |
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE\n
|
1083 |
|
|
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n
|
1084 |
|
|
POSSIBILITY OF SUCH DAMAGE."
|
1085 |
|
|
}
|
1086 |
|
|
|
1087 |
|
|
## enable pop up console for debug
|
1088 |
|
|
bind . <F12> {catch {console show}}
|
1089 |
|
|
##catch {console show}
|
1090 |
|
|
##-------------------------------------------------------------------------------
|
1091 |
|
|
##-- Revision History:
|
1092 |
|
|
##-- $Log: not supported by cvs2svn $
|
1093 |
|
|
##--
|
1094 |
|
|
##-- Jul 23 2011
|
1095 |
|
|
##-- Fix trailing inline comments error.
|
1096 |
|
|
##-- version now 2.02
|
1097 |
|
|
##----------------------------------------------------------------------------
|