Generate signal initial values from `initial' processes

This commit is contained in:
Nick Gasson 2008-06-13 14:10:28 +01:00
parent 0a8fd50c4a
commit be3c4cf268
3 changed files with 28 additions and 5 deletions

View File

@ -198,9 +198,8 @@ static int draw_nbassign(vhdl_process *proc, stmt_container *container,
// declaration // declaration
// The second test ensures that we only try to initialise // The second test ensures that we only try to initialise
// internal signals not ports // internal signals not ports
if (proc->is_initial() if (proc->is_initial() && ivl_signal_port(sig) == IVL_SIP_NONE) {
&& !proc->get_parent()->get_parent()->get_decl(signame)) { decl->set_initial(rhs);
std::cout << "Pushing " << signame << " init up" << std::endl;
} }
else { else {
// The type here can be null as it is never actually needed // The type here can be null as it is never actually needed

View File

@ -371,6 +371,15 @@ vhdl_decl::~vhdl_decl()
{ {
if (type_ != NULL) if (type_ != NULL)
delete type_; 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 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_ << " : "; of << "variable " << name_ << " : ";
type_->emit(of, level); type_->emit(of, level);
if (initial_) {
of << " := ";
initial_->emit(of, level);
}
of << ";"; of << ";";
emit_comment(of, level, true); emit_comment(of, level, true);
} }
@ -404,6 +419,12 @@ void vhdl_signal_decl::emit(std::ofstream &of, int level) const
{ {
of << "signal " << name_ << " : "; of << "signal " << name_ << " : ";
type_->emit(of, level); type_->emit(of, level);
if (initial_) {
of << " := ";
initial_->emit(of, level);
}
of << ";"; of << ";";
emit_comment(of, level, true); emit_comment(of, level, true);
} }

View File

@ -314,15 +314,18 @@ private:
*/ */
class vhdl_decl : public vhdl_element { class vhdl_decl : public vhdl_element {
public: public:
vhdl_decl(const char *name, vhdl_type *type=NULL) vhdl_decl(const char *name, vhdl_type *type = NULL,
: name_(name), type_(type) {} vhdl_expr *initial = NULL)
: name_(name), type_(type), initial_(initial) {}
virtual ~vhdl_decl(); virtual ~vhdl_decl();
const std::string &get_name() const { return name_; } const std::string &get_name() const { return name_; }
const vhdl_type *get_type() const { return type_; } const vhdl_type *get_type() const { return type_; }
void set_initial(vhdl_expr *initial);
protected: protected:
std::string name_; std::string name_;
vhdl_type *type_; vhdl_type *type_;
vhdl_expr *initial_;
}; };
typedef std::list<vhdl_decl*> decl_list_t; typedef std::list<vhdl_decl*> decl_list_t;