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] - Diff between revs 5 and 6

Show entire file | Details | Blame | View Log

Rev 5 Rev 6
Line 12... Line 12...
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##   See the License for the specific language governing permissions and
##   See the License for the specific language governing permissions and
##   limitations under the License.
##   limitations under the License.
##-------------------------------------------------------------------------------
##-------------------------------------------------------------------------------
##-- $Author:  $ Ken Campbell
##-- $Author:  $ Ken Campbell
##-- $Date:  $ Jan. 2019
##-- $Date:  $ April 2019
##-- $Id:  $
##-- $Id:  $
##-- $Source:  $
##-- $Source:  $
##-- Description :
##-- Description :
##--      This application takes a text file containing the definition of a Verilog
##--      This application takes a text file containing the definition of a Verilog
##           module, produces a file set for the SV Directed Test Bench.
##--         module, produces a file set for the SV Directed Test Bench.
##--      This file is the parser and generator.
##--      This file is the parser and generator.
 
##--         The parser is a simple one, in that it is not able to provide reliable
 
##--         code generation for all possible syntax.  It is intended that it will
 
##--         generate good code if the module I/O are defined like shown in the examples.
 
##--
 
##--         If you intend to generate many TB, and this parser is not quite what you
 
##--         need, feel free to modify it for your needs.  There are ample comments
 
##--         and left over puts statements that should help with any efforts to 
 
##--         modify the parser.
##------------------------------------------------------------------------------
##------------------------------------------------------------------------------
 
 
 
#################################################################
 
##  parse out the pin definitions from the list of raw pins text from the module.
 
##    input :  list of strings containing pin definitions.
 
##    output :  list of list of pin properties.
 
##           three lists are output, each designed to provide information for
 
