diff --git a/driver/main.c b/driver/main.c index c2b2a96a0..2f3383764 100644 --- a/driver/main.c +++ b/driver/main.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: main.c,v 1.67 2005/07/14 23:38:44 steve Exp $" +#ident "$Id: main.c,v 1.68 2006/07/26 00:02:48 steve Exp $" #endif # include "config.h" @@ -111,8 +111,6 @@ const char*generation = "2x"; char warning_flags[16] = ""; -char*inc_list = 0; -char*def_list = 0; char*mod_list = 0; char*command_filename = 0; @@ -123,6 +121,9 @@ char*source_path = 0; FILE*source_file = 0; unsigned source_count = 0; +char*defines_path = 0; +FILE*defines_file = 0; + char*iconfig_path = 0; FILE*iconfig_file = 0; @@ -269,8 +270,11 @@ static int t_default(char*cmd, unsigned ncmd) rc = system(cmd); remove(source_path); - if ( ! getenv("IVERILOG_ICONFIG")) + if ( ! getenv("IVERILOG_ICONFIG")) { remove(iconfig_path); + remove(defines_path); + } + if (rc != 0) { if (rc == 127) { fprintf(stderr, "Failed to execute: %s\n", cmd); @@ -340,32 +344,12 @@ void process_library2_switch(const char *name) void process_include_dir(const char *name) { - if (inc_list == 0) { - inc_list = malloc(strlen(" -I")+strlen(name)+1); - strcpy(inc_list, " -I"); - strcat(inc_list, name); - } else { - inc_list = realloc(inc_list, strlen(inc_list) - + strlen(" -I") - + strlen(name) + 1); - strcat(inc_list, " -I"); - strcat(inc_list, name); - } + fprintf(defines_file, "I:%s\n", name); } void process_define(const char*name) { - if (def_list == 0) { - def_list = malloc(strlen(" -D")+strlen(name)+1); - strcpy(def_list, " -D"); - strcat(def_list, name); - } else { - def_list = realloc(def_list, strlen(def_list) - + strlen(" -D") - + strlen(name) + 1); - strcat(def_list, " -D"); - strcat(def_list, name); - } + fprintf(defines_file,"D:%s\n", name); } /* @@ -465,6 +449,19 @@ int main(int argc, char **argv) return 1; } + defines_path = strdup(my_tempfile("ivrlg2", &defines_file)); + if (NULL == defines_file) { + fprintf(stderr, "%s: Error opening temporary file %s\n", + argv[0], defines_path); + fprintf(stderr, "%s: Please check TMP or TMPDIR.\n", argv[0]); + + fclose(source_file); + remove(source_path); + return 1; + } + + fprintf(defines_file, "D:__ICARUS__=1\n"); + /* Create another temporary file for passing configuration information to ivl. */ @@ -485,6 +482,9 @@ int main(int argc, char **argv) fprintf(stderr, "%s: Please check TMP or TMPDIR.\n", argv[0]); fclose(source_file); remove(source_path); + + fclose(defines_file); + remove(defines_path); return 1; } @@ -647,6 +647,9 @@ int main(int argc, char **argv) fclose(source_file); source_file = 0; + fclose(defines_file); + defines_file = 0; + if (source_count == 0) { fprintf(stderr, "%s: No input files.\n", argv[0]); fprintf(stderr, "%s\n", HELP); @@ -656,26 +659,14 @@ int main(int argc, char **argv) /* Start building the preprocess command line. */ - sprintf(tmp, "%s%civlpp %s%s -D__ICARUS__=1 -f%s ", pbase,sep, + sprintf(tmp, "%s%civlpp %s%s -F%s -f%s ", pbase,sep, verbose_flag?" -v":"", - e_flag?"":" -L", source_path); + e_flag?"":" -L", defines_path, source_path); ncmd = strlen(tmp); cmd = malloc(ncmd + 1); strcpy(cmd, tmp); - if (inc_list) { - cmd = realloc(cmd, ncmd + strlen(inc_list) + 1); - strcat(cmd, inc_list); - ncmd += strlen(inc_list); - } - - if (def_list) { - cmd = realloc(cmd, ncmd + strlen(def_list) + 1); - strcat(cmd, def_list); - ncmd += strlen(def_list); - } - if (depfile) { cmd = realloc(cmd, ncmd + strlen(depfile) + 5); strcat(cmd, " -M "); @@ -720,10 +711,8 @@ int main(int argc, char **argv) /* Write the preprocessor command needed to preprocess a single file. This may be used to preprocess library files. */ - fprintf(iconfig_file, "ivlpp:%s%civlpp -D__ICARUS__ -L %s %s\n", - pbase, sep, - inc_list? inc_list : "", - def_list? def_list : ""); + fprintf(iconfig_file, "ivlpp:%s%civlpp -D__ICARUS__ -L -F%s\n", + pbase, sep, defines_path); /* Done writing to the iconfig file. Close it now. */ fclose(iconfig_file); @@ -735,6 +724,9 @@ int main(int argc, char **argv) /* * $Log: main.c,v $ + * Revision 1.68 2006/07/26 00:02:48 steve + * Pass defines and includes through temp file. + * * Revision 1.67 2005/07/14 23:38:44 steve * Display as version 0.9.devel * diff --git a/ivlpp/main.c b/ivlpp/main.c index 2b79fbe5c..c0903e4ce 100644 --- a/ivlpp/main.c +++ b/ivlpp/main.c @@ -17,7 +17,7 @@ const char COPYRIGHT[] = * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: main.c,v 1.20 2004/09/10 00:15:45 steve Exp $" +#ident "$Id: main.c,v 1.21 2006/07/26 00:02:48 steve Exp $" #endif # include "config.h" @@ -89,6 +89,69 @@ int line_direct_flag = 0; unsigned error_count = 0; FILE *depend_file = NULL; +static int flist_read_flags(const char*path) +{ + char line_buf[2048]; + FILE*fd = fopen(path, "r"); + if (fd == 0) { + fprintf(stderr, "%s: unable to open for reading.\n", path); + return -1; + } + + while (fgets(line_buf, sizeof line_buf, fd) != 0) { + /* Skip leading white space. */ + char*cp = line_buf + strspn(line_buf, " \t\r\b\f"); + /* Remove trailing white space. */ + char*tail = cp + strlen(cp); + while (tail > cp) { + if (! isspace(tail[-1])) + break; + tail -= 1; + tail[0] = 0; + } + + /* Skip empty lines */ + if (*cp == 0) + continue; + /* Skip comment lines */ + if (cp[0] == '#') + continue; + + /* The arg points to the argument to the keyword. */ + char*arg = strchr(cp, ':'); + if (arg) *arg++ = 0; + + if (strcmp(cp,"D") == 0) { + char*val = strchr(arg, '='); + if (val) + *val++ = 0; + else + val = "1"; + + define_macro(arg, val, 0); + + } else if (strcmp(cp,"I") == 0) { + include_dir = realloc(include_dir, + (include_cnt+1)*sizeof(char*)); + include_dir[include_cnt] = strdup(arg); + include_cnt += 1; + + } else if (strcmp(cp,"keyword") == 0) { + char*buf = malloc(strlen(arg) + 2); + buf[0] = '`'; + strcpy(buf+1, optarg); + define_macro(optarg, buf, 1); + free(buf); + + } else { + fprintf(stderr, "%s: Invalid keyword %s\n", path, cp); + } + } + + fclose(fd); + return 0; +} + /* * This function reads from a file a list of file names. Each name * starts with the first non-space character, and ends with the last @@ -153,20 +216,11 @@ int main(int argc, char*argv[]) include_dir[0] = strdup("."); include_cnt = 1; - while ((opt = getopt(argc, argv, "D:f:I:K:LM:o:v")) != EOF) switch (opt) { + while ((opt=getopt(argc, argv, "F:f:K:LM:o:v")) != EOF) switch (opt) { - case 'D': { - char*tmp = strdup(optarg); - char*val = strchr(tmp, '='); - if (val) - *val++ = 0; - else - val = "1"; - - define_macro(tmp, val, 0); - free(tmp); - break; - } + case 'F': + flist_read_flags(optarg); + break; case 'f': if (flist_path) { @@ -176,13 +230,6 @@ int main(int argc, char*argv[]) flist_path = optarg; break; - case 'I': - include_dir = realloc(include_dir, - (include_cnt+1)*sizeof(char*)); - include_dir[include_cnt] = strdup(optarg); - include_cnt += 1; - break; - case 'K': { char*buf = malloc(strlen(optarg) + 2); buf[0] = '`'; @@ -225,10 +272,9 @@ int main(int argc, char*argv[]) } if (flag_errors) { - fprintf(stderr, "\nUsage: %s [-v][-L][-I][-D] ...\n" - " -D - Predefine a value.\n" + fprintf(stderr, "\nUsage: %s [-v][-L][-F][-f] ...\n" + " -F - Get defines and includes from file\n" " -f - Read the sources listed in the file\n" - " -I - Add an include file search directory\n" " -K - Define a keyword macro that I just pass\n" " -L - Emit line number directives\n" " -M - Write dependencies to \n" @@ -290,6 +336,9 @@ int main(int argc, char*argv[]) /* * $Log: main.c,v $ + * Revision 1.21 2006/07/26 00:02:48 steve + * Pass defines and includes through temp file. + * * Revision 1.20 2004/09/10 00:15:45 steve * Remove bad casts. *