2011-01-10 18:30:27 +01:00
|
|
|
/*
|
2016-07-23 01:10:01 +02:00
|
|
|
* Copyright (C) 2010-2016 Cary R. (cygcary@yahoo.com)
|
2011-01-10 18:30:27 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it 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.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include "config.h"
|
|
|
|
|
# include "vlog95_priv.h"
|
2011-01-14 04:57:53 +01:00
|
|
|
# include "ivl_alloc.h"
|
2011-01-10 18:30:27 +01:00
|
|
|
|
2013-07-19 19:48:39 +02:00
|
|
|
const char *func_rtn_name = 0;
|
|
|
|
|
|
2014-07-10 22:15:03 +02:00
|
|
|
static void emit_func_return(ivl_signal_t sig)
|
2011-01-10 18:30:27 +01:00
|
|
|
{
|
|
|
|
|
if (ivl_signal_dimensions(sig) > 0) {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: A function cannot return "
|
|
|
|
|
"an array.\n", ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
} else if (ivl_signal_integer(sig)) {
|
|
|
|
|
fprintf(vlog_out, " integer");
|
|
|
|
|
} else if (ivl_signal_data_type(sig) == IVL_VT_REAL) {
|
|
|
|
|
fprintf(vlog_out, " real");
|
|
|
|
|
} else {
|
2012-08-06 00:03:50 +02:00
|
|
|
int msb, lsb;
|
|
|
|
|
get_sig_msb_lsb(sig, &msb, &lsb);
|
2011-01-10 18:30:27 +01:00
|
|
|
if (msb != 0 || lsb != 0) fprintf(vlog_out, " [%d:%d]", msb, lsb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-10 06:08:29 +01:00
|
|
|
void emit_sig_file_line(ivl_signal_t sig)
|
|
|
|
|
{
|
|
|
|
|
if (emit_file_line) {
|
|
|
|
|
fprintf(vlog_out, " /* %s:%u */",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:13:39 +01:00
|
|
|
static void emit_sig_id(ivl_signal_t sig)
|
|
|
|
|
{
|
|
|
|
|
emit_id(ivl_signal_basename(sig));
|
|
|
|
|
fprintf(vlog_out, ";");
|
|
|
|
|
emit_sig_file_line(sig);
|
|
|
|
|
fprintf(vlog_out, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 22:15:03 +02:00
|
|
|
static void emit_var_def(ivl_signal_t sig)
|
2011-01-10 18:30:27 +01:00
|
|
|
{
|
2011-01-22 00:33:25 +01:00
|
|
|
if (ivl_signal_local(sig)) return;
|
2011-01-10 18:30:27 +01:00
|
|
|
fprintf(vlog_out, "%*c", indent, ' ');
|
|
|
|
|
if (ivl_signal_integer(sig)) {
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "integer ");
|
|
|
|
|
emit_sig_id(sig);
|
2011-01-10 18:30:27 +01:00
|
|
|
if (ivl_signal_dimensions(sig) > 0) {
|
2011-01-22 00:33:25 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Integer arrays (%s) "
|
|
|
|
|
"are not supported.\n", ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
2011-01-10 18:30:27 +01:00
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
|
|
|
|
} else if (ivl_signal_data_type(sig) == IVL_VT_REAL) {
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "real ");
|
|
|
|
|
emit_sig_id(sig);
|
2011-01-10 18:30:27 +01:00
|
|
|
if (ivl_signal_dimensions(sig) > 0) {
|
2011-01-22 00:33:25 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Real arrays (%s) "
|
|
|
|
|
"are not supported.\n", ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
2011-01-10 18:30:27 +01:00
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
2012-08-07 03:12:05 +02:00
|
|
|
} else if (ivl_signal_data_type(sig) == IVL_VT_STRING) {
|
|
|
|
|
fprintf(vlog_out, "string ");
|
|
|
|
|
emit_sig_id(sig);
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: SystemVerilog strings (%s) "
|
|
|
|
|
"are not supported.\n", ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig), ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
} else if (ivl_signal_data_type(sig) == IVL_VT_DARRAY) {
|
|
|
|
|
fprintf(vlog_out, "<dynamic array> ");
|
|
|
|
|
emit_sig_id(sig);
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: SystemVerilog dynamic "
|
|
|
|
|
"arrays (%s) are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig), ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
2014-08-26 01:35:54 +02:00
|
|
|
} else if (ivl_signal_data_type(sig) == IVL_VT_QUEUE) {
|
|
|
|
|
fprintf(vlog_out, "<queue> ");
|
|
|
|
|
emit_sig_id(sig);
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: SystemVerilog queues "
|
|
|
|
|
"(%s) are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig), ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
2011-01-10 18:30:27 +01:00
|
|
|
} else {
|
2012-08-06 00:03:50 +02:00
|
|
|
int msb, lsb;
|
|
|
|
|
get_sig_msb_lsb(sig, &msb, &lsb);
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "reg ");
|
2011-03-16 03:17:04 +01:00
|
|
|
if (ivl_signal_signed(sig)) {
|
|
|
|
|
if (allow_signed) {
|
|
|
|
|
fprintf(vlog_out, "signed ");
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Signed registers "
|
|
|
|
|
"(%s) are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-14 00:13:39 +01:00
|
|
|
if (msb != 0 || lsb != 0) fprintf(vlog_out, "[%d:%d] ", msb, lsb);
|
|
|
|
|
emit_id(ivl_signal_basename(sig));
|
2011-01-10 18:30:27 +01:00
|
|
|
if (ivl_signal_dimensions(sig) > 0) {
|
|
|
|
|
unsigned wd_count = ivl_signal_array_count(sig);
|
|
|
|
|
int first = ivl_signal_array_base(sig);
|
|
|
|
|
int last = first + wd_count - 1;
|
|
|
|
|
if (ivl_signal_array_addr_swapped(sig)) {
|
|
|
|
|
fprintf(vlog_out, " [%d:%d]", last, first);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(vlog_out, " [%d:%d]", first, last);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-10 06:08:29 +01:00
|
|
|
fprintf(vlog_out, ";");
|
|
|
|
|
emit_sig_file_line(sig);
|
|
|
|
|
fprintf(vlog_out, "\n");
|
2011-01-10 18:30:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-07 05:08:23 +01:00
|
|
|
/*
|
|
|
|
|
* Keep a list of constants that drive nets and need to be emitted as
|
|
|
|
|
* a continuous assignment.
|
|
|
|
|
*/
|
|
|
|
|
static ivl_signal_t *net_consts = 0;
|
|
|
|
|
static unsigned num_net_consts = 0;
|
|
|
|
|
|
|
|
|
|
static void add_net_const_to_list(ivl_signal_t net_const)
|
|
|
|
|
{
|
|
|
|
|
num_net_consts += 1;
|
|
|
|
|
net_consts = realloc(net_consts, num_net_consts * sizeof(ivl_signal_t));
|
|
|
|
|
net_consts[num_net_consts-1] = net_const;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned emit_and_free_net_const_list(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx;
|
|
|
|
|
for (idx = 0; idx < num_net_consts; idx += 1) {
|
|
|
|
|
emit_signal_net_const_as_ca(scope, net_consts[idx]);
|
|
|
|
|
}
|
|
|
|
|
free(net_consts);
|
|
|
|
|
net_consts = 0;
|
|
|
|
|
idx = num_net_consts != 0;
|
|
|
|
|
num_net_consts = 0;
|
|
|
|
|
return idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void save_net_constants(ivl_scope_t scope, ivl_signal_t sig)
|
|
|
|
|
{
|
|
|
|
|
ivl_nexus_t nex = ivl_signal_nex(sig, 0);
|
|
|
|
|
unsigned idx, count = ivl_nexus_ptrs(nex);
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_nexus_ptr_t nex_ptr = ivl_nexus_ptr(nex, idx);
|
|
|
|
|
ivl_net_const_t net_const = ivl_nexus_ptr_con(nex_ptr);
|
|
|
|
|
if (! net_const) continue;
|
|
|
|
|
if (scope != ivl_const_scope(net_const)) continue;
|
|
|
|
|
add_net_const_to_list(sig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 22:15:03 +02:00
|
|
|
static void emit_net_def(ivl_scope_t scope, ivl_signal_t sig)
|
2011-01-10 18:30:27 +01:00
|
|
|
{
|
2012-08-06 00:03:50 +02:00
|
|
|
int msb, lsb;
|
|
|
|
|
get_sig_msb_lsb(sig, &msb, &lsb);
|
2011-01-22 00:33:25 +01:00
|
|
|
if (ivl_signal_local(sig)) return;
|
|
|
|
|
fprintf(vlog_out, "%*c", indent, ' ');
|
2011-01-10 18:30:27 +01:00
|
|
|
if (ivl_signal_data_type(sig) == IVL_VT_REAL){
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "wire ");
|
|
|
|
|
emit_sig_id(sig);
|
2011-01-22 00:33:25 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Real nets (%s) are "
|
2011-01-10 18:30:27 +01:00
|
|
|
"not supported.\n", ivl_signal_file(sig),
|
2011-01-22 00:33:25 +01:00
|
|
|
ivl_signal_lineno(sig), ivl_signal_basename(sig));
|
2011-01-10 18:30:27 +01:00
|
|
|
vlog_errors += 1;
|
|
|
|
|
} else if (ivl_signal_dimensions(sig) > 0) {
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "wire ");
|
|
|
|
|
if (msb != 0 || lsb != 0) fprintf(vlog_out, "[%d:%d] ", msb, lsb);
|
|
|
|
|
emit_sig_id(sig);
|
2011-01-22 00:33:25 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Array nets (%s) are "
|
2011-01-10 18:30:27 +01:00
|
|
|
"not supported.\n", ivl_signal_file(sig),
|
2011-01-22 00:33:25 +01:00
|
|
|
ivl_signal_lineno(sig), ivl_signal_basename(sig));
|
2011-01-10 18:30:27 +01:00
|
|
|
vlog_errors += 1;
|
|
|
|
|
} else {
|
2012-01-02 20:28:50 +01:00
|
|
|
switch (ivl_signal_type(sig)) {
|
2011-01-10 18:30:27 +01:00
|
|
|
case IVL_SIT_TRI:
|
|
|
|
|
case IVL_SIT_UWIRE:
|
|
|
|
|
// HERE: Need to add support for supply nets. Probably supply strength
|
|
|
|
|
// with a constant 0/1 driver for all the bits.
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "wire ");
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SIT_TRI0:
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "tri0 ");
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SIT_TRI1:
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "tri1 ");
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SIT_TRIAND:
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "wand ");
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SIT_TRIOR:
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "wor ");
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "<unknown> ");
|
2011-01-10 18:30:27 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Unknown net type "
|
|
|
|
|
"(%d).\n", ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig), (int)ivl_signal_type(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-03-16 03:17:04 +01:00
|
|
|
if (ivl_signal_signed(sig)) {
|
|
|
|
|
if (allow_signed) {
|
|
|
|
|
fprintf(vlog_out, "signed ");
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Signed nets (%s) "
|
|
|
|
|
"are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-14 00:13:39 +01:00
|
|
|
if (msb != 0 || lsb != 0) fprintf(vlog_out, "[%d:%d] ", msb, lsb);
|
|
|
|
|
emit_sig_id(sig);
|
2011-02-07 05:08:23 +01:00
|
|
|
/* A constant driving a net does not create an lpm or logic
|
|
|
|
|
* element in the design so save them from the definition. */
|
|
|
|
|
save_net_constants(scope, sig);
|
2011-01-10 18:30:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:13:39 +01:00
|
|
|
static void emit_mangled_name(ivl_scope_t scope, unsigned root)
|
2011-01-14 04:57:53 +01:00
|
|
|
{
|
2011-03-11 20:27:54 +01:00
|
|
|
/* If the module has parameters and it's not a root module then it
|
2011-03-14 00:13:39 +01:00
|
|
|
* may not be unique so we create a mangled name version instead.
|
|
|
|
|
* The mangled name is of the form:
|
|
|
|
|
* <module_name>[<full_instance_scope>]. */
|
2011-01-14 06:01:04 +01:00
|
|
|
if (ivl_scope_params(scope) && ! root) {
|
2011-03-14 00:13:39 +01:00
|
|
|
char *name;
|
2011-01-14 04:57:53 +01:00
|
|
|
size_t len = strlen(ivl_scope_name(scope)) +
|
2011-03-14 00:13:39 +01:00
|
|
|
strlen(ivl_scope_tname(scope)) + 3;
|
2011-01-14 04:57:53 +01:00
|
|
|
name = (char *)malloc(len);
|
|
|
|
|
(void) strcpy(name, ivl_scope_tname(scope));
|
2011-03-14 00:13:39 +01:00
|
|
|
(void) strcat(name, "[");
|
2011-01-14 04:57:53 +01:00
|
|
|
(void) strcat(name, ivl_scope_name(scope));
|
2011-03-14 00:13:39 +01:00
|
|
|
(void) strcat(name, "]");
|
2011-01-14 04:57:53 +01:00
|
|
|
assert(name[len-1] == 0);
|
2011-03-14 00:13:39 +01:00
|
|
|
/* Emit the mangled name as an escaped identifier. */
|
|
|
|
|
fprintf(vlog_out, "\\%s ", name);
|
|
|
|
|
free(name);
|
2011-01-14 04:57:53 +01:00
|
|
|
} else {
|
2011-03-14 00:13:39 +01:00
|
|
|
emit_id(ivl_scope_tname(scope));
|
2011-01-14 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-17 19:51:05 +01:00
|
|
|
/*
|
|
|
|
|
* This function is called for each process in the design so that we
|
|
|
|
|
* can extract the processes for the given scope.
|
|
|
|
|
*/
|
|
|
|
|
static int find_process(ivl_process_t proc, ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
if (scope == ivl_process_scope(proc)) emit_process(scope, proc);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 08:53:53 +01:00
|
|
|
void emit_scope_variables(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count;
|
2011-02-07 05:08:23 +01:00
|
|
|
assert(! num_net_consts);
|
2011-01-31 08:53:53 +01:00
|
|
|
/* Output the parameters for this scope. */
|
|
|
|
|
count = ivl_scope_params(scope);
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_parameter_t par = ivl_scope_param(scope, idx);
|
|
|
|
|
ivl_expr_t pex = ivl_parameter_expr(par);
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "%*cparameter ", indent, ' ');
|
|
|
|
|
emit_id(ivl_parameter_basename(par));
|
|
|
|
|
fprintf(vlog_out, " = ");
|
2013-07-05 19:33:23 +02:00
|
|
|
/* Need to emit the parameters value not its name. */
|
|
|
|
|
emitting_param = par;
|
2013-07-10 03:21:36 +02:00
|
|
|
emit_expr(scope, pex, ivl_parameter_width(par), 1, 0, 0);
|
2013-07-05 19:33:23 +02:00
|
|
|
emitting_param = 0;
|
2011-02-10 06:08:29 +01:00
|
|
|
fprintf(vlog_out, ";");
|
|
|
|
|
if (emit_file_line) {
|
|
|
|
|
fprintf(vlog_out, " /* %s:%u */",
|
|
|
|
|
ivl_parameter_file(par),
|
|
|
|
|
ivl_parameter_lineno(par));
|
|
|
|
|
}
|
|
|
|
|
fprintf(vlog_out, "\n");
|
2011-01-31 08:53:53 +01:00
|
|
|
}
|
|
|
|
|
if (count) fprintf(vlog_out, "\n");
|
|
|
|
|
|
|
|
|
|
/* Output the signals for this scope. */
|
|
|
|
|
count = ivl_scope_sigs(scope);
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_signal_t sig = ivl_scope_sig(scope, idx);
|
|
|
|
|
if (ivl_signal_type(sig) == IVL_SIT_REG) {
|
|
|
|
|
/* Do not output the implicit function return register. */
|
|
|
|
|
if (ivl_scope_type(scope) == IVL_SCT_FUNCTION &&
|
|
|
|
|
strcmp(ivl_signal_basename(sig),
|
|
|
|
|
ivl_scope_tname(scope)) == 0) continue;
|
|
|
|
|
emit_var_def(sig);
|
|
|
|
|
} else {
|
2011-02-07 05:08:23 +01:00
|
|
|
emit_net_def(scope, sig);
|
2011-01-31 08:53:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (count) fprintf(vlog_out, "\n");
|
|
|
|
|
|
|
|
|
|
/* Output the named events for this scope. */
|
|
|
|
|
count = ivl_scope_events(scope);
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_event_t event = ivl_scope_event(scope, idx);
|
|
|
|
|
/* If this event has any type of edge sensitivity then it is
|
|
|
|
|
* not a named event. */
|
|
|
|
|
if (ivl_event_nany(event)) continue;
|
|
|
|
|
if (ivl_event_npos(event)) continue;
|
|
|
|
|
if (ivl_event_nneg(event)) continue;
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "%*cevent ", indent, ' ');
|
|
|
|
|
emit_id(ivl_event_basename(event));
|
|
|
|
|
fprintf(vlog_out, ";");
|
2011-02-10 06:08:29 +01:00
|
|
|
if (emit_file_line) {
|
|
|
|
|
fprintf(vlog_out, " /* %s:%u */",
|
|
|
|
|
ivl_event_file(event),
|
|
|
|
|
ivl_event_lineno(event));
|
|
|
|
|
}
|
|
|
|
|
fprintf(vlog_out, "\n");
|
2011-01-31 08:53:53 +01:00
|
|
|
}
|
|
|
|
|
if (count) fprintf(vlog_out, "\n");
|
2011-02-10 06:08:29 +01:00
|
|
|
if (emit_and_free_net_const_list(scope)) fprintf(vlog_out, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emit_scope_file_line(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
if (emit_file_line) {
|
|
|
|
|
fprintf(vlog_out, " /* %s:%u */",
|
|
|
|
|
ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope));
|
|
|
|
|
}
|
2011-01-31 08:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-07 20:33:22 +01:00
|
|
|
static void emit_module_ports(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count = ivl_scope_ports(scope);
|
|
|
|
|
|
|
|
|
|
if (count == 0) return;
|
|
|
|
|
|
|
|
|
|
fprintf(vlog_out, "(");
|
2013-06-28 04:42:45 +02:00
|
|
|
emit_nexus_as_ca(scope, ivl_scope_mod_port(scope, 0), 0, 0);
|
2011-03-07 20:33:22 +01:00
|
|
|
for (idx = 1; idx < count; idx += 1) {
|
|
|
|
|
fprintf(vlog_out, ", ");
|
2013-06-28 04:42:45 +02:00
|
|
|
emit_nexus_as_ca(scope, ivl_scope_mod_port(scope, idx), 0, 0);
|
2011-03-07 20:33:22 +01:00
|
|
|
}
|
|
|
|
|
fprintf(vlog_out, ")");
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-02 20:28:50 +01:00
|
|
|
static ivl_signal_t get_port_from_nexus(ivl_scope_t scope, ivl_nexus_t nex,
|
|
|
|
|
unsigned *word)
|
2011-03-14 00:13:39 +01:00
|
|
|
{
|
|
|
|
|
assert(nex);
|
|
|
|
|
unsigned idx, count = ivl_nexus_ptrs(nex);
|
|
|
|
|
ivl_signal_t sig = 0;
|
2012-01-02 20:28:50 +01:00
|
|
|
*word = 0;
|
2011-03-14 00:13:39 +01:00
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_nexus_ptr_t nex_ptr = ivl_nexus_ptr(nex, idx);
|
|
|
|
|
ivl_signal_t t_sig = ivl_nexus_ptr_sig(nex_ptr);
|
|
|
|
|
if (t_sig) {
|
|
|
|
|
if (ivl_signal_scope(t_sig) != scope) continue;
|
|
|
|
|
assert(! sig);
|
|
|
|
|
sig = t_sig;
|
2012-01-02 20:28:50 +01:00
|
|
|
*word = ivl_nexus_ptr_pin(nex_ptr);
|
2011-03-14 00:13:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return sig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emit_sig_type(ivl_signal_t sig)
|
|
|
|
|
{
|
|
|
|
|
ivl_signal_type_t type = ivl_signal_type(sig);
|
2014-04-10 23:17:50 +02:00
|
|
|
if (ivl_signal_dimensions(sig) != 0) {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Array ports (%s) are not "
|
|
|
|
|
"supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
2011-03-14 00:13:39 +01:00
|
|
|
/* Check to see if we have a variable (reg) or a net. */
|
|
|
|
|
if (type == IVL_SIT_REG) {
|
2015-05-19 00:16:53 +02:00
|
|
|
/* The variable data type will be declared later, so here
|
|
|
|
|
we just want to declare the range and whether or not it
|
|
|
|
|
is signed. */
|
2011-03-14 00:13:39 +01:00
|
|
|
if (ivl_signal_integer(sig)) {
|
2015-05-19 00:16:53 +02:00
|
|
|
/* nothing to do */
|
2011-03-14 00:13:39 +01:00
|
|
|
} else if (ivl_signal_data_type(sig) == IVL_VT_REAL) {
|
2015-05-19 00:16:53 +02:00
|
|
|
/* nothing to do */
|
2011-03-14 00:13:39 +01:00
|
|
|
} else {
|
2012-08-06 00:03:50 +02:00
|
|
|
int msb, lsb;
|
|
|
|
|
get_sig_msb_lsb(sig, &msb, &lsb);
|
2011-03-16 03:17:04 +01:00
|
|
|
if (ivl_signal_signed(sig)) {
|
|
|
|
|
if (allow_signed) {
|
|
|
|
|
fprintf(vlog_out, " signed");
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Signed "
|
|
|
|
|
"ports (%s) are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-14 00:13:39 +01:00
|
|
|
if (msb != 0 || lsb != 0) {
|
|
|
|
|
fprintf(vlog_out, " [%d:%d]", msb, lsb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2011-03-21 22:37:59 +01:00
|
|
|
assert((type == IVL_SIT_TRI) ||
|
|
|
|
|
(type == IVL_SIT_TRI0) ||
|
2013-01-25 03:25:24 +01:00
|
|
|
(type == IVL_SIT_TRI1) ||
|
|
|
|
|
(type == IVL_SIT_UWIRE));
|
2011-03-14 00:13:39 +01:00
|
|
|
if (ivl_signal_data_type(sig) == IVL_VT_REAL) {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Real net ports (%s) "
|
|
|
|
|
"are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
} else {
|
2012-08-06 00:03:50 +02:00
|
|
|
int msb, lsb;
|
|
|
|
|
get_sig_msb_lsb(sig, &msb, &lsb);
|
2011-03-14 00:13:39 +01:00
|
|
|
if (ivl_signal_signed(sig)) {
|
2011-03-16 03:17:04 +01:00
|
|
|
if (allow_signed) {
|
|
|
|
|
fprintf(vlog_out, " signed");
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Signed net "
|
|
|
|
|
"ports (%s) are not supported.\n",
|
|
|
|
|
ivl_signal_file(sig),
|
|
|
|
|
ivl_signal_lineno(sig),
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
2011-03-14 00:13:39 +01:00
|
|
|
}
|
|
|
|
|
if (msb != 0 || lsb != 0) {
|
|
|
|
|
fprintf(vlog_out, " [%d:%d]", msb, lsb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emit_port(ivl_signal_t port)
|
|
|
|
|
{
|
|
|
|
|
assert(port);
|
|
|
|
|
fprintf(vlog_out, "%*c", indent, ' ');
|
|
|
|
|
switch (ivl_signal_port(port)) {
|
|
|
|
|
case IVL_SIP_INPUT:
|
|
|
|
|
fprintf(vlog_out, "input");
|
|
|
|
|
break;
|
|
|
|
|
case IVL_SIP_OUTPUT:
|
|
|
|
|
fprintf(vlog_out, "output");
|
|
|
|
|
break;
|
|
|
|
|
case IVL_SIP_INOUT:
|
|
|
|
|
fprintf(vlog_out, "inout");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(vlog_out, "<unknown>");
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Unknown port direction (%d) "
|
|
|
|
|
"for signal %s.\n", ivl_signal_file(port),
|
|
|
|
|
ivl_signal_lineno(port), (int)ivl_signal_port(port),
|
|
|
|
|
ivl_signal_basename(port));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
emit_sig_type(port);
|
|
|
|
|
fprintf(vlog_out, " ");
|
2012-01-02 20:28:50 +01:00
|
|
|
/* Split port (arg[7:4],arg[3:0]) are generated using local signals. */
|
|
|
|
|
if (ivl_signal_local(port)) {
|
|
|
|
|
fprintf(vlog_out, "ivlog%s", ivl_signal_basename(port));
|
|
|
|
|
} else {
|
|
|
|
|
emit_id(ivl_signal_basename(port));
|
|
|
|
|
}
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, ";");
|
|
|
|
|
emit_sig_file_line(port);
|
|
|
|
|
fprintf(vlog_out, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 20:33:22 +01:00
|
|
|
static void emit_module_port_defs(ivl_scope_t scope)
|
|
|
|
|
{
|
2012-01-02 20:28:50 +01:00
|
|
|
unsigned word, idx, count = ivl_scope_ports(scope);
|
2011-03-07 20:33:22 +01:00
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
2011-03-14 00:13:39 +01:00
|
|
|
ivl_nexus_t nex = ivl_scope_mod_port(scope, idx);
|
2012-01-02 20:28:50 +01:00
|
|
|
ivl_signal_t port = get_port_from_nexus(scope, nex, &word);
|
|
|
|
|
// HERE: Do we need to use word?
|
2011-03-14 00:13:39 +01:00
|
|
|
if (port) emit_port(port);
|
|
|
|
|
else {
|
|
|
|
|
fprintf(vlog_out, "<missing>");
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Could not find signal "
|
|
|
|
|
"definition for port (%u) of module %s.\n",
|
|
|
|
|
ivl_scope_file(scope), ivl_scope_lineno(scope),
|
|
|
|
|
idx + 1, ivl_scope_basename(scope));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
2011-03-07 20:33:22 +01:00
|
|
|
}
|
|
|
|
|
if (count) fprintf(vlog_out, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:13:39 +01:00
|
|
|
static void emit_module_call_expr(ivl_scope_t scope, unsigned idx)
|
|
|
|
|
{
|
2012-01-02 20:28:50 +01:00
|
|
|
unsigned word;
|
2011-03-14 00:13:39 +01:00
|
|
|
ivl_nexus_t nex = ivl_scope_mod_port(scope, idx);
|
2012-01-02 20:28:50 +01:00
|
|
|
ivl_signal_t port = get_port_from_nexus(scope, nex, &word);
|
2011-03-14 00:13:39 +01:00
|
|
|
/* For an input port we need to emit the driving expression. */
|
|
|
|
|
if (ivl_signal_port(port) == IVL_SIP_INPUT) {
|
|
|
|
|
emit_nexus_port_driver_as_ca(ivl_scope_parent(scope),
|
2012-01-02 20:28:50 +01:00
|
|
|
ivl_signal_nex(port, word));
|
2011-03-14 00:13:39 +01:00
|
|
|
/* For an output we need to emit the signal the output is driving. */
|
|
|
|
|
} else {
|
2012-01-02 20:28:50 +01:00
|
|
|
emit_nexus_as_ca(ivl_scope_parent(scope),
|
2013-06-28 04:42:45 +02:00
|
|
|
ivl_signal_nex(port, word), 0, 0);
|
2011-03-14 00:13:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emit_module_call_expressions(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count = ivl_scope_ports(scope);
|
|
|
|
|
if (count == 0) return;
|
|
|
|
|
emit_module_call_expr(scope, 0);
|
|
|
|
|
for (idx = 1; idx < count; idx += 1) {
|
|
|
|
|
fprintf(vlog_out, ", ");
|
|
|
|
|
emit_module_call_expr(scope, idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 20:33:22 +01:00
|
|
|
static void emit_task_func_port_defs(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count = ivl_scope_ports(scope);
|
|
|
|
|
unsigned start = ivl_scope_type(scope) == IVL_SCT_FUNCTION;
|
|
|
|
|
for (idx = start; idx < count; idx += 1) {
|
|
|
|
|
ivl_signal_t port = ivl_scope_port(scope, idx);
|
2011-03-14 00:13:39 +01:00
|
|
|
emit_port(port);
|
2013-07-25 04:39:17 +02:00
|
|
|
}
|
|
|
|
|
/* If the start and count are both 1 then this is a SystemVerilog
|
|
|
|
|
* function that does not have an argument so add a dummy one. */
|
|
|
|
|
if ((start == 1) && (count == 1)) {
|
|
|
|
|
fprintf(vlog_out, "%*cinput _vlog95_dummy;", indent, ' ');
|
|
|
|
|
if (emit_file_line) fprintf(vlog_out, " /* no file/line */");
|
|
|
|
|
fprintf(vlog_out, "\n");
|
2011-03-07 20:33:22 +01:00
|
|
|
}
|
|
|
|
|
if (count) fprintf(vlog_out, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-02 20:28:50 +01:00
|
|
|
/*
|
2013-07-25 04:39:17 +02:00
|
|
|
* Recursively look for the named block in the given statement.
|
2012-01-02 20:28:50 +01:00
|
|
|
*/
|
2013-07-25 04:39:17 +02:00
|
|
|
static int has_named_block(ivl_scope_t scope, ivl_statement_t stmt)
|
2012-01-02 20:28:50 +01:00
|
|
|
{
|
2013-07-25 04:39:17 +02:00
|
|
|
unsigned idx, count;
|
|
|
|
|
int rtn = 0;
|
|
|
|
|
if (! stmt) return 0;
|
2012-01-02 20:28:50 +01:00
|
|
|
switch (ivl_statement_type(stmt)) {
|
2013-07-25 04:39:17 +02:00
|
|
|
/* Block or fork items can contain a named block. */
|
2012-01-02 20:28:50 +01:00
|
|
|
case IVL_ST_BLOCK:
|
|
|
|
|
case IVL_ST_FORK:
|
2013-07-25 04:39:17 +02:00
|
|
|
case IVL_ST_FORK_JOIN_ANY:
|
|
|
|
|
case IVL_ST_FORK_JOIN_NONE:
|
2012-01-02 20:28:50 +01:00
|
|
|
if (ivl_stmt_block_scope(stmt) == scope) return 1;
|
2013-07-25 04:39:17 +02:00
|
|
|
count = ivl_stmt_block_count(stmt);
|
|
|
|
|
for (idx = 0; (idx < count) && ! rtn ; idx += 1) {
|
|
|
|
|
rtn |= has_named_block(scope,
|
|
|
|
|
ivl_stmt_block_stmt(stmt, idx));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* Case items can contain a named block. */
|
|
|
|
|
case IVL_ST_CASE:
|
|
|
|
|
case IVL_ST_CASER:
|
|
|
|
|
case IVL_ST_CASEX:
|
|
|
|
|
case IVL_ST_CASEZ:
|
|
|
|
|
count = ivl_stmt_case_count(stmt);
|
|
|
|
|
for (idx = 0; (idx < count) && ! rtn; idx += 1) {
|
|
|
|
|
rtn |= has_named_block(scope,
|
|
|
|
|
ivl_stmt_case_stmt(stmt, idx));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* Either the true or false clause may have a named block. */
|
|
|
|
|
case IVL_ST_CONDIT:
|
|
|
|
|
rtn = has_named_block(scope, ivl_stmt_cond_true(stmt));
|
|
|
|
|
if (! rtn) {
|
|
|
|
|
rtn = has_named_block(scope, ivl_stmt_cond_false(stmt));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* The looping statements may have a named block. */
|
2013-09-24 02:30:30 +02:00
|
|
|
case IVL_ST_DO_WHILE:
|
2013-07-25 04:39:17 +02:00
|
|
|
case IVL_ST_FOREVER:
|
|
|
|
|
case IVL_ST_REPEAT:
|
|
|
|
|
case IVL_ST_WHILE:
|
|
|
|
|
/* The delay and wait statements may have a named block. */
|
|
|
|
|
case IVL_ST_DELAY:
|
|
|
|
|
case IVL_ST_DELAYX:
|
|
|
|
|
case IVL_ST_WAIT:
|
|
|
|
|
rtn = has_named_block(scope, ivl_stmt_sub_stmt(stmt));
|
|
|
|
|
break;
|
|
|
|
|
default: /* The rest cannot have a named block. */ ;
|
2012-01-02 20:28:50 +01:00
|
|
|
}
|
2013-07-25 04:39:17 +02:00
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Look at all the processes to see if we can find one with the expected
|
|
|
|
|
* scope. If we don't find one then we can assume the block only has
|
|
|
|
|
* variable definitions and needs to be emitted here in the scope code.
|
|
|
|
|
*/
|
|
|
|
|
static int no_stmts_in_process(ivl_process_t proc, ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
return has_named_block(scope, ivl_process_stmt(proc));
|
2012-01-02 20:28:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If a named block has no statements then we may need to emit it here if
|
|
|
|
|
* there are variable definitions in the scope. We translate all this to
|
|
|
|
|
* an initial and named begin since that is enough to hold the variables.
|
|
|
|
|
*/
|
|
|
|
|
static void emit_named_block_scope(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count = ivl_scope_events(scope);
|
|
|
|
|
unsigned named_ev = 0;
|
|
|
|
|
|
|
|
|
|
/* If there are no parameters, signals or named events then skip
|
|
|
|
|
* this block. */
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_event_t event = ivl_scope_event(scope, idx);
|
|
|
|
|
/* If this event has any type of edge sensitivity then it is
|
|
|
|
|
* not a named event. */
|
|
|
|
|
if (ivl_event_nany(event)) continue;
|
|
|
|
|
if (ivl_event_npos(event)) continue;
|
|
|
|
|
if (ivl_event_nneg(event)) continue;
|
|
|
|
|
named_ev = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((ivl_scope_params(scope) == 0) && (ivl_scope_sigs(scope) == 0) &&
|
|
|
|
|
(named_ev == 0)) return;
|
|
|
|
|
/* Currently we only need to emit a named block for the variables
|
|
|
|
|
* if the parent scope is a module. This gets much more complicated
|
|
|
|
|
* if this is not true. */
|
|
|
|
|
if (ivl_scope_type(ivl_scope_parent(scope)) != IVL_SCT_MODULE) return;
|
|
|
|
|
/* Scan all the processes looking for one that matches this scope.
|
|
|
|
|
* If a match is found then this named block was already emitted by
|
|
|
|
|
* the process code. */
|
|
|
|
|
if (ivl_design_process(design, (ivl_process_f)no_stmts_in_process,
|
|
|
|
|
scope)) return;
|
|
|
|
|
/* A match was not found so emit the named block here to get the
|
|
|
|
|
* variable definitions. */
|
|
|
|
|
fprintf(vlog_out, "\n%*cinitial begin: ", indent, ' ');
|
|
|
|
|
emit_id(ivl_scope_tname(scope));
|
|
|
|
|
emit_scope_file_line(scope);
|
|
|
|
|
fprintf(vlog_out, "\n");
|
|
|
|
|
indent += indent_incr;
|
|
|
|
|
emit_scope_variables(scope);
|
|
|
|
|
indent -= indent_incr;
|
|
|
|
|
fprintf(vlog_out, "%*cend /* ", indent, ' ');
|
|
|
|
|
emit_id(ivl_scope_tname(scope));
|
|
|
|
|
fprintf(vlog_out, " */\n");
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 04:29:29 +01:00
|
|
|
/*
|
|
|
|
|
* In SystemVerilog a task or function can have a process to initialize
|
|
|
|
|
* variables. In reality SystemVerilog requires this to be before the
|
|
|
|
|
* initial/always blocks are processed, but that's not how it is currently
|
|
|
|
|
* implemented in Icarus!
|
|
|
|
|
*/
|
|
|
|
|
static int find_tf_process(ivl_process_t proc, ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
if (scope == ivl_process_scope(proc)) {
|
|
|
|
|
ivl_scope_t mod_scope = scope;
|
|
|
|
|
/* A task or function can only have initial processes that
|
|
|
|
|
* are used to set local variables. */
|
|
|
|
|
assert(ivl_process_type(proc) == IVL_PR_INITIAL);
|
|
|
|
|
/* Find the module scope for this task/function. */
|
|
|
|
|
while (ivl_scope_type(mod_scope) != IVL_SCT_MODULE) {
|
|
|
|
|
mod_scope = ivl_scope_parent(mod_scope);
|
|
|
|
|
assert(mod_scope);
|
|
|
|
|
}
|
|
|
|
|
/* Emit the process in the module scope since that is where
|
|
|
|
|
* this all started. */
|
|
|
|
|
emit_process(mod_scope, proc);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Emit any initial blocks for the tasks or functions in a module.
|
|
|
|
|
*/
|
|
|
|
|
static int emit_tf_process(ivl_scope_t scope, ivl_scope_t parent)
|
|
|
|
|
{
|
|
|
|
|
ivl_scope_type_t sc_type = ivl_scope_type(scope);
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)parent; /* Parameter is not used. */
|
2013-02-16 04:29:29 +01:00
|
|
|
if ((sc_type == IVL_SCT_FUNCTION) || (sc_type == IVL_SCT_TASK)) {
|
|
|
|
|
/* Output the initial/always blocks for this module. */
|
|
|
|
|
ivl_design_process(design, (ivl_process_f)find_tf_process, scope);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 23:24:17 +01:00
|
|
|
static void emit_path_delay(ivl_scope_t scope, ivl_delaypath_t dpath)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count = 6;
|
|
|
|
|
uint64_t pdlys [12];
|
|
|
|
|
pdlys[0] = ivl_path_delay(dpath, IVL_PE_01);
|
|
|
|
|
pdlys[1] = ivl_path_delay(dpath, IVL_PE_10);
|
|
|
|
|
pdlys[2] = ivl_path_delay(dpath, IVL_PE_0z);
|
|
|
|
|
pdlys[3] = ivl_path_delay(dpath, IVL_PE_z1);
|
|
|
|
|
pdlys[4] = ivl_path_delay(dpath, IVL_PE_1z);
|
|
|
|
|
pdlys[5] = ivl_path_delay(dpath, IVL_PE_z0);
|
|
|
|
|
pdlys[6] = ivl_path_delay(dpath, IVL_PE_0x);
|
|
|
|
|
pdlys[7] = ivl_path_delay(dpath, IVL_PE_x1);
|
|
|
|
|
pdlys[8] = ivl_path_delay(dpath, IVL_PE_1x);
|
|
|
|
|
pdlys[9] = ivl_path_delay(dpath, IVL_PE_x0);
|
|
|
|
|
pdlys[10] = ivl_path_delay(dpath, IVL_PE_xz);
|
|
|
|
|
pdlys[11] = ivl_path_delay(dpath, IVL_PE_zx);
|
|
|
|
|
/* If the first six pdlys match then this may be a 1 delay form. */
|
|
|
|
|
if ((pdlys[0] == pdlys[1]) &&
|
|
|
|
|
(pdlys[0] == pdlys[2]) &&
|
|
|
|
|
(pdlys[0] == pdlys[3]) &&
|
|
|
|
|
(pdlys[0] == pdlys[4]) &&
|
|
|
|
|
(pdlys[0] == pdlys[5])) count = 1;
|
|
|
|
|
/* Check to see if only a rise and fall value are given for the first
|
|
|
|
|
* six pdlys. */
|
|
|
|
|
else if ((pdlys[0] == pdlys[2]) &&
|
|
|
|
|
(pdlys[0] == pdlys[3]) &&
|
|
|
|
|
(pdlys[1] == pdlys[4]) &&
|
|
|
|
|
(pdlys[1] == pdlys[5])) count = 2;
|
|
|
|
|
/* Check to see if a rise, fall and high-Z value are given for the
|
|
|
|
|
* first six pdlys. */
|
|
|
|
|
else if ((pdlys[0] == pdlys[3]) &&
|
|
|
|
|
(pdlys[1] == pdlys[5]) &&
|
|
|
|
|
(pdlys[2] == pdlys[4])) count = 3;
|
|
|
|
|
/* Now check to see if the 'bx related pdlys match the reduced
|
|
|
|
|
* delay form. If not then this is a twelve delay value. */
|
|
|
|
|
if ((pdlys[6] != ((pdlys[0] < pdlys[2]) ? pdlys[0] : pdlys[2])) ||
|
|
|
|
|
(pdlys[8] != ((pdlys[1] < pdlys[4]) ? pdlys[1] : pdlys[4])) ||
|
|
|
|
|
(pdlys[11] != ((pdlys[3] < pdlys[5]) ? pdlys[3] : pdlys[5])) ||
|
|
|
|
|
(pdlys[7] != ((pdlys[0] > pdlys[3]) ? pdlys[0] : pdlys[3])) ||
|
|
|
|
|
(pdlys[9] != ((pdlys[1] > pdlys[5]) ? pdlys[1] : pdlys[5])) ||
|
|
|
|
|
(pdlys[10] != ((pdlys[2] > pdlys[4]) ? pdlys[2] : pdlys[4]))) {
|
|
|
|
|
count = 12;
|
|
|
|
|
}
|
|
|
|
|
emit_scaled_delay(scope, pdlys[0]);
|
|
|
|
|
for(idx = 1; idx < count; idx += 1) {
|
|
|
|
|
fprintf(vlog_out, ", ");
|
|
|
|
|
emit_scaled_delay(scope, pdlys[idx]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emit_specify_paths(ivl_scope_t scope, ivl_signal_t sig)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count = ivl_signal_npath(sig);
|
|
|
|
|
for(idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_delaypath_t dpath = ivl_signal_path(sig, idx);
|
|
|
|
|
ivl_nexus_t cond = ivl_path_condit(dpath);
|
|
|
|
|
ivl_nexus_t source = ivl_path_source(dpath);
|
|
|
|
|
unsigned has_edge = 0;
|
|
|
|
|
fprintf(vlog_out, "%*c", indent, ' ');
|
|
|
|
|
if (cond) {
|
|
|
|
|
fprintf(vlog_out, "if (");
|
2013-06-28 04:42:45 +02:00
|
|
|
emit_nexus_as_ca(scope, cond, 0, 0);
|
2013-02-23 23:24:17 +01:00
|
|
|
fprintf(vlog_out, ") ");
|
|
|
|
|
} else if (ivl_path_is_condit(dpath)) {
|
|
|
|
|
fprintf(vlog_out, "ifnone ");
|
|
|
|
|
}
|
|
|
|
|
fprintf(vlog_out, "(");
|
|
|
|
|
if (ivl_path_source_posedge(dpath)) {
|
|
|
|
|
fprintf(vlog_out, "posedge ");
|
|
|
|
|
has_edge = 1;
|
|
|
|
|
}
|
|
|
|
|
if (ivl_path_source_negedge(dpath)) {
|
|
|
|
|
fprintf(vlog_out, "negedge ");
|
|
|
|
|
has_edge = 1;
|
|
|
|
|
}
|
2013-06-28 04:42:45 +02:00
|
|
|
emit_nexus_as_ca(scope, source, 0, 0);
|
2013-02-23 23:24:17 +01:00
|
|
|
fprintf(vlog_out, " =>");
|
|
|
|
|
/* The compiler does not keep the source expression for an edge
|
|
|
|
|
* sensitive path so add a constant to get the syntax right. */
|
|
|
|
|
if (has_edge) {
|
|
|
|
|
fprintf(vlog_out, "(%s : 1'bx /* Missing */)",
|
|
|
|
|
ivl_signal_basename(sig));
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(vlog_out, "%s", ivl_signal_basename(sig));
|
|
|
|
|
}
|
|
|
|
|
fprintf(vlog_out, ") = (");
|
|
|
|
|
emit_path_delay(scope, dpath);
|
|
|
|
|
fprintf(vlog_out, ");\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The path delay information from the specify block is attached to the
|
|
|
|
|
* output ports.
|
|
|
|
|
*/
|
|
|
|
|
static void emit_specify(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned word, idx, count = ivl_scope_ports(scope);
|
|
|
|
|
unsigned need_specify = 0;
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
ivl_nexus_t nex = ivl_scope_mod_port(scope, idx);
|
|
|
|
|
ivl_signal_t port = get_port_from_nexus(scope, nex, &word);
|
|
|
|
|
// HERE: Do we need to use word? See emit_module_port_def().
|
|
|
|
|
assert(port);
|
|
|
|
|
if (ivl_signal_npath(port)) {
|
|
|
|
|
if (! need_specify) {
|
|
|
|
|
fprintf(vlog_out, "\n%*cspecify\n", indent, ' ');
|
|
|
|
|
need_specify = 1;
|
|
|
|
|
indent += indent_incr;
|
|
|
|
|
}
|
|
|
|
|
emit_specify_paths(scope, port);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (need_specify) {
|
|
|
|
|
indent -= indent_incr;
|
|
|
|
|
fprintf(vlog_out, "%*cendspecify\n", indent, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-19 19:48:39 +02:00
|
|
|
/*
|
|
|
|
|
* Look for a disable in the statement (function body) for this scope.
|
|
|
|
|
*/
|
|
|
|
|
static unsigned has_func_disable(ivl_scope_t scope, ivl_statement_t stmt)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx, count, rtn = 0;
|
|
|
|
|
/* If there is a statement then look to see if it is or has a
|
|
|
|
|
* disable for this function scope. */
|
|
|
|
|
if (! stmt) return 0;
|
|
|
|
|
assert(ivl_scope_type(scope) == IVL_SCT_FUNCTION);
|
|
|
|
|
switch (ivl_statement_type(stmt)) {
|
|
|
|
|
/* These are not allowed in a function. */
|
|
|
|
|
case IVL_ST_ASSIGN_NB:
|
|
|
|
|
case IVL_ST_DELAY:
|
|
|
|
|
case IVL_ST_DELAYX:
|
|
|
|
|
case IVL_ST_FORK:
|
|
|
|
|
case IVL_ST_FORK_JOIN_ANY:
|
|
|
|
|
case IVL_ST_FORK_JOIN_NONE:
|
|
|
|
|
case IVL_ST_UTASK:
|
|
|
|
|
case IVL_ST_WAIT:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
/* These are allowed in a function and cannot have a disable. */
|
|
|
|
|
case IVL_ST_NOOP:
|
|
|
|
|
case IVL_ST_ALLOC:
|
|
|
|
|
case IVL_ST_ASSIGN:
|
|
|
|
|
case IVL_ST_CASSIGN:
|
|
|
|
|
case IVL_ST_DEASSIGN:
|
|
|
|
|
case IVL_ST_FORCE:
|
|
|
|
|
case IVL_ST_FREE:
|
|
|
|
|
case IVL_ST_RELEASE:
|
|
|
|
|
case IVL_ST_STASK:
|
|
|
|
|
case IVL_ST_TRIGGER:
|
|
|
|
|
break;
|
|
|
|
|
/* Look for a disable in each block statement. */
|
|
|
|
|
case IVL_ST_BLOCK:
|
|
|
|
|
count = ivl_stmt_block_count(stmt);
|
|
|
|
|
for (idx = 0; (idx < count) && ! rtn; idx += 1) {
|
|
|
|
|
rtn |= has_func_disable(scope,
|
|
|
|
|
ivl_stmt_block_stmt(stmt, idx));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* Look for a disable in each case branch. */
|
|
|
|
|
case IVL_ST_CASE:
|
|
|
|
|
case IVL_ST_CASER:
|
|
|
|
|
case IVL_ST_CASEX:
|
|
|
|
|
case IVL_ST_CASEZ:
|
|
|
|
|
count = ivl_stmt_case_count(stmt);
|
|
|
|
|
for (idx = 0; (idx < count) && ! rtn; idx += 1) {
|
|
|
|
|
rtn |= has_func_disable(scope,
|
|
|
|
|
ivl_stmt_case_stmt(stmt, idx));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* Either the true or false clause may have a disable. */
|
|
|
|
|
case IVL_ST_CONDIT:
|
|
|
|
|
rtn = has_func_disable(scope, ivl_stmt_cond_true(stmt));
|
|
|
|
|
if (! rtn) {
|
|
|
|
|
rtn = has_func_disable(scope, ivl_stmt_cond_false(stmt));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* These have a single sub-statement so look for a disable there. */
|
2013-09-24 02:30:30 +02:00
|
|
|
case IVL_ST_DO_WHILE:
|
2013-07-19 19:48:39 +02:00
|
|
|
case IVL_ST_FOREVER:
|
|
|
|
|
case IVL_ST_REPEAT:
|
|
|
|
|
case IVL_ST_WHILE:
|
|
|
|
|
rtn = has_func_disable(scope, ivl_stmt_sub_stmt(stmt));
|
|
|
|
|
break;
|
|
|
|
|
/* The function has a disable if the disable scope matches the
|
|
|
|
|
* function scope. */
|
|
|
|
|
case IVL_ST_DISABLE:
|
|
|
|
|
rtn = scope == ivl_stmt_call(stmt);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2013-12-20 05:37:55 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Unknown statement type (%d) "
|
|
|
|
|
"in function disable check.\n",
|
2013-07-19 19:48:39 +02:00
|
|
|
ivl_stmt_file(stmt),
|
|
|
|
|
ivl_stmt_lineno(stmt),
|
|
|
|
|
(int)ivl_statement_type(stmt));
|
|
|
|
|
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is the block name used when a SystemVerilog return is used in a
|
|
|
|
|
* function and the body does not already have an enclosing named block.
|
|
|
|
|
* This is needed since the actual function cannot be disabled.
|
|
|
|
|
*/
|
|
|
|
|
static char *get_func_return_name(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
const char *name_func = ivl_scope_basename(scope);
|
|
|
|
|
const char *name_head = "_ivl_";
|
|
|
|
|
const char *name_tail = "_return";
|
|
|
|
|
char *name_return;
|
|
|
|
|
name_return = (char *)malloc(strlen(name_head) +
|
|
|
|
|
strlen(name_func) +
|
|
|
|
|
strlen(name_tail) + 1);
|
|
|
|
|
name_return[0] = 0;
|
|
|
|
|
(void) strcpy(name_return, name_head);
|
|
|
|
|
(void) strcat(name_return, name_func);
|
|
|
|
|
(void) strcat(name_return, name_tail);
|
|
|
|
|
return name_return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 04:57:53 +01:00
|
|
|
/*
|
|
|
|
|
* This search method may be slow for a large structural design with a
|
|
|
|
|
* large number of gate types. That's not what this converter was built
|
|
|
|
|
* for so this is probably OK. If this becomes an issue then we need a
|
|
|
|
|
* better method/data structure.
|
2013-07-19 19:48:39 +02:00
|
|
|
*/
|
2011-01-14 04:57:53 +01:00
|
|
|
static const char **scopes_emitted = 0;
|
|
|
|
|
static unsigned num_scopes_emitted = 0;
|
|
|
|
|
|
|
|
|
|
static unsigned scope_has_been_emitted(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned idx;
|
|
|
|
|
for (idx = 0; idx < num_scopes_emitted; idx += 1) {
|
|
|
|
|
if (! strcmp(ivl_scope_tname(scope), scopes_emitted[idx])) return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_scope_to_list(ivl_scope_t scope)
|
|
|
|
|
{
|
|
|
|
|
num_scopes_emitted += 1;
|
|
|
|
|
scopes_emitted = realloc(scopes_emitted, num_scopes_emitted *
|
|
|
|
|
sizeof(char *));
|
|
|
|
|
scopes_emitted[num_scopes_emitted-1] = ivl_scope_tname(scope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free_emitted_scope_list()
|
|
|
|
|
{
|
|
|
|
|
free(scopes_emitted);
|
|
|
|
|
scopes_emitted = 0;
|
|
|
|
|
num_scopes_emitted = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A list of module scopes that need to have their definition emitted when
|
|
|
|
|
* the current root scope (module) is finished is kept here.
|
|
|
|
|
*/
|
|
|
|
|
static ivl_scope_t *scopes_to_emit = 0;
|
|
|
|
|
static unsigned num_scopes_to_emit = 0;
|
|
|
|
|
static unsigned emitting_scopes = 0;
|
|
|
|
|
|
2011-01-10 18:30:27 +01:00
|
|
|
int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
|
|
|
|
|
{
|
2013-03-11 18:43:29 +01:00
|
|
|
char *package_name = 0;
|
2011-01-10 18:30:27 +01:00
|
|
|
ivl_scope_type_t sc_type = ivl_scope_type(scope);
|
|
|
|
|
unsigned is_auto = ivl_scope_is_auto(scope);
|
2013-04-15 20:53:07 +02:00
|
|
|
unsigned idx;
|
2011-01-10 18:30:27 +01:00
|
|
|
|
|
|
|
|
/* Output the scope definition. */
|
|
|
|
|
switch (sc_type) {
|
|
|
|
|
case IVL_SCT_MODULE:
|
|
|
|
|
assert(!is_auto);
|
2011-01-14 04:57:53 +01:00
|
|
|
/* This is an instantiation. */
|
|
|
|
|
if (parent) {
|
|
|
|
|
assert(indent != 0);
|
2011-03-11 20:27:54 +01:00
|
|
|
/* If the module has parameters then it may not be unique
|
2011-01-14 04:57:53 +01:00
|
|
|
* so we create a mangled name version instead. */
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "\n%*c", indent, ' ');
|
|
|
|
|
emit_mangled_name(scope, !parent && !emitting_scopes);
|
|
|
|
|
fprintf(vlog_out, " ");
|
|
|
|
|
emit_id(ivl_scope_basename(scope));
|
|
|
|
|
fprintf(vlog_out, "(");
|
|
|
|
|
emit_module_call_expressions(scope);
|
2011-02-10 06:08:29 +01:00
|
|
|
fprintf(vlog_out, ");");
|
|
|
|
|
emit_scope_file_line(scope);
|
|
|
|
|
fprintf(vlog_out, "\n");
|
2011-01-14 04:57:53 +01:00
|
|
|
num_scopes_to_emit += 1;
|
|
|
|
|
scopes_to_emit = realloc(scopes_to_emit, num_scopes_to_emit *
|
|
|
|
|
sizeof(ivl_scope_t));
|
|
|
|
|
scopes_to_emit[num_scopes_to_emit-1] = scope;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-01-10 18:30:27 +01:00
|
|
|
assert(indent == 0);
|
|
|
|
|
/* Set the time scale for this scope. */
|
|
|
|
|
fprintf(vlog_out, "\n`timescale %s/%s\n",
|
|
|
|
|
get_time_const(ivl_scope_time_units(scope)),
|
|
|
|
|
get_time_const(ivl_scope_time_precision(scope)));
|
2011-01-11 18:22:49 +01:00
|
|
|
if (ivl_scope_is_cell(scope)) {
|
|
|
|
|
fprintf(vlog_out, "`celldefine\n");
|
|
|
|
|
}
|
2011-01-28 18:47:16 +01:00
|
|
|
fprintf(vlog_out, "/* This module was originally defined in "
|
|
|
|
|
"file %s at line %u. */\n",
|
|
|
|
|
ivl_scope_def_file(scope),
|
|
|
|
|
ivl_scope_def_lineno(scope));
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "module ");
|
|
|
|
|
emit_mangled_name(scope, !parent && !emitting_scopes);
|
2011-03-07 20:33:22 +01:00
|
|
|
emit_module_ports(scope);
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SCT_FUNCTION:
|
2014-10-13 18:50:42 +02:00
|
|
|
/* Root scope functions have already been emitted. */
|
|
|
|
|
if (! parent) return 0;
|
2011-01-14 04:57:53 +01:00
|
|
|
assert(indent != 0);
|
2011-01-10 18:30:27 +01:00
|
|
|
fprintf(vlog_out, "\n%*cfunction", indent, ' ');
|
2013-07-25 04:39:17 +02:00
|
|
|
if (ivl_scope_ports(scope) < 1) {
|
2013-02-08 02:06:54 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Function (%s) has "
|
2013-07-25 04:39:17 +02:00
|
|
|
"no return value.\n",
|
2013-02-08 02:06:54 +01:00
|
|
|
ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope),
|
|
|
|
|
ivl_scope_tname(scope));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
2011-01-10 18:30:27 +01:00
|
|
|
/* The function return information is the zero port. */
|
|
|
|
|
emit_func_return(ivl_scope_port(scope, 0));
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, " ");
|
|
|
|
|
emit_id(ivl_scope_tname(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
if (is_auto) {
|
2011-01-22 00:33:25 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Automatic functions "
|
|
|
|
|
"(%s) are not supported.\n", ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope), ivl_scope_tname(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IVL_SCT_TASK:
|
2014-10-13 18:50:42 +02:00
|
|
|
/* Root scope tasks have already been emitted. */
|
|
|
|
|
if (! parent) return 0;
|
2011-01-14 04:57:53 +01:00
|
|
|
assert(indent != 0);
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "\n%*ctask ", indent, ' ');
|
|
|
|
|
emit_id(ivl_scope_tname(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
if (is_auto) {
|
2011-01-22 00:33:25 +01:00
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Automatic tasks "
|
|
|
|
|
"(%s) are not supported.\n", ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope), ivl_scope_tname(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
vlog_errors += 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IVL_SCT_BEGIN:
|
|
|
|
|
case IVL_SCT_FORK:
|
2011-01-14 04:57:53 +01:00
|
|
|
assert(indent != 0);
|
2012-01-02 20:28:50 +01:00
|
|
|
emit_named_block_scope(scope);
|
2011-01-10 18:30:27 +01:00
|
|
|
return 0; /* A named begin/fork is handled in line. */
|
2012-08-06 00:03:50 +02:00
|
|
|
case IVL_SCT_GENERATE:
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 sorry: generate scopes are not "
|
|
|
|
|
"currently translated \"%s\".\n",
|
|
|
|
|
ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope),
|
|
|
|
|
ivl_scope_tname(scope));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
return 0;
|
2013-03-07 19:36:33 +01:00
|
|
|
case IVL_SCT_PACKAGE:
|
2013-03-11 18:43:29 +01:00
|
|
|
assert(indent == 0);
|
|
|
|
|
assert(! parent);
|
|
|
|
|
/* Set the time scale for this scope. */
|
|
|
|
|
fprintf(vlog_out, "\n`timescale %s/%s\n",
|
|
|
|
|
get_time_const(ivl_scope_time_units(scope)),
|
|
|
|
|
get_time_const(ivl_scope_time_precision(scope)));
|
|
|
|
|
/* Emit a package as a module with a special name. */
|
|
|
|
|
fprintf(vlog_out, "/* This package (module) was originally "
|
|
|
|
|
"defined in file %s at line %u. */\n",
|
|
|
|
|
ivl_scope_def_file(scope),
|
|
|
|
|
ivl_scope_def_lineno(scope));
|
|
|
|
|
fprintf(vlog_out, "module ");
|
|
|
|
|
package_name = get_package_name(scope);
|
|
|
|
|
emit_id(package_name);
|
|
|
|
|
break;
|
2013-04-17 19:41:39 +02:00
|
|
|
case IVL_SCT_CLASS:
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 sorry: class scopes are not "
|
|
|
|
|
"currently translated \"%s\".\n",
|
|
|
|
|
ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope),
|
|
|
|
|
ivl_scope_tname(scope));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
return 0;
|
2011-01-10 18:30:27 +01:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "%s:%u: vlog95 error: Unsupported scope type "
|
|
|
|
|
"(%d) named: %s.\n", ivl_scope_file(scope),
|
|
|
|
|
ivl_scope_lineno(scope), sc_type,
|
|
|
|
|
ivl_scope_tname(scope));
|
|
|
|
|
vlog_errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-02-10 06:08:29 +01:00
|
|
|
fprintf(vlog_out, ";");
|
|
|
|
|
emit_scope_file_line(scope);
|
|
|
|
|
fprintf(vlog_out, "\n");
|
2011-01-10 18:30:27 +01:00
|
|
|
indent += indent_incr;
|
|
|
|
|
|
2011-01-31 08:53:53 +01:00
|
|
|
/* Output the scope ports for this scope. */
|
2011-03-07 20:33:22 +01:00
|
|
|
if (sc_type == IVL_SCT_MODULE) {
|
|
|
|
|
emit_module_port_defs(scope);
|
|
|
|
|
} else {
|
|
|
|
|
emit_task_func_port_defs(scope);
|
2011-01-10 18:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-31 08:53:53 +01:00
|
|
|
emit_scope_variables(scope);
|
2011-01-10 18:30:27 +01:00
|
|
|
|
2011-01-31 08:53:53 +01:00
|
|
|
if (sc_type == IVL_SCT_MODULE) {
|
2013-07-19 19:48:39 +02:00
|
|
|
unsigned count = ivl_scope_lpms(scope);
|
2011-01-31 08:53:53 +01:00
|
|
|
/* Output the LPM devices. */
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
emit_lpm(scope, ivl_scope_lpm(scope, idx));
|
2011-01-10 18:30:27 +01:00
|
|
|
}
|
2011-01-17 19:51:05 +01:00
|
|
|
|
|
|
|
|
/* Output any logic devices. */
|
|
|
|
|
count = ivl_scope_logs(scope);
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
emit_logic(scope, ivl_scope_log(scope, idx));
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 18:01:59 +01:00
|
|
|
/* Output any switch (logic) devices. */
|
|
|
|
|
count = ivl_scope_switches(scope);
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
emit_tran(scope, ivl_scope_switch(scope, idx));
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 04:29:29 +01:00
|
|
|
/* Output any initial blocks for tasks or functions defined
|
|
|
|
|
* in this module. Used to initialize local variables. */
|
|
|
|
|
ivl_scope_children(scope, (ivl_scope_f*) emit_tf_process, scope);
|
|
|
|
|
|
2011-01-17 19:51:05 +01:00
|
|
|
/* Output the initial/always blocks for this module. */
|
|
|
|
|
ivl_design_process(design, (ivl_process_f)find_process, scope);
|
|
|
|
|
}
|
2011-01-14 04:57:53 +01:00
|
|
|
|
2013-07-19 19:48:39 +02:00
|
|
|
/* Output the function body. */
|
|
|
|
|
if (sc_type == IVL_SCT_FUNCTION) {
|
|
|
|
|
ivl_statement_t body = ivl_scope_def(scope);
|
|
|
|
|
assert(func_rtn_name == 0);
|
|
|
|
|
/* If the function disables itself then that is really a
|
|
|
|
|
* SystemVerilog return statement in disguise. A toplevel
|
|
|
|
|
* named begin is needed to make this work in standard Verilog
|
|
|
|
|
* so add one if it is needed. */
|
|
|
|
|
if (ivl_statement_type(body) == IVL_ST_BLOCK) {
|
|
|
|
|
ivl_scope_t blk_scope = ivl_stmt_block_scope(body);
|
|
|
|
|
if (blk_scope) {
|
|
|
|
|
func_rtn_name = ivl_scope_basename(blk_scope);
|
|
|
|
|
emit_stmt(scope, body);
|
|
|
|
|
func_rtn_name = 0;
|
|
|
|
|
} else if (has_func_disable(scope, body)) {
|
|
|
|
|
char *name_return = get_func_return_name(scope);
|
|
|
|
|
unsigned count = ivl_stmt_block_count(body);
|
|
|
|
|
fprintf(vlog_out, "%*cbegin: %s\n", indent, ' ',
|
|
|
|
|
name_return);
|
|
|
|
|
indent += indent_incr;
|
|
|
|
|
func_rtn_name = name_return;
|
|
|
|
|
for (idx = 0; idx < count; idx += 1) {
|
|
|
|
|
emit_stmt(scope, ivl_stmt_block_stmt(body, idx));
|
|
|
|
|
}
|
|
|
|
|
func_rtn_name = 0;
|
|
|
|
|
indent -= indent_incr;
|
|
|
|
|
fprintf(vlog_out, "%*cend /* %s */\n", indent, ' ',
|
|
|
|
|
name_return);
|
|
|
|
|
free(name_return);
|
|
|
|
|
} else emit_stmt(scope, body);
|
2013-12-20 05:37:55 +01:00
|
|
|
/* A non-block statement may need a named block for a return. */
|
2013-07-19 19:48:39 +02:00
|
|
|
} else if (has_func_disable(scope, body)) {
|
|
|
|
|
char *name_return = get_func_return_name(scope);
|
|
|
|
|
fprintf(vlog_out, "%*cbegin: %s\n", indent, ' ',
|
|
|
|
|
name_return);
|
|
|
|
|
indent += indent_incr;
|
|
|
|
|
func_rtn_name = name_return;
|
|
|
|
|
emit_stmt(scope, body);
|
|
|
|
|
func_rtn_name = 0;
|
|
|
|
|
indent -= indent_incr;
|
|
|
|
|
fprintf(vlog_out, "%*cend /* %s */\n", indent, ' ',
|
|
|
|
|
name_return);
|
|
|
|
|
free(name_return);
|
|
|
|
|
} else emit_stmt(scope, body);
|
2011-01-10 18:30:27 +01:00
|
|
|
}
|
2013-07-19 19:48:39 +02:00
|
|
|
/* Output the task body. */
|
|
|
|
|
if (sc_type == IVL_SCT_TASK) emit_stmt(scope, ivl_scope_def(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
|
2013-02-23 23:24:17 +01:00
|
|
|
/* Print any sub-scopes. */
|
2011-01-10 18:30:27 +01:00
|
|
|
ivl_scope_children(scope, (ivl_scope_f*) emit_scope, scope);
|
|
|
|
|
|
2013-02-23 23:24:17 +01:00
|
|
|
/* And finally print a specify block when needed. */
|
|
|
|
|
if (sc_type == IVL_SCT_MODULE) emit_specify(scope);
|
|
|
|
|
|
2011-01-10 18:30:27 +01:00
|
|
|
/* Output the scope ending. */
|
|
|
|
|
assert(indent >= indent_incr);
|
|
|
|
|
indent -= indent_incr;
|
|
|
|
|
switch (sc_type) {
|
|
|
|
|
case IVL_SCT_MODULE:
|
|
|
|
|
assert(indent == 0);
|
2011-03-14 00:13:39 +01:00
|
|
|
fprintf(vlog_out, "endmodule /* ");
|
|
|
|
|
emit_mangled_name(scope, !parent && !emitting_scopes);
|
|
|
|
|
fprintf(vlog_out, " */\n");
|
2011-01-11 18:22:49 +01:00
|
|
|
if (ivl_scope_is_cell(scope)) {
|
|
|
|
|
fprintf(vlog_out, "`endcelldefine\n");
|
2011-01-14 04:57:53 +01:00
|
|
|
}
|
|
|
|
|
/* If this is a root scope then emit any saved instance scopes.
|
|
|
|
|
* Save any scope that does not have parameters/a mangled name
|
|
|
|
|
* to a list so we don't print duplicate module definitions. */
|
|
|
|
|
if (!emitting_scopes) {
|
|
|
|
|
emitting_scopes = 1;
|
|
|
|
|
for (idx =0; idx < num_scopes_to_emit; idx += 1) {
|
|
|
|
|
ivl_scope_t scope_to_emit = scopes_to_emit[idx];
|
|
|
|
|
if (scope_has_been_emitted(scope_to_emit)) continue;
|
|
|
|
|
(void) emit_scope(scope_to_emit, 0);
|
|
|
|
|
/* If we used a mangled name then the instance is
|
|
|
|
|
* unique so don't add it to the list. */
|
|
|
|
|
if (ivl_scope_params(scope_to_emit)) continue;
|
|
|
|
|
add_scope_to_list(scope_to_emit);
|
|
|
|
|
}
|
|
|
|
|
free(scopes_to_emit);
|
|
|
|
|
scopes_to_emit = 0;
|
|
|
|
|
num_scopes_to_emit = 0;
|
|
|
|
|
emitting_scopes = 0;
|
2011-01-11 18:22:49 +01:00
|
|
|
}
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SCT_FUNCTION:
|
2011-01-13 23:11:41 +01:00
|
|
|
fprintf(vlog_out, "%*cendfunction /* %s */\n", indent, ' ',
|
|
|
|
|
ivl_scope_tname(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
|
|
|
|
case IVL_SCT_TASK:
|
2011-01-13 23:11:41 +01:00
|
|
|
fprintf(vlog_out, "%*cendtask /* %s */\n", indent, ' ',
|
|
|
|
|
ivl_scope_tname(scope));
|
2011-01-10 18:30:27 +01:00
|
|
|
break;
|
2013-03-11 18:43:29 +01:00
|
|
|
case IVL_SCT_PACKAGE:
|
|
|
|
|
fprintf(vlog_out, "endmodule /* ");
|
|
|
|
|
emit_id(package_name);
|
|
|
|
|
free(package_name);
|
|
|
|
|
fprintf(vlog_out, " */\n");
|
|
|
|
|
break;
|
2011-01-10 18:30:27 +01:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|