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/,/, $tmp;
    foreach $tmp(@temp)
    {
      push @save, ".$tmp($tmp),\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/,/, $tmp;
    foreach $tmp(@temp)
    {
      push @save, ".$tmp($tmp),\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;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值