From be3c4cf268f97b73df2a84160ebeea6493119def Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 13 Jun 2008 14:10:28 +0100 Subject: [PATCH] Generate signal initial values from `initial' processes --- tgt-vhdl/stmt.cc | 5 ++--- tgt-vhdl/vhdl_syntax.cc | 21 +++++++++++++++++++++ tgt-vhdl/vhdl_syntax.hh | 7 +++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index 1e80d11b4..8d875c4dc 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -198,9 +198,8 @@ static int draw_nbassign(vhdl_process *proc, stmt_container *container, // declaration // The second test ensures that we only try to initialise // internal signals not ports - if (proc->is_initial() - && !proc->get_parent()->get_parent()->get_decl(signame)) { - std::cout << "Pushing " << signame << " init up" << std::endl; + if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE) { + decl->set_initial(rhs); } else { // The type here can be null as it is never actually needed diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index f0248c61e..4d8532c38 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -371,6 +371,15 @@ vhdl_decl::~vhdl_decl() { if (type_ != NULL) delete type_; + if (initial_ != NULL) + delete initial_; +} + +void vhdl_decl::set_initial(vhdl_expr *initial) +{ + if (initial_ != NULL) + delete initial_; + initial_ = initial; } void vhdl_port_decl::emit(std::ofstream &of, int level) const @@ -396,6 +405,12 @@ void vhdl_var_decl::emit(std::ofstream &of, int level) const { of << "variable " << name_ << " : "; type_->emit(of, level); + + if (initial_) { + of << " := "; + initial_->emit(of, level); + } + of << ";"; emit_comment(of, level, true); } @@ -404,6 +419,12 @@ void vhdl_signal_decl::emit(std::ofstream &of, int level) const { of << "signal " << name_ << " : "; type_->emit(of, level); + + if (initial_) { + of << " := "; + initial_->emit(of, level); + } + of << ";"; emit_comment(of, level, true); } diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index 27607d076..3478fbb83 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -314,15 +314,18 @@ private: */ class vhdl_decl : public vhdl_element { public: - vhdl_decl(const char *name, vhdl_type *type=NULL) - : name_(name), type_(type) {} + vhdl_decl(const char *name, vhdl_type *type = NULL, + vhdl_expr *initial = NULL) + : name_(name), type_(type), initial_(initial) {} virtual ~vhdl_decl(); const std::string &get_name() const { return name_; } const vhdl_type *get_type() const { return type_; } + void set_initial(vhdl_expr *initial); protected: std::string name_; vhdl_type *type_; + vhdl_expr *initial_; }; typedef std::list decl_list_t;