OpenCores
URL https://opencores.org/ocsvn/sv_dir_tb/sv_dir_tb/trunk

Subversion Repositories sv_dir_tb

[/] [sv_dir_tb/] [trunk/] [tb_gen/] [tb_gen_parser.tcl] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sckoarn
##-------------------------------------------------------------------------------
2
##                     Copyright 2019 Ken Campbell
3
##
4
##   Licensed under the Apache License, Version 2.0 (the "License");
5
##   you may not use this file except in compliance with the License.
6
##   You may obtain a copy of the License at
7
##
8
##     http://www.apache.org/licenses/LICENSE-2.0
9
##
10
##   Unless required by applicable law or agreed to in writing, software
11
##   distributed under the License is distributed on an "AS IS" BASIS,
12
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
##   See the License for the specific language governing permissions and
14
##   limitations under the License.
15
##-------------------------------------------------------------------------------
16
##-- $Author:  $ Ken Campbell
17 6 sckoarn
##-- $Date:  $ April 2019
18 5 sckoarn
##-- $Id:  $
19
##-- $Source:  $
20
##-- Description :
21
##--      This application takes a text file containing the definition of a Verilog
22 6 sckoarn
##--         module, produces a file set for the SV Directed Test Bench.
23 5 sckoarn
##--      This file is the parser and generator.
24 6 sckoarn
##--         The parser is a simple one, in that it is not able to provide reliable
25
##--         code generation for all possible syntax.  It is intended that it will
26
##--         generate good code if the module I/O are defined like shown in the examples.
27
##--
28
##--         If you intend to generate many TB, and this parser is not quite what you
29
##--         need, feel free to modify it for your needs.  There are ample comments
30
##--         and left over puts statements that should help with any efforts to 
31
##--         modify the parser.
32 5 sckoarn
##------------------------------------------------------------------------------
33 6 sckoarn
 
34
#################################################################
35
##  parse out the pin definitions from the list of raw pins text from the module.
36
##    input :  list of strings containing pin definitions.
37
##    output :  list of list of pin properties.
38
##           three lists are output, each designed to provide information for
39
##           the generation process.  
40 5 sckoarn
proc pars_pindef { pins } {
41
    set pdef  {}
42
    set def_lst  {}
43
    set lc 0
44
 
45
    set logic_lst {}
46
    set dut_modport {}
47
    set names_lst {}
48
 
49
    foreach l $pins {
50
        set is_mult [string first "," $l]
51
        set is_bv   [string first "\[" $l]
52
        set l [string trim $l "\;"]
53
        #puts $l
54
        #handle precompile
55
        set ispre [string first "`" $l]
56
        if {$ispre >= 0} {
57
            if {[string first "timescale" $l] >= 0} {
58
                continue
59
            }
60
            lappend names_lst $l
61
            lappend logic_lst $l
62
            lappend dut_modport $l
63
            continue
64
        }
65 6 sckoarn
        ##  if is a vector def
66 5 sckoarn
        #puts "is_bv:  $is_bv"
67
        if {$is_bv > 0} {
68 6 sckoarn
 
69
            set is_cbv [string last "\]" $l]
70 5 sckoarn
            set bv_spec [string range $l $is_bv $is_cbv]
71
            set type [string range $l 0 $is_bv-1]
72
            set names [string range $l $is_cbv+1 end]
73
            set snames [split $names ","]
74
            foreach n $snames {
75 6 sckoarn
                #puts $n
76
                set sn [string trim $n]
77
                if {$sn == ""} {
78
                    break
79
                }
80 5 sckoarn
                lappend names_lst [string trim $n]
81
                if {$type != "inout"} {
82
                    set tmp "logic "
83
                } else {
84
                    set tmp "wire "
85
                }
86
                append tmp $bv_spec " [string trim $n]\;"
87
                lappend logic_lst $tmp
88
                set tmp [string trim $type]
89
                append tmp " [string trim $n],"
90
                lappend dut_modport $tmp
91
            }
92
        } else {
93 6 sckoarn
            #puts $l
94 5 sckoarn
            set sl [split $l ","]
95
            set frst [split [lindex $sl 0]]
96
            set type [string trim [lindex $frst 0]]
97 6 sckoarn
            ## get the pin type from the def.
98
            set tmp ""
99
            foreach pt [lrange $frst 1 end] {
100
                if {$pt != ""} {
101
                    if {$pt == "var"} {
102
                        set tmp "$pt "
103
                    }  else {
104
                        append tmp $pt
105
                        set pin_type $tmp
106
                        break
107
                    }
108
                }
109
            }
110
            #puts $pin_type
111 5 sckoarn
            set fname [string trim [lindex $frst end]]
112
            set sl [lrange $sl 1 end]
113
            lappend names_lst [string trim $fname]
114
            if {$type != "inout"} {
115 6 sckoarn
                set tmp "$pin_type "
116 5 sckoarn
            } else {
117
                set tmp "wire "
118
            }
119
            #set tmp "logic "
120
            append tmp "$fname\;"
121
            lappend logic_lst $tmp
122
            set tmp $type
123
            append tmp " $fname,"
124
            lappend dut_modport $tmp
125
            foreach n $sl {
126
                if {$n == ""} {
127
                    continue
128
                }
129 6 sckoarn
                #puts $n
130 5 sckoarn
                lappend names_lst [string trim $n]
131
                if {$type != "inout"} {
132
                    set tmp "logic "
133
                } else {
134
                    set tmp "wire "
135
                }
136
                append tmp "[string trim $n]\;"
137
                lappend logic_lst $tmp
138
                set tmp $type
139
                append tmp " [string trim $n],"
140
                lappend dut_modport $tmp
141
            }
142
        }
143
    }
144
 
145
    lappend def_lst $logic_lst
146
    lappend def_lst $dut_modport
147
    lappend def_lst $names_lst
148
 
149
    return $def_lst
150
}
151
##  end pars_pindef
152
 
