Working function calls

This commit is contained in:
Nick Gasson 2008-06-25 22:15:57 +01:00
parent 2baf31dff8
commit 500442e5c5
4 changed files with 30 additions and 14 deletions

View File

@ -426,6 +426,11 @@ int draw_function(ivl_scope_t scope, ivl_scope_t parent)
rename_signal(sig, signame); rename_signal(sig, signame);
} }
// Non-blocking assignment not allowed in functions
func->get_scope()->set_allow_signal_assignment(false);
draw_stmt(func, func->get_container(), ivl_scope_def(scope));
assert(func); assert(func);
ent->get_arch()->get_scope()->add_decl(func); ent->get_arch()->get_scope()->add_decl(func);
return 0; return 0;

View File

@ -116,6 +116,8 @@ static int draw_nbassign(vhdl_procedural *proc, stmt_container *container,
return 1; return 1;
} }
assert(proc->get_scope()->allow_signal_assignment());
ivl_lval_t lval = ivl_stmt_lval(stmt, 0); ivl_lval_t lval = ivl_stmt_lval(stmt, 0);
ivl_signal_t sig; ivl_signal_t sig;
if ((sig = ivl_lval_sig(lval))) { if ((sig = ivl_lval_sig(lval))) {
@ -201,21 +203,27 @@ static int draw_assign(vhdl_procedural *proc, stmt_container *container,
decl->set_initial(rhs); decl->set_initial(rhs);
// This signal may be used e.g. in a loop test so we need if (proc->get_scope()->allow_signal_assignment()) {
// to make a variable as well // This signal may be used e.g. in a loop test so we need
blocking_assign_to(proc, sig); // to make a variable as well
blocking_assign_to(proc, sig);
// The signal may have been renamed by the above call // The signal may have been renamed by the above call
const std::string &renamed = get_renamed_signal(sig); const std::string &renamed = get_renamed_signal(sig);
vhdl_var_ref *lval_ref = new vhdl_var_ref(renamed.c_str(), NULL); 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_var_ref *sig_ref = new vhdl_var_ref(signame.c_str(), NULL);
vhdl_assign_stmt *assign = new vhdl_assign_stmt(lval_ref, sig_ref); vhdl_assign_stmt *assign = new vhdl_assign_stmt(lval_ref, sig_ref);
container->add_stmt(assign); container->add_stmt(assign);
}
} }
else { else {
blocking_assign_to(proc, sig); if (proc->get_scope()->allow_signal_assignment()) {
// Remember we need to write the variable back to the
// original signal
blocking_assign_to(proc, sig);
}
// The signal may have been renamed by the above call // The signal may have been renamed by the above call
const std::string &renamed = get_renamed_signal(sig); const std::string &renamed = get_renamed_signal(sig);

View File

@ -26,7 +26,7 @@
#include <typeinfo> #include <typeinfo>
vhdl_scope::vhdl_scope() vhdl_scope::vhdl_scope()
: parent_(NULL), init_(false) : parent_(NULL), init_(false), sig_assign_(true)
{ {
} }

View File

@ -547,10 +547,13 @@ public:
bool initializing() const { return init_; } bool initializing() const { return init_; }
void set_initializing(bool i) { init_ = i; } void set_initializing(bool i) { init_ = i; }
void set_allow_signal_assignment(bool b) { sig_assign_ = b; }
bool allow_signal_assignment() const { return sig_assign_; }
private: private:
decl_list_t decls_; decl_list_t decls_;
vhdl_scope *parent_; vhdl_scope *parent_;
bool init_; bool init_, sig_assign_;
}; };