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.vnOUtput: 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*modules+(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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |