项目需求:
1.根据项目需要,将2bit 或3bit的rtc进行替换为64bit rtc
难点:
2.由于rtl各层次之间的信号关联会发生变化。
3.不同module之间的rtc名字存在相同性。
解决办法:
1.分析出了lib rtl的输入名都是RTC,因此写脚本的时候把RTC相关的行全部抓出来。
2.除了极少部分的名字采用了特殊命名。绝大部分都是采用rf1p_rtc,rf2p_rtc,sf1p_rtc,sf2p_rtc。因此这对于替换
带来了极大的方便。
3.对于关联信号的变化,需要单独分析,对于rtc = rf1p_rtc这样的赋值变化,要追踪去处。
perl脚本如下。
#! /usr/bin/perl
use 5.010;
use strict;
my @all_files_1 = glob '/proj/../../../../..units/*/src/*.v';
my @all_files_2 = glob '/proj/../../../../../units/*/src/*/*.v';
my @all_files = (@all_files_1,@all_files_2);
my $flag = 0;
my $cnt = 0;
if (-e "good_file.txt") {
say "good_file.txt is exists";
unlink "good_file.txt";
say "good_file.txt is delete";
}
if (-e "store_text_001.txt") {
say "store_text_001.txt is exists";
unlink "store_text_001.txt";
say "store_text_001.txt is delete";
}
foreach my $file_name (@all_files){
open my $file_text,'<',"$file_name";
open my $good_file,'>>',"good_file.txt";
open my $store_text_001,'>>',"store_text_001.txt";
while(<$file_text>){
chomp;
$cnt++;
if(/rf1p_rtc|rf2p_rtc|sr1p_rtc|sr2p_rtc|rom_rtc|rom_rtc_ref|rtc/i){
$flag = 1;
say $store_text_001 "$cnt $_";
}
}
if ($flag == 1){
$cnt = 0;
say $good_file "$file_name";
say $store_text_001 "$file_name";
$flag = 0;
}else {
$cnt = 0;
$flag = 0;
};
close $file_text;
close $good_file;
close $store_text_001;
}
&func_rtc;
sub func_rtc{
open my $file,'<',"good_file.txt";
my $cnt;
while(<$file>){
$cnt++;
# if($cnt <= 3){
my $file_name_store = $_;
`soscmd discardco -F $file_name_store`;
`soscmd co $_`;
open my $new_file_text,"$_";
open my $new_file,'>',"new_file.v";
while(<$new_file_text>){
chmod;
if (s/input\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/input [`NEW_MEM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/output\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/output [`NEW_MEM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/wire\s*\[\d+\:0\]\s*(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)/wire [`NEW_MEM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/(\brf1p_rtc\b|\brf2p_rtc\b|\bsr1p_rtc\b|\bsr2p_rtc\b)\s*\[\d+:0\]/\1/){
printf $new_file "$_";
}
elsif (s/input\s*\[\d+\:0\]\s*(\brom_rtc\b)/input [`NEW_ROM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/output\s*\[\d+\:0\]\s*(\brom_rtc\b)/output [`NEW_ROM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/wire\s*\[\d+\:0\]\s*(\brom_rtc\b)/wire [`NEW_ROM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/(\brom_rtc\b)\s*\[\d+:0\]/\1/){
printf $new_file "$_";
}
elsif (s/wire \[1\:0\] (rtc0, rtc1, rtc2, rtc3, rtc4, rtc5, rtc6)/wire [`NEW_MEM_CTRL-1:0] \1/){
printf $new_file "$_";
}
elsif (s/(input|output|wire)\s*\[\d+\:0\]\s*RTC/\1 [`NEW_MEM_CTRL-1:0] RTC/){
printf $new_file "$_";
}
elsif (s/RTC\[\d+\:0\]/RTC/){
printf $new_file "$_";
}
elsif (s/input\s*\[\d+\:0\]\s*(txmod_rf_rtc|rf2p_txmod_rtc)/input [`NEW_MEM_CTRL-1:0] \1/){
#say "$file_name_store";
#say "$_";
printf $new_file "$_";
}
elsif (s/rf2p_txmod_rtc\[\d+\:0\]/rf2p_txmod_rtc/){
#say "$file_name_store";
#say "$_";
printf $new_file "$_";
}
elsif (s/input\s*\[\d+\:0\]\s*\brsd_rtc\b/input [`NEW_ROM_CTRL-1:0] rsd_rtc/){
say "$file_name_store";
say "$_";
printf $new_file "$_";
}
#elsif (s/RTC\s*\(rsd_rtc\[\d+\:0\]\)/RTC (rsd_rtc)/){
elsif (s/rsd_rtc\[\d+\:0\]/rsd_rtc/){
say "$file_name_store";
say "$_";
printf $new_file "$_";
}
else{
printf $new_file "$_";
}
}
close $new_file_text;
close $new_file;
system("cp new_file.v $file_name_store");
# `soscmd discardco -F $file_name_store`;
# }
}
close $file;
}