1999-07-03 22:03:47 +02:00
|
|
|
const char COPYRIGHT[] =
|
|
|
|
|
"Copyright (c) 1999 Stephen Williams (steve@icarus.com)";
|
1999-07-03 19:24:11 +02:00
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2000-08-20 19:49:04 +02:00
|
|
|
#if !defined(WINNT) && !defined(macintosh)
|
2001-06-23 20:41:02 +02:00
|
|
|
#ident "$Id: main.c,v 1.10 2001/06/23 18:41:02 steve Exp $"
|
1999-07-03 19:24:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
1999-07-03 22:03:47 +02:00
|
|
|
const char NOTICE[] =
|
|
|
|
|
" This program is free software; you can redistribute it and/or modify\n"
|
|
|
|
|
" it under the terms of the GNU General Public License as published by\n"
|
|
|
|
|
" the Free Software Foundation; either version 2 of the License, or\n"
|
|
|
|
|
" (at your option) any later version.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" This program is distributed in the hope that it will be useful,\n"
|
|
|
|
|
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
|
|
|
|
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
|
|
|
|
" GNU General Public License for more details.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" You should have received a copy of the GNU General Public License\n"
|
|
|
|
|
" along with this program; if not, write to the Free Software\n"
|
|
|
|
|
" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\n"
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
const char VERSION[] = "$Name: $ $State: Exp $";
|
|
|
|
|
|
1999-07-03 19:24:11 +02:00
|
|
|
# include <stdio.h>
|
2001-06-23 20:41:02 +02:00
|
|
|
# include <stdlib.h>
|
1999-07-03 22:03:47 +02:00
|
|
|
# include <malloc.h>
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
# include <string.h>
|
1999-11-29 18:02:21 +01:00
|
|
|
#if defined(HAVE_GETOPT_H)
|
|
|
|
|
# include <getopt.h>
|
|
|
|
|
#endif
|
1999-07-03 22:03:47 +02:00
|
|
|
# include "globals.h"
|
1999-07-03 19:24:11 +02:00
|
|
|
|
2001-05-20 20:06:57 +02:00
|
|
|
#if defined(__MINGW32__) && !defined(HAVE_GETOPT_H)
|
|
|
|
|
extern int getopt(int argc, char*argv[], const char*fmt);
|
|
|
|
|
extern int optind;
|
|
|
|
|
extern const char*optarg;
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-07-03 22:03:47 +02:00
|
|
|
char**include_dir = 0;
|
|
|
|
|
unsigned include_cnt = 0;
|
|
|
|
|
|
|
|
|
|
int line_direct_flag = 0;
|
1999-07-03 19:24:11 +02:00
|
|
|
|
2000-06-30 17:49:44 +02:00
|
|
|
unsigned error_count = 0;
|
|
|
|
|
|
1999-07-03 19:24:11 +02:00
|
|
|
int main(int argc, char*argv[])
|
|
|
|
|
{
|
1999-07-03 22:03:47 +02:00
|
|
|
int opt;
|
|
|
|
|
unsigned flag_errors = 0;
|
|
|
|
|
char*out_path = 0;
|
|
|
|
|
FILE*out;
|
|
|
|
|
|
2000-09-14 00:33:13 +02:00
|
|
|
/* Define preprocessor keywords that I plan to just pass. */
|
|
|
|
|
define_macro("celldefine", "`celldefine", 1);
|
|
|
|
|
define_macro("default_nettype", "`default_nettype", 1);
|
|
|
|
|
define_macro("delay_mode_distributed", "`delay_mode_distributed", 1);
|
|
|
|
|
define_macro("delay_mode_unit", "`delay_mode_unit", 1);
|
|
|
|
|
define_macro("delay_mode_path", "`delay_mode_path", 1);
|
2000-12-06 06:15:21 +01:00
|
|
|
define_macro("disable_portfaults", "`disable_portfaults", 1);
|
|
|
|
|
define_macro("enable_portfaults", "`enable_portfaults", 1);
|
2000-09-14 00:33:13 +02:00
|
|
|
define_macro("endcelldefine", "`endcelldefine", 1);
|
|
|
|
|
define_macro("endprotect", "`endprotect", 1);
|
|
|
|
|
define_macro("nosuppress_faults", "`nosuppress_faults", 1);
|
|
|
|
|
define_macro("nounconnected_drive", "`nounconnected_drive", 1);
|
|
|
|
|
define_macro("protect", "`protect", 1);
|
|
|
|
|
define_macro("resetall", "`resetall", 1);
|
|
|
|
|
define_macro("suppress_faults", "`suppress_faults", 1);
|
|
|
|
|
define_macro("timescale", "`timescale", 1);
|
|
|
|
|
define_macro("unconnected_drive", "`unconnected_drive", 1);
|
|
|
|
|
define_macro("uselib", "`uselib", 1);
|
|
|
|
|
|
1999-07-03 22:03:47 +02:00
|
|
|
include_dir = malloc(sizeof(char*));
|
|
|
|
|
include_dir[0] = strdup(".");
|
|
|
|
|
include_cnt = 1;
|
|
|
|
|
|
2000-09-14 00:33:13 +02:00
|
|
|
while ((opt = getopt(argc, argv, "D:I:K:Lo:v")) != EOF) switch (opt) {
|
1999-07-03 22:03:47 +02:00
|
|
|
|
|
|
|
|
case 'D': {
|
|
|
|
|
char*tmp = strdup(optarg);
|
|
|
|
|
char*val = strchr(tmp, '=');
|
|
|
|
|
if (val)
|
|
|
|
|
*val++ = 0;
|
|
|
|
|
else
|
|
|
|
|
val = "1";
|
|
|
|
|
|
2000-09-14 00:33:13 +02:00
|
|
|
define_macro(tmp, val, 0);
|
1999-07-03 22:03:47 +02:00
|
|
|
free(tmp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
|
include_dir = realloc(include_dir, (include_cnt+1)*sizeof(char*));
|
|
|
|
|
include_dir[include_cnt] = strdup(optarg);
|
|
|
|
|
include_cnt += 1;
|
|
|
|
|
break;
|
|
|
|
|
|
2000-09-14 00:33:13 +02:00
|
|
|
case 'K': {
|
|
|
|
|
char*buf = malloc(strlen(optarg) + 2);
|
|
|
|
|
buf[0] = '`';
|
|
|
|
|
strcpy(buf+1, optarg);
|
|
|
|
|
define_macro(optarg, buf, 1);
|
|
|
|
|
free(buf);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-03 22:03:47 +02:00
|
|
|
case 'L':
|
|
|
|
|
line_direct_flag = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
|
if (out_path) {
|
|
|
|
|
fprintf(stderr, "duplicate -o flag.\n");
|
|
|
|
|
} else {
|
|
|
|
|
out_path = optarg;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
|
fprintf(stderr, "Icarus Verilog Preprocessor version %s\n",
|
|
|
|
|
VERSION);
|
|
|
|
|
fprintf(stderr, "%s\n", COPYRIGHT);
|
|
|
|
|
fputs(NOTICE, stderr);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
flag_errors += 1;
|
|
|
|
|
break;
|
1999-07-03 19:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
1999-07-03 22:03:47 +02:00
|
|
|
if (optind == argc)
|
|
|
|
|
flag_errors += 1;
|
1999-07-03 19:24:11 +02:00
|
|
|
|
1999-07-03 22:03:47 +02:00
|
|
|
if (flag_errors) {
|
1999-09-06 00:33:18 +02:00
|
|
|
fprintf(stderr, "\nUsage: %s [-v][-L][-I<dir>][-D<def>] <file>...\n"
|
1999-07-03 22:03:47 +02:00
|
|
|
" -D<def> - Predefine a value.\n"
|
|
|
|
|
" -I<dir> - Add an include file search directory\n"
|
2000-09-14 00:33:13 +02:00
|
|
|
" -K<def> - Define a keyword macro that I just pass\n"
|
1999-07-03 22:03:47 +02:00
|
|
|
" -L - Emit line number directives\n"
|
|
|
|
|
" -o<fil> - Send the output to <fil>\n"
|
|
|
|
|
" -v - Print version information\n",
|
|
|
|
|
argv[0]);
|
|
|
|
|
return flag_errors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (out_path) {
|
|
|
|
|
out = fopen(out_path, "w");
|
|
|
|
|
if (out == 0) {
|
|
|
|
|
perror(out_path);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
out = stdout;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-06 00:33:18 +02:00
|
|
|
if (argv[optind] == 0) {
|
|
|
|
|
fprintf(stderr, "%s: No input files given.\n", argv[0]);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset_lexor(out, argv+optind);
|
2000-06-30 17:49:44 +02:00
|
|
|
|
|
|
|
|
if (yyparse()) return -1;
|
|
|
|
|
|
|
|
|
|
return error_count;
|
1999-07-03 19:24:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: main.c,v $
|
2001-06-23 20:41:02 +02:00
|
|
|
* Revision 1.10 2001/06/23 18:41:02 steve
|
|
|
|
|
* Include stdlib.h
|
|
|
|
|
*
|
2001-05-20 20:06:57 +02:00
|
|
|
* Revision 1.9 2001/05/20 18:08:07 steve
|
|
|
|
|
* local declares if the header is missing.
|
|
|
|
|
*
|
2000-12-06 06:15:21 +01:00
|
|
|
* Revision 1.8 2000/12/06 05:15:21 steve
|
|
|
|
|
* fix portfaults pass values.
|
|
|
|
|
*
|
2000-09-14 00:33:13 +02:00
|
|
|
* Revision 1.7 2000/09/13 22:33:13 steve
|
|
|
|
|
* undefined macros are null (with warnings.)
|
|
|
|
|
*
|
2000-08-20 19:49:04 +02:00
|
|
|
* Revision 1.6 2000/08/20 17:49:05 steve
|
|
|
|
|
* Clean up warnings and portability issues.
|
|
|
|
|
*
|
2000-06-30 17:49:44 +02:00
|
|
|
* Revision 1.5 2000/06/30 15:49:44 steve
|
|
|
|
|
* Handle errors from parser slightly differently.
|
|
|
|
|
*
|
1999-11-29 18:02:21 +01:00
|
|
|
* Revision 1.4 1999/11/29 17:02:21 steve
|
|
|
|
|
* include getopt if present.
|
|
|
|
|
*
|
1999-09-06 00:33:18 +02:00
|
|
|
* Revision 1.3 1999/09/05 22:33:18 steve
|
|
|
|
|
* Take multiple source files on the command line.
|
|
|
|
|
*
|
1999-07-03 22:03:47 +02:00
|
|
|
* Revision 1.2 1999/07/03 20:03:47 steve
|
|
|
|
|
* Add include path and line directives.
|
|
|
|
|
*
|
1999-07-03 19:24:11 +02:00
|
|
|
* Revision 1.1 1999/07/03 17:24:11 steve
|
|
|
|
|
* Add a preprocessor.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|