From f81129aa6835541b560b9e2e4e942e1c69bf62fe Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 23 Jun 2008 13:36:28 +0100 Subject: [PATCH] Fix some bugs with blocking assignment --- tgt-vhdl/process.cc | 7 ++++++- tgt-vhdl/stmt.cc | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tgt-vhdl/process.cc b/tgt-vhdl/process.cc index 511dec64c..4d6ac6b8f 100644 --- a/tgt-vhdl/process.cc +++ b/tgt-vhdl/process.cc @@ -123,7 +123,11 @@ void draw_blocking_assigns(vhdl_process *proc, stmt_container *container) rename_signal((*it).second, stripped); } - g_assign_vars.clear(); + // If this this wait is within e.g. an `if' statement then + // we cannot correctly clear the variables list here (since + // they might not be assigned on another path) + if (container == proc->get_container()) + g_assign_vars.clear(); } /* @@ -163,6 +167,7 @@ static int generate_vhdl_process(vhdl_entity *ent, ivl_process_t proc) // Output any remaning blocking assignments draw_blocking_assigns(vhdl_proc, vhdl_proc->get_container()); + g_assign_vars.clear(); // Initial processes are translated to VHDL processes with // no sensitivity list and and indefinite wait statement at diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index 52415715f..6a0f562ba 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -172,7 +172,7 @@ static int draw_assign(vhdl_process *proc, stmt_container *container, 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); + const std::string signame(get_renamed_signal(sig)); vhdl_decl *decl = proc->get_decl(signame); assert(decl); @@ -187,6 +187,19 @@ static int draw_assign(vhdl_process *proc, stmt_container *container, if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE && rhs->constant()) { decl->set_initial(rhs); + + // This signal may be used e.g. in a loop test so we need + // to make a variable as well + blocking_assign_to(proc, sig); + + // The signal may have been renamed by the above call + const std::string &renamed = get_renamed_signal(sig); + + vhdl_var_ref *lval_ref = new vhdl_var_ref(renamed.c_str(), NULL); + vhdl_var_ref *sig_ref = new vhdl_var_ref(signame.c_str(), NULL); + + vhdl_assign_stmt *assign = new vhdl_assign_stmt(lval_ref, sig_ref); + container->add_stmt(assign); } else { blocking_assign_to(proc, sig);