eval 'exec perl -S $0 ${1+"$@"}' if 0; # # Copyright (c) 2000 Qualis Design Corporation. # All rights reserved. # # Qualis Design Corporation # PO Box 4444 # Beaverton OR 97075-4444 # Phone: +1-503-670-9700 # E-mail: info@qualis.com # World Wide Web: http:#www.qualis.com # # Description: # Fix the automatically-generated *.vrh files by # prepending any included file in the original *.vr file. # and virtual port declarations. # # Author: $Author: janick $ # Revision: $Revision: 1.4 $ # sub usage { print STDERR <) { $line++; # Strip line comments $_ =~ s#\s*//.*$##; # Is it an include directive ? if (m/^\s*#\s*include\s*([<"](\S+)[">])\s*$/) { $incl = $1; $fname = $2; # Don't copy included *.vr files if ($fname =~ m/\.vr$/) { # but parse them &parse($fname); } else { push(@include, $incl); } next; } # Is it an external class declaration ? if (m/^\s*extern\s+(\S+)$/) { push(@externs, "$1"); next; } # Strip comments s#//.*$##; # Is it a virtual port declaration ? $port_decl = $_; if (s/^\s*port\s+(\S+)\s*($|{)/\2/) { $port = $1; # Find the '{' while (!s/^\s*\{\s*//) { # Slurp the next line if (!($_ = <$source>)) { print STDERR "ERROR: $source: Unexpected end-of-file in port declaration: $port_decl"; exit(0); } # Strip comments s#//.*$##; $line++; } # Parse the semi-colon separated list of signals # until we reach a '}' @signals = (); while ($_ !~ m/^\s*\}/) { # Is the line empty? if (m/^\s*$/) { # Slurp the next line if (!($_ = <$source>)) { print STDERR "ERROR: $source: Unexpected end-of-file in port declaration: $port_decl"; exit(0); } # Strip comments s#//.*$##; $line++; next; } if (!s/\s*(\w+)\s*(;\s*)?//) { print STDERR "ERROR: $source, line $line: Invalid port syntax: $port_decl"; exit(0); } push(@signals, $1); } $ports{$port} = join(":", @signals); next; } } close($source); } #sub parse # Open the original *.vrh file, and the new one if (!open(VRH, "< $header")) { print STDERR "ERROR: Cannot open $header for reading: $!\n"; next; } if (!open(NEW, "> $new")) { print STDERR "ERROR: Cannot open $new for writing: $!\n"; close(VRH); next; } # Copy the old file into the new file, until # we reach the '#define ..._VRH' symbol to control # multiple inclusion of the *.vrh file. while ($_ = ) { print NEW $_; last if m/^\s*#\s*define.*_VRH\s*$/; } print NEW "\n\n// start - Added by $0, ", '$Revision: 1.4 $', ":\n\n"; #' # Insert the needed #include directives print NEW "// Required 'include' directives:\n"; foreach $include (@include) { print NEW "#include $include\n"; } print NEW "\n"; # Insert the needed extern declarations print NEW "// Required external class declarations:\n"; foreach $extern (@externs) { print NEW "extern $extern\n"; } print NEW "\n"; # Insert the needed port declarations print NEW "// Required virtual port declarations:\n"; foreach $name (keys(%ports)) { @signals = split(/:/, $ports{$name}); print NEW "port $name\n{\n ", join(";\n ", @signals), ";\n}\n"; } print NEW "\n// end - Added by $0, ", '$Revision: 1.4 $', ":\n\n\n"; #' # Copy the rest of the file while ($_ = ) { # Comment out any port declation # They'll be taken care of by the include directives # or have been re-inserted at the top of this file. if (m/^\s*port\s+/) { print NEW "// start - Removed by $0, ", '$Revision: 1.4 $', ":\n"; #' print NEW "// $_"; # Comment-out until we reach a '}' while (!m/^\s*\}/) { $_ = ; print NEW "// $_"; } print NEW "// end - Removed by $0, ", '$Revision: 1.4 $', ":\n"; #' next; } # Replace VeraList* classes with a external macro calls if (m/ VeraListNode(\S+) /) { $element = $1; $n = 0; while ($_ = ) { $n++ if m/^}$/; last if $n == 3; } print NEW "ExternVeraList($element)\n"; next; } print NEW $_; } close(NEW); close(VRH); # Replace the original *.vrh file with the new one if (!unlink($header)) { print STDERR "ERROR: Cannot replace $header: $!\n"; next; } if (!rename("$new", $header)) { print STDERR "ERROR: Cannot rename $new to $header: $!\n"; next; } exit(0);