From 75631bd8f1c99f765353ca17fa83eb4a75f357ba Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 24 Jun 2008 19:06:06 +0100 Subject: [PATCH] Move is_inital code out of vhdl_process into vhdl_scope Part of tidy up before implementing functions --- tgt-vhdl/process.cc | 2 +- tgt-vhdl/stmt.cc | 15 +++++++++++---- tgt-vhdl/vhdl_syntax.cc | 15 +-------------- tgt-vhdl/vhdl_syntax.hh | 14 +++++++++----- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tgt-vhdl/process.cc b/tgt-vhdl/process.cc index cc6ca855a..5783e71b2 100644 --- a/tgt-vhdl/process.cc +++ b/tgt-vhdl/process.cc @@ -158,7 +158,7 @@ static int generate_vhdl_process(vhdl_entity *ent, ivl_process_t proc) // If this is an initial process, push signal initialisation // into the declarations if (ivl_process_type(proc) == IVL_PR_INITIAL) - vhdl_proc->set_initial(true); + vhdl_proc->get_scope()->set_initializing(true); ivl_statement_t stmt = ivl_process_stmt(proc); int rc = draw_stmt(vhdl_proc, vhdl_proc->get_container(), stmt); diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index 90d63c475..4eb76f421 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -129,6 +129,7 @@ static int draw_nbassign(vhdl_process *proc, stmt_container *container, return 1; vhdl_expr *rhs = rhs_raw->cast(decl->get_type()); + // TODO: CORRECT THIS!!! // If this is an `inital' process and we haven't yet // generated a `wait' statement then this assignment // needs to be moved to the declaration. Otherwise the @@ -139,8 +140,10 @@ static int draw_nbassign(vhdl_process *proc, stmt_container *container, // then use the uninitialized signal value. // The second test ensures that we only try to initialise // internal signals not ports - if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE + if (proc->get_scope()->initializing() + && ivl_signal_port(sig) == IVL_SIP_NONE && rhs->constant()) { + decl->set_initial(rhs); } else { @@ -185,8 +188,11 @@ static int draw_assign(vhdl_process *proc, stmt_container *container, // As with non-blocking assignment, push constant assignments // into the initialisation if we can - if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE - && rhs->constant() && !proc->get_scope()->have_declared(signame)) { + if (proc->get_scope()->initializing() + && ivl_signal_port(sig) == IVL_SIP_NONE + && rhs->constant() + && !proc->get_scope()->have_declared(signame)) { + decl->set_initial(rhs); // This signal may be used e.g. in a loop test so we need @@ -281,7 +287,8 @@ static int draw_delay(vhdl_process *proc, stmt_container *container, // Any further assignments occur after simulation time 0 // so they cannot be used to initialize signal declarations - proc->set_initial(false); + // (if this scope is an initial process) + proc->get_scope()->set_initializing(false); return 0; } diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 770e8db7d..4f07eb0e8 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -26,7 +26,7 @@ #include vhdl_scope::vhdl_scope() - : parent_(NULL) + : parent_(NULL), init_(false) { } @@ -106,12 +106,6 @@ void vhdl_entity::emit(std::ofstream &of, int level) const arch_->emit(of, level); } -vhdl_arch::vhdl_arch(const char *entity, const char *name) - : name_(name), entity_(entity) -{ - -} - vhdl_arch::~vhdl_arch() { delete_children(stmts_); @@ -159,13 +153,6 @@ bool vhdl_arch::have_declared(const std::string &name) const return scope_.have_declared(name); } - -vhdl_process::vhdl_process(const char *name) - : name_(name), initial_(false) -{ - -} - void vhdl_process::add_sensitivity(const char *name) { sens_.push_back(name); diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index 72d9ce2d2..fffc08352 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -517,6 +517,8 @@ private: /* * Contains a list of declarations in a hierarchy. + * A scope can be `initializing' where assignments automatically + * create initial values for declarations. */ class vhdl_scope { public: @@ -531,28 +533,29 @@ public: bool empty() const { return decls_.empty(); } const decl_list_t &get_decls() const { return decls_; } void set_parent(vhdl_scope *p) { parent_ = p; } + + bool initializing() const { return init_; } + void set_initializing(bool i) { init_ = i; } private: decl_list_t decls_; vhdl_scope *parent_; + bool init_; }; class vhdl_process : public vhdl_conc_stmt { public: - vhdl_process(const char *name = ""); + vhdl_process(const char *name = "") : name_(name) {} void emit(std::ofstream &of, int level) const; stmt_container *get_container() { return &stmts_; } void add_sensitivity(const char *name); vhdl_scope *get_scope() { return &scope_; } - void set_initial(bool i) { initial_ = i; } - bool is_initial() const { return initial_; } private: stmt_container stmts_; vhdl_scope scope_; std::string name_; string_list_t sens_; - bool initial_; }; @@ -561,7 +564,8 @@ private: */ class vhdl_arch : public vhdl_element { public: - vhdl_arch(const char *entity, const char *name); + vhdl_arch(const char *entity, const char *name) + : name_(name), entity_(entity) {} virtual ~vhdl_arch(); void emit(std::ofstream &of, int level=0) const;