⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vrename

📁 Verilog Parser in Perl
💻
📖 第 1 页 / 共 2 页
字号:
	    else {		$filestrg .= $char; $pos++;	    }	}	elsif ($char eq '"') {	    $filestrg .= $char; $pos++;	    $literal = ! $literal;	}	elsif ($char eq " " && !$literal && !$define) {	    if ($pos > 80) {		$filestrg .= "\n"; $pos = 0;	    }	    elsif ($pos != 0) {		$filestrg .= $char; $pos++;	    }	}	else {	    $filestrg .= $char; $pos++;	}    }    $filestrg =~ s/[ \t]+/ /g;    while ($filestrg =~ /$magicb([\000-\377]*?)$magice/) {	my $rep = $1;	$rep =~ s/[\n]/ /g;	$filestrg =~ s/$magicb([\000-\377]*?)$magice/\n\/\*$rep\*\/\n/;    }    $filestrg .= "\n";    return $filestrg;}######################################################################sub _recurse_dir {    my $dir = shift;    my $callback = shift;    my $dh = new IO::Dir($dir) or warn "%Warning: $! $dir\n";    while (defined (my $basefile = $dh->read)) {	next if Verilog::Getopt->file_skip_special($basefile);	&$callback("$dir/$basefile");    }    $dh->close();    return;}sub parse_file {    my $filename = shift;    print "parse file $filename\n";    if (-d $filename) {	_recurse_dir($filename, \&parse_file);	return;    }    my $parser = Verilog::Vrename::Reader->new();    $parser->parse_file ($filename);}sub verilog_change_sig {    # Rename signals in this filename    my $filename = shift;    if (-d $filename) {	_recurse_dir($filename, \&verilog_change_sig);	return;    }    # Read in the whole file in a swath    my $fh = IO::File->new ("<$filename") or die "%Error: $! $filename";    my $filestrg = join('',$fh->getlines());    $fh->close();    if ($Opt_Crypt) {	if ($filestrg =~ /ENCRYPT_ME/) {	    $Encrypt{$filename} = 1;	}    }    # If crypting, strip comments    if ($Encrypt{$filename}) {	$filestrg = crypt_string ($filestrg);    }    # Replace any changed signals    my $hadrepl = 0;    my %signal_magic = ();    # pass1: replace with magic replacement string    # (two steps so renaming a->b and b->a at the same time doesn't screw up)    foreach my $sig (keys %Signal_Newname) {	my $new = $Signal_Newname{$sig};	if ($new ne $sig) {	    my $magic = "@@@@@!~${hadrepl}~!@@@@@";	    my $sig_quoted = quotemeta $sig;	    if ($filestrg =~ s/([^a-zA-Z0-9_\$\%\'\"])$sig_quoted(?=[^a-zA-Z0-9_])/$1$magic/g) {		print "match s$sig n$new m$magic\n" if $Debug;		$hadrepl ++;		$signal_magic{$sig} = $magic;	    }	}    }    # pass2: magic->new    foreach my $sig (keys %Signal_Newname) {	if (defined $signal_magic{$sig}) {	    my $magic = $signal_magic{$sig};	    my $new = $Signal_Newname{$sig};	    if ($filestrg =~ s/$magic/$new/g) {		print "match s$sig n$new m$magic\n" if $Debug;	    }	}    }    # Save it    if ($hadrepl || $Opt_Crypt) {	if (!$Opt_Write) {	    print "$filename  ($hadrepl signals matched) (-n: Not written)\n";	} else {	    my $fh = IO::File->new(">$output_dir$filename")		or die "%Error: $! $output_dir$filename.\n";	    $fh->print($filestrg);	    $fh->close;	    if ($Encrypt{$filename}) {print "Encrypted ";} else {print "Wrote ";}	    print "$filename  ($hadrepl signals matched)\n";	}    }}######################################################################package Verilog::Vrename::Reader;use Carp;use Verilog::Parser;use base qw(Verilog::Parser);use vars qw($Debug);use strict;sub new {    my $class = shift;    my $self = $class->SUPER::new	(_last_keyword=>'',	 _file_sigs=>{},	 @_);    bless $self, $class;    return $self;}sub _track_signal {    my $self = shift;    my $sig = shift;    $sig =~ s/\`//g;	# Remove `s from define usages else won't match define declaration    if (!$self->{_file_sigs}{$sig}) {	push @{$main::Signal_Locs{$sig}}, $self->filename;    }    $self->{_file_sigs}{$sig} = 1;    if ($main::Opt_Crypt && ($self->{_last_keyword} eq "module"			     || $self->{_last_keyword} eq "function"			     || $self->{_last_keyword} eq "task")) {	$main::Dont_Decrypt{$sig} = 1;	$self->{_last_keyword} = "";    }}sub keyword {    # Callback from parser when a keyword occurs    my $self = shift;	# Parser invoked    my $token = shift;	# What token was parsed    $self->{_last_keyword} = $token;    if ($main::Opt_Keywords) {	$self->_track_signal($token);    }}sub symbol {    # Callback from parser when a symbol occurs    my $self = shift;	# Parser invoked    my $sig = shift;	# What token was parsed    #print "Signal callback $self $token\n" if ($Debug);    $self->_track_signal($sig);}sub parse_file {    # Read all signals in this filename    @_ == 2 or croak 'usage: $parser->parse_file($filename)';    my $self = shift;    my $filename = shift;    $self->{_file_sigs} = {}; # Signals already found in module    $self->{_last_keyword} = "";    $self->SUPER::parse_file($filename);    if ($main::Opt_Crypt) {	my $fh = IO::File->new("<$filename") or die "%Error: $! $filename\n";	local $/ = undef;	my $filestrg = <$fh>;	# Same test below	if ($filestrg =~ /ENCRYPT_ME/) {	    $main::Encrypt{$filename} = 1;	}	$fh->close;    }}############################################################################################################################################__END__=pod=head1 NAMEvrename - change signal names across many Verilog files=head1 SYNOPSIS  vrename <filename_or_directory>...=head1 DESCRIPTIONVrename will allow a signal to be changed across all levels of the designhierarchy, or to create a cross reference of signal names.  (It actuallyincludes module names, macros, and other definitions, so those can bechanged too.)Vpm uses a three step process.  First, use    vrename --list  [<file.v>...]  [<directory>....]This reads the specified files, or all files below the specified directory,and creates a signals.vrename file.Now, edit the signals.vrename file manually to specify the new signalnames.  Then, use    vrename --change [<file.v>...]  [<directory>....]=head1 ARGUMENTSvrename takes the following arguments:=over 4=item --helpDisplays this message and program version and exits.=item --versionDisplays program version and exits.=item --changeTake the signals file signals.vrename in the current directoryand change the signals in the design as specified by thesignals file.  Either --list or --change must be specified.=item --changefile {file}Use the given filename instead of "signals.vrename".=item --cryptWith --list, randomize the signal renames.  With --change, compress spacesand comments and apply those renames listed in the file (presumably createdwith vrename --list --crypt).The comment /*ENCRYPT_ME*/ must be included in all files that need to beencrypted, or use the --cryptall flag.  If a signal should not beencrypted, it can simply be set in the signals.vrename list to be changedto itself.  After encrypting, you may want to save the signals.vrename fileso you have a key for decoding, and also so that it may be used for thenext encryption run.  When used in this way for the next encryption run,only new signals will get new encryptions, all other encryptions will beencrypted the same.=item --cryptallAs with --crypt, but put cryptic names into signals.vrename even if thefile does not include ENCRYPT_ME.  Generally you will then need to edit thesignals.vrename file manually to exclude any top level signals that shouldbe preserved.=item --keywordsInclude keywords in the renaming list.  Default is to ignore keywords, aschanging a keyword will probably result in unrunnable code, however,occasionally it may be necessary to rename signals which happen to matchthe name of keywords recently added to the language (such as 'bit').=item --listCreate a list of signals in the design and write tosignals.vrename.  Either --list or --change must be specified.=item --nowriteDon't write the actual changes, just report the files that would be changed.=item --o {dir}Use the given directory for output instead of the current directory.=item --readRead the changes list, allows --list to append to thechanges already read.=item --xrefInclude a cross reference of where the signals are used.--list must also be specified.=back=head1 DISTRIBUTIONVerilog-Perl is part of the L<http://www.veripool.org/> free Verilog EDAsoftware tool suite.  The latest version is available from CPAN and fromL<http://www.veripool.org/verilog-perl>.Copyright 2000-2009 by Wilson Snyder.  This package is free software; youcan redistribute it and/or modify it under the terms of either the GNULesser General Public License or the Perl Artistic License.=head1 AUTHORSWilson Snyder <wsnyder@wsnyder.org>=head1 SEE ALSOL<Verilog-Perl>, L<Verilog::Parser>=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -