2008-06-03 19:26:36 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL code generation for statements.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
|
|
|
|
|
*
|
|
|
|
|
* 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 "vhdl_target.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2008-06-03 19:44:17 +02:00
|
|
|
#include <cstring>
|
2008-06-04 21:57:15 +02:00
|
|
|
#include <cassert>
|
2008-06-07 15:21:50 +02:00
|
|
|
#include <sstream>
|
2008-06-03 19:44:17 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generate VHDL for the $display system task.
|
2008-06-03 20:14:47 +02:00
|
|
|
* This is implemented using the functions in std.textio. Each
|
|
|
|
|
* parameter is written to a line variable in the process and
|
|
|
|
|
* then the line is written to the special variable `Output'
|
2008-06-03 20:46:10 +02:00
|
|
|
* (which represents the console). Subsequent $displays will
|
|
|
|
|
* use the same line variable.
|
2008-06-03 20:14:47 +02:00
|
|
|
*
|
|
|
|
|
* It's possible, although quite unlikely, that there will be
|
|
|
|
|
* name collision with an existing variable called
|
2008-06-03 20:46:10 +02:00
|
|
|
* `Verilog_Display_Line' -- do something about this?
|
2008-06-03 19:44:17 +02:00
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_stask_display(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-03 19:44:17 +02:00
|
|
|
{
|
2008-06-04 14:52:56 +02:00
|
|
|
// Add the package requirement to the containing entity
|
|
|
|
|
proc->get_parent()->get_parent()->requires_package("std.textio");
|
2008-06-03 20:46:10 +02:00
|
|
|
|
|
|
|
|
const char *display_line = "Verilog_Display_Line";
|
|
|
|
|
|
|
|
|
|
if (!proc->have_declared_var(display_line)) {
|
|
|
|
|
vhdl_var_decl *line_var =
|
2008-06-08 13:48:56 +02:00
|
|
|
new vhdl_var_decl(display_line, vhdl_type::line());
|
2008-06-03 20:46:10 +02:00
|
|
|
line_var->set_comment("For generating $display output");
|
|
|
|
|
proc->add_decl(line_var);
|
|
|
|
|
}
|
2008-06-10 13:21:48 +02:00
|
|
|
|
2008-06-04 16:19:44 +02:00
|
|
|
// Write the data into the line
|
|
|
|
|
int count = ivl_stmt_parm_count(stmt);
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2008-06-04 21:57:15 +02:00
|
|
|
// $display may have an empty parameter, in which case
|
|
|
|
|
// the expression will be null
|
|
|
|
|
// The behaviour here seems to be to output a space
|
|
|
|
|
ivl_expr_t net = ivl_stmt_parm(stmt, i);
|
|
|
|
|
vhdl_expr *e = NULL;
|
|
|
|
|
if (net) {
|
2008-06-07 15:21:50 +02:00
|
|
|
vhdl_expr *base = translate_expr(net);
|
|
|
|
|
if (NULL == base)
|
2008-06-04 21:57:15 +02:00
|
|
|
return 1;
|
2008-06-07 15:21:50 +02:00
|
|
|
|
|
|
|
|
// Need to add a call to Type'Image for types not
|
|
|
|
|
// supported by std.textio
|
2008-06-08 13:48:56 +02:00
|
|
|
if (base->get_type()->get_name() != VHDL_TYPE_STRING) {
|
|
|
|
|
std::string name(base->get_type()->get_string());
|
2008-06-07 15:21:50 +02:00
|
|
|
name += "'Image";
|
|
|
|
|
|
|
|
|
|
vhdl_fcall *cast
|
2008-06-08 13:48:56 +02:00
|
|
|
= new vhdl_fcall(name.c_str(), vhdl_type::string());
|
2008-06-07 15:21:50 +02:00
|
|
|
cast->add_expr(base);
|
|
|
|
|
e = cast;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
e = base;
|
2008-06-04 21:57:15 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
e = new vhdl_const_string(" ");
|
2008-06-04 16:19:44 +02:00
|
|
|
|
|
|
|
|
vhdl_pcall_stmt *write = new vhdl_pcall_stmt("Write");
|
2008-06-07 14:23:21 +02:00
|
|
|
vhdl_var_ref *ref =
|
2008-06-08 13:48:56 +02:00
|
|
|
new vhdl_var_ref(display_line, vhdl_type::line());
|
2008-06-07 14:23:21 +02:00
|
|
|
write->add_expr(ref);
|
2008-06-04 16:19:44 +02:00
|
|
|
write->add_expr(e);
|
|
|
|
|
|
2008-06-11 15:11:37 +02:00
|
|
|
container->add_stmt(write);
|
2008-06-04 16:19:44 +02:00
|
|
|
}
|
2008-06-03 20:46:10 +02:00
|
|
|
|
2008-06-04 14:52:56 +02:00
|
|
|
// WriteLine(Output, Verilog_Display_Line)
|
|
|
|
|
vhdl_pcall_stmt *write_line = new vhdl_pcall_stmt("WriteLine");
|
2008-06-07 14:23:21 +02:00
|
|
|
vhdl_var_ref *output_ref =
|
2008-06-08 13:48:56 +02:00
|
|
|
new vhdl_var_ref("std.textio.Output", new vhdl_type(VHDL_TYPE_FILE));
|
2008-06-07 14:23:21 +02:00
|
|
|
write_line->add_expr(output_ref);
|
|
|
|
|
vhdl_var_ref *ref =
|
2008-06-08 13:48:56 +02:00
|
|
|
new vhdl_var_ref(display_line, vhdl_type::line());
|
2008-06-07 14:23:21 +02:00
|
|
|
write_line->add_expr(ref);
|
2008-06-11 15:11:37 +02:00
|
|
|
container->add_stmt(write_line);
|
2008-06-03 20:14:47 +02:00
|
|
|
|
2008-06-03 19:44:17 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 14:37:21 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL has no real equivalent of Verilog's $finish task. The
|
|
|
|
|
* current solution is to use `assert false ...' to terminate
|
|
|
|
|
* the simulator. This isn't great, as the simulator will
|
|
|
|
|
* return a failure exit code when in fact it completed
|
|
|
|
|
* successfully.
|
2008-06-17 21:16:16 +02:00
|
|
|
*
|
|
|
|
|
* An alternative is to use the VHPI interface supported by
|
|
|
|
|
* some VHDL simulators and implement the $finish funcitonality
|
|
|
|
|
* in C. This function can be enabled with the flag
|
|
|
|
|
* -puse-vhpi-finish=1.
|
2008-06-11 14:37:21 +02:00
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_stask_finish(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-11 14:37:21 +02:00
|
|
|
{
|
2008-06-17 21:16:16 +02:00
|
|
|
const char *use_vhpi = ivl_design_flag(get_vhdl_design(), "use-vhpi-finish");
|
|
|
|
|
if (strcmp(use_vhpi, "1") == 0) {
|
|
|
|
|
proc->get_parent()->get_parent()->requires_package("work.Verilog_Support");
|
|
|
|
|
container->add_stmt(new vhdl_pcall_stmt("work.Verilog_Support.Finish"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
container->add_stmt(new vhdl_assert_stmt("SIMULATION FINISHED"));
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 14:37:21 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-03 19:44:17 +02:00
|
|
|
/*
|
|
|
|
|
* Generate VHDL for system tasks (like $display). Not all of
|
|
|
|
|
* these are supported.
|
|
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_stask(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-03 19:44:17 +02:00
|
|
|
{
|
|
|
|
|
const char *name = ivl_stmt_name(stmt);
|
|
|
|
|
|
|
|
|
|
if (strcmp(name, "$display") == 0)
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_stask_display(proc, container, stmt);
|
2008-06-11 14:37:21 +02:00
|
|
|
else if (strcmp(name, "$finish") == 0)
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_stask_finish(proc, container, stmt);
|
2008-06-03 19:44:17 +02:00
|
|
|
else {
|
|
|
|
|
error("No VHDL translation for system task %s", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-03 19:26:36 +02:00
|
|
|
|
2008-06-04 21:57:15 +02:00
|
|
|
/*
|
|
|
|
|
* Generate VHDL for a block of Verilog statements. This doesn't
|
|
|
|
|
* actually do anything, other than recursively translate the
|
|
|
|
|
* block's statements and add them to the process. This is OK as
|
2008-06-11 15:11:37 +02:00
|
|
|
* the stmt_container class behaves like a Verilog block.
|
2008-06-04 21:57:15 +02:00
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_block(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-04 21:57:15 +02:00
|
|
|
{
|
|
|
|
|
int count = ivl_stmt_block_count(stmt);
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2008-06-11 15:11:37 +02:00
|
|
|
if (draw_stmt(proc, container, ivl_stmt_block_stmt(stmt, i)) != 0)
|
2008-06-04 21:57:15 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-05 14:16:35 +02:00
|
|
|
/*
|
|
|
|
|
* A no-op statement. This corresponds to a `null' statement in
|
|
|
|
|
* VHDL.
|
|
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_noop(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-05 14:16:35 +02:00
|
|
|
{
|
2008-06-11 15:11:37 +02:00
|
|
|
container->add_stmt(new vhdl_null_stmt());
|
2008-06-05 14:16:35 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-18 14:06:27 +02:00
|
|
|
/*
|
|
|
|
|
* A non-blocking assignment inside a process. The semantics for
|
|
|
|
|
* this are essentially the same as VHDL's non-blocking signal
|
|
|
|
|
* assignment.
|
|
|
|
|
*/
|
|
|
|
|
static int draw_nbassign(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt, vhdl_expr *after = NULL)
|
2008-06-06 17:55:45 +02:00
|
|
|
{
|
2008-06-07 15:54:00 +02:00
|
|
|
int nlvals = ivl_stmt_lvals(stmt);
|
|
|
|
|
if (nlvals != 1) {
|
|
|
|
|
error("Can only have 1 lval at the moment (found %d)", nlvals);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivl_lval_t lval = ivl_stmt_lval(stmt, 0);
|
|
|
|
|
ivl_signal_t sig;
|
|
|
|
|
if ((sig = ivl_lval_sig(lval))) {
|
2008-06-13 13:39:18 +02:00
|
|
|
const char *signame = get_renamed_signal(sig).c_str();
|
2008-06-07 15:54:00 +02:00
|
|
|
|
2008-06-07 17:19:10 +02:00
|
|
|
vhdl_decl *decl = proc->get_parent()->get_decl(signame);
|
|
|
|
|
assert(decl);
|
2008-06-07 17:44:01 +02:00
|
|
|
|
|
|
|
|
vhdl_expr *rhs_raw = translate_expr(ivl_stmt_rval(stmt));
|
|
|
|
|
if (NULL == rhs_raw)
|
2008-06-07 15:54:00 +02:00
|
|
|
return 1;
|
2008-06-08 13:48:56 +02:00
|
|
|
vhdl_expr *rhs = rhs_raw->cast(decl->get_type());
|
2008-06-07 15:57:20 +02:00
|
|
|
|
2008-06-13 14:59:48 +02:00
|
|
|
// If this is an `inital' process and we haven't yet
|
2008-06-13 15:47:06 +02:00
|
|
|
// generated a `wait' statement then this assignment
|
|
|
|
|
// needs to be moved to the declaration. Otherwise the
|
|
|
|
|
// Verilog behaviour won't be preserved: VHDL does not
|
|
|
|
|
// distinguish `initial' and `always' processes so an
|
|
|
|
|
// `always' process might be activatated before an
|
|
|
|
|
// `initial' process at time 0. The `always' process may
|
|
|
|
|
// then use the uninitialized signal value.
|
2008-06-13 14:59:48 +02:00
|
|
|
// The second test ensures that we only try to initialise
|
|
|
|
|
// internal signals not ports
|
2008-06-13 15:10:28 +02:00
|
|
|
if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE) {
|
|
|
|
|
decl->set_initial(rhs);
|
2008-06-13 14:59:48 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// The type here can be null as it is never actually needed
|
|
|
|
|
vhdl_var_ref *lval_ref = new vhdl_var_ref(signame, NULL);
|
|
|
|
|
|
2008-06-18 14:06:27 +02:00
|
|
|
vhdl_nbassign_stmt *assign = new vhdl_nbassign_stmt(lval_ref, rhs);
|
2008-06-13 14:59:48 +02:00
|
|
|
if (after != NULL)
|
2008-06-18 13:51:11 +02:00
|
|
|
assign->set_after(after);
|
|
|
|
|
container->add_stmt(assign);
|
2008-06-13 14:59:48 +02:00
|
|
|
}
|
2008-06-07 15:54:00 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
error("Only signals as lvals supported at the moment");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-06 17:55:45 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-18 13:51:11 +02:00
|
|
|
static int draw_assign(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
|
|
|
|
{
|
2008-06-18 14:06:27 +02:00
|
|
|
int nlvals = ivl_stmt_lvals(stmt);
|
|
|
|
|
if (nlvals != 1) {
|
|
|
|
|
error("Can only have 1 lval at the moment (found %d)", nlvals);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivl_lval_t lval = ivl_stmt_lval(stmt, 0);
|
|
|
|
|
ivl_signal_t sig;
|
|
|
|
|
if ((sig = ivl_lval_sig(lval))) {
|
|
|
|
|
const std::string &signame = get_renamed_signal(sig);
|
|
|
|
|
|
|
|
|
|
vhdl_decl *decl = proc->get_decl(signame);
|
|
|
|
|
assert(decl);
|
|
|
|
|
|
|
|
|
|
vhdl_expr *rhs_raw = translate_expr(ivl_stmt_rval(stmt));
|
|
|
|
|
if (NULL == rhs_raw)
|
|
|
|
|
return 1;
|
|
|
|
|
vhdl_expr *rhs = rhs_raw->cast(decl->get_type());
|
|
|
|
|
|
|
|
|
|
// As with non-blocking assignment, push assignments into the
|
|
|
|
|
// initialisation if we can
|
|
|
|
|
if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE) {
|
|
|
|
|
decl->set_initial(rhs);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-06-18 14:30:19 +02:00
|
|
|
blocking_assign_to(proc, sig);
|
|
|
|
|
|
|
|
|
|
// The signal may have been renamed by the above call
|
|
|
|
|
const std::string &renamed = get_renamed_signal(sig);
|
|
|
|
|
|
2008-06-18 14:06:27 +02:00
|
|
|
// The type here can be null as it is never actually needed
|
2008-06-18 14:30:19 +02:00
|
|
|
vhdl_var_ref *lval_ref = new vhdl_var_ref(renamed.c_str(), NULL);
|
2008-06-18 14:06:27 +02:00
|
|
|
|
|
|
|
|
vhdl_assign_stmt *assign = new vhdl_assign_stmt(lval_ref, rhs);
|
|
|
|
|
container->add_stmt(assign);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
error("Only signals as lvals supported at the moment");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-06-18 13:51:11 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-06 17:55:45 +02:00
|
|
|
/*
|
|
|
|
|
* Delay statements are equivalent to the `wait for' form of the
|
|
|
|
|
* VHDL wait statement.
|
|
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_delay(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-06 17:55:45 +02:00
|
|
|
{
|
2008-06-09 13:40:59 +02:00
|
|
|
uint64_t value = ivl_stmt_delay_val(stmt);
|
|
|
|
|
|
|
|
|
|
// This currently ignores the time units and precision
|
|
|
|
|
// of the enclosing scope
|
|
|
|
|
// A neat way to do this would be to make these values
|
|
|
|
|
// constants in the scope (type is Time), and have the
|
|
|
|
|
// VHDL wait statement compute the value from that.
|
|
|
|
|
// The other solution is to add them as parameters to
|
|
|
|
|
// the vhdl_process class
|
2008-06-12 12:24:43 +02:00
|
|
|
vhdl_expr *time = new vhdl_const_int(value);
|
|
|
|
|
|
|
|
|
|
// If the sub-statement is an assignment then VHDL lets
|
|
|
|
|
// us put the delay after it, which is more compact and
|
|
|
|
|
// idiomatic
|
2008-06-09 17:40:32 +02:00
|
|
|
ivl_statement_t sub_stmt = ivl_stmt_sub_stmt(stmt);
|
2008-06-12 12:24:43 +02:00
|
|
|
ivl_statement_type_t type = ivl_statement_type(sub_stmt);
|
|
|
|
|
if (type == IVL_ST_ASSIGN_NB) {
|
|
|
|
|
draw_nbassign(proc, container, sub_stmt, time);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
vhdl_wait_stmt *wait =
|
|
|
|
|
new vhdl_wait_stmt(VHDL_WAIT_FOR_NS, time);
|
|
|
|
|
container->add_stmt(wait);
|
|
|
|
|
|
|
|
|
|
// Expand the sub-statement as well
|
|
|
|
|
// Often this would result in a useless `null' statement which
|
|
|
|
|
// is caught here instead
|
|
|
|
|
if (ivl_statement_type(sub_stmt) != IVL_ST_NOOP)
|
|
|
|
|
draw_stmt(proc, container, sub_stmt);
|
|
|
|
|
}
|
2008-06-09 13:40:59 +02:00
|
|
|
|
2008-06-13 14:59:48 +02:00
|
|
|
// Any further assignments occur after simulation time 0
|
|
|
|
|
// so they cannot be used to initialize signal declarations
|
|
|
|
|
proc->set_initial(false);
|
|
|
|
|
|
2008-06-06 17:55:45 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-13 13:52:20 +02:00
|
|
|
/*
|
|
|
|
|
* Make edge detectors from the signals in `nexus' and add them
|
|
|
|
|
* to the expression `test'. Also adds the signals to the process
|
|
|
|
|
* sensitivity list. Type should be one of `rising_edge' or
|
|
|
|
|
* `falling_edge'.
|
|
|
|
|
*/
|
|
|
|
|
static void edge_detector(ivl_nexus_t nexus, vhdl_process *proc,
|
|
|
|
|
vhdl_binop_expr *test, const char *type)
|
|
|
|
|
{
|
2008-06-16 21:06:06 +02:00
|
|
|
vhdl_var_ref *ref = nexus_to_var_ref(proc->get_parent(), nexus);
|
|
|
|
|
vhdl_fcall *detect = new vhdl_fcall(type, vhdl_type::boolean());
|
|
|
|
|
detect->add_expr(ref);
|
|
|
|
|
test->add_expr(detect);
|
|
|
|
|
proc->add_sensitivity(ref->get_name().c_str());
|
2008-06-13 13:52:20 +02:00
|
|
|
}
|
|
|
|
|
|
2008-06-06 17:55:45 +02:00
|
|
|
/*
|
|
|
|
|
* A wait statement waits for a level change on a @(..) list of
|
2008-06-06 18:36:15 +02:00
|
|
|
* signals.
|
2008-06-06 17:55:45 +02:00
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_wait(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-06 17:55:45 +02:00
|
|
|
{
|
2008-06-12 11:47:52 +02:00
|
|
|
ivl_statement_t sub_stmt = ivl_stmt_sub_stmt(stmt);
|
|
|
|
|
|
2008-06-06 18:36:15 +02:00
|
|
|
int nevents = ivl_stmt_nevent(stmt);
|
|
|
|
|
for (int i = 0; i < nevents; i++) {
|
|
|
|
|
ivl_event_t event = ivl_stmt_events(stmt, i);
|
|
|
|
|
|
2008-06-12 11:36:38 +02:00
|
|
|
// A list of the non-edge triggered signals to they can
|
|
|
|
|
// be added to the edge-detecting `if' statement later
|
|
|
|
|
string_list_t non_edges;
|
2008-06-06 18:36:15 +02:00
|
|
|
|
|
|
|
|
int nany = ivl_event_nany(event);
|
|
|
|
|
for (int i = 0; i < nany; i++) {
|
|
|
|
|
ivl_nexus_t nexus = ivl_event_any(event, i);
|
|
|
|
|
|
|
|
|
|
int nptrs = ivl_nexus_ptrs(nexus);
|
|
|
|
|
for (int j = 0; j < nptrs; j++) {
|
|
|
|
|
ivl_nexus_ptr_t nexus_ptr = ivl_nexus_ptr(nexus, j);
|
|
|
|
|
|
|
|
|
|
ivl_signal_t sig;
|
|
|
|
|
if ((sig = ivl_nexus_ptr_sig(nexus_ptr))) {
|
|
|
|
|
const char *signame = ivl_signal_basename(sig);
|
2008-06-07 12:48:38 +02:00
|
|
|
|
|
|
|
|
// Only add this signal to the sensitivity if it's part
|
|
|
|
|
// of the containing architecture (i.e. it has already
|
|
|
|
|
// been declared)
|
2008-06-12 11:36:38 +02:00
|
|
|
if (proc->get_parent()->have_declared(signame)) {
|
2008-06-07 12:48:38 +02:00
|
|
|
proc->add_sensitivity(signame);
|
2008-06-12 11:36:38 +02:00
|
|
|
non_edges.push_back(signame);
|
2008-06-12 11:47:52 +02:00
|
|
|
break;
|
2008-06-12 11:36:38 +02:00
|
|
|
}
|
2008-06-06 18:36:15 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2008-06-07 12:48:38 +02:00
|
|
|
// Ignore all other types of nexus pointer
|
2008-06-06 18:36:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-06-12 11:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nneg = ivl_event_nneg(event);
|
|
|
|
|
int npos = ivl_event_npos(event);
|
|
|
|
|
if (nneg + npos > 0) {
|
|
|
|
|
vhdl_binop_expr *test =
|
|
|
|
|
new vhdl_binop_expr(VHDL_BINOP_OR, vhdl_type::boolean());
|
|
|
|
|
|
|
|
|
|
// Generate falling_edge(..) calls for each negedge event
|
2008-06-13 13:52:20 +02:00
|
|
|
for (int i = 0; i < nneg; i++)
|
|
|
|
|
edge_detector(ivl_event_neg(event, i), proc, test, "falling_edge");
|
|
|
|
|
|
2008-06-12 11:36:38 +02:00
|
|
|
// Generate rising_edge(..) calls for each posedge event
|
2008-06-13 13:52:20 +02:00
|
|
|
for (int i = 0; i < npos; i++)
|
|
|
|
|
edge_detector(ivl_event_pos(event, i), proc, test, "rising_edge");
|
|
|
|
|
|
2008-06-12 11:36:38 +02:00
|
|
|
// Add Name'Event terms for each non-edge-triggered signal
|
|
|
|
|
string_list_t::iterator it;
|
|
|
|
|
for (it = non_edges.begin(); it != non_edges.end(); ++it) {
|
|
|
|
|
test->add_expr
|
|
|
|
|
(new vhdl_var_ref((*it + "'Event").c_str(),
|
|
|
|
|
vhdl_type::boolean()));
|
|
|
|
|
}
|
2008-06-12 11:47:52 +02:00
|
|
|
|
|
|
|
|
vhdl_if_stmt *edge_det = new vhdl_if_stmt(test);
|
|
|
|
|
container->add_stmt(edge_det);
|
2008-06-12 11:36:38 +02:00
|
|
|
|
2008-06-12 11:47:52 +02:00
|
|
|
draw_stmt(proc, edge_det->get_then_container(), sub_stmt);
|
2008-06-12 11:36:38 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Don't bother generating an edge detector if there
|
|
|
|
|
// are no edge-triggered events
|
2008-06-12 11:47:52 +02:00
|
|
|
draw_stmt(proc, container, sub_stmt);
|
2008-06-12 11:36:38 +02:00
|
|
|
}
|
2008-06-06 18:36:15 +02:00
|
|
|
}
|
|
|
|
|
|
2008-06-06 17:55:45 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 15:11:37 +02:00
|
|
|
static int draw_if(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
|
|
|
|
{
|
2008-06-11 15:20:05 +02:00
|
|
|
vhdl_expr *test = translate_expr(ivl_stmt_cond_expr(stmt));
|
|
|
|
|
if (NULL == test)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
vhdl_if_stmt *vhdif = new vhdl_if_stmt(test);
|
|
|
|
|
|
|
|
|
|
draw_stmt(proc, vhdif->get_then_container(),
|
|
|
|
|
ivl_stmt_cond_true(stmt));
|
2008-06-16 13:13:01 +02:00
|
|
|
|
|
|
|
|
ivl_statement_t cond_false_stmt = ivl_stmt_cond_false(stmt);
|
|
|
|
|
if (cond_false_stmt)
|
|
|
|
|
draw_stmt(proc, vhdif->get_else_container(), cond_false_stmt);
|
2008-06-11 15:20:05 +02:00
|
|
|
|
|
|
|
|
container->add_stmt(vhdif);
|
|
|
|
|
|
2008-06-11 15:11:37 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-03 19:26:36 +02:00
|
|
|
/*
|
|
|
|
|
* Generate VHDL statements for the given Verilog statement and
|
2008-06-11 15:11:37 +02:00
|
|
|
* add them to the given VHDL process. The container is the
|
|
|
|
|
* location to add statements: e.g. the process body, a branch
|
|
|
|
|
* of an if statement, etc.
|
2008-06-03 19:26:36 +02:00
|
|
|
*/
|
2008-06-11 15:11:37 +02:00
|
|
|
int draw_stmt(vhdl_process *proc, stmt_container *container,
|
|
|
|
|
ivl_statement_t stmt)
|
2008-06-03 19:26:36 +02:00
|
|
|
{
|
2008-06-03 19:44:17 +02:00
|
|
|
switch (ivl_statement_type(stmt)) {
|
|
|
|
|
case IVL_ST_STASK:
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_stask(proc, container, stmt);
|
2008-06-04 21:57:15 +02:00
|
|
|
case IVL_ST_BLOCK:
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_block(proc, container, stmt);
|
2008-06-05 14:16:35 +02:00
|
|
|
case IVL_ST_NOOP:
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_noop(proc, container, stmt);
|
2008-06-18 13:51:11 +02:00
|
|
|
case IVL_ST_ASSIGN:
|
|
|
|
|
return draw_assign(proc, container, stmt);
|
2008-06-06 17:55:45 +02:00
|
|
|
case IVL_ST_ASSIGN_NB:
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_nbassign(proc, container, stmt);
|
2008-06-06 17:55:45 +02:00
|
|
|
case IVL_ST_DELAY:
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_delay(proc, container, stmt);
|
2008-06-06 17:55:45 +02:00
|
|
|
case IVL_ST_WAIT:
|
2008-06-11 15:11:37 +02:00
|
|
|
return draw_wait(proc, container, stmt);
|
|
|
|
|
case IVL_ST_CONDIT:
|
|
|
|
|
return draw_if(proc, container, stmt);
|
2008-06-03 19:44:17 +02:00
|
|
|
default:
|
|
|
|
|
error("No VHDL translation for statement at %s:%d (type = %d)",
|
|
|
|
|
ivl_stmt_file(stmt), ivl_stmt_lineno(stmt),
|
|
|
|
|
ivl_statement_type(stmt));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-06-03 19:26:36 +02:00
|
|
|
}
|