perl:verilog dummy module

29 篇文章 11 订阅

https://code.csdn.net/snippets/1903886.git
样板工程

#!/usr/bin/perl

######description
#not support parameter [WIDTH:1]
#not support bigendian
######
use strict;
use warnings;

#delete all comments;
open my $file,"<","dummy.v";
$/=undef;#分隔符默认是\n,设置为undef,是想把整个段落作为一行。
my $file_without_comments;#文件内容清理后的整个段落,赋值进一个标量
while(<$file>){
    s/\/\/.*?\n/\n/g;#删除//注释部分
    s/\/\*.*?\*\///g; #删除/**/注释部分
    s/\s+/ /g;       #删除2个空白符
    s/\n+\s*\n+/\n/g; #删除多个空行
    $file_without_comments = $_;
}
#####################
#print "/*\n";
#print "*moduename \tis\t $modulename\n";#得到module名称
#print "*inputname \tis\t @inputname\n";#得到input port名称
#print "*outputname \tis\t @outputname\n";#得到output port名称
#print "*inoutname \tis\t @inoutname\n";#得到inout port名称
#my @inputname_width;#得到input port的width
#my @outputname_width;#得到output port的width
#my @inoutname_width;#得到inout port的width
#print "*/\n";

my @file = split /;/,$file_without_comments;#以;作为分隔符,把段落分成多个变量,形成一个数组。
my @file_context;

my $modulename;
my @inputname;
my @outputname;
my @inoutname;

my @inputname_width;
my @outputname_width;
my @inoutname_width;
foreach (@file){
    if(m/module\s+(\S+)\s*\(/){
        $modulename = $1;#得到module名称
    }
    if(m/\binput\s*\[*\s*([0-9]*)\s*:*\s*([0-9]*)\s*\]*\s*(.*?)$/){
        my $input_leftwidth = $1;
        my $input_rightwidth = $2;
        unless($1){$input_leftwidth=0;}#input有时候没有[31:0]的字段,赋值左宽度为初始值0
        unless($2){$input_rightwidth=0;}#input有时候没有[31:0]的字段,赋值右宽度为初始值0
        my @input_1 = split /,/,$3;#所有的input name;并以,作为分隔符。
        foreach (@input_1){
            s/input//;
            s/\s//;
            s/\n//;
            push @inputname,$_;
            push @inputname_width,abs($input_leftwidth-$input_rightwidth)+1;
            if(abs($input_leftwidth-$input_rightwidth) == ($input_leftwidth-$input_rightwidth)) {
                my $bigendian = 1;
            }#暂时不支持bigendian,要实现,也容易。
        }
    }
    if(m/\boutput\s*\[*\s*([0-9]*)\s*:*\s*([0-9]*)\s*\]*\s*(.*?)$/){
        my $output_leftwidth = $1;
        my $output_rightwidth = $2;
        unless($1){$output_leftwidth=0;}
        unless($2){$output_rightwidth=0;}
        my @output_1 = split /,/,$3;
        foreach (@output_1){
            s/output//;
            s/\s//;
            s/\n//;
            push @outputname,$_;
            push @outputname_width,abs($output_leftwidth-$output_rightwidth)+1;
        }
    }
    if(m/\binout\s*\[*\s*([0-9]*)\s*:*\s*([0-9]*)\s*\]*\s*(.*?)$/){
        my $inout_leftwidth = $1;
        my $inout_rightwidth = $2;
        unless($1){$inout_leftwidth=0;}
        unless($2){$inout_rightwidth=0;}
        my @inout_1 = split /,/,$3;
        foreach (@inout_1){
            s/inout//;
            s/\s//;
            s/\n//;
            push @inoutname,$_;
            push @inoutname_width,abs($inout_leftwidth-$inout_rightwidth)+1;
        }
    }
}
print "/*\n";
print "*moduename \tis\t $modulename\n";
print "*inputname \tis\t @inputname\n";
print "*inputname_width \tis\t @inputname_width\n";
print "*outputname \tis\t @outputname\n";
print "*outputname_width \tis\t @outputname_width\n";
print "*inoutname \tis\t @inoutname\n";
print "*inoutname_width \tis\t @inoutname_width\n";
print "*/\n";

#####Result
my @outputname_join1 = join ",", @outputname;   
my @inputname_join1 = join ",", @inputname;
my @inoutname_join1 = join ",", @inoutname;

my @outputname_join;   
my @inputname_join;
my @inoutname_join;

#module声明
print "module $modulename (\n";
if(@inoutname){
    print "@inoutname_join1,\n";
}
if(@outputname){
    print "@outputname_join1,";
}
if(@inputname){
    print "@inputname_join1);\n";
}

#inout变量声明
for (my $i=0;$i<$#inoutname + 1;$i=$i+1){
    $inoutname_join[$i] = "inout [$inoutname_width[$i]-1:0] $inoutname[$i];\n";
}
print @inoutname_join;

#output变量声明
for (my $i=0;$i<$#outputname + 1;$i=$i+1){
    $outputname_join[$i] = "output [$outputname_width[$i]-1:0] $outputname[$i];\n";
}
print @outputname_join;

#input变量声明
for (my $i=0;$i<$#inputname + 1;$i=$i+1){
    $inputname_join[$i] = "input [$inputname_width[$i]-1:0] $inputname[$i];\n";
}
print @inputname_join;

#所有output信号,赋值为'b0
if(@outputname){
    print "assign { @outputname_join1 } = 'b0;\n";
}

#结束endmodule
print "endmodule\n";
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iscas2spice spice netlist generation tool -- version 2.2 by Jingye Xu @ VLSI Group, Dept. of ECE, UIC, June, 2008 This tool reads the ISCAS85 benchmark circuit "*.bench" file and translate the file into SPICE netlist using the given technology and the standard cell library. platform: linux x86 sytem Input: ISCAS85 benchmark circuit: *.bench; standard cell library: stdcells.sclb; standard cell models: stdcells.lib; interconnect paramaters: *.int; Output: SPICE netlist: out.sp The whole procedure of the tools can be divided into several steps: 1. Gate replacement: replace the gates that can't be found in the with the gates in the standard cell lib. (break.pl) Output: *.bench, *.bench.bak 2. Generate the GSRC files: generate the GSRC files for the fengshui placer. (gsrcgen.pl) Output: gsrcfile/iscas.* 3. Placement: using the fengshui placement tool to perform the component placement. (fs50) Output: gsrcfile/iscas_fs50.pl 4. Generate ISPD file: tanslate the placement results into ISPD98 format file that can be used as the input of the global router. (gsrc2ispd.pl) Output: gsrcfile/iscas.laby.txt 5. Perform the routing: use the labyrinth global router to perform the routing. (mazeRoute) Output: gsrcfile/output 6. Generate the SPICE netlist: use all the available information to generate the final SPICE netlist. (spicegen.pl) Output: out.sp Usage: iscas2spice.pl Iscas85BenchmarkFile [-C/L/N] options: -C :default value, use the RC model for interconnect -L :use the RLC model for interconnect -N :treat interconnect as short circuit wire This package used the fengshui placement tools and labyrinth global routing tools, for information regarding these two free tools, please vist: http://www.ece.ucsb.edu/~kastner/labyrinth/ http://vlsicad.cs.binghamton.edu/software.html For information regarding this software itself please visit: http://wave.ece.uic.edu/~iscas2spice Many thanks to my advisor Masud H. Chowdhury for his support!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值