##           the generation process.  
proc pars_pindef { pins } {
proc pars_pindef { pins } {
    set pdef  {}
    set pdef  {}
    set def_lst  {}
    set def_lst  {}
    set lc 0
    set lc 0
 
 
Line 33... Line 48...
 
 
    foreach l $pins {
    foreach l $pins {
        set is_mult [string first "," $l]
        set is_mult [string first "," $l]
        set is_bv   [string first "\[" $l]
        set is_bv   [string first "\[" $l]
        set l [string trim $l "\;"]
        set l [string trim $l "\;"]
        ##  if is a vector def
 
        #puts $l
        #puts $l
        #handle precompile
        #handle precompile
        set ispre [string first "`" $l]
        set ispre [string first "`" $l]
        if {$ispre >= 0} {
        if {$ispre >= 0} {
            #strip `timescale
 
            if {[string first "timescale" $l] >= 0} {
            if {[string first "timescale" $l] >= 0} {
                continue
                continue
            }
            }
            lappend names_lst $l
            lappend names_lst $l
            lappend logic_lst $l
            lappend logic_lst $l
            lappend dut_modport $l
            lappend dut_modport $l
            continue
            continue
        }
        }
 
        ##  if is a vector def
        #puts "is_bv:  $is_bv"
        #puts "is_bv:  $is_bv"
        if {$is_bv > 0} {
        if {$is_bv > 0} {
            set is_cbv [string first "\]" $l]
 
 
            set is_cbv [string last "\]" $l]
            set bv_spec [string range $l $is_bv $is_cbv]
            set bv_spec [string range $l $is_bv $is_cbv]
            set type [string range $l 0 $is_bv-1]
            set type [string range $l 0 $is_bv-1]
            set names [string range $l $is_cbv+1 end]
            set names [string range $l $is_cbv+1 end]
            set snames [split $names ","]
            set snames [split $names ","]
            foreach n $snames {
            foreach n $snames {
                ##set n [string trim $n "\;"]
                #puts $n
 
                set sn [string trim $n]
 
                if {$sn == ""} {
 
                    break
 
                }
                lappend names_lst [string trim $n]
                lappend names_lst [string trim $n]
                if {$type != "inout"} {
                if {$type != "inout"} {
                    set tmp "logic "
                    set tmp "logic "
                } else {
                } else {
                    set tmp "wire "
                    set tmp "wire "
Line 67... Line 86...
                append tmp $bv_spec " [string trim $n]\;"
                append tmp $bv_spec " [string trim $n]\;"
                lappend logic_lst $tmp
                lappend logic_lst $tmp
                set tmp [string trim $type]
                set tmp [string trim $type]
                append tmp " [string trim $n],"
                append tmp " [string trim $n],"
                lappend dut_modport $tmp
                lappend dut_modport $tmp
                #puts "$type $bv_spec [string trim $n]\;"
 
            }
            }
        } else {
        } else {
 
            #puts $l
            set sl [split $l ","]
            set sl [split $l ","]
            set frst [split [lindex $sl 0]]
            set frst [split [lindex $sl 0]]
            set type [string trim [lindex $frst 0]]
            set type [string trim [lindex $frst 0]]
 
            ## get the pin type from the def.
 
            set tmp ""
 
            foreach pt [lrange $frst 1 end] {
 
                if {$pt != ""} {
 
                    if {$pt == "var"} {
 
                        set tmp "$pt "
 
                    }  else {
 
                        append tmp $pt
 
                        set pin_type $tmp
 
                        break
 
                    }
 
                }
 
            }
 
            #puts $pin_type
            set fname [string trim [lindex $frst end]]
            set fname [string trim [lindex $frst end]]
            set sl [lrange $sl 1 end]
            set sl [lrange $sl 1 end]
            lappend names_lst [string trim $fname]
            lappend names_lst [string trim $fname]
            if {$type != "inout"} {
            if {$type != "inout"} {
                set tmp "logic "
                set tmp "$pin_type "
            } else {
            } else {
                set tmp "wire "
                set tmp "wire "
            }
            }
            #set tmp "logic "
            #set tmp "logic "
            append tmp "$fname\;"
            append tmp "$fname\;"
Line 91... Line 124...
            lappend dut_modport $tmp
            lappend dut_modport $tmp
            foreach n $sl {
            foreach n $sl {
                if {$n == ""} {
                if {$n == ""} {
                    continue
                    continue
                }
                }
                puts $n
                #puts $n
                lappend names_lst [string trim $n]
                lappend names_lst [string trim $n]
                if {$type != "inout"} {
                if {$type != "inout"} {
                    set tmp "logic "
                    set tmp "logic "
                } else {
                } else {
                    set tmp "wire "
                    set tmp "wire "
Line 115... Line 148...
 
 
    return $def_lst
    return $def_lst
}
}
##  end pars_pindef
##  end pars_pindef
 
 
 
##-------------------------------------------------------------------------------
 
##  pars parameters 
 
proc pars_params {plst} {
 
    set rtn {}
 
    foreach p $plst {
 
        set sp [split [string trim $p ","] " "]
 
        set tmp [lindex $sp 1]
 
        lappend tmp [lindex $sp end]
 
        lappend rtn $tmp
 
    }
 
    return $rtn
 
}
 
##  end  pars_params
##--------------------------------------------------------------------------------
##--------------------------------------------------------------------------------
##  Write header to file passed
##  Write header to file passed
 
##    if you intend to use this tool many times and it matters
 
##    mod this section to output the header as required.
proc write_header { handle } {
proc write_header { handle } {
    global version
    global version
    ##global scan_date
    ##global scan_date
    set raw_date [clock scan now]
    set raw_date [clock scan now]
    set scan_date [clock format $raw_date -format "%d %b %Y %T"]
    set scan_date [clock format $raw_date -format "%d %b %Y %T"]
Line 149... Line 197...
 
 
#####################################################################
#####################################################################
##  A directory has been selected now fill the list win with *V files
##  A directory has been selected now fill the list win with *V files
proc fill_list {} {
proc fill_list {} {
    global ent_dir odir
    global ent_dir odir
    global tlist_ent use_list list_win ts_ent statsVar
    global use_list list_win ts_ent statsVar
    global view_win mo_sel sel_lst
    global view_win mo_sel sel_lst list_ent
 
 
    ## get the user selection
    ## get the user selection
    browsed_from_set $ent_dir $ent_dir
    browsed_from_set $ent_dir $ent_dir
    ## as a default make output dir = input dir
    ## as a default make output dir = input dir
    set tmp_dir [$ent_dir get]
    set tmp_dir [$ent_dir get]
    $odir delete 0 end
    $odir delete 0 end
    $odir insert end $tmp_dir
    $odir insert end $tmp_dir
    $odir configure -state readonly
    $odir configure -state readonly
 
 
    ## clear the list window and selection
    ## clear the list window and selection
    #$list_win clear items
    $list_win delete 0 end
 
    $list_ent delete 0 end
    #$list_win clear selection
    #$list_win clear selection
    #$view_win clear
    $view_win delet 0.0 end
    ## get the working directory
    ## get the working directory
    set dir [$ent_dir get]
    set dir [$ent_dir get]
    ## get the list of VHDL files in working directory
    ## get the list of SV & v files in working directory
    set ftype ".*v"
    set ftype ".*v"
    set file_lst ""
    set file_lst ""
 
    set are_files [catch {glob -directory $dir *$ftype} rtn_code]
 
    if {$are_files == 0} {
    set file_lst [glob -directory $dir *$ftype]
    set file_lst [glob -directory $dir *$ftype]
 
    } else {
 
        return
 
    }
    #puts $file_lst
    #puts $file_lst
    ##  for each of the files in the file_lst
    ##  for each of the files in the file_lst
    foreach l $file_lst {
    foreach l $file_lst {
        ## creat string that is just the file name: no path
        ## creat string that is just the file name: no path
        puts "File : $l"
        #puts "File : $l"
        set testt $l
        set testt $l
        set nstart [string last "/" $l]
        set nstart [string last "/" $l]
        incr nstart
        incr nstart
        #puts "Index : $nstart"
        #puts "Index : $nstart"
        set name_str [string range $l $nstart end]
        set name_str [string range $l $nstart end]
        set sel_lst [lappend sel_lst $name_str]
        set sel_lst [lappend sel_lst $name_str]
        #puts $sel_lst
        #puts $sel_lst
        ## insert item on list
    }
        #$list_win insert items 1 $name_str
}
 
 
 
######################################################################
 
##   click on the  listbox  process it.
 
proc process_selected {} {
 
    global list_win m_select
 
 
 
    set sz [$list_win size]
 
    #puts $sz
 
    if {$sz > 0} {
 
        set sel_dx [$list_win curselection]
 
        set m_select [$list_win get $sel_dx]
 
        load_ent_file
 
    } else {
    }
    }
}
}
 
 
######################################################################
######################################################################
##  load the vhdl file that has just been selected from list_win
##  load the vhdl file that has just been selected from list_win
proc load_ent_file {} {
proc load_ent_file {} {
    global ent_dir list_win view_win statsVar gen_prog
    global ent_dir list_win view_win statsVar gen_prog
 
 
    set gen_prog 0.0
    set gen_prog 0.0
    ## update selection with selected item
    ## update selection with selected item
    #set fn [$list_win curselection]
 
    set sel_dx [$list_win curselection]
    set sel_dx [$list_win curselection]
    if {$sel_dx == ""} {
    if {$sel_dx == ""} {
        return
        return
    }
    }
    ## recover the selected item
    ## recover the selected item
Line 222... Line 288...
        ##  Get a line
        ##  Get a line
        set rline [gets $ent_file]
        set rline [gets $ent_file]
        lappend file_list $rline
        lappend file_list $rline
    }
    }
    close $ent_file
    close $ent_file
    ## put file in text window and highlite the entity part
    ## put file in text window and highlite the module part
    set ent_found 0
    set ent_found 0
    set in_ent 0
    set in_ent 0
    set statsVar ""
    set statsVar ""
    foreach l $file_list {
    foreach l $file_list {
        if {$in_ent == 0} {
        if {$in_ent == 0} {
            set ent_def [string first module $l]
            set ent_def [string first module $l]
            if {$ent_def >= 0} {
            ## Make crazy assumption the module def is in the first few chars.
 
            if {$ent_def >= 0 && $ent_def <= 6} {
                set ent_name [lindex $l 1]
                set ent_name [lindex $l 1]
                set statsVar "Module:  $ent_name found"
                set statsVar "Module:  $ent_name found"
                set ent_found 1
                set ent_found 1
                set in_ent 1
                set in_ent 1
                $view_win insert end "$l\n" highlite
                $view_win insert end "$l\n" highlite
Line 253... Line 320...
    }
    }
    }
    }
    if {$ent_found == 0} {
    if {$ent_found == 0} {
        set statsVar "No Module found!!"
        set statsVar "No Module found!!"
    }
    }
    ##$view_win import $lp
 
    ##$view_win yview moveto 1
 
    ##puts $lp
 
}
}
 
 
#########################################################################
#########################################################################
 
##  The main generator proc
proc ttb_gen {} {
proc ttb_gen {} {
    global mo_sel template ent_dir list_win odir p_view tdir
    global mo_sel template ent_dir list_win odir p_view tdir
    global cpakv gbatv gen_prog comb_val m_select
    global cpakv gbatv gen_prog comb_val m_select
 
 
    set template [$tdir get]
    set template [$tdir get]
 
 
    $p_view configure -maximum 7
    $p_view configure -maximum 7
    set gen_prog 1.0
    set gen_prog 1.0
    ## recover the selected item
    ## recover the selected item
    #set sel_dx [$list_win curselection]
 
    set ln $m_select
    set ln $m_select
    ##  Get the working directory
    ##  Get the working directory
    #puts $ln
    #puts $ln
    set lp [$ent_dir get]
    set lp [$ent_dir get]
    ##  append the file name
    ##  append the file name
Line 281... Line 345...
    set path_text $lp
    set path_text $lp
    set destin_text [$odir get]
    set destin_text [$odir get]
    set infile [open $path_text r]
    set infile [open $path_text r]
    set file_list {}
    set file_list {}
 
 
 
    set bl_comm 0;   ##  block comment indication.
##################################################################
##################################################################
##  Read in the file and strip comments as we do
##  Read in the file and strip comments as we do
    while {![eof $infile]} {
    while {![eof $infile]} {
        ##  Get a line
        ##  Get a line
        set rline [gets $infile]
        set rline [gets $infile]
        #puts $rline
        #puts $rline
        ## get rid of white space
        ## get rid of white space
        set rline [string trim $rline]
        set rline [string trim $rline]
        ##  Find comment if there
        ##  Find comment if there
        set cindex [string first "//" $rline]
        set cindex [string first "//" $rline]
 
        ##  Block comments.
 
        set bcomm_s [string first "/*" $rline]
 
        set bcomm_e [string first "*/" $rline]
 
        ##  this will break if  block start  after some code ...
 
        if {$bcomm_s >= 0} {
 
            set bl_comm 1
 
            continue
 
        }
 
        if {$bcomm_s == 1} {
 
            if {$bcomm_e >= 0} {
 
                set bl_comm 0
 
            }
 
            continue
 
        }
        ## if a comment was found at the start of the line
        ## if a comment was found at the start of the line
        if {$cindex == 0 || $rline == ""} {
        if {$cindex == 0 || $rline == ""} {
            continue
            continue
        ## else was not found so put line in list
        ## else if comment somewhere in the line
        } elseif {$cindex > 0} {
        } elseif {$cindex > 0} {
            #  get rid of trailing comments and trim off spaces
            #  get rid of trailing comments and trim off spaces
            set rline [string trim [string range $rline 0 $cindex-1]]
            set rline [string trim [string range $rline 0 $cindex-1]]
            lappend file_list $rline
            lappend file_list $rline
 
        ## else was not found so put line in list
        } else {
        } else {
            lappend file_list $rline
            lappend file_list $rline
        }
        }
    }
    }
    close $infile
    close $infile
 
 
    $p_view step
 
 
    #foreach l $file_list {
 
    #    puts $l
 
    #}
 
    #return
 
 
 
    #$p_view step
    ## check for the module def
    ## check for the module def
    set mod_name ""
    set mod_name ""
    foreach l $file_list {
    foreach l $file_list {
        set mod_def [string first module $l]
        set mod_def [string first module $l]
        if {$mod_def >= 0} {
        if {$mod_def >= 0} {
Line 325... Line 410...
    if {$mod_def < 0} {
    if {$mod_def < 0} {
        dbg_msg "A module definition was not found in the file provided."
        dbg_msg "A module definition was not found in the file provided."
        return
        return
        ##  exit
        ##  exit
    }
    }
    $p_view step
    #$p_view step
    set mod_list {}
    set mod_list {}
    ## check for end module
    ## check for end module
    foreach l $file_list {
    foreach l $file_list {
        lappend mod_list $l
        lappend mod_list $l
        set end_def [string first endmodule $l]
        set end_def [string first endmodule $l]
Line 348... Line 433...
    set parameter_list {}
    set parameter_list {}
    set p_found 0
    set p_found 0
    foreach l $mod_list {
    foreach l $mod_list {
        set p_found [string first "parameter" $l]
        set p_found [string first "parameter" $l]
        if {$p_found >= 0} {
        if {$p_found >= 0} {
            lappend $parameter_list $l
            lappend parameter_list $l
        }
        }
    }
    }
 
    #foreach pl $parameter_list {
 
    #    puts $pl
 
    #}
 
    ##  inc the progress bar
    set gen_prog 2.0
    set gen_prog 2.0
    #foreach l $mod_list {
    #foreach l $mod_list {
    #    puts $l
    #    puts $l
    #}
    #}
    ####################################################################
    ####################################################################
    ##  a few checks have been done, and non-relevant stuff stripped off.
    ##  a few checks have been done, and non-relevant stuff stripped off.
    ##  now create an arrry of just the pin names and related info
    ##  now create an arrry of just the pin names and related info
    set port_lst {}
    set port_lst {}
 
    set import_lst {}
    set lc 0
    set lc 0
    foreach l $mod_list {
    foreach l $mod_list {
        ## make lines that are continued, one line.
        ## make lines that are continued, one line.
        set cont [string first "\;" $l]
        set cont [string first "\;" $l]
        #set tick [string first "`" $l]
 
        #if {$tick >= 0} {
 
        #    continue
 
        #}
 
        ## look for the port statements
        ## look for the port statements
        set inp [string first "input " $l]
        set inp [string first "input " $l]
        if {$inp >= 0} {
        if {$inp >= 0} {
            lappend port_lst $l
            lappend port_lst $l
        }
        }
Line 384... Line 470...
        }
        }
        set tick_dir [string first "`" $l]
        set tick_dir [string first "`" $l]
        if {$tick_dir >= 0} {
        if {$tick_dir >= 0} {
            lappend port_lst $l
            lappend port_lst $l
        }
        }
        #puts $port_lst
        set is_import [string first "import" $l]
 
        if {$is_import >= 0} {
 
            lappend import_lst $l
 
        }
 
        set end_pins [string first "\)\;" $l]
 
        set end_len [string length $l]
 
        if {$end_pins >= 0 && $end_len >= 2} {
 
            set stl [string trim $l "\)\;"]
 
            if {$stl != ""} {
 
                lappend port_lst $l
 
            }
 
            break
 
        }
    }
    }
 
 
    #foreach p $port_lst {
    #foreach p $port_lst {
    #    puts $p
    #    puts $p
    #}
    #}
    ##  Change the port list into a pin info list
    #return
 
    ##  Change the port list into a pin info list of lists
    set io_pins [pars_pindef $port_lst]
    set io_pins [pars_pindef $port_lst]
 
    ##  get the lists
    set log_lst [lindex $io_pins 0]
    set log_lst [lindex $io_pins 0]
    set mod_lst [lindex $io_pins 1]
    set mod_lst [lindex $io_pins 1]
    set name_lst [lindex $io_pins 2]
    set name_lst [lindex $io_pins 2]
 
 
    #foreach r $log_lst {
    #foreach r $log_lst {
Line 406... Line 505...
    #    puts $r
    #    puts $r
    #}
    #}
    #foreach r $name_lst {
    #foreach r $name_lst {
    #    puts $r
    #    puts $r
    #}
    #}
 
    #return
 
    ##########################################
 
    ##  if there are parameters.
 
    if {[llength $parameter_list] > 0} {
 
        set param_lst [pars_params $parameter_list]
 
    }
 
 
 
    #foreach l $param_lst {
 
    #    puts $l
 
    #}
 
 
    # dbg_msg $split_pin
    # dbg_msg $split_pin
    ## calculate the longest pin name in characters
    ## calculate the longest pin name in characters
    set name_length 0
    set name_length 0
    foreach l $name_lst {
    foreach l $name_lst {
Line 421... Line 529...
    }
    }
    #dbg_msg $name_length
    #dbg_msg $name_length
    ##  Make the name length one bigger
    ##  Make the name length one bigger
    incr name_length
    incr name_length
 
 
 
    ##  inc the progress bar
    set gen_prog 3.0
    set gen_prog 3.0
#$p_view step
 
#########################################################################
#########################################################################
## Generate the tb top.
## Generate the tb top.
    set tfn $destin_text
    set tfn $destin_text
    append tfn "/tb_top.sv"
    append tfn "/tb_top.sv"
    set tfh [open $tfn w]
    set tfh [open $tfn w]
 
 
    write_header $tfh
    write_header $tfh
    puts $tfh "`include \"../sv/tb_prg.sv\""
    puts $tfh "`include \"../sv/tb_mod.sv\""
    puts $tfh ""
    puts $tfh ""
    puts $tfh "module tb_top \(\)\;"
    puts $tfh "module tb_top \(\)\;"
    puts $tfh ""
    puts $tfh ""
    puts $tfh "  string STM_FILE = \"../stm/stimulus_file.stm\"\;"
    puts $tfh "  string STM_FILE = \"../stm/stimulus_file.stm\"\;"
    puts $tfh "  string tmp_fn;"
    puts $tfh "  string tmp_fn;"
    puts $tfh ""
    puts $tfh ""
    puts $tfh "  //  Handle plus args"
    puts $tfh "  //  Handle plus args"
    puts $tfh "  initial begin : file_select"
    puts $tfh "  initial begin : file_select"
    puts $tfh "    if\(\$value\$plusargs\(\"STM_FILE=%s\", tmp_fn\)\) begin"
    puts $tfh "    if\(\$value\$plusargs\(\"STM_FILE=%s\", tmp_fn\)\) begin"
    puts $tfh "      stm_file = tmp_fn\;"
    puts $tfh "      STM_FILE = tmp_fn\;"
    puts $tfh "    end"
    puts $tfh "    end"
    puts $tfh "  end"
    puts $tfh "  end"
    puts $tfh ""
    puts $tfh ""
    puts $tfh "  dut_if theif\(\)\;"
    puts $tfh "  dut_if theif\(\)\;"
    puts $tfh ""
    puts $tfh ""
 
    ## handle parameters.
 
    if {[llength $param_lst] == 0} {
    puts $tfh "  $mod_name u1 \("
    puts $tfh "  $mod_name u1 \("
 
    } else {
 
        puts $tfh "  $mod_name"
 
        puts $tfh "  \#\("
 
        set llen [llength $param_lst]
 
        set idx 1
 
        foreach p $param_lst {
 
            set tmp "    .[lindex $p 0]\("
 
            if {$idx < $llen} {
 
                append tmp "[lindex $p 1]\),"
 
            } else {
 
                append tmp "[lindex $p 1]\)"
 
            }
 
            puts $tfh $tmp
 
            incr idx
 
        }
 
         puts $tfh "  \) u1 \("
 
    }
 
 
    set llen [llength $name_lst]
    set llen [llength $name_lst]
    set idx 1
    set idx 1
    foreach n $name_lst {
    foreach n $name_lst {
        set ln $n
        set ln $n
Line 478... Line 605...
    puts $tfh "  tb_mod prg_inst\(theif\)\;"
    puts $tfh "  tb_mod prg_inst\(theif\)\;"
    puts $tfh ""
    puts $tfh ""
    puts $tfh "endmodule"
    puts $tfh "endmodule"
 
 
    close $tfh
    close $tfh
 
    ##  inc the progress bar
    set gen_prog 4.0
    set gen_prog 4.0
    #$p_view step
 
############################################################################
############################################################################
##  generate the interface file.
##  generate the interface file.
    set ifn $destin_text
    set ifn $destin_text
    append ifn "/dut_if.sv"
    append ifn "/dut_if.sv"
    set ifh [open $ifn w]
    set ifh [open $ifn w]
 
 
    write_header $ifh
    write_header $ifh
 
    ##  handle the parameters.
 
    if {[llength $param_lst] == 0} {
    puts $ifh "interface dut_if\(\)\;"
    puts $ifh "interface dut_if\(\)\;"
 
    } else {
 
        puts $tfh "  $mod_name"
 
        puts $tfh "  \#\("
 
        set llen [llength $param_lst]
 
        set idx 1
 
        foreach p $param_lst {
 
            set tmp "    [lindex $p 0] = "
 
            if {$idx < $llen} {
 
                append tmp "[lindex $p 1],"
 
            } else {
 
                append tmp "[lindex $p 1]"
 
            }
 
            puts $tfh $tmp
 
            incr idx
 
        }
 
         puts $tfh "  \)\(\)\;"
 
    }
 
    puts $ifh ""
 
    foreach i $import_lst {
 
        puts $ifh "  $i"
 
    }
    puts $ifh ""
    puts $ifh ""
    foreach l $log_lst {
    foreach l $log_lst {
        puts $ifh "  $l"
        puts $ifh "  $l"
    }
    }
 
 
    puts $ifh ""
    puts $ifh ""
    puts $ifh "  modport dut_conn\("
    puts $ifh "  modport dut_conn\("
    set llen [llength $mod_lst]
    set llen [llength $mod_lst]
    set idx 1
    set idx 1
    foreach p $mod_lst {
    foreach p $mod_lst {
 
        ## if there is an `ifdef ...
        set tick_dir [string first "`" $l]
        set tick_dir [string first "`" $l]
        if {$tick_dir >= 0} {
        if {$tick_dir >= 0} {
            puts $ifh "    $p"
            puts $ifh "    $p"
            incr idx
            incr idx
            continue
            continue
        }
        }
 
        set sp [split $p]
        if {$idx < $llen} {
        if {$idx < $llen} {
            puts $ifh "    $p"
            puts $ifh "    [lindex $sp 0]   [lindex $sp end]"
        } else {
        } else {
            puts $ifh "    [string trim $p ","]"
            puts $ifh "    [lindex $sp 0]   [string trim [lindex $sp end] ","]"
        }
        }
        incr idx
        incr idx
    }
    }
    puts $ifh "  \)\;"
    puts $ifh "  \)\;"
    puts $ifh ""
    puts $ifh ""
    puts $ifh "  modport tb_conn\("
    puts $ifh "  modport tb_conn\("
    set idx 1
    set idx 1
    foreach p $mod_lst {
    foreach p $mod_lst {
 
        ## if there is an `ifdef ...
        set tick_dir [string first "`" $p]
        set tick_dir [string first "`" $p]
        if {$tick_dir >= 0} {
        if {$tick_dir >= 0} {
            puts $ifh "    $p"
            puts $ifh "    $p"
            incr idx
            incr idx
            continue
            continue
Line 533... Line 686...
        } else {
        } else {
            set type "inout   "
            set type "inout   "
        }
        }
 
 
        set sp [split $p]
        set sp [split $p]
 
        #puts $sp
        if {$idx < $llen} {
        if {$idx < $llen} {
            puts $ifh "    $type [lindex $sp end]"
            puts $ifh "    $type [lindex $sp end]"
        } else {
        } else {
            puts $ifh "    $type [string trim [lindex $sp end] ","]"
            puts $ifh "    $type [string trim [lindex $sp end] ","]"
        }
        }
Line 544... Line 698...
    }
    }
    puts $ifh "  \)\;"
    puts $ifh "  \)\;"
    puts $ifh ""
    puts $ifh ""
    puts $ifh "endinterface"
    puts $ifh "endinterface"
    close $ifh
    close $ifh
 
    ##  inc the progress bar
    set gen_prog 5.0
    set gen_prog 5.0
    #$p_view step
 
##########################################################################
##########################################################################
##   generate the tb_prg  file from template.
##   generate the tb_prg  file from template.
    #set prg_gen [$mo_sel get]
    #puts $comb_val
    if {$comb_val == "No mod"} {
    if {$comb_val == "No mod"} {
 
        ##  indicate done in progress bar.
        set gen_prog 7.0
        set gen_prog 7.0
        #$p_view step
        puts "No tb_mod file was generated."
        #$p_view step
 
        return
        return
    }
    }
    set tpl_fh [open $template r]
    set tpl_fh [open $template r]
    set tpl_lst {}
    set tpl_lst {}
    set hfound 0
    set hfound 0
Line 596... Line 750...
 
 
    #foreach l $tpl_lst {
    #foreach l $tpl_lst {
    #    puts  $l
    #    puts  $l
    #}
    #}
 
 
 
    ##  inc the progress bar
    set gen_prog 6.0
    set gen_prog 6.0
    #$p_view step
 
    set idx 0
    set idx 0
    foreach l $tpl_lst {
    foreach l $tpl_lst {
        set ent_pt [string first ">>drive sigs" $l]
        set ent_pt [string first ">>drive sigs" $l]
        if {$ent_pt == 0} {
        if {$ent_pt == 0} {
            set tpl_lst [lreplace $tpl_lst $idx $idx]
            set tpl_lst [lreplace $tpl_lst $idx $idx]
Line 622... Line 776...
                }
                }
                set tpl_lst [linsert $tpl_lst $idx $tmp]
                set tpl_lst [linsert $tpl_lst $idx $tmp]
                #puts [lindex $tpl_lst $idx]
                #puts [lindex $tpl_lst $idx]
                incr idx
                incr idx
                incr midx
                incr midx
                #$p_view step
 
            }
            }
            break
            break
        }
        }
        incr idx
        incr idx
    }
    }
Line 634... Line 787...
    write_header $pfh
    write_header $pfh
    foreach l $tpl_lst {
    foreach l $tpl_lst {
        puts $pfh $l
        puts $pfh $l
    }
    }
    set gen_prog 7.0
    set gen_prog 7.0
    #$p_view step
 
    close $pfh
    close $pfh
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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