Add dependency generation.

This commit is contained in:
steve 2002-04-04 05:26:13 +00:00
parent 3c8551ce90
commit 284c6fd85d
10 changed files with 162 additions and 33 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: build_string.c,v 1.6 2001/11/16 05:07:19 steve Exp $"
#ident "$Id: build_string.c,v 1.7 2002/04/04 05:26:13 steve Exp $"
#endif
# include "config.h"
@ -54,6 +54,7 @@ int build_string(char*output, size_t olen, const char*pattern)
if (((*pattern == 's') && start)
|| ((*pattern == 'v') && verbose_flag)
|| ((*pattern == 'M') && depfile)
|| ((*pattern == 'N') && npath)
|| ((*pattern == 'T') && mtm)) {
int rc = build_string(output, olen,
@ -87,6 +88,14 @@ int build_string(char*output, size_t olen, const char*pattern)
}
break;
case 'M':
if (depfile) {
strcpy(output, depfile);
output += strlen(depfile);
olen -= strlen(depfile);
}
break;
case 'N':
if (npath) {
strcpy(output, npath);
@ -160,6 +169,9 @@ int build_string(char*output, size_t olen, const char*pattern)
/*
* $Log: build_string.c,v $
* Revision 1.7 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.6 2001/11/16 05:07:19 steve
* Add support for +libext+ in command files.
*

View File

@ -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.10 2001/11/16 05:07:19 steve Exp $"
#ident "$Id: globals.h,v 1.11 2002/04/04 05:26:13 steve Exp $"
#endif
# include <stddef.h>
@ -36,6 +36,9 @@ extern char*mod_list;
/* This is the optional -Tmin|typ|max setting. */
extern const char*mtm;
/* Ths is the optional -M<dependfile> value, if one was supplied. */
extern const char*depfile;
/* Ths is the optional -N<path> value, if one was supplied. */
extern const char*npath;
@ -79,6 +82,9 @@ extern int build_string(char*out, size_t olen, const char*pattern);
/*
* $Log: globals.h,v $
* Revision 1.11 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.10 2001/11/16 05:07:19 steve
* Add support for +libext+ in command files.
*

View File

@ -1,12 +1,12 @@
.TH iverilog 1 "$Date: 2002/02/16 03:18:54 $" Version "$Date: 2002/02/16 03:18:54 $"
.TH iverilog 1 "$Date: 2002/04/04 05:26:13 $" Version "$Date: 2002/04/04 05:26:13 $"
.SH NAME
iverilog - Icarus Verilog compiler
.SH SYNOPSIS
.B iverilog
[-ESVv] [-Cpath] [-ccmdfile] [-Dmacro[=defn]] [-pflag=value]
[-Iincludedir] [-mmodule] [-Nfile] [-ooutputfilename] [-stopmodule]
[-ttype] [-Tmin/typ/max] [-Wclass] [-ypath] sourcefile
[-Iincludedir] [-mmodule] [-Mfile] [-Nfile] [-ooutputfilename]
[-stopmodule] [-ttype] [-Tmin/typ/max] [-Wclass] [-ypath] sourcefile
.SH DESCRIPTION
.PP
@ -61,6 +61,13 @@ for Verilog include files. The \fB-I\fP switch may be used many times
to specify several directories to search, the directories are searched
in the order they appear on the command line.
.TP 8
.B -M\fIpath\fP
Write into the file specified by path a list of files that contribute
to the compilation of the design. This includes files that are
included by include directives and files that are automatically loaded
by library support. The output is one file name per line, with no
leading or trailing space.
.TP 8
.B -m\fImodule\fP
Add this module to the list of VPI modules to be loaded by the
simulation. Many modules can be specified, and all will be loaded, in

View File

@ -16,14 +16,14 @@
* 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: main.c,v 1.33 2002/03/15 23:27:42 steve Exp $"
#ident "$Id: main.c,v 1.34 2002/04/04 05:26:13 steve Exp $"
# include "config.h"
const char HELP[] =
"Usage: iverilog [-ESvV] [-B base] [-C path] [-c cmdfile]\n"
" [-D macro[=defn]] [-I includedir] [-m module]\n"
" [-D macro[=defn]] [-I includedir] [-M depfile] [-m module]\n"
" [-N file] [-o filename] [-p flag=value]\n"
" [-s topmodule] [-t target] [-T min|typ|max]\n"
" [-W class] [-y dir] [-Y suf] source_file(s)\n"
@ -87,6 +87,7 @@ const char*mtm = 0;
const char*opath = "a.out" EXEEXT;
const char*npath = 0;
const char*targ = "vvp";
const char*depfile = 0;
char warning_flags[16] = "";
char *library_flags = 0;
@ -399,7 +400,7 @@ int main(int argc, char **argv)
return 1;
}
while ((opt = getopt(argc, argv, "B:C:c:D:Ef:hI:m:N::o:p:Ss:T:t:vVW:y:")) != EOF) {
while ((opt = getopt(argc, argv, "B:C:c:D:Ef:hI:M:m:N::o:p:Ss:T:t:vVW:y:Y:")) != EOF) {
switch (opt) {
case 'B':
@ -442,6 +443,10 @@ int main(int argc, char **argv)
process_include_dir(optarg);
break;
case 'M':
depfile = optarg;
break;
case 'm':
if (mod_list == 0) {
mod_list = malloc(strlen(" -m")+strlen(optarg)+1);
@ -601,6 +606,12 @@ int main(int argc, char **argv)
ncmd += strlen(def_list);
}
if (depfile) {
cmd = realloc(cmd, ncmd + strlen(depfile) + 5);
strcat(cmd, " -M ");
strcat(cmd, depfile);
ncmd += strlen(depfile) + 4;
}
/* If the -E flag was given on the command line, then all we
do is run the preprocessor and put the output where the
@ -643,6 +654,9 @@ int main(int argc, char **argv)
/*
* $Log: main.c,v $
* Revision 1.34 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.33 2002/03/15 23:27:42 steve
* Patch to allow user to set place for temporary files.
*

View File

@ -32,6 +32,8 @@
#
# %s Substitute the start module (-s flag) from the user.
#
# %M Substitute the value of the -M<depfile> flag.
#
# %N Substitute the value of the -N<path> flag.
#
# %o Substitute the value of the -o<path> flag, or the default
@ -59,20 +61,20 @@
# be useful and interesting if the -N flag is included.
[-tnull -S]
<ivl>%B/ivl %[v-v] %y %Y %W %s %[N-N%N] %[T-T%T] -tdll -fDLL=%B/null.tgt -Fsynth -Fsyn-rules -- -
<ivl>%B/ivl %[v-v] %y %Y %W %s %[M-M%M] %[N-N%N] %[T-T%T] -tdll -fDLL=%B/null.tgt -Fsynth -Fsyn-rules -- -
[-tnull]
<ivl>%B/ivl %[v-v] %y %Y %W %s %[N-N%N] %[T-T%T] -tdll -fDLL=%B/null.tgt -- -
<ivl>%B/ivl %[v-v] %y %Y %W %s %[M-M%M] %[N-N%N] %[T-T%T] -tdll -fDLL=%B/null.tgt -- -
# --
# The vvp target generates code that the vvp simulation engine can execute.
# These rules support synthesized and non-synthesized variants.
[-tvvp -S]
<ivl>%B/ivl %[v-v] %y %Y %W %s %[N-N%N] %[T-T%T] -tdll -fDLL=%B/vvp.tgt -fVVP_EXECUTABLE=%B/../../bin/vvp -Fsynth -Fsyn-rules -Fcprop -Fnodangle %f %m -o%o -- -
<ivl>%B/ivl %[v-v] %y %Y %W %s %[M-M%M] %[N-N%N] %[T-T%T] -tdll -fDLL=%B/vvp.tgt -fVVP_EXECUTABLE=%B/../../bin/vvp -Fsynth -Fsyn-rules -Fcprop -Fnodangle %f %m -o%o -- -
[-tvvp]
<ivl>%B/ivl %[v-v] %y %Y %W %s %[N-N%N] %[T-T%T] -tdll -fDLL=%B/vvp.tgt -fVVP_EXECUTABLE=%B/../../bin/vvp -Fcprop -Fnodangle %f %m -o%o -- -
<ivl>%B/ivl %[v-v] %y %Y %W %s %[M-M%M] %[N-N%N] %[T-T%T] -tdll -fDLL=%B/vvp.tgt -fVVP_EXECUTABLE=%B/../../bin/vvp -Fcprop -Fnodangle %f %m -o%o -- -
# --
# The vvm target uses the <ivl> string to take the preprocessed code from
@ -87,14 +89,14 @@
# This is the XNF code generator.
[-txnf]
<ivl>%B/ivl %y %Y %[v-v] %s %[N-N%N] %[T-T%T] -txnf -Fsynth -Fsyn-rules -Fxnfio -Fcprop -Fnodangle -o%o -- -
<ivl>%B/ivl %y %Y %[v-v] %s %[M-M%M] %[N-N%N] %[T-T%T] -txnf -Fsynth -Fsyn-rules -Fxnfio -Fcprop -Fnodangle -o%o -- -
# And this is another XNF code generator, under development.
[-tfpga]
<ivl>%B/ivl %y %Y %[v-v] %s %[N-N%N] %[T-T%T] %f -tdll -fDLL=%B/fpga.tgt -Fsynth -Fsyn-rules -Fcprop -Fnodangle -o%o -- -
<ivl>%B/ivl %y %Y %[v-v] %s %[M-M%M] %[N-N%N] %[T-T%T] %f -tdll -fDLL=%B/fpga.tgt -Fsynth -Fsyn-rules -Fcprop -Fnodangle -o%o -- -
# --
# This is the pal code generator. The target module requires the -fpart=<type>
# flag to specify the part type.
[-tpal]
<ivl>%B/ivl %y %Y %[v-v] %s %[N-N%N] %[T-T%T] %f -tdll -fDLL=%B/pal.tgt -Fsynth -Fsyn-rules -Fcprop -Fnodangle -o%o -- -
<ivl>%B/ivl %y %Y %[v-v] %s %[M-M%M] %[N-N%N] %[T-T%T] %f -tdll -fDLL=%B/pal.tgt -Fsynth -Fsyn-rules -Fcprop -Fnodangle -o%o -- -

View File

@ -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.5 2000/09/13 22:33:13 steve Exp $"
#ident "$Id: globals.h,v 1.6 2002/04/04 05:26:13 steve Exp $"
#endif
# include <stdio.h>
@ -37,11 +37,16 @@ extern int line_direct_flag;
extern unsigned error_count;
extern FILE *depend_file;
/* This is the entry to the parser. */
extern int yyparse();
/*
* $Log: globals.h,v $
* Revision 1.6 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.5 2000/09/13 22:33:13 steve
* undefined macros are null (with warnings.)
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: lexor.lex,v 1.31 2002/03/09 06:37:49 steve Exp $"
#ident "$Id: lexor.lex,v 1.32 2002/04/04 05:26:13 steve Exp $"
#endif
# include "config.h"
@ -67,6 +67,8 @@ struct include_stack_t {
struct include_stack_t*next;
};
static void emit_pathline(struct include_stack_t *isp);
static struct include_stack_t*file_queue = 0;
static struct include_stack_t*istack = 0;
static struct include_stack_t*standby = 0;
@ -135,6 +137,7 @@ W [ \t\b\f]+
^{W}?`include { yy_push_state(PPINCLUDE); }
<PPINCLUDE>`[a-zA-Z][a-zA-Z0-9_]* { def_match(); }
<PPINCLUDE>\"[^\"]*\" { include_filename(); }
<PPINCLUDE>[ \t\b\f] { ; }
@ -156,9 +159,9 @@ W [ \t\b\f]+
/* Anything that is not matched by the above is an error of some
sort. Print and error message and absorb the rest of the line. */
<PPINCLUDE>. {
fprintf(stderr, "%s:%u: error: malformed `include directive."
" Did you quote the file name?\n", istack->path,
istack->lineno+1);
emit_pathline(istack);
fprintf(stderr, "error: malformed `include directive."
" Did you quote the file name?\n");
error_count += 1;
BEGIN(ERROR_LINE); }
@ -319,9 +322,9 @@ static void def_match()
yy_switch_to_buffer(yy_new_buffer(istack->file, YY_BUF_SIZE));
} else {
fprintf(stderr, "%s:%u: warning: macro %s undefined "
"(and assumed null) at this point.\n",
istack->path, istack->lineno, yytext);
emit_pathline(istack);
fprintf(stderr, "warning: macro %s undefined "
"(and assumed null) at this point.\n", yytext);
}
}
@ -580,7 +583,11 @@ static void output_init()
static void include_filename()
{
assert(standby == 0);
if(standby) {
emit_pathline(istack);
fprintf(stderr, "error: malformed `include directive. Extra junk on line?\n");
exit(1);
}
standby = malloc(sizeof(struct include_stack_t));
standby->path = strdup(yytext+1);
standby->path[strlen(standby->path)-1] = 0;
@ -592,7 +599,9 @@ static void do_include()
if (standby->path[0] == '/') {
standby->file = fopen(standby->path, "r");
if(depend_file && standby->file) {
fprintf(depend_file, "%s\n", istack->path);
}
} else {
unsigned idx = 0;
standby->file = 0;
@ -600,9 +609,12 @@ static void do_include()
char path[4096];
sprintf(path, "%s/%s", include_dir[idx], standby->path);
standby->file = fopen(path, "r");
if (standby->file)
if (standby->file) {
if(depend_file) {
fprintf(depend_file, "%s\n", path);
}
break;
}
}
}
@ -624,6 +636,22 @@ static void do_include()
istack->lineno+1, istack->path);
}
/* walk the include stack until we find an entry with a valid pathname,
* and print the file and line from that entry for use in an error message.
* The istack entries created by def_match() for macro expansions do not
* contain pathnames. This finds instead the real file in which the outermost
* macro was used.
*/
static void emit_pathline(struct include_stack_t*isp)
{
while(isp && (isp->path == NULL)) {
isp = isp->next;
}
assert(isp);
fprintf(stderr, "%s:%u: ",
isp->path, isp->lineno+1);
}
/*
* The lexical analyzer calls this function when the current file
* ends. Here I pop the include stack and resume the previous file. If
@ -674,6 +702,9 @@ static int yywrap()
if (line_direct_flag)
fprintf(yyout, "\n`line 1 \"%s\" 0\n", istack->path);
if(depend_file) {
fprintf(depend_file, "%s\n", istack->path);
}
yyrestart(istack->file);
return 0;
@ -709,6 +740,9 @@ void reset_lexor(FILE*out, char*paths[])
perror(paths[0]);
exit(1);
}
if(depend_file) {
fprintf(depend_file, "%s\n", paths[0]);
}
yyout = out;

View File

@ -17,7 +17,7 @@ const char COPYRIGHT[] =
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: main.c,v 1.14 2001/11/21 02:59:27 steve Exp $"
#ident "$Id: main.c,v 1.15 2002/04/04 05:26:13 steve Exp $"
#endif
# include "config.h"
@ -86,6 +86,7 @@ unsigned include_cnt = 0;
int line_direct_flag = 0;
unsigned error_count = 0;
FILE *depend_file = NULL;
/*
* This function reads from a file a list of file names. Each name
@ -125,6 +126,7 @@ int main(int argc, char*argv[])
const char*flist_path = 0;
unsigned flag_errors = 0;
char*out_path = 0;
char *dep_path = NULL;
FILE*out;
/* Define preprocessor keywords that I plan to just pass. */
@ -150,7 +152,7 @@ int main(int argc, char*argv[])
include_dir[0] = strdup(".");
include_cnt = 1;
while ((opt = getopt(argc, argv, "D:f:I:K:Lo:v")) != EOF) switch (opt) {
while ((opt = getopt(argc, argv, "D:f:I:K:LM:o:v")) != EOF) switch (opt) {
case 'D': {
char*tmp = strdup(optarg);
@ -192,6 +194,14 @@ int main(int argc, char*argv[])
line_direct_flag = 1;
break;
case 'M':
if (dep_path) {
fprintf(stderr, "duplicate -M flag.\n");
} else {
dep_path = optarg;
}
break;
case 'o':
if (out_path) {
fprintf(stderr, "duplicate -o flag.\n");
@ -219,6 +229,7 @@ int main(int argc, char*argv[])
" -I<dir> - Add an include file search directory\n"
" -K<def> - Define a keyword macro that I just pass\n"
" -L - Emit line number directives\n"
" -M<fil> - Write dependencies to <fil>\n"
" -o<fil> - Send the output to <fil>\n"
" -v - Print version information\n",
argv[0]);
@ -250,6 +261,14 @@ int main(int argc, char*argv[])
out = stdout;
}
if(dep_path) {
depend_file = fopen(dep_path, "w");
if (depend_file == 0) {
perror(dep_path);
exit(1);
}
}
if (source_cnt == 0) {
fprintf(stderr, "%s: No input files given.\n", argv[0]);
return 1;
@ -260,11 +279,18 @@ int main(int argc, char*argv[])
reset_lexor(out, source_list);
if (yyparse()) return -1;
if(depend_file) {
fclose(depend_file);
}
return error_count;
}
/*
* $Log: main.c,v $
* Revision 1.15 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.14 2001/11/21 02:59:27 steve
* Remove diag print.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: load_module.cc,v 1.4 2001/11/20 23:36:34 steve Exp $"
#ident "$Id: load_module.cc,v 1.5 2002/04/04 05:26:13 steve Exp $"
#endif
# include "config.h"
@ -28,6 +28,7 @@
const char dir_character = '/';
extern FILE *depend_file;
bool load_module(const char*type)
{
@ -45,7 +46,10 @@ bool load_module(const char*type)
FILE*file = fopen(path, "r");
if (file == 0)
continue;
if(depend_file) {
fprintf(depend_file, "%s\n", path);
}
if (verbose_flag) {
cerr << "Loading library file " << path << "." << endl;
}
@ -62,6 +66,9 @@ bool load_module(const char*type)
/*
* $Log: load_module.cc,v $
* Revision 1.5 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.4 2001/11/20 23:36:34 steve
* Close library files after parsing.
*

20
main.cc
View File

@ -19,7 +19,7 @@ const char COPYRIGHT[] =
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: main.cc,v 1.51 2001/11/16 05:07:19 steve Exp $"
#ident "$Id: main.cc,v 1.52 2002/04/04 05:26:13 steve Exp $"
#endif
# include "config.h"
@ -81,6 +81,7 @@ map<string,string> flags;
list<const char*> library_dirs;
list<const char*> library_suff;
FILE *depend_file = NULL;
/*
* These are the warning enable flags.
*/
@ -182,6 +183,7 @@ int main(int argc, char*argv[])
unsigned flag_errors = 0;
queue<net_func> net_func_queue;
list<const char*> roots;
const char* depfile_name = NULL;
struct tms cycles[5];
@ -190,7 +192,7 @@ int main(int argc, char*argv[])
min_typ_max_flag = TYP;
min_typ_max_warn = 10;
while ((opt = getopt(argc, argv, "F:f:hm:N:o:P:p:s:T:t:VvW:Y:y:")) != EOF) switch (opt) {
while ((opt = getopt(argc, argv, "F:f:hm:M:N:o:P:p:s:T:t:VvW:Y:y:")) != EOF) switch (opt) {
case 'F': {
net_func tmp = name_to_net_func(optarg);
if (tmp == 0) {
@ -211,6 +213,9 @@ int main(int argc, char*argv[])
case 'm':
flags["VPI_MODULE_LIST"] = flags["VPI_MODULE_LIST"]+","+optarg;
break;
case 'M':
depfile_name = optarg;
break;
case 'N':
net_path = optarg;
break;
@ -311,6 +316,14 @@ int main(int argc, char*argv[])
return 1;
}
if( depfile_name ) {
depend_file = fopen(depfile_name, "a");
if(! depend_file) {
perror(depfile_name);
}
}
/* If there were no -Y flags, then create a minimal library
suffix search list. */
if (library_suff.empty()) {
@ -477,6 +490,9 @@ int main(int argc, char*argv[])
/*
* $Log: main.cc,v $
* Revision 1.52 2002/04/04 05:26:13 steve
* Add dependency generation.
*
* Revision 1.51 2001/11/16 05:07:19 steve
* Add support for +libext+ in command files.
*