mirror of
https://github.com/steveicarus/iverilog.git
synced 2026-08-22 13:57:18 +02:00
Add include path and line directives.
This commit is contained in:
+109
-10
@@ -1,6 +1,6 @@
|
||||
const char COPYRIGHT[] =
|
||||
"Copyright (c) 1999 Stephen Williams ([email protected])";
|
||||
/*
|
||||
* Copyright (c) 1999 Stephen Williams ([email protected])
|
||||
*
|
||||
* 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
|
||||
@@ -17,28 +17,127 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: main.c,v 1.1 1999/07/03 17:24:11 steve Exp $"
|
||||
#ident "$Id: main.c,v 1.2 1999/07/03 20:03:47 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <stdio.h>
|
||||
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"
|
||||
;
|
||||
|
||||
extern void reset_lexor(const char*);
|
||||
extern int yylex();
|
||||
const char VERSION[] = "$Name: $ $State: Exp $";
|
||||
|
||||
# include <stdio.h>
|
||||
# include <malloc.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include "globals.h"
|
||||
|
||||
char**include_dir = 0;
|
||||
unsigned include_cnt = 0;
|
||||
|
||||
int line_direct_flag = 0;
|
||||
|
||||
int main(int argc, char*argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <file>\n", argv[0]);
|
||||
return 1;
|
||||
int opt;
|
||||
unsigned flag_errors = 0;
|
||||
char*out_path = 0;
|
||||
FILE*out;
|
||||
|
||||
include_dir = malloc(sizeof(char*));
|
||||
include_dir[0] = strdup(".");
|
||||
include_cnt = 1;
|
||||
|
||||
while ((opt = getopt(argc, argv, "D:I:Lo: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);
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
reset_lexor(argv[1]);
|
||||
if (optind == argc)
|
||||
flag_errors += 1;
|
||||
|
||||
if (flag_errors) {
|
||||
fprintf(stderr, "\nUsage: %s [-v][-L][-I<dir>][-D<def>] <file>\n"
|
||||
" -D<def> - Predefine a value.\n"
|
||||
" -I<dir> - Add an include file search directory\n"
|
||||
" -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;
|
||||
}
|
||||
|
||||
reset_lexor(out, argv[optind]);
|
||||
return yyparse();
|
||||
}
|
||||
|
||||
/*
|
||||
* $Log: main.c,v $
|
||||
* Revision 1.2 1999/07/03 20:03:47 steve
|
||||
* Add include path and line directives.
|
||||
*
|
||||
* Revision 1.1 1999/07/03 17:24:11 steve
|
||||
* Add a preprocessor.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user