More sophisticated command file parser.

This commit is contained in:
steve 2001-11-12 01:26:36 +00:00
parent 0045d7d1bf
commit d1ad10c90f
8 changed files with 284 additions and 59 deletions

View File

@ -3,4 +3,8 @@ parse.c
parse.h
parse.output
lexor.c
cfparse.c
cfparse.h
cfparse.output
cflexor.c
iverilog

View File

@ -18,7 +18,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
#ident "$Id: Makefile.in,v 1.7 2001/10/21 21:59:49 steve Exp $"
#ident "$Id: Makefile.in,v 1.8 2001/11/12 01:26:36 steve Exp $"
#
#
SHELL = /bin/sh
@ -54,8 +54,9 @@ all: iverilog@EXEEXT@
clean:
rm -f *.o lexor.c parse.c parse.h parse.output
rm -r cflexor.c cfparse.c cfparse.h cfparse.output
O = main.o build_string.o lexor.o parse.o
O = main.o build_string.o lexor.o parse.o cflexor.o cfparse.o
iverilog@EXEEXT@: $O
$(CC) $(LDFLAGS) $O -o iverilog@EXEEXT@ @EXTRALIBS@
@ -66,6 +67,12 @@ lexor.c: lexor.lex
parse.h parse.c: parse.y
bison --verbose -t -d -o parse.c $(srcdir)/parse.y
cflexor.c: cflexor.lex
flex -s -Pcf -ocflexor.c $(srcdir)/cflexor.lex
cfparse.h cfparse.c: cfparse.y
bison --verbose -t -d -o cfparse.c --name-prefix=cf $(srcdir)/cfparse.y
main.o: main.c globals.h
$(CC) $(CFLAGS) -c -DCXX='"@CXX@"' -DIVL_ROOT='"@libdir@/ivl"' -DIVL_INC='"@includedir@"' -DIVL_LIB='"@libdir@"' -DRDYNAMIC=\"$(rdynamic)\" -DDLLIB='"@DLLIB@"' -DEXEEXT='"@EXEEXT@"' $(srcdir)/main.c
@ -73,6 +80,8 @@ main.o: main.c globals.h
build_string.o: build_string.c globals.h
lexor.o: lexor.c parse.h globals.h
parse.o: parse.c globals.h
cflexor.o: cflexor.c cfparse.h cfparse_misc.h globals.h
cfparse.o: cfparse.c globals.h
iverilog.pdf: $(srcdir)/iverilog.man
man -t $(srcdir)/iverilog.man | ps2pdf - iverilog.pdf

90
driver/cflexor.lex Normal file
View File

@ -0,0 +1,90 @@
%{
/*
* Copyright (c) 2001 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
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: cflexor.lex,v 1.1 2001/11/12 01:26:36 steve Exp $"
#endif
# include "cfparse.h"
# include "cfparse_misc.h"
# include <string.h>
/*
* Lexical location information is passed in the yylloc variable to th
* parser. The file names, strings, are kept in a list so that I can
* re-use them. The set_file_name function will return a pointer to
* the name as it exists in the list (and delete the passed string.)
* If the name is new, it will be added to the list.
*/
YYLTYPE yylloc;
static int comment_enter;
%}
%x CCOMMENT
%x LCOMMENT
%%
/* Accept C++ style comments. */
"//".* { comment_enter = YY_START; BEGIN(LCOMMENT); }
<LCOMMENT>. { yymore(); }
<LCOMMENT>\n { yylloc.first_line += 1; BEGIN(comment_enter); }
/* Accept C style comments. */
"/*" { comment_enter = YY_START; BEGIN(CCOMMENT); }
<CCOMMENT>. { yymore(); }
<CCOMMENT>\n { yylloc.first_line += 1; yymore(); }
<CCOMMENT>"*/" { BEGIN(comment_enter); }
/* Accept shell type comments. */
^"#".* { ; }
/* Skip white space. */
[ \t\f] { ; }
/* Skip line ends, but also count the line. */
\n { yylloc.first_line += 1; }
"-y" { return TOK_Dy; }
"/"[^\*\/].* { cflval.text = strdup(yytext);
return TOK_STRING; }
[^/\n \t\b\r-].* { cflval.text = strdup(yytext);
return TOK_STRING; }
/* Fallback match. */
. { return yytext[0]; }
%%
int yywrap()
{
return 1;
}
void cfreset(FILE*fd)
{
yyin = fd;
yyrestart(fd);
yylloc.first_line = 1;
yylloc.text = "";
}

