Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

How do I get this tcl script to run?

Hey again :)

Within the link (http://www.altera.com/support/examples/tcl/tcl-increment-version.html), this code is available that updates the version number.


set file_name 
set output_file_name ${file_name}.updated_version_number
if {  } {
    post_message -type critical_warning "Could not update version number: $res"
} else {
    if {  } {
        post_message -type critical_warning 
            "Could not update version number: $res"
    }
}
My aim now is to update the date of the vhdl file using Date2HDL (http://www.ht-lab.com/freeutils/date2hdl/date2hdl.html), and if change 'update_version_number' to 'date2hdl', it doesn't work which is no surprise since it's a proc, while date2hdl is a tcl script. How can I make it work?

Thanks

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    No worries, I copied the file into a new proc like so. Didn't know tcl was that easy :)

    
    proc date2hdl {input_fn output_fn } {#  Date2HDL version 0.1 HT-Lab 2003#  #  Useage: Date2HDL <input_filename>    <output_filename># #  Date2HDL will search for the string 'define/constant DATE_VECTOR_C and #  replace the constant with the current date.# #  VHDL (.vhd extention)#      constant DATE_VECTOR_C : std_logic_vector(12 downto 0):="0000000000000";#  Verilog (.v extention)#   `define DATE_VECTOR_C 13'b0000000000000# #  Date String format:#  Day 0..31, 5 bits#  Month 0..12, 4 bits#  Year 0..15, 4 bits#  Bit    12 11 10 09 08 07 06 05 04 03 02 01 00 #  Format   # #  set to 1 to print debugging info
    set debug 1
    #  Convert Decimal to Boolean String
    proc dec2bool {decstring} {
        switch $decstring {
            00 {return "00000"}
            01 {return "00001"}
            02 {return "00010"}
            03 {return "00011"}
            04 {return "00100"}
            05 {return "00101"}
            06 {return "00110"}
            07 {return "00111"}
            08 {return "01000"}
            09 {return "01001"}
            10 {return "01010"}
            11 {return "01011"}
            12 {return "01100"}
            13 {return "01101"}
            14 {return "01110"}
            15 {return "01111"}
            16 {return "10000"}
            17 {return "10001"}
            18 {return "10010"}
            19 {return "10011"}
            20 {return "10100"}
            21 {return "10101"}
            22 {return "10110"}
            23 {return "10111"}
            24 {return "11000"}
            25 {return "11001"}
            26 {return "11010"}
            27 {return "11011"}
            28 {return "11100"}
            29 {return "11101"}
            30 {return "11110"}
            31 {return "11111"}
            default {
                puts "Error in dec2bool proc, can't convert $decstring"
             #     exit
             }        
        }                        
    }
    puts "Date2HDL version 0.1 WWW.HT-LAB.COM"
    #  Check number of argments# if {!=2} {#     puts "Useage : Date2HDL <source_filename> <destination_filename>"#     puts "Example: Date2HDL top.vhd top_date.vhd"#     puts "Example: Date2HDL main.v mainsynth.v"#      exit# }
    #  Check for HDL type
    if { == 0} {
        set hdl_type "Verilog"
        set search_string {\s*`define\s*DATE_VECTOR_C}
    } else {
        set hdl_type "VHDL"
        set search_string {\s*constant\s*DATE_VECTOR_C}
    }
    if {$debug} { puts "HDL Type=$hdl_type" }
    #  Read Date
    set current_day    -format "%d"]
    set current_month  -format "%m"]
    set current_year   -format "%y"]
    set bool_date " 1 4] 1 4]"
    if {$debug} {
        puts "Date: $current_day -> "
        puts "Date: $current_month -> "
        puts "Date: $current_year -> "
        puts "Date: $bool_date"
    }
    #  Open Source File
    if } msg] {
        puts $msg
        exit
    }
    #  Open Destination file
    if } msg] {
        puts $msg
        exit
    }
    #  Scan for: DATE_VECTOR_C string & replace
    while {!} {
        if {>=0} {
            if {} {
                puts "Replacing :$line"
                if {$hdl_type=="VHDL"} {
                    regexp {(.*?")} $line ignore leftstring
                    puts "With      :$leftstring$bool_date\";"
                    puts $fpw "$leftstring$bool_date\";"
                } else {
                    regexp {(.*?'b)} $line ignore leftstring
                    puts "With      :$leftstring$bool_date"
                    puts $fpw "$leftstring$bool_date"
                }
            } else {
                puts $fpw $line
            }
        }    
    }
    close $fp
    close $fpw
    puts "Done.."
    }
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yea, that usually doesn't apply when it comes to technology.

    anyway, here is an adaptation of altera's code to search for every vhdl file in the folder to change the date, just in case someone in the future decides my vhdl file name is silly. Got the idea from a newsgroup post.

    
    set strlist 
    foreach strfile $strlist {
            set file_name $strfile
            set output_file_name ${file_name}.updated_version_number
            
           # date2hdl $file_name $output_file_name
            if {  } {
                post_message -type critical_warning "Could not update version number: $res"
            } else {
            
                if {  } {
                    post_message -type critical_warning 
                        "Could not update version number: $res"
                }
            }
    }