Pass list of file to ivlpp via temporary file.

This commit is contained in:
steve
2001-11-21 02:20:34 +00:00
parent da4901bb17
commit 39ef2b7605
2 changed files with 117 additions and 31 deletions
+27 -22
View File
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ident "$Id: main.c,v 1.30 2001/11/16 05:07:19 steve Exp $" #ident "$Id: main.c,v 1.31 2001/11/21 02:20:34 steve Exp $"
# include "config.h" # include "config.h"
@@ -94,16 +94,21 @@ char *library_flags2 = 0;
char*inc_list = 0; char*inc_list = 0;
char*def_list = 0; char*def_list = 0;
char*mod_list = 0; char*mod_list = 0;
char*src_list = 0;
char*command_filename = 0; char*command_filename = 0;
char*start = 0; char*start = 0;
char*f_list = 0; char*f_list = 0;
/* These are used to collect the list of file names that will be
passed to ivlpp. Keep the list in a file because it can be a long
list. */
char*source_path = 0;
FILE*source_file = 0;
unsigned source_count = 0;
int synth_flag = 0; int synth_flag = 0;
int verbose_flag = 0; int verbose_flag = 0;
int command_file = 0; int command_file = 0;
int inside_c_comment = 0;
FILE *fp; FILE *fp;
@@ -151,6 +156,7 @@ static int t_default(char*cmd, unsigned ncmd)
rc = system(cmd); rc = system(cmd);
remove(source_path);
if (rc != 0) { if (rc != 0) {
if (rc == 127) { if (rc == 127) {
fprintf(stderr, "Failed to execute: %s\n", cmd); fprintf(stderr, "Failed to execute: %s\n", cmd);
@@ -206,6 +212,7 @@ static int t_vvm(char*cmd, unsigned ncmd)
printf("translate: %s\n", cmd); printf("translate: %s\n", cmd);
rc = system(cmd); rc = system(cmd);
remove(source_path);
if (rc != 0) { if (rc != 0) {
if (WIFEXITED(rc)) { if (WIFEXITED(rc)) {
fprintf(stderr, "errors translating Verilog program.\n"); fprintf(stderr, "errors translating Verilog program.\n");
@@ -330,15 +337,8 @@ void process_define(const char*name)
void process_file_name(const char*name) void process_file_name(const char*name)
{ {
if (src_list) { fprintf(source_file, "%s\n", name);
src_list = realloc(src_list, source_count += 1;
strlen(src_list) + strlen(name) + 2);
strcat(src_list, " ");
strcat(src_list, name);
} else {
src_list = malloc(strlen(name) + 1);
strcpy(src_list, name);
}
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@@ -387,6 +387,11 @@ int main(int argc, char **argv)
base = ivl_root; base = ivl_root;
#endif #endif
source_path = strdup(tmpnam(0));
assert(source_path);
source_file = fopen(source_path, "w");
assert(source_file);
while ((opt = getopt(argc, argv, "B:C:c:D:Ef:hI:m:N::o:p:Ss:T:t:vW:y:")) != EOF) { while ((opt = getopt(argc, argv, "B:C:c:D:Ef:hI:m:N::o:p:Ss:T:t:vW:y:")) != EOF) {
switch (opt) { switch (opt) {
@@ -527,7 +532,10 @@ int main(int argc, char **argv)
process_file_name(argv[idx]); process_file_name(argv[idx]);
if (src_list == 0) { fclose(source_file);
source_file = 0;
if (source_count == 0) {
fprintf(stderr, "%s: No input files.\n", argv[0]); fprintf(stderr, "%s: No input files.\n", argv[0]);
fprintf(stderr, "%s\n", HELP); fprintf(stderr, "%s\n", HELP);
return 1; return 1;
@@ -554,9 +562,9 @@ int main(int argc, char **argv)
/* Start building the preprocess command line. */ /* Start building the preprocess command line. */
sprintf(tmp, "%s%civlpp %s%s", base,sep, sprintf(tmp, "%s%civlpp %s%s -f%s ", base,sep,
verbose_flag?" -v":"", verbose_flag?" -v":"",
e_flag?"":" -L"); e_flag?"":" -L", source_path);
ncmd = strlen(tmp); ncmd = strlen(tmp);
cmd = malloc(ncmd + 1); cmd = malloc(ncmd + 1);
@@ -575,13 +583,6 @@ int main(int argc, char **argv)
} }
/* Add the file names to the preprocessor command line. */
cmd = realloc(cmd, ncmd+strlen(src_list)+2);
strcpy(cmd+ncmd, " ");
ncmd += 1;
strcpy(cmd+ncmd, src_list);
ncmd += strlen(src_list);
/* If the -E flag was given on the command line, then all we /* If the -E flag was given on the command line, then all we
do is run the preprocessor and put the output where the do is run the preprocessor and put the output where the
user wants it. */ user wants it. */
@@ -598,6 +599,7 @@ int main(int argc, char **argv)
printf("preprocess: %s\n", cmd); printf("preprocess: %s\n", cmd);
rc = system(cmd); rc = system(cmd);
remove(source_path);
if (rc != 0) { if (rc != 0) {
if (WIFEXITED(rc)) { if (WIFEXITED(rc)) {
fprintf(stderr, "errors preprocessing Verilog program.\n"); fprintf(stderr, "errors preprocessing Verilog program.\n");
@@ -622,6 +624,9 @@ int main(int argc, char **argv)
/* /*
* $Log: main.c,v $ * $Log: main.c,v $
* Revision 1.31 2001/11/21 02:20:34 steve
* Pass list of file to ivlpp via temporary file.
*
* Revision 1.30 2001/11/16 05:07:19 steve * Revision 1.30 2001/11/16 05:07:19 steve
* Add support for +libext+ in command files. * Add support for +libext+ in command files.
* *
+90 -9
View File
@@ -17,7 +17,7 @@ const char COPYRIGHT[] =
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #if !defined(WINNT) && !defined(macintosh)
#ident "$Id: main.c,v 1.12 2001/09/15 18:27:04 steve Exp $" #ident "$Id: main.c,v 1.13 2001/11/21 02:20:35 steve Exp $"
#endif #endif
# include "config.h" # include "config.h"
@@ -58,6 +58,29 @@ extern int optind;
extern const char*optarg; extern const char*optarg;
#endif #endif
/*
* Keep in source_list an array of pointers to file names. The array
* is terminated by a pointer to null.
*/
static char**source_list = 0;
static unsigned source_cnt = 0;
void add_source_file(const char*name)
{
fprintf(stderr, "add_source_file: %s\n", name);
if (source_list == 0) {
source_list = calloc(2, sizeof(char*));
source_list[0] = strdup(name);
source_list[1] = 0;
source_cnt = 1;
} else {
source_list = realloc(source_list, sizeof(char*) * (source_cnt+2));
source_list[source_cnt+0] = strdup(name);
source_list[source_cnt+1] = 0;
source_cnt += 1;
}
}
char**include_dir = 0; char**include_dir = 0;
unsigned include_cnt = 0; unsigned include_cnt = 0;
@@ -65,9 +88,42 @@ int line_direct_flag = 0;
unsigned error_count = 0; unsigned error_count = 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
* non-space character. Spaces in the middle are OK.
*/
static int flist_read_names(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) {
char*cp = line_buf + strspn(line_buf, " \t\r\b\f");
char*tail = cp + strlen(cp);
while (tail > cp) {
if (! isspace(tail[-1]))
break;
tail -= 1;
tail[0] = 0;
}
if (cp < tail)
add_source_file(cp);
}
return 0;
}
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
int opt; int opt, idx;
const char*flist_path = 0;
unsigned flag_errors = 0; unsigned flag_errors = 0;
char*out_path = 0; char*out_path = 0;
FILE*out; FILE*out;
@@ -95,7 +151,7 @@ int main(int argc, char*argv[])
include_dir[0] = strdup("."); include_dir[0] = strdup(".");
include_cnt = 1; include_cnt = 1;
while ((opt = getopt(argc, argv, "D:I:K:Lo:v")) != EOF) switch (opt) { while ((opt = getopt(argc, argv, "D:f:I:K:Lo:v")) != EOF) switch (opt) {
case 'D': { case 'D': {
char*tmp = strdup(optarg); char*tmp = strdup(optarg);
@@ -110,6 +166,14 @@ int main(int argc, char*argv[])
break; break;
} }
case 'f':
if (flist_path) {
fprintf(stderr, "%s: duplicate -f flag\n", argv[0]);
flag_errors += 1;
}
flist_path = optarg;
break;
case 'I': case 'I':
include_dir = realloc(include_dir, (include_cnt+1)*sizeof(char*)); include_dir = realloc(include_dir, (include_cnt+1)*sizeof(char*));
include_dir[include_cnt] = strdup(optarg); include_dir[include_cnt] = strdup(optarg);
@@ -149,12 +213,10 @@ int main(int argc, char*argv[])
break; break;
} }
if (optind == argc)
flag_errors += 1;
if (flag_errors) { if (flag_errors) {
fprintf(stderr, "\nUsage: %s [-v][-L][-I<dir>][-D<def>] <file>...\n" fprintf(stderr, "\nUsage: %s [-v][-L][-I<dir>][-D<def>] <file>...\n"
" -D<def> - Predefine a value.\n" " -D<def> - Predefine a value.\n"
" -f<fil> - Read the sources listed in the file\n"
" -I<dir> - Add an include file search directory\n" " -I<dir> - Add an include file search directory\n"
" -K<def> - Define a keyword macro that I just pass\n" " -K<def> - Define a keyword macro that I just pass\n"
" -L - Emit line number directives\n" " -L - Emit line number directives\n"
@@ -164,6 +226,21 @@ int main(int argc, char*argv[])
return flag_errors; return flag_errors;
} }
/* Collect the file names on the command line in the source
file list, then if there is a file list, read more file
names from there. */
for (idx = optind ; idx < argc ; idx += 1)
add_source_file(argv[idx]);
if (flist_path) {
int rc = flist_read_names(flist_path);
if (rc != 0)
return rc;
}
/* Figure out what to use for an output file. Write to stdout
if no path is specified. */
if (out_path) { if (out_path) {
out = fopen(out_path, "w"); out = fopen(out_path, "w");
if (out == 0) { if (out == 0) {
@@ -174,13 +251,14 @@ int main(int argc, char*argv[])
out = stdout; out = stdout;
} }
if (argv[optind] == 0) { if (source_cnt == 0) {
fprintf(stderr, "%s: No input files given.\n", argv[0]); fprintf(stderr, "%s: No input files given.\n", argv[0]);
return 1; return 1;
} }
reset_lexor(out, argv+optind); /* Pass to the lexical analyzer the list of input file, and
start the parser. */
reset_lexor(out, source_list);
if (yyparse()) return -1; if (yyparse()) return -1;
return error_count; return error_count;
@@ -188,6 +266,9 @@ int main(int argc, char*argv[])
/* /*
* $Log: main.c,v $ * $Log: main.c,v $
* Revision 1.13 2001/11/21 02:20:35 steve
* Pass list of file to ivlpp via temporary file.
*
* Revision 1.12 2001/09/15 18:27:04 steve * Revision 1.12 2001/09/15 18:27:04 steve
* Make configure detect malloc.h * Make configure detect malloc.h
* *