61
driver/cfparse.y Normal file
View File

@ -0,0 +1,61 @@
%{
/*
* Copyright (c) 20001 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
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: cfparse.y,v 1.1 2001/11/12 01:26:36 steve Exp $"
#endif
# include "globals.h"
%}
%union {
char*text;
};
%token TOK_Dy
%token <text> TOK_STRING
%%
start
:
| item_list
;
item_list
: item_list item
| item
;
item : TOK_STRING
{ process_file_name($1);
free($1);
}
| TOK_Dy TOK_STRING
{ process_library_switch($2);
free($2);
}
;
%%
int yyerror(const char*msg)
{
}

48
driver/cfparse_misc.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef __cfparse_misc_H
#define __cfparse_misc_H
/*
* Copyright (c) 2001 Picture Elements, Inc.
* Stephen Williams (steve@picturel.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
*/
#if !defined(WINNT)
#ident "$Id: cfparse_misc.h,v 1.1 2001/11/12 01:26:36 steve Exp $"
#endif
/*
* The vlltype supports the passing of detailed source file location
* information between the lexical analyzer and the parser. Defining
* YYLTYPE compels the lexor to use this type and not something other.
*/
struct cfltype {
unsigned first_line;
unsigned first_column;
unsigned last_line;
unsigned last_column;
const char*text;
};
# define YYLTYPE struct cfltype
extern YYLTYPE yylloc;
/*
* $Log: cfparse_misc.h,v $
* Revision 1.1 2001/11/12 01:26:36 steve
* More sophisticated command file parser.
*
*/
#endif

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.6 2001/10/23 00:37:30 steve Exp $"
#ident "$Id: globals.h,v 1.7 2001/11/12 01:26:36 steve Exp $"
#endif
# include <stddef.h>
@ -51,6 +51,12 @@ extern int synth_flag;
/* This is the name of the selected target. */
extern const char*targ;
/* Add the name to the list of source files. */
extern void process_file_name(const char*name);
/* Add the name to the list of library directories. */
extern void process_library_switch(const char*name);
/* -v */
extern int verbose_flag;
@ -65,6 +71,9 @@ extern int build_string(char*out, size_t olen, const char*pattern);
/*
* $Log: globals.h,v $
* Revision 1.7 2001/11/12 01:26:36 steve
* More sophisticated command file parser.
*
* Revision 1.6 2001/10/23 00:37:30 steve
* The -s flag can now be repeated on the iverilog command.
*

View File

@ -1,4 +1,4 @@
.TH iverilog 1 "$Date: 2001/10/23 00:37:30 $" Version "$Date: 2001/10/23 00:37:30 $"
.TH iverilog 1 "$Date: 2001/11/12 01:26:36 $" Version "$Date: 2001/11/12 01:26:36 $"
.SH NAME
iverilog - Icarus Verilog compiler
@ -32,9 +32,7 @@ given is used to locate \fIivlpp\fP, \fIivl\fP and the VPI modules.
This flag specifies an input file that contains a list of Verilog
source files. This is similar to the \fIcommand file\fP of other
Verilog simulators, in that it is a file that contains the file names
instead of taking them on the command line. The command file may
contain C-style comments (/*-*/) or shell-style comments (# to the end
of the line.)
instead of taking them on the command line. See \fBCommand Files\fP below.
.TP 8
.B -C\fIpath\fP
This flag selects the driver configuration file to use. Normally, the
@ -187,6 +185,19 @@ This enables warnings for creation of implicit declarations. For
example, if a scaler wire X is used but not declared in the Verilog
source, this will print a warning at its first use.
.SH "Command Files"
The command file allows the user to place source file names and
certain command line switches into a text file instead of on a long
command line. Command files can include C or C++ style comments, as
well as # comments, if the # starts the line.
A simple file name or file path is taken to be the name of a Verilog
source file. The path starts with the a non-white-space character.
A \fB-y\fP token prefixes a library directory in the command file,
exactly like it does on the command line. The paramter to the \fB-y\fP
flag may be on the same line or the next non-comment line.
.SH EXAMPLES
These examples assume that you have a Verilog source file called hello.v in
the current directory