153 6 sckoarn
##-------------------------------------------------------------------------------
154
##  pars parameters 
155
proc pars_params {plst} {
156
    set rtn {}
157
    foreach p $plst {
158
        set sp [split [string trim $p ","] " "]
159
        set tmp [lindex $sp 1]
160
        lappend tmp [lindex $sp end]
161
        lappend rtn $tmp
162
    }
163
    return $rtn
164
}
165
##  end  pars_params
166 5 sckoarn
##--------------------------------------------------------------------------------
167
##  Write header to file passed
168 6 sckoarn
##    if you intend to use this tool many times and it matters
169
##    mod this section to output the header as required.
170 5 sckoarn
proc write_header { handle } {
171
    global version
172
    ##global scan_date
173
    set raw_date [clock scan now]
174
    set scan_date [clock format $raw_date -format "%d %b %Y %T"]
175
 
176
    ## so CVS will not modify selections, they have to be chopped up
177
    set auth "// \$Auth"
178
    append auth "or:  \$"
179
 
180
    puts $handle "///////////////////////////////////////////////////////////////////////////////"
181
    puts $handle "//             Copyright ///////////////////////////////////"
182
    puts $handle "//                        All Rights Reserved"
183
    puts $handle "///////////////////////////////////////////////////////////////////////////////"
184
    puts $handle "$auth"
185
    puts $handle "//"
186
    puts $handle "//"
187
    puts $handle "// Description :"
188
    puts $handle "//          This file was generated by SV TB Gen $version"
189
    puts $handle "//            on $scan_date"
190
    puts $handle "//////////////////////////////////////////////////////////////////////////////"
191
    puts $handle "// This software contains concepts confidential to ////////////////"
192
    puts $handle "// /////////. and is only made available within the terms of a written"
193
    puts $handle "// agreement."
194
    puts $handle "///////////////////////////////////////////////////////////////////////////////"
195
    puts $handle ""
196
  }
197
 
