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-*-
# Copyright (c) 1996 Silicon Engineering Inc.
# Permission is granted to modify and distribute this # program
# provided that this copyright message remains
# unaltered.
#
# Author: Peter Johnson 3 July, 1996
# $Id: vpp.pl,v 1.2 1996/07/04 16:39:52 pete Exp $
#
# Revision History
# PAJ 4 July, 1996 Initial release
#
# Usage:
# Parses the following Verilog command line syntax:
# +define+var
# +define+var1+var2+...+varN
# +define+var1=val1+var2=val2+...+varN=valN
# +incdir+dir
# +incdir+dir1+dir2+...+dirN
# -f <command-file>
# Other Verilog options are accepted but ignored.
# If Verilog files are omitted, reads standard input.
# Notes:
# This program requires perl 5 to run.

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*)
(\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
Compare Files
Convert
Def2Verilog
Gen XOR Tree
GetValue
IHEX2VHEX
nand tree
Name Instance
OnesCompSum
Preprocessor
Verilog Tag

Verilog Tag2
Verilog2DEF
VHDL2HTML
VRename
XNF2VHDL


Products:

Undertow Suite
Undertow
Interactive_tool
Optimizing_tool
VeriPower
Power_tool
Toggle_tool
Express_VCT
Personal_VCT
VBIT«
verilog2vhdl™
vhdl2verilogmkt
Script Pool


 

 Company    Products     News    Assistance     Download     Contact Us    Sales

Veritools, Inc.
459 Hamilton Avenue, Suite 200, Palo Alto, California 94301
(650) 462 - 5590 Main    (650) 462 - 5593 Fax
inquiry@veritools.com

For Web site information please email Webmaster