| Verilog Preprocessor Script
Go To Script Pool |
|
| This script allows the user to allow the
use of `define, `ifdef, etc.. Depending on your needs, you may be able to just use
#define and use the C preprocessor or a simple sed script #!/usr/local/bin/perl5 -w- -*-Perl-*- require 5; @incdirs = ("."); # always include current directory GetArgs(@ARGV); # process our argiments if ($#files >= 0) { for (@files) { open(FILE,$_) || die ("$_: $!"); ScanText(*FILE,undef,0); close(FILE); } } else { ScanText(*STDIN,undef,0); } sub ScanText { my $file = shift; # filehandle to read from my $scanTo = shift; # stop when input matches this (never if undefined) my $ignore = shift; # true if we should ignore what we see while (<$file>) { return $_ if (defined $scanTo && /$scanTo/); if (/^\s*`ifdef\s+([a-zA-z_][A-Za-z0-9_]*)/) { # `){ my $defined = (defined $defines{$1}); $_ = ScanText($file,"^\\s*`(endif|else)\\b",$ignore || !$defined); # ` next unless (/^\s*`else\b/); # `) ScanText($file,"^\\s*`endif\\b",$ignore || $defined); # `) next; } next if $ignore; if (/^\s*`define\s+([a-zA-z_][A-Za-z0-9_]*|\\\S*) $defines{$1} = defined $3 ? $3 : ""; print; next; } if (/^\s*`include\s*"(.*)"/) { # `) { my $dir; local *INCLUDE; ($dir) = grep {-e "$_/$1"} @incdirs; defined $dir || die "$0: $1: could not find included file.\n"; open(INCLUDE,"$dir/$1") || die "$0: $1: $!\n"; ScanText(*INCLUDE,undef,0); close(INCLUDE); next; } print; } } # GetArgs -- read command line arguments. # files go into @files, include dirs into @incdirs, # and defines into %defines. # No check on recursive -f, so watch out! sub GetArgs { while ($_ = shift) { if (/^\+define\+(.*)/) { for (split(/\+/,$1)) { /([^=]*)(=(.*))?/; $defines{$1} = defined $3 ? $3 : ""; } } elsif (/^\+incdir\+(.*)/) { push(@incdirs,split(/\+/,$1)); } elsif (/^[^+-]/) { push(@files,$_); } elsif (/^-f$/) { # get options from file local *ARGS; open(ARGS,$_=shift) || die "$0: $_: $!\n"; @args = <ARGS>; GetArgs(split(/\s+/,"@args")); close(ARGS); } elsif (/^-[iklrvy]$/) { # Verilog options with args shift; # ignore the argument } } }
|
Other Scripts: Batch
Simulation
Products: Undertow Suite
|
| Company
Products News
Assistance Download Contact Us Sales Veritools, Inc. |