Perl 产生testbench的框架

前端之家收集整理的这篇文章主要介绍了Perl 产生testbench的框架前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

对于如下的 .v文件,我们可以利用Perl产生testbench的框架:然后自己填充内容即可。

module module_name(inputs and outputs);

input  [n:0] ..............

output [n:0] ..............

inout [n:0]  ...................

.................

always @(...........)

.....

endmodule


perl文件如下:


#!/usr/bin/perl -w # this script is designed to create the frame of testbench for a .v file## # Designed by Casey Zhu 2014### use strict; use Getopt::Long; my ($input,$output,$inout,$file_name,$module_name); my (@all_content,@save); GetOptions(          'file=s'  => \$file_name,          ); unless($file_name) {   print "Usage:./create_testbench_frame.pl -f file_name.v\nOUtput: file_name.vt";   exit(1); } open IN,"$file_name" or die "fail to open $file_name $!\n"; chomp(@all_content=<IN>); close IN; $file_name =~ s/(\.v)$/\.vt/; open OUT,">$file_name" or die "fail to open $file_name $!\n"; foreach(@all_content) {   if(/\s*module\s+(\w+)\s*\(/)    {      $module_name=$1;      print OUT "module $module_name\_test();\n";    }     if(/\s*input(.*)\;/)   {     $input=$1;      print OUT "reg $input;\n";     my $tmp;     if($input =~ /.*\[\d+\:0\](.*)/)     {        $tmp = $1;     }     else      {      $tmp = $input;     }     $tmp =~ s/\s+//g;     my @temp = split/,/,$tmp;     foreach $tmp(@temp)     {       push @save,".$tmp($tmp),\n";     }   }    if(/\s*output(.*)\;/)   {     $output=$1;      print OUT "wire $output;\n";      my $tmp;     if($output =~ /.*\[\d+\:0\](.*)/)     {        $tmp = $1;     }     else     {      $tmp = $output;     }     $tmp =~ s/\s+//g;     my @temp = split/,\n";     }   }   if(/\s*inout(.*)\;/)   {     $inout=$1;      print OUT "wire $inout;\n";      print OUT "reg  $inout;\n";      my $tmp;     if($inout =~ /.*\[\d+\:0\](.*)/)     {        $tmp = $1;     }     else     {      $tmp = $inout;     }     $tmp =~ s/\s+//g;     my @temp = split/,\n";     }   } } my $temp= pop @save; $temp =~ s/\,//; push @save,$temp; print OUT "$module_name test (\n @save );\n"; print OUT "\n initial \n begin \n // insert code here --> begin \n \n // --> end \n \n end \n always \n // optional sensitivity list \n // \@(event1 or event2 or .... eventn) \n begin \n // insert code here --> begin \n  \n \n// --> end \n end \n endmodule"; close OUT;

猜你在找的Perl相关文章