2001-03-19 02:20:46 +01:00
|
|
|
/*
|
2008-01-01 18:45:02 +01:00
|
|
|
* Copyright (c) 2001-2007 Stephen Williams (steve@icarus.com)
|
2001-03-19 02:20:46 +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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "vvp_priv.h"
|
2001-03-23 03:41:04 +01:00
|
|
|
# include <string.h>
|
2001-03-19 02:20:46 +01:00
|
|
|
# include <assert.h>
|
2001-07-16 20:26:08 +02:00
|
|
|
# include <sys/types.h>
|
|
|
|
|
# include <sys/stat.h>
|
2001-03-19 02:20:46 +01:00
|
|
|
|
|
|
|
|
FILE*vvp_out = 0;
|
|
|
|
|
|
2001-04-28 22:06:07 +02:00
|
|
|
inline static void draw_execute_header(ivl_design_t des)
|
|
|
|
|
{
|
2001-07-30 04:44:05 +02:00
|
|
|
#if !defined(__MINGW32__)
|
2001-04-28 22:06:07 +02:00
|
|
|
const char*cp = ivl_design_flag(des, "VVP_EXECUTABLE");
|
2001-07-16 20:26:08 +02:00
|
|
|
if (cp) {
|
|
|
|
|
fprintf(vvp_out, "#! %s\n", cp);
|
|
|
|
|
fchmod(fileno(vvp_out), 0755);
|
|
|
|
|
}
|
2001-07-30 04:44:05 +02:00
|
|
|
#endif
|
2001-04-28 22:06:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline static void draw_module_declarations(ivl_design_t des)
|
2001-03-23 03:41:04 +01:00
|
|
|
{
|
|
|
|
|
const char*cp = ivl_design_flag(des, "VPI_MODULE_LIST");
|
|
|
|
|
|
|
|
|
|
while (*cp) {
|
|
|
|
|
char buffer[128];
|
|
|
|
|
const char*comma = strchr(cp, ',');
|
|
|
|
|
|
|
|
|
|
if (comma == 0)
|
|
|
|
|
comma = cp + strlen(cp);
|
|
|
|
|
|
|
|
|
|
strncpy(buffer, cp, comma-cp);
|
|
|
|
|
buffer[comma-cp] = 0;
|
|
|
|
|
fprintf(vvp_out, ":vpi_module \"%s\";\n", buffer);
|
|
|
|
|
|
|
|
|
|
cp = comma;
|
2001-05-14 02:55:31 +02:00
|
|
|
if (*cp) cp += 1;
|
2001-03-23 03:41:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-30 18:45:10 +02:00
|
|
|
|
2001-03-19 02:20:46 +01:00
|
|
|
int target_design(ivl_design_t des)
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2001-03-19 02:20:46 +01:00
|
|
|
{
|
2001-03-27 05:31:06 +02:00
|
|
|
int rc;
|
2001-10-19 23:53:24 +02:00
|
|
|
ivl_scope_t *roots;
|
|
|
|
|
unsigned nroots, i;
|
2001-03-19 02:20:46 +01:00
|
|
|
const char*path = ivl_design_flag(des, "-o");
|
|
|
|
|
assert(path);
|
|
|
|
|
|
2003-05-16 05:22:52 +02:00
|
|
|
#ifdef HAVE_FOPEN64
|
|
|
|
|
vvp_out = fopen64(path, "w");
|
|
|
|
|
#else
|
2001-03-19 02:20:46 +01:00
|
|
|
vvp_out = fopen(path, "w");
|
2003-05-16 05:22:52 +02:00
|
|
|
#endif
|
2001-03-19 02:20:46 +01:00
|
|
|
if (vvp_out == 0) {
|
|
|
|
|
perror(path);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-28 22:06:07 +02:00
|
|
|
draw_execute_header(des);
|
|
|
|
|
|
2001-07-01 01:03:16 +02:00
|
|
|
{ int pre = ivl_design_time_precision(des);
|
|
|
|
|
char sign = '+';
|
|
|
|
|
if (pre < 0) {
|
|
|
|
|
pre = -pre;
|
|
|
|
|
sign = '-';
|
|
|
|
|
}
|
|
|
|
|
fprintf(vvp_out, ":vpi_time_precision %c %d;\n", sign, pre);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 03:41:04 +01:00
|
|
|
draw_module_declarations(des);
|
|
|
|
|
|
2007-11-01 05:45:34 +01:00
|
|
|
/* This causes all structural records to be drawn. */
|
2001-10-19 23:53:24 +02:00
|
|
|
ivl_design_roots(des, &roots, &nroots);
|
|
|
|
|
for (i = 0; i < nroots; i++)
|
|
|
|
|
draw_scope(roots[i], 0);
|
2001-03-19 02:20:46 +01:00
|
|
|
|
2007-11-01 05:45:34 +01:00
|
|
|
/* Finish up any modpaths that are not yet emitted. */
|
|
|
|
|
cleanup_modpath();
|
|
|
|
|
|
2001-03-27 05:31:06 +02:00
|
|
|
rc = ivl_design_process(des, draw_process, 0);
|
2001-03-19 02:20:46 +01:00
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
/* Dump the file name table. */
|
2008-01-02 19:42:23 +01:00
|
|
|
unsigned size = ivl_file_table_size();
|
|
|
|
|
fprintf(vvp_out, "# The file index is used to find the file name in "
|
|
|
|
|
"the following table.\n:file_names %u;\n", size);
|
|
|
|
|
unsigned idx;
|
|
|
|
|
for (idx = 0; idx < size; idx++) {
|
|
|
|
|
fprintf(vvp_out, " \"%s\";\n", ivl_file_table_item(idx));
|
|
|
|
|
}
|
2008-01-01 18:45:02 +01:00
|
|
|
|
2001-03-19 02:20:46 +01:00
|
|
|
fclose(vvp_out);
|
|
|
|
|
|
2001-03-27 05:31:06 +02:00
|
|
|
return rc;
|
2001-03-19 02:20:46 +01:00
|
|
|
}
|
|
|
|
|
|