198
#####################################################################
199
##  A directory has been selected now fill the list win with *V files
200
proc fill_list {} {
201
    global ent_dir odir
202 6 sckoarn
    global use_list list_win ts_ent statsVar
203
    global view_win mo_sel sel_lst list_ent
204 5 sckoarn
 
205
    ## get the user selection
206
    browsed_from_set $ent_dir $ent_dir
207
    ## as a default make output dir = input dir
208
    set tmp_dir [$ent_dir get]
209
    $odir delete 0 end
210
    $odir insert end $tmp_dir
211
    $odir configure -state readonly
212
 
213
    ## clear the list window and selection
214 6 sckoarn
    $list_win delete 0 end
215
    $list_ent delete 0 end
216 5 sckoarn
    #$list_win clear selection
217 6 sckoarn
    $view_win delet 0.0 end
218 5 sckoarn
    ## get the working directory
219
    set dir [$ent_dir get]
220 6 sckoarn
    ## get the list of SV & v files in working directory
221 5 sckoarn
    set ftype ".*v"
222
    set file_lst ""
223 6 sckoarn
    set are_files [catch {glob -directory $dir *$ftype} rtn_code]
224
    if {$are_files == 0} {
225
        set file_lst [glob -directory $dir *$ftype]
226
    } else {
227
        return
228
    }
229 5 sckoarn
    #puts $file_lst
230
    ##  for each of the files in the file_lst
231
    foreach l $file_lst {
232
        ## creat string that is just the file name: no path
233 6 sckoarn
        #puts "File : $l"
234 5 sckoarn
        set testt $l
235
        set nstart [string last "/" $l]
236
        incr nstart
237
        #puts "Index : $nstart"
238
        set name_str [string range $l $nstart end]
239
        set sel_lst [lappend sel_lst $name_str]
240
        #puts $sel_lst
241
    }
242
}
243
 
244
######################################################################
245 6 sckoarn
##   click on the  listbox  process it.
246
proc process_selected {} {
247
    global list_win m_select
248
 
249
    set sz [$list_win size]
250
    #puts $sz
251
    if {$sz > 0} {
252
        set sel_dx [$list_win curselection]
253
        set m_select [$list_win get $sel_dx]
254
        load_ent_file
255
    } else {
256
    }
257
}
258
 
259
######################################################################
260 5 sckoarn
##  load the vhdl file that has just been selected from list_win
261
proc load_ent_file {} {
262
    global ent_dir list_win view_win statsVar gen_prog
263
 
264
    set gen_prog 0.0
265
    ## update selection with selected item
266
    set sel_dx [$list_win curselection]
267
    if {$sel_dx == ""} {
268
        return
269
    }
270
    ## recover the selected item
271
    set ln [$list_win get $sel_dx]
272
    ##  Get the working directory
273
    #puts $ln
274
    set lp [$ent_dir get]
275
    ##  append the file name
276
    append lp "/" $ln
277
    ## if the file does not exist  return
278
    set fexist [file exist $lp]
279
    if {$fexist == 0} {
280
        return
281
    }
282
    set ent_file [open $lp r]
283
    ## clear the view_win
284
    $view_win delete 1.0 end
285
    set file_list {}
286
    ## load file to memory
287
    while {![eof $ent_file]} {
288
        ##  Get a line
289
        set rline [gets $ent_file]
290
        lappend file_list $rline
291
    }
292
    close $ent_file
293 6 sckoarn
    ## put file in text window and highlite the module part
294 5 sckoarn
    set ent_found 0
295
    set in_ent 0
296
    set statsVar ""
297
    foreach l $file_list {
298
        if {$in_ent == 0} {
299
            set ent_def [string first module $l]
300 6 sckoarn
            ## Make crazy assumption the module def is in the first few chars.
301
            if {$ent_def >= 0 && $ent_def <= 6} {
302 5 sckoarn
                set ent_name [lindex $l 1]
303
                set statsVar "Module:  $ent_name found"
304
                set ent_found 1
305
                set in_ent 1
306
                $view_win insert end "$l\n" highlite
307
            } else {
308
                $view_win insert end "$l\n"
309 6 sckoarn
            }
310 5 sckoarn
        } else {
311 6 sckoarn
            set ent_def [string first "endmodule" $l]
312
            if {$ent_def >= 0} {
313
                set end_name [lindex $l 1]
314
                set end_found 1
315
                set in_ent 0
316 5 sckoarn
                $view_win insert end "$l\n" highlite
317 6 sckoarn
            } else {
318
                $view_win insert end "$l\n" highlite
319
            }
320 5 sckoarn
        }
321
    }
322
    if {$ent_found == 0} {
323
        set statsVar "No Module found!!"
324
    }
325
}
326
 
