2010-12-13 05:02:18 +01:00
|
|
|
|
|
|
|
|
const char COPYRIGHT[] =
|
2012-09-01 23:51:04 +02:00
|
|
|
"Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com)\n"
|
|
|
|
|
"Copyright CERN 2012 / Stephen Williams (steve@icarus.com)";
|
2010-12-13 05:02:18 +01: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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-12-13 05:02:18 +01:00
|
|
|
*/
|
|
|
|
|
# include "vhdlpp_config.h"
|
|
|
|
|
# include "version_base.h"
|
|
|
|
|
# include "version_tag.h"
|
|
|
|
|
|
2011-07-25 00:24:32 +02:00
|
|
|
/*
|
|
|
|
|
* Usage: vhdlpp [flags] sourcefile...
|
|
|
|
|
* Flags:
|
|
|
|
|
*
|
|
|
|
|
** -D <token>
|
|
|
|
|
* This activates various sorts of debugging aids. The <token>
|
|
|
|
|
* specifies which debugging aid to activate. Valid tokens are:
|
|
|
|
|
*
|
|
|
|
|
* yydebug | no-yydebug
|
|
|
|
|
* Enable (disable) debug prints from the bison parser
|
|
|
|
|
*
|
|
|
|
|
* libraries=<path>
|
|
|
|
|
* Enable debugging of library support by dumping library
|
|
|
|
|
* information to the file named <path>.
|
|
|
|
|
*
|
2012-09-01 23:51:04 +02:00
|
|
|
* elaboration=<path>
|
|
|
|
|
* Enable debugging of elaboratin by dumping elaboration
|
|
|
|
|
* process information to the file named <path>.
|
|
|
|
|
*
|
2011-07-25 00:24:32 +02:00
|
|
|
* entities=<path>
|
|
|
|
|
* Enable debugging of elaborated entities by writing the
|
|
|
|
|
* elaboration results to the file named <path>.
|
|
|
|
|
*
|
|
|
|
|
** -v
|
|
|
|
|
* Verbose operation. Display verbose non-debug information.
|
|
|
|
|
*
|
|
|
|
|
** -V
|
|
|
|
|
* Version. Print the version of this binary.
|
|
|
|
|
*
|
|
|
|
|
** -w <path>
|
|
|
|
|
* Work path. This sets the path to the working library
|
|
|
|
|
* directory. I write into that directory files for packages that
|
|
|
|
|
* I declare, and I read from that directory packages that are
|
|
|
|
|
* already declared. The default path is "ivl_vhdl_work".
|
|
|
|
|
*/
|
|
|
|
|
|
2010-12-13 05:02:18 +01: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 along\n"
|
|
|
|
|
" with this program; if not, write to the Free Software Foundation, Inc.,\n"
|
|
|
|
|
" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
|
|
|
|
|
;
|
|
|
|
|
|
2011-01-03 07:30:09 +01:00
|
|
|
# include "compiler.h"
|
2014-10-01 14:56:32 +02:00
|
|
|
# include "library.h"
|
2015-06-10 18:41:51 +02:00
|
|
|
# include "std_funcs.h"
|
2010-12-15 06:36:47 +01:00
|
|
|
# include "parse_api.h"
|
2011-02-07 05:55:31 +01:00
|
|
|
# include "vtype.h"
|
2011-04-18 02:19:09 +02:00
|
|
|
# include <fstream>
|
2010-12-15 06:36:47 +01:00
|
|
|
# include <cstdio>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cstring>
|
2011-07-20 04:19:27 +02:00
|
|
|
# include <cerrno>
|
2014-08-06 17:04:52 +02:00
|
|
|
# include <limits>
|
2010-12-13 05:02:18 +01:00
|
|
|
#if defined(HAVE_GETOPT_H)
|
|
|
|
|
# include <getopt.h>
|
|
|
|
|
#endif
|
2011-07-20 04:19:27 +02:00
|
|
|
# include <sys/stat.h>
|
2011-12-18 20:41:21 +01:00
|
|
|
// MinGW only supports mkdir() with a path. If this stops working because
|
|
|
|
|
// we need to use _mkdir() for mingw-w32 and mkdir() for mingw-w64 look
|
|
|
|
|
// at using the autoconf AX_FUNC_MKDIR macro to figure this all out.
|
2011-11-02 21:09:42 +01:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
|
# include <io.h>
|
2011-12-18 20:41:21 +01:00
|
|
|
# define mkdir(path, mode) mkdir(path)
|
2011-11-02 21:09:42 +01:00
|
|
|
#endif
|
2010-12-13 05:02:18 +01:00
|
|
|
|
2011-01-03 07:30:09 +01:00
|
|
|
|
2010-12-19 12:33:04 +01:00
|
|
|
bool verbose_flag = false;
|
2011-01-03 07:30:09 +01:00
|
|
|
// Where to dump design entities
|
|
|
|
|
const char*dump_design_entities_path = 0;
|
2011-04-18 02:19:09 +02:00
|
|
|
const char*dump_libraries_path = 0;
|
2012-09-01 23:51:04 +02:00
|
|
|
const char*debug_log_path = 0;
|
2011-04-18 02:19:09 +02:00
|
|
|
|
2012-09-01 23:51:04 +02:00
|
|
|
bool debug_elaboration = false;
|
|
|
|
|
ofstream debug_log_file;
|
2011-07-20 04:19:27 +02:00
|
|
|
|
2011-04-18 02:19:09 +02:00
|
|
|
extern void dump_libraries(ostream&file);
|
2011-07-20 18:19:48 +02:00
|
|
|
extern void parser_cleanup();
|
2010-12-19 12:33:04 +01:00
|
|
|
|
2010-12-15 06:36:47 +01:00
|
|
|
static void process_debug_token(const char*word)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(word, "yydebug") == 0) {
|
|
|
|
|
yydebug = 1;
|
|
|
|
|
} else if (strcmp(word, "no-yydebug") == 0) {
|
|
|
|
|
yydebug = 0;
|
2011-01-03 07:30:09 +01:00
|
|
|
} else if (strncmp(word, "entities=", 9) == 0) {
|
|
|
|
|
dump_design_entities_path = strdup(word+9);
|
2011-04-18 02:19:09 +02:00
|
|
|
} else if (strncmp(word, "libraries=", 10) == 0) {
|
|
|
|
|
dump_libraries_path = strdup(word+10);
|
2012-09-01 23:51:04 +02:00
|
|
|
} else if (strncmp(word, "log=", 4) == 0) {
|
|
|
|
|
debug_log_path = strdup(word+4);
|
|
|
|
|
} else if (strcmp(word, "elaboration") == 0) {
|
|
|
|
|
debug_elaboration = true;
|
2010-12-15 06:36:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-13 05:02:18 +01:00
|
|
|
int main(int argc, char*argv[])
|
|
|
|
|
{
|
|
|
|
|
int opt;
|
2010-12-15 06:36:47 +01:00
|
|
|
int rc;
|
2011-07-20 04:19:27 +02:00
|
|
|
const char*work_path = "ivl_vhdl_work";
|
2010-12-15 06:36:47 +01:00
|
|
|
|
2011-07-31 00:04:07 +02:00
|
|
|
while ( (opt=getopt(argc, argv, "D:L:vVw:")) != EOF) switch (opt) {
|
2010-12-13 05:02:18 +01:00
|
|
|
|
2010-12-15 06:36:47 +01:00
|
|
|
case 'D':
|
|
|
|
|
process_debug_token(optarg);
|
|
|
|
|
break;
|
2010-12-13 05:02:18 +01:00
|
|
|
|
2011-07-31 00:04:07 +02:00
|
|
|
case 'L':
|
|
|
|
|
library_add_directory(optarg);
|
|
|
|
|
break;
|
|
|
|
|
|
2010-12-13 05:02:18 +01:00
|
|
|
case 'v':
|
|
|
|
|
fprintf(stderr, "Icarus Verilog VHDL Parse version "
|
|
|
|
|
VERSION " (" VERSION_TAG ")\n\n");
|
|
|
|
|
fprintf(stderr, "%s\n\n", COPYRIGHT);
|
|
|
|
|
fputs(NOTICE, stderr);
|
2010-12-19 12:33:04 +01:00
|
|
|
verbose_flag = true;
|
2010-12-13 05:02:18 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
|
fprintf(stdout, "Icarus Verilog VHDL Parse version "
|
|
|
|
|
VERSION " (" VERSION_TAG ")\n\n");
|
|
|
|
|
fprintf(stdout, "%s\n\n", COPYRIGHT);
|
|
|
|
|
fputs(NOTICE, stdout);
|
|
|
|
|
break;
|
|
|
|
|
|
2011-07-20 04:19:27 +02:00
|
|
|
case 'w':
|
|
|
|
|
work_path = optarg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-01 23:51:04 +02:00
|
|
|
if (debug_log_path) {
|
|
|
|
|
debug_log_file.open(debug_log_path);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-20 04:19:27 +02:00
|
|
|
if ( (rc = mkdir(work_path, 0777)) < 0 ) {
|
|
|
|
|
if (errno != EEXIST) {
|
|
|
|
|
fprintf(stderr, "Icarus Verilog VHDL unable to create work directory %s, errno=%d\n", work_path, errno);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
struct stat stat_buf;
|
|
|
|
|
rc = stat(work_path, &stat_buf);
|
|
|
|
|
|
|
|
|
|
if (!S_ISDIR(stat_buf.st_mode)) {
|
|
|
|
|
fprintf(stderr, "Icarus Verilog VHDL work path `%s' is not a directory.\n", work_path);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-12-13 05:02:18 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-06 17:04:52 +02:00
|
|
|
std::cout.precision(std::numeric_limits<double>::digits10);
|
2011-07-20 04:19:27 +02:00
|
|
|
library_set_work_path(work_path);
|
|
|
|
|
|
2011-02-14 01:37:10 +01:00
|
|
|
preload_global_types();
|
2015-06-10 18:41:51 +02:00
|
|
|
preload_std_funcs();
|
|
|
|
|
|
2011-03-22 17:16:20 +01:00
|
|
|
int errors = 0;
|
2011-02-14 01:37:10 +01:00
|
|
|
|
2010-12-15 06:36:47 +01:00
|
|
|
for (int idx = optind ; idx < argc ; idx += 1) {
|
|
|
|
|
parse_errors = 0;
|
2011-03-20 02:26:43 +01:00
|
|
|
parse_sorrys = 0;
|
2011-07-31 00:04:07 +02:00
|
|
|
rc = parse_source_file(argv[idx], perm_string());
|
2011-07-23 19:07:20 +02:00
|
|
|
if (rc < 0)
|
2010-12-15 06:36:47 +01:00
|
|
|
return 1;
|
2011-07-23 05:49:57 +02:00
|
|
|
|
2010-12-19 12:33:04 +01:00
|
|
|
if (verbose_flag)
|
2011-07-23 19:07:20 +02:00
|
|
|
fprintf(stderr, "parse_source_file() returns %d, parse_errors=%d, parse_sorrys=%d\n", rc, parse_errors, parse_sorrys);
|
2010-12-15 06:36:47 +01:00
|
|
|
|
|
|
|
|
if (parse_errors > 0) {
|
2011-03-20 02:26:43 +01:00
|
|
|
fprintf(stderr, "Encountered %d errors parsing %s\n", parse_errors, argv[idx]);
|
|
|
|
|
}
|
|
|
|
|
if (parse_sorrys > 0) {
|
|
|
|
|
fprintf(stderr, "Encountered %d unsupported constructs parsing %s\n", parse_sorrys, argv[idx]);
|
2010-12-15 06:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-22 17:16:20 +01:00
|
|
|
if (parse_errors || parse_sorrys) {
|
|
|
|
|
errors += parse_errors;
|
|
|
|
|
errors += parse_sorrys;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-12-15 06:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-18 02:19:09 +02:00
|
|
|
if (dump_libraries_path) {
|
|
|
|
|
ofstream file(dump_libraries_path);
|
|
|
|
|
dump_libraries(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dump_design_entities_path) {
|
|
|
|
|
ofstream file(dump_design_entities_path);
|
|
|
|
|
dump_design_entities(file);
|
|
|
|
|
}
|
2011-01-03 07:30:09 +01:00
|
|
|
|
2011-07-20 18:19:48 +02:00
|
|
|
if (errors > 0) {
|
2013-05-12 05:00:00 +02:00
|
|
|
parser_cleanup();
|
2011-03-22 17:16:20 +01:00
|
|
|
return 2;
|
2011-07-20 18:19:48 +02:00
|
|
|
}
|
2011-03-22 17:16:20 +01:00
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
errors = elaborate_entities();
|
|
|
|
|
if (errors > 0) {
|
|
|
|
|
fprintf(stderr, "%d errors elaborating design.\n", errors);
|
2013-05-12 05:00:00 +02:00
|
|
|
parser_cleanup();
|
2011-01-03 08:38:08 +01:00
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 15:07:53 +02:00
|
|
|
emit_std_types(cout);
|
|
|
|
|
|
2013-05-12 05:00:00 +02:00
|
|
|
errors = emit_packages();
|
|
|
|
|
if (errors > 0) {
|
|
|
|
|
fprintf(stderr, "%d errors emitting packages.\n", errors);
|
|
|
|
|
parser_cleanup();
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 20:16:14 +01:00
|
|
|
errors = emit_entities();
|
|
|
|
|
if (errors > 0) {
|
|
|
|
|
fprintf(stderr, "%d errors emitting design.\n", errors);
|
2011-07-20 18:19:48 +02:00
|
|
|
parser_cleanup();
|
2011-01-31 20:16:14 +01:00
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-20 18:19:48 +02:00
|
|
|
parser_cleanup();
|
2010-12-13 05:02:18 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|