diff --git a/driver/Makefile.in b/driver/Makefile.in index b40e596c1..c014d09b3 100644 --- a/driver/Makefile.in +++ b/driver/Makefile.in @@ -18,7 +18,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.12 2002/05/24 01:13:00 steve Exp $" +#ident "$Id: Makefile.in,v 1.13 2002/06/23 20:10:51 steve Exp $" # # SHELL = /bin/sh @@ -56,7 +56,7 @@ clean: rm -f *.o lexor.c parse.c parse.h parse.output rm -f cflexor.c cfparse.c cfparse.h cfparse.output -O = main.o build_string.o lexor.o parse.o cflexor.o cfparse.o +O = main.o build_string.o lexor.o parse.o substit.o cflexor.o cfparse.o iverilog@EXEEXT@: $O $(CC) $(LDFLAGS) $O -o iverilog@EXEEXT@ @EXTRALIBS@ diff --git a/driver/cfparse.y b/driver/cfparse.y index ceed944df..664148ef8 100644 --- a/driver/cfparse.y +++ b/driver/cfparse.y @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: cfparse.y,v 1.7 2002/05/28 20:40:37 steve Exp $" +#ident "$Id: cfparse.y,v 1.8 2002/06/23 20:10:51 steve Exp $" #endif @@ -78,9 +78,11 @@ item of a source file. Add the file to the file list. */ : TOK_STRING - { translate_file_name($1); - process_file_name($1); + { char*tmp = substitutions($1); + translate_file_name(tmp); + process_file_name(tmp); free($1); + free(tmp); } /* The -a flag is completely ignored. */ @@ -91,11 +93,13 @@ item as an ordinary source file. */ | TOK_Dv TOK_STRING - { translate_file_name($2); - process_file_name($2); + { char*tmp = substitutions($2); + translate_file_name(tmp); + process_file_name(tmp); fprintf(stderr, "%s:%u: Ignoring -v in front of %s\n", @1.text, @1.first_line, $2); free($2); + free(tmp); } /* This rule matches "-y " sequences. This does the same thing @@ -103,18 +107,24 @@ item directory list. */ | TOK_Dy TOK_STRING - { process_library_switch($2); + { char*tmp = substitutions($2); + process_library_switch(tmp); free($2); + free(tmp); } | TOK_LIBDIR TOK_PLUSARG - { process_library_switch($2); + { char*tmp = substitutions($2); + process_library_switch(tmp); free($2); + free(tmp); } | TOK_LIBDIR_NOCASE TOK_PLUSARG - { process_library_nocase_switch($2); + { char*tmp = substitutions($2); + process_library_nocase_switch(tmp); free($2); + free(tmp); } | TOK_DEFINE TOK_PLUSARG @@ -161,8 +171,10 @@ inc_args ; inc_arg : TOK_PLUSARG - { process_include_dir($1); + { char*tmp = substitutions($1); + process_include_dir(tmp); free($1); + free(tmp); } ; diff --git a/driver/globals.h b/driver/globals.h index 91cfe8716..e1a87c8fe 100644 --- a/driver/globals.h +++ b/driver/globals.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: globals.h,v 1.14 2002/05/28 20:40:37 steve Exp $" +#ident "$Id: globals.h,v 1.15 2002/06/23 20:10:51 steve Exp $" #endif # include @@ -60,6 +60,9 @@ extern const char*targ; /* This is the language generation flag. */ extern const char*generation; + /* Perform variable substitutions on the string. */ +extern char* substitutions(const char*str); + /* Add the name to the list of source files. */ extern void process_file_name(const char*name); @@ -89,6 +92,9 @@ extern int build_string(char*out, size_t olen, const char*pattern); /* * $Log: globals.h,v $ + * Revision 1.15 2002/06/23 20:10:51 steve + * Variable substitution in command files. + * * Revision 1.14 2002/05/28 20:40:37 steve * ivl indexes the search path for libraries, and * supports case insensitive module-to-file lookup. diff --git a/driver/iverilog.man b/driver/iverilog.man index d7703059a..de077b171 100644 --- a/driver/iverilog.man +++ b/driver/iverilog.man @@ -1,4 +1,4 @@ -.TH iverilog 1 "$Date: 2002/05/28 20:46:51 $" Version "$Date: 2002/05/28 20:46:51 $" +.TH iverilog 1 "$Date: 2002/06/23 20:10:51 $" Version "$Date: 2002/06/23 20:10:51 $" .SH NAME iverilog - Icarus Verilog compiler @@ -187,7 +187,7 @@ mostly by EDIF format output. .SH "WARNING TYPES" These are the types of warnings that can be selected by the \fB-W\fP switch. All the warning types (other then \fBall\fP) can also be -prefixed with \fBno-\fP to turn of that warning. This is most useful +prefixed with \fBno-\fP to turn off that warning. This is most useful after a \fB-Wall\fP argument to suppress isolated warning types. .TP 8 @@ -217,7 +217,8 @@ well as # comments, if the # starts the line. .TP 8 .I "file name" A simple file name or file path is taken to be the name of a Verilog -source file. The path starts with the first non-white-space character. +source file. The path starts with the first non-white-space +character. Variables are substitued in file names. .TP 8 .B -y\ \fIlibdir\fP @@ -225,6 +226,8 @@ A \fB-y\fP token prefixes a library directory in the command file, exactly like it does on the command line. The parameter to the \fB-y\fP flag may be on the same line or the next non-comment line. +Variables in the \fIlibdir\fP are substituted. + .TP 8 .B +incdir+\fIincludedir\fP The \fB+incdir+\fP token in command files gives directories to search @@ -233,6 +236,8 @@ command line. The difference is that multiple \fI+includedir\fP directories are valid parameters to a single \fB+incdir+\fP token, although you may also have multiple \fB+incdir+\fP lines. +Variables in the \fIincludedir\fP are substituted. + .TP 8 .B +libext+\fIext\fP The \fB+libext\fP token in command files fives file extensions to try @@ -268,6 +273,18 @@ become munged. .B +tolower-filename\fP This is similar to the \fB+toupper-filename\fP hack described above. +.SH "VARIABLES IN COMMAND FILES" + +In certain cases, iverilog supports variables in command files. These +are strings of the form "$(\fIvarname\fP)", where \fIvarname\fP is the +name of the environment variable to read. The entire string is +replaced with the contents of that variable. Variables are only +substitued in contexts that explicitly support them, including file +and directory strings. + +Variable values come from the operating system environment, and not +from preprocessor defines elsewhere in the file or the command line. + .SH EXAMPLES These examples assume that you have a Verilog source file called hello.v in the current directory @@ -299,7 +316,7 @@ vvp(1), .SH COPYRIGHT .nf -Copyright \(co 2000 Stephen Williams +Copyright \(co 2002 Stephen Williams This document can be freely redistributed according to the terms of the GNU General Public License version 2.0 diff --git a/driver/substit.c b/driver/substit.c new file mode 100644 index 000000000..c5e7d2fc6 --- /dev/null +++ b/driver/substit.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2002 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ident "$Id: substit.c,v 1.1 2002/06/23 20:10:51 steve Exp $" + +# include +# include +# include + + +char* substitutions(const char*str) +{ + size_t nbuf = strlen(str) + 1; + char*buf = malloc(nbuf); + char*cp = buf; + + while (*str) { + + if ((str[0] == '$') && (str[1] == '(')) { + /* If I find a $(x) string in the source, replace + it in the destination with the contents of the + environment variable x. */ + char*name; + char*value; + const char*ep = strchr(str, ')'); + str += 2; + + name = malloc(ep-str+1); + strncpy(name, str, ep-str); + name[ep-str] = 0; + + str = ep + 1; + + value = getenv(name); + free(name); + if (value == 0) + continue; + + if (strlen(value) >= (nbuf - (cp-buf))) { + size_t old_size = cp - buf; + nbuf = (cp - buf) + strlen(value) + 1; + buf = realloc(buf, nbuf); + cp = buf + old_size; + } + + strcpy(cp, value); + cp += strlen(cp); + + } else { + if ( (cp - buf) == nbuf ) { + size_t old_size = nbuf; + nbuf = old_size + 32; + buf = realloc(buf, nbuf); + cp = buf + old_size; + } + + *cp++ = *str++; + } + } + + /* Add the trailing nul to the string, and reallocate the + buffer to be a tight fit. */ + if ( (cp - buf) == nbuf ) { + size_t old_size = nbuf; + nbuf = old_size + 1; + buf = realloc(buf, nbuf); + buf[old_size] = 0; + } else { + *cp++ = 0; + nbuf = cp - buf; + buf = realloc(buf, nbuf); + } + + return buf; +} + + +/* + * $Log: substit.c,v $ + * Revision 1.1 2002/06/23 20:10:51 steve + * Variable substitution in command files. + * + */ +