327
#########################################################################
328 6 sckoarn
##  The main generator proc
329 5 sckoarn
proc ttb_gen {} {
330
    global mo_sel template ent_dir list_win odir p_view tdir
331
    global cpakv gbatv gen_prog comb_val m_select
332
 
333
    set template [$tdir get]
334
 
335
    $p_view configure -maximum 7
336
    set gen_prog 1.0
337
    ## recover the selected item
338
    set ln $m_select
339
    ##  Get the working directory
340
    #puts $ln
341
    set lp [$ent_dir get]
342
    ##  append the file name
343
    append lp "/" $ln
344
 
345
    set path_text $lp
346
    set destin_text [$odir get]
347
    set infile [open $path_text r]
348
    set file_list {}
349
 
350 6 sckoarn
    set bl_comm 0;   ##  block comment indication.
351 5 sckoarn
##################################################################
352
##  Read in the file and strip comments as we do
353
    while {![eof $infile]} {
354
        ##  Get a line
355
        set rline [gets $infile]
356
        #puts $rline
357
        ## get rid of white space
358
        set rline [string trim $rline]
359
        ##  Find comment if there
360
        set cindex [string first "//" $rline]
361 6 sckoarn
        ##  Block comments.
362
        set bcomm_s [string first "/*" $rline]
363
        set bcomm_e [string first "*/" $rline]
364
        ##  this will break if  block start  after some code ...
365
        if {$bcomm_s >= 0} {
366
            set bl_comm 1
367
            continue
368
        }
369
        if {$bcomm_s == 1} {
370
            if {$bcomm_e >= 0} {
371
                set bl_comm 0
372
            }
373
            continue
374
        }
375 5 sckoarn
        ## if a comment was found at the start of the line
376
        if {$cindex == 0 || $rline == ""} {
377
            continue
378 6 sckoarn
        ## else if comment somewhere in the line
379 5 sckoarn
        } elseif {$cindex > 0} {
380
            #  get rid of trailing comments and trim off spaces
381
            set rline [string trim [string range $rline 0 $cindex-1]]
382
            lappend file_list $rline
383 6 sckoarn
        ## else was not found so put line in list
384 5 sckoarn
        } else {
385
            lappend file_list $rline
386
        }
387
    }
388
    close $infile
389
 
390 6 sckoarn
 
391
    #foreach l $file_list {
392
    #    puts $l
393
    #}
394
    #return
395
 
396
    #$p_view step
397 5 sckoarn
    ## check for the module def
398
    set mod_name ""
399
    foreach l $file_list {
400
        set mod_def [string first module $l]
401
        if {$mod_def >= 0} {
402
            set ml [split $l]
403
            set mod_name [lindex $l 1]
404
            break
405
        }
406
    }
407
 
408
    #puts "Module name is: $mod_name"
409
    ## if no ent  die
410
    if {$mod_def < 0} {
411
        dbg_msg "A module definition was not found in the file provided."
412
        return
413
        ##  exit
414
    }
415 6 sckoarn
    #$p_view step
416 5 sckoarn
    set mod_list {}
417
    ## check for end module
418
    foreach l $file_list {
419
        lappend mod_list $l
420
        set end_def [string first endmodule $l]
421
        if {$end_def >= 0} {
422
            break
423
        }
424
    }
425
    ## if no end die
426
    if {$end_def < 0} {
427
        dbg_msg "no endmodule statement found for this module"
428
        return
429
        ##  exit
430
    }
431
    ####
432
    ## collect the parameters if there are.
433
    set parameter_list {}
434
    set p_found 0
435
    foreach l $mod_list {
436
        set p_found [string first "parameter" $l]
437
        if {$p_found >= 0} {
438 6 sckoarn
            lappend parameter_list $l
439 5 sckoarn
        }
440
    }
441 6 sckoarn
    #foreach pl $parameter_list {
442
    #    puts $pl
443
    #}
444
    ##  inc the progress bar
445 5 sckoarn
    set gen_prog 2.0
446
    #foreach l $mod_list {
447
    #    puts $l
448
    #}
449
    ####################################################################
450
    ##  a few checks have been done, and non-relevant stuff stripped off.
451
    ##  now create an arrry of just the pin names and related info
452
    set port_lst {}
453 6 sckoarn
    set import_lst {}
454 5 sckoarn
    set lc 0
455
    foreach l $mod_list {
456
        ## make lines that are continued, one line.
457
        set cont [string first "\;" $l]
458
        ## look for the port statements
459
        set inp [string first "input " $l]
460
        if {$inp >= 0} {
461
            lappend port_lst $l
462
        }
463
        set onp [string first "output " $l]
464
        if {$onp >= 0} {
465
            lappend port_lst $l
466
        }
467
        set ionp [string first "inout " $l]
468
        if {$ionp >= 0} {
469
            lappend port_lst $l
470
        }
471
        set tick_dir [string first "`" $l]
472
        if {$tick_dir >= 0} {
473
            lappend port_lst $l
474
        }
475 6 sckoarn
        set is_import [string first "import" $l]
476
        if {$is_import >= 0} {
477
            lappend import_lst $l
478
        }
479
        set end_pins [string first "\)\;" $l]
480
        set end_len [string length $l]
481
        if {$end_pins >= 0 && $end_len >= 2} {
482
            set stl [string trim $l "\)\;"]
483
            if {$stl != ""} {
484
                lappend port_lst $l
485
            }
486
            break
487
        }
488 5 sckoarn
    }
489
 
490
    #foreach p $port_lst {
491
    #    puts $p
492
    #}
493 6 sckoarn
    #return
494
    ##  Change the port list into a pin info list of lists
495 5 sckoarn
    set io_pins [pars_pindef $port_lst]
496 6 sckoarn
    ##  get the lists
497 5 sckoarn
    set log_lst [lindex $io_pins 0]
498
    set mod_lst [lindex $io_pins 1]
499
    set name_lst [lindex $io_pins 2]
500
 
501
    #foreach r $log_lst {
502
    #    puts $r
503
    #}
504
    #foreach r $mod_lst {
505
    #    puts $r
506
    #}
507
    #foreach r $name_lst {
508
    #    puts $r
509
    #}
510 6 sckoarn
    #return
511
    ##########################################
512
    ##  if there are parameters.
513
    if {[llength $parameter_list] > 0} {
514
        set param_lst [pars_params $parameter_list]
515
    }
516 5 sckoarn
 
517 6 sckoarn
    #foreach l $param_lst {
518
    #    puts $l
519
    #}
520 5 sckoarn
 
521
    # dbg_msg $split_pin
522
    ## calculate the longest pin name in characters
523
    set name_length 0
524
    foreach l $name_lst {
525
        set temp_length [string length $l]
526
        if {$temp_length > $name_length} {
527
            set name_length $temp_length
528
        }
529
    }
530
    #dbg_msg $name_length
531
    ##  Make the name length one bigger
532
    incr name_length
533
 
534 6 sckoarn
    ##  inc the progress bar
535 5 sckoarn
    set gen_prog 3.0
536
#########################################################################
537
## Generate the tb top.
538
    set tfn $destin_text
539
    append tfn "/tb_top.sv"
540
    set tfh [open $tfn w]
541
 
542
    write_header $tfh
543 6 sckoarn
    puts $tfh "`include \"../sv/tb_mod.sv\""
544 5 sckoarn
    puts $tfh ""
545
    puts $tfh "module tb_top \(\)\;"
546
    puts $tfh ""
547
    puts $tfh "  string STM_FILE = \"../stm/stimulus_file.stm\"\;"
548
    puts $tfh "  string tmp_fn;"
549
    puts $tfh ""
550
    puts $tfh "  //  Handle plus args"
551
    puts $tfh "  initial begin : file_select"
552
    puts $tfh "    if\(\$value\$plusargs\(\"STM_FILE=%s\", tmp_fn\)\) begin"
553 6 sckoarn
    puts $tfh "      STM_FILE = tmp_fn\;"
554 5 sckoarn
    puts $tfh "    end"
555
    puts $tfh "  end"
556
    puts $tfh ""
557
    puts $tfh "  dut_if theif\(\)\;"
558
    puts $tfh ""
559 6 sckoarn
    ## handle parameters.
560
    if {[llength $param_lst] == 0} {
561
        puts $tfh "  $mod_name u1 \("
562
    } else {
563
        puts $tfh "  $mod_name"
564
        puts $tfh "  \#\("
565
        set llen [llength $param_lst]
566
        set idx 1
567
        foreach p $param_lst {
568
            set tmp "    .[lindex $p 0]\("
569
            if {$idx < $llen} {
570
                append tmp "[lindex $p 1]\),"
571
            } else {
572
                append tmp "[lindex $p 1]\)"
573
            }
574
            puts $tfh $tmp
575
            incr idx
576
        }
577
         puts $tfh "  \) u1 \("
578
    }
579 5 sckoarn
 
580
    set llen [llength $name_lst]
581
    set idx 1
582
    foreach n $name_lst {
583
        set ln $n
584
        set tick_dir [string first "`" $n]
585
        if {$tick_dir >= 0} {
586
            puts $tfh "    $n"
587
            incr idx
588
            continue
589
        }
590
        set len [string length $ln]
591
        while {$len < $name_length} {
592
            append ln " "
593
            set len [string length $ln]
594
        }
595
        if {$idx < $llen} {
596
            puts $tfh "    .$ln \(theif.$n\),"
597
        } else {
598
            puts $tfh "    .$ln \(theif.$n\)"
599
        }
600
        incr idx
601
    }
602
 
603
    puts $tfh "  \)\;"
604
    puts $tfh ""
605
    puts $tfh "  tb_mod prg_inst\(theif\)\;"
606
    puts $tfh ""
607
    puts $tfh "endmodule"
608
 
609
    close $tfh
610 6 sckoarn
    ##  inc the progress bar
611 5 sckoarn
    set gen_prog 4.0
612
############################################################################
613
##  generate the interface file.
614
    set ifn $destin_text
615
    append ifn "/dut_if.sv"
616
    set ifh [open $ifn w]
617
 
618
    write_header $ifh
619 6 sckoarn
    ##  handle the parameters.
620
    if {[llength $param_lst] == 0} {
621
        puts $ifh "interface dut_if\(\)\;"
622
    } else {
623
        puts $tfh "  $mod_name"
624
        puts $tfh "  \#\("
625
        set llen [llength $param_lst]
626
        set idx 1
627
        foreach p $param_lst {
628
            set tmp "    [lindex $p 0] = "
629
            if {$idx < $llen} {
630
                append tmp "[lindex $p 1],"
631
            } else {
632
                append tmp "[lindex $p 1]"
633
            }
634
            puts $tfh $tmp
635
            incr idx
636
        }
637
         puts $tfh "  \)\(\)\;"
638
    }
639 5 sckoarn
    puts $ifh ""
640 6 sckoarn
    foreach i $import_lst {
641
        puts $ifh "  $i"
642
    }
643
    puts $ifh ""
644 5 sckoarn
    foreach l $log_lst {
645
        puts $ifh "  $l"
646
    }
647
 
648
    puts $ifh ""
649
    puts $ifh "  modport dut_conn\("
650
    set llen [llength $mod_lst]
651
    set idx 1
652
    foreach p $mod_lst {
653 6 sckoarn
        ## if there is an `ifdef ...
654 5 sckoarn
        set tick_dir [string first "`" $l]
655
        if {$tick_dir >= 0} {
656
            puts $ifh "    $p"
657
            incr idx
658
            continue
659
        }
660 6 sckoarn
        set sp [split $p]
661 5 sckoarn
        if {$idx < $llen} {
662 6 sckoarn
            puts $ifh "    [lindex $sp 0]   [lindex $sp end]"
663 5 sckoarn
        } else {
664 6 sckoarn
            puts $ifh "    [lindex $sp 0]   [string trim [lindex $sp end] ","]"
665 5 sckoarn
        }
666
        incr idx
667
    }
668
    puts $ifh "  \)\;"
669
    puts $ifh ""
670
    puts $ifh "  modport tb_conn\("
671
    set idx 1
672
    foreach p $mod_lst {
673 6 sckoarn
        ## if there is an `ifdef ...
674 5 sckoarn
        set tick_dir [string first "`" $p]
675
        if {$tick_dir >= 0} {
676
            puts $ifh "    $p"
677
            incr idx
678
            continue
679
        }
680
        set in [string first "input" $p]
681
        set out [string first "output" $p]
682
        if {$in >= 0} {
683
            set type "output  "
684
        } elseif {$out >= 0} {
685
            set type "input   "
686
        } else {
687
            set type "inout   "
688
        }
689
 
690
        set sp [split $p]
691 6 sckoarn
        #puts $sp
692 5 sckoarn
        if {$idx < $llen} {
693
            puts $ifh "    $type [lindex $sp end]"
694
        } else {
695
            puts $ifh "    $type [string trim [lindex $sp end] ","]"
696
        }
697
        incr idx
698
    }
699
    puts $ifh "  \)\;"
700
    puts $ifh ""
701
    puts $ifh "endinterface"
702
    close $ifh
703 6 sckoarn
    ##  inc the progress bar
704 5 sckoarn
    set gen_prog 5.0
705
##########################################################################
706
##   generate the tb_prg  file from template.
707 6 sckoarn
    #puts $comb_val
708 5 sckoarn
    if {$comb_val == "No mod"} {
709 6 sckoarn
        ##  indicate done in progress bar.
710 5 sckoarn
        set gen_prog 7.0
711 6 sckoarn
        puts "No tb_mod file was generated."
712
            return
713 5 sckoarn
    }
714
    set tpl_fh [open $template r]
715
    set tpl_lst {}
716
    set hfound 0
717
    while {![eof $tpl_fh]} {
718
        set rline [gets $tpl_fh]
719
        if {$hfound == 0} {
720
            set head [string first ">>header" $rline]
721
            if {$head == 0} {
722
                set hfound 1
723
            }
724
        } else {
725
            lappend tpl_lst $rline
726
        }
727
    }
728
 
729
    #foreach l $tpl_lst {
730
    #    puts  $l
731
    #}
732
 
733
    set pfn $destin_text
734
    append pfn "/tb_mod.sv"
735
    set pfh [open $pfn w]
736
 
737
    set idx 0
738
    foreach l $tpl_lst {
739
        set ent_pt [string first ">>insert sigs" $l]
740
        if {$ent_pt == 0} {
741
            set tpl_lst [lreplace $tpl_lst $idx $idx]
742
            foreach l $log_lst {
743
                set tpl_lst [linsert $tpl_lst $idx "  $l"]
744
                incr idx
745
            }
746
            break
747
        }
748
        incr idx
749
    }
750
 
751
    #foreach l $tpl_lst {
752
    #    puts  $l
753
    #}
754
 
755 6 sckoarn
    ##  inc the progress bar
756 5 sckoarn
    set gen_prog 6.0
757
    set idx 0
758
    foreach l $tpl_lst {
759
        set ent_pt [string first ">>drive sigs" $l]
760
        if {$ent_pt == 0} {
761
            set tpl_lst [lreplace $tpl_lst $idx $idx]
762
            set midx 0
763
            foreach l $name_lst {
764
                set dir [lindex $mod_lst $midx]
765
                #puts $dir
766
                #puts "$idx $l"
767
                set idir [string first "input" $dir]
768
                if {[string first "`" $l] >= 0} {
769
                    set tmp $l
770
                } elseif {$idir >= 0} {
771
                    set tmp "  assign tif."
772
                    append tmp "$l = $l\;"
773
                } else {
774
                    set tmp "  assign $l"
775
                    append tmp " = tif.$l\;"
776
                }
777
                set tpl_lst [linsert $tpl_lst $idx $tmp]
778
                #puts [lindex $tpl_lst $idx]
779
                incr idx
780
                incr midx
781
            }
782
            break
783
        }
784
        incr idx
785
    }
786
 
787
    write_header $pfh
788
    foreach l $tpl_lst {
789
        puts $pfh $l
790
    }
791
    set gen_prog 7.0
792
    close $pfh
793
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.