144 lines
4.3 KiB
Tcl
144 lines
4.3 KiB
Tcl
#usage : do find_unreferenced_sources.tcl [-d]
|
|
# if -d is not specified,only list out the unrefferenced files
|
|
# the script does:
|
|
# step 1 :generate the report
|
|
# step 2 :get all referced files from the report
|
|
# step 3 :get all compiled files from the 01_source/01_func directory
|
|
# step 4 :compare the two list,find out the unrefferenced ones
|
|
# step 5:optionnnaly,delete the unrefferenced files
|
|
# step 6: remove the generated reports
|
|
|
|
proc relative_to_absolute {relative_path} {
|
|
|
|
#replace all "../" and count how many "../" occured in the original string
|
|
set parent_dir_count [regsub -all {\.\.\/} $relative_path "" sufix_path];
|
|
set redir_path [pwd];
|
|
|
|
#cut the current path by N-times to get the common parent path for both "abs" and "rela"
|
|
for {set i 0 } {$i < $parent_dir_count} {incr i} {
|
|
set last_dir [file tail $redir_path];
|
|
regsub /$last_dir $redir_path "" redir_path;
|
|
}
|
|
set prefix_path $redir_path;
|
|
# puts redir_path=$redir_path
|
|
set absolute_path $prefix_path/$sufix_path;
|
|
|
|
return $absolute_path;
|
|
}
|
|
|
|
|
|
proc find_files {root_path } {
|
|
set results [list];
|
|
# lappend results;
|
|
|
|
#store the current path
|
|
set current_path [pwd];
|
|
cd $root_path;
|
|
set root_path [pwd];
|
|
|
|
puts "entering $root_path"
|
|
# get all files recusively
|
|
foreach element [glob -nocomplain * ;] {
|
|
|
|
# entering sub dirs
|
|
if { [file isdirectory $element]} {
|
|
|
|
set sublist [find_files $element];
|
|
set results [concat $results $sublist];
|
|
} else {
|
|
# only valid source files are filtered
|
|
if {[string match "*.v" $element] || [string match "*.sv" $element] || [string match "*.vhd" $element] || [string match "*.vhdl" $element]} {
|
|
lappend results "$root_path/$element";
|
|
}
|
|
}
|
|
}
|
|
|
|
cd $current_path;
|
|
|
|
puts "++++++++++++++++++++++++++++"
|
|
return $results;
|
|
}
|
|
|
|
.main clear
|
|
#exit simulation ,unless the change dir will not work
|
|
q -sim
|
|
|
|
puts "---------------------------------ATTENTION----------------------------------------"
|
|
puts "----------- this file should be sourced after the vsim load sucessfully-----------"
|
|
puts "----------- this file should be sourced from the funcXXX director-----------------"
|
|
puts ""
|
|
|
|
|
|
puts ":::::::::get referced dut files:::::::::"
|
|
set referenced_files [list ]
|
|
set f_report [open $TEMP_REF_FILES r];
|
|
|
|
#read the report,get all referenced files
|
|
while {![eof $f_report]} {
|
|
gets $f_report line ;
|
|
|
|
if { [string match "*Source File*" $line] } {
|
|
lappend referenced_files $line;
|
|
}
|
|
}
|
|
close $f_report
|
|
|
|
#remove those source file,point to precompiled vendor library
|
|
#convert the relative path to absolute path
|
|
#list referenced_dut_files;
|
|
foreach element $referenced_files {
|
|
if { [string match "*Source File: \.\./\.\./*" $element] } {
|
|
regsub {^.*Source File:} $element "" path;
|
|
set relative_path [string trim $path ];
|
|
set abs_path [relative_to_absolute $relative_path];
|
|
lappend referenced_dut_files $abs_path
|
|
# puts $abs_path
|
|
}
|
|
}
|
|
|
|
puts ":::::::::get all compiled source files:::::::::"
|
|
#get all source files in the source file directory ,recursively
|
|
set root_path ../../../01_source/01_func;
|
|
set all_sources [find_files $root_path;];
|
|
.main clear
|
|
|
|
puts ":::::::::try to match:::::::::"
|
|
#try to match the two lists,and filter the mis-matched ones
|
|
|
|
#set f_referenced_dut_files [open "referenced.txt" w+];
|
|
#foreach sim_file $referenced_dut_files {
|
|
# puts $f_referenced_dut_files $sim_file;
|
|
#}
|
|
#close $f_referenced_dut_files;
|
|
|
|
#set f_dir_files [open "dir.txt" w+];
|
|
#foreach dir_file $all_sources {
|
|
# puts $f_dir_files $dir_file;
|
|
#}
|
|
#close $f_dir_files
|
|
|
|
puts "found dismated files as follow:"
|
|
set mis_matched_dir_files [list]
|
|
foreach dir_file $all_sources {
|
|
|
|
set index [lsearch $referenced_dut_files $dir_file];
|
|
if {$index == -1} {
|
|
lappend mis_matched_dir_files $dir_file;
|
|
puts "path=$dir_file"
|
|
}
|
|
}
|
|
|
|
#if specified the -d switch,just delete the files
|
|
if {$argc == 1 && [string equal $1 "-d"]} {
|
|
|
|
puts "the -d switch specified ,delete the dismatched files automatically"
|
|
foreach del_file $mis_matched_dir_files {
|
|
file delete -force $del_file
|
|
}
|
|
}
|
|
|
|
|
|
#file delete -force $TEMP_REF_FILES
|
|
|
|
|