View File

@ -16,7 +16,7 @@
* 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.26 2001/11/11 00:10:05 steve Exp $"
#ident "$Id: main.c,v 1.27 2001/11/12 01:26:36 steve Exp $"
# include "config.h"
@ -91,6 +91,7 @@ char *library_flags = 0;
char*inc_list = 0;
char*def_list = 0;
char*mod_list = 0;
char*src_list = 0;
char*command_filename = 0;
char*start = 0;
@ -268,7 +269,7 @@ static void process_warning_switch(const char*name)
}
}
static void process_library_switch(const char *name)
void process_library_switch(const char *name)
{
if (library_flags) {
library_flags = realloc(library_flags,
@ -281,6 +282,19 @@ static void process_library_switch(const char *name)
strcat(library_flags, name);
}
void process_file_name(const char*name)
{
if (src_list) {
src_list = realloc(src_list,
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)
{
const char*config_path = 0;
@ -459,7 +473,26 @@ int main(int argc, char **argv)
}
}
if ((optind == argc) && !command_filename) {
if (command_filename) {
int rc;
if (( fp = fopen(command_filename, "r")) == NULL ) {
fprintf(stderr, "%s: Can't open %s\n",
argv[0], command_filename);
return 1;
}
cfreset(fp);
rc = cfparse();
}
/* Finally, process all the remaining words on the command
line as file names. */
for (idx = optind ; idx < argc ; idx += 1)
process_file_name(argv[idx]);
if (src_list == 0) {
fprintf(stderr, "%s: No input files.\n", argv[0]);
fprintf(stderr, "%s\n", HELP);
return 1;
@ -506,56 +539,13 @@ int main(int argc, char **argv)
ncmd += strlen(def_list);
}
/* If user supplied a command file, retain its contents -- this
process supersedes command line source files. */
if (command_filename != 0) {
if (( fp = fopen(command_filename, "r")) == NULL ) {
fprintf(stderr, "%s: Can't open %s\n",
argv[0], command_filename);
return 1;
} else {
/* Process file and skip over commented-out lines.
Skips over c-like comment as well as '//' or
'#' lines. */
sprintf(tmp, "");
while (fgets(line, MAXSIZE, fp) != NULL) {
if ( strstr(line, "*/") != NULL ) {
inside_c_comment = 0;
continue;
}
if (inside_c_comment || (strstr(line, "/*") != NULL)) {
inside_c_comment = 1;
continue;
}
if ( (line[0] != '/' || line[1] != '/')
&& line[0] != '#' ) {
strcat (tmp, " ");
strncat (tmp, line, (strlen(line)-1));
}
}
fclose(fp);
}
cmd = realloc(cmd, ncmd+strlen(tmp)+1);
strcpy(cmd+ncmd, tmp);
ncmd += strlen(tmp);
} else {
/* Add all verilog source files to the preprocess
command line. */
for (idx = optind ; idx < argc ; idx += 1) {
sprintf(tmp, " %s", argv[idx]);
cmd = realloc(cmd, ncmd+strlen(tmp)+1);
strcpy(cmd+ncmd, tmp);
ncmd += strlen(tmp);
}
}
/* 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
do is run the preprocessor and put the output where the
@ -597,6 +587,9 @@ int main(int argc, char **argv)
/*
* $Log: main.c,v $
* Revision 1.27 2001/11/12 01:26:36 steve
* More sophisticated command file parser.
*
* Revision 1.26 2001/11/11 00:10:05 steve
* Remov XNF dead wood.
*