verilog 文本自动对齐:input output wire reg

12 篇文章 5 订阅

1、之前有个脚本可以对齐input和output,但是没有解决wire和reg定义不对齐的问题。所以脚本改进了下,支持input output wire reg对齐

2、知识点总结:perl的字符串进行比较时需要使用eq,lt,gt,不能使用数字比较符==,>=,否则会出现逻辑错误。

#! /usr/bin/perl

use 5.010;
use strict;


my ($sec,$min,$hour,$day,$mon,$year,$weekday,$yeardate,$savinglightday)   =  (localtime(time));
$sec   =   ($sec   <   10)?   "0$sec":$sec;
$min   =   ($min   <   10)?   "0$min":$min;
$hour   =   ($hour   <   10)?   "0$hour":$hour;
$day   =   ($day   <   10)?   "0$day":$day;
$mon   =   ($mon   <   9)?   "0".($mon+1):($mon+1);
$year   +=   1900;
my $date = "${mon}${day}";

my $dir = '*.v';
my @all_files = glob($dir);


foreach my $file_name (@all_files){
    open my $file_text,'<',"$file_name";
    my $file_name_store = $file_name;
    open my $new_file,'>',"new_file.v"; 
    while(<$file_text>){
        chomp;
            if (/^\s*(input|wire|reg)\s*(\w.*)/){
                if ($1 eq 'reg') {
                      printf $new_file "%s                           %-70s\n",$1,$2;}
                else {printf $new_file "%s                          %-70s\n",$1,$2;}
            }
            elsif (/^\s*(input|wire|reg)\s*(\[.*\])\s*(\w.*)/){
                if ($1 eq 'reg') {
                      printf $new_file "%s    %-20s   %-50s\n",$1,$2,$3;}
                else {printf $new_file "%s   %-20s   %-50s\n",$1,$2,$3;}
            }
            elsif (/^\s*(output)\s*(\w.*)/){
                    printf $new_file "%s                         %-70s\n",$1,$2;
            }
            elsif (/^\s*(output)\s*(\[.*\])\s*(\w.*)/){
                    printf $new_file "%s  %-20s   %-50s\n",$1,$2,$3;
            }
            else {
                print $new_file "$_\n";
            }
    }
    close $file_text;
    close $new_file;
    system("cp new_file.v $file_name_store");
}

    system("rm new_file.v");

效果如下:

 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值