From d6ef813a20894de2978cdd56e9c2cf6ccbe9bca1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 15 Mar 2016 16:03:43 +0100 Subject: [PATCH 1/5] vhdlpp: Emit subprograms as automatic by default. --- vhdlpp/subprogram_emit.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vhdlpp/subprogram_emit.cc b/vhdlpp/subprogram_emit.cc index 2dab34a89..af25ea3bf 100644 --- a/vhdlpp/subprogram_emit.cc +++ b/vhdlpp/subprogram_emit.cc @@ -54,13 +54,13 @@ int SubprogramHeader::emit_package(ostream&fd) const int errors = 0; if (return_type_) { - fd << "function "; + fd << "function automatic "; return_type_->emit_def(fd, empty_perm_string); } else { - fd << "task"; + fd << "task automatic"; } - fd << " \\" << name_ << " ("; + fd << " \\" << name_ << " ("; for (list::const_iterator cur = ports_->begin() ; cur != ports_->end() ; ++cur) { From 97e31ec9fac70608c4ae9b8ec3453e722626f589 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 15 Mar 2016 16:03:56 +0100 Subject: [PATCH 2/5] vhdlpp: Workaround to make subprograms work as if they were automatic. --- vhdlpp/subprogram_emit.cc | 18 +++++++++++++++--- vhdlpp/vsignal.cc | 4 ++-- vhdlpp/vsignal.h | 3 +-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/vhdlpp/subprogram_emit.cc b/vhdlpp/subprogram_emit.cc index af25ea3bf..0b6f27f11 100644 --- a/vhdlpp/subprogram_emit.cc +++ b/vhdlpp/subprogram_emit.cc @@ -32,9 +32,21 @@ int SubprogramBody::emit_package(ostream&fd) const for (map::const_iterator cur = new_variables_.begin() ; cur != new_variables_.end() ; ++cur) { - // Enable reg_flag for variables - cur->second->count_ref_sequ(); - errors += cur->second->emit(fd, NULL, NULL); + // Enable reg_flag for variables + cur->second->count_ref_sequ(); + errors += cur->second->emit(fd, NULL, NULL); + } + + // Emulate automatic functions (add explicit initial value assignments) + for (map::const_iterator cur = new_variables_.begin() + ; cur != new_variables_.end() ; ++cur) { + Variable*var = cur->second; + + if(const Expression*init = var->peek_init_expr()) { + fd << cur->first << " = "; + init->emit(fd, NULL, NULL); + fd << "; -- automatic function emulation" << endl; + } } if (statements_) { diff --git a/vhdlpp/vsignal.cc b/vhdlpp/vsignal.cc index ab949d7e1..8576c212e 100644 --- a/vhdlpp/vsignal.cc +++ b/vhdlpp/vsignal.cc @@ -62,7 +62,7 @@ int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope) decl.reg_flag = true; errors += decl.emit(out, peek_name()); - Expression*init_expr = peek_init_expr(); + const Expression*init_expr = peek_init_expr(); if (init_expr) { /* Emit initialization value for wires as a weak assignment */ if(!decl.reg_flag && !type->type_match(&primitive_REAL)) @@ -84,7 +84,7 @@ int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope) decl.reg_flag = true; errors += decl.emit(out, peek_name()); - Expression*init_expr = peek_init_expr(); + const Expression*init_expr = peek_init_expr(); if (init_expr) { out << " = "; init_expr->emit(out, ent, scope); diff --git a/vhdlpp/vsignal.h b/vhdlpp/vsignal.h index 9beda6cef..e387d8954 100644 --- a/vhdlpp/vsignal.h +++ b/vhdlpp/vsignal.h @@ -46,14 +46,13 @@ class SigVarBase : public LineInfo { void elaborate(Entity*ent, ScopeBase*scope); perm_string peek_name() const { return name_; } + const Expression* peek_init_expr() const { return init_expr_; } protected: unsigned peek_refcnt_sequ_() const { return refcnt_sequ_; } void type_elaborate_(VType::decl_t&decl); - Expression* peek_init_expr() const { return init_expr_; } - private: perm_string name_; const VType*type_; From 4c82352229dd3b27af5d9e9d5d34f3fc06b6f426 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 15 Mar 2016 17:33:11 +0100 Subject: [PATCH 3/5] vhdlpp: Corrected the comment mark from the previous commit. --- vhdlpp/subprogram_emit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vhdlpp/subprogram_emit.cc b/vhdlpp/subprogram_emit.cc index 0b6f27f11..0a38c58f2 100644 --- a/vhdlpp/subprogram_emit.cc +++ b/vhdlpp/subprogram_emit.cc @@ -45,7 +45,7 @@ int SubprogramBody::emit_package(ostream&fd) const if(const Expression*init = var->peek_init_expr()) { fd << cur->first << " = "; init->emit(fd, NULL, NULL); - fd << "; -- automatic function emulation" << endl; + fd << "; // automatic function emulation" << endl; } } From b7d263462c019e4a291d165a53c522c990b1be6d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 22 Mar 2016 15:49:51 +0100 Subject: [PATCH 4/5] vhdlpp: Fixed automatic variables initalization in subprograms. --- vhdlpp/subprogram.h | 2 +- vhdlpp/subprogram_emit.cc | 6 +++--- vhdlpp/vsignal.cc | 8 ++++---- vhdlpp/vsignal.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vhdlpp/subprogram.h b/vhdlpp/subprogram.h index 82ba804d1..7b4bcceee 100644 --- a/vhdlpp/subprogram.h +++ b/vhdlpp/subprogram.h @@ -49,7 +49,7 @@ class SubprogramBody : public LineInfo, public ScopeBase { int emit(ostream&out, Entity*ent, ScopeBase*scope); // Emit body as it would show up in a package. - int emit_package(std::ostream&fd) const; + int emit_package(std::ostream&fd); void write_to_stream(std::ostream&fd) const; void dump(std::ostream&fd) const; diff --git a/vhdlpp/subprogram_emit.cc b/vhdlpp/subprogram_emit.cc index 0a38c58f2..2d9e4e533 100644 --- a/vhdlpp/subprogram_emit.cc +++ b/vhdlpp/subprogram_emit.cc @@ -26,7 +26,7 @@ using namespace std; -int SubprogramBody::emit_package(ostream&fd) const +int SubprogramBody::emit_package(ostream&fd) { int errors = 0; @@ -34,7 +34,7 @@ int SubprogramBody::emit_package(ostream&fd) const ; cur != new_variables_.end() ; ++cur) { // Enable reg_flag for variables cur->second->count_ref_sequ(); - errors += cur->second->emit(fd, NULL, NULL); + errors += cur->second->emit(fd, NULL, this, false); } // Emulate automatic functions (add explicit initial value assignments) @@ -44,7 +44,7 @@ int SubprogramBody::emit_package(ostream&fd) const if(const Expression*init = var->peek_init_expr()) { fd << cur->first << " = "; - init->emit(fd, NULL, NULL); + init->emit(fd, NULL, this); fd << "; // automatic function emulation" << endl; } } diff --git a/vhdlpp/vsignal.cc b/vhdlpp/vsignal.cc index 8576c212e..5065356e0 100644 --- a/vhdlpp/vsignal.cc +++ b/vhdlpp/vsignal.cc @@ -49,7 +49,7 @@ void SigVarBase::type_elaborate_(VType::decl_t&decl) decl.type = type_; } -int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope) +int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope, bool initialize) { int errors = 0; @@ -63,7 +63,7 @@ int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope) errors += decl.emit(out, peek_name()); const Expression*init_expr = peek_init_expr(); - if (init_expr) { + if (initialize && init_expr) { /* Emit initialization value for wires as a weak assignment */ if(!decl.reg_flag && !type->type_match(&primitive_REAL)) out << ";" << endl << "/*init*/ assign (weak1, weak0) " << peek_name(); @@ -75,7 +75,7 @@ int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope) return errors; } -int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope) +int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope, bool initialize) { int errors = 0; @@ -85,7 +85,7 @@ int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope) errors += decl.emit(out, peek_name()); const Expression*init_expr = peek_init_expr(); - if (init_expr) { + if (initialize && init_expr) { out << " = "; init_expr->emit(out, ent, scope); } diff --git a/vhdlpp/vsignal.h b/vhdlpp/vsignal.h index e387d8954..27de1d778 100644 --- a/vhdlpp/vsignal.h +++ b/vhdlpp/vsignal.h @@ -70,7 +70,7 @@ class Signal : public SigVarBase { public: Signal(perm_string name, const VType*type, Expression*init_expr); - int emit(ostream&out, Entity*ent, ScopeBase*scope); + int emit(ostream&out, Entity*ent, ScopeBase*scope, bool initalize = true); }; class Variable : public SigVarBase { @@ -78,7 +78,7 @@ class Variable : public SigVarBase { public: Variable(perm_string name, const VType*type, Expression*init_expr = NULL); - int emit(ostream&out, Entity*ent, ScopeBase*scope); + int emit(ostream&out, Entity*ent, ScopeBase*scope, bool initialize = true); void write_to_stream(std::ostream&fd); }; From 163a91355916a0c3893a6468e02ee05f285ffce7 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 22 Mar 2016 15:50:09 +0100 Subject: [PATCH 5/5] vhdlpp: Specify lifetime for variables. --- vhdlpp/scope.h | 2 ++ vhdlpp/subprogram.h | 1 + vhdlpp/vsignal.cc | 3 +++ 3 files changed, 6 insertions(+) diff --git a/vhdlpp/scope.h b/vhdlpp/scope.h index 118dbb862..f92a74403 100644 --- a/vhdlpp/scope.h +++ b/vhdlpp/scope.h @@ -67,6 +67,8 @@ class ScopeBase { // type is returned, otherwise NULL. const VTypeEnum* is_enum_name(perm_string name) const; + virtual bool is_subprogram() const { return false; } + // Moves signals, variables and components from another scope to // this one. After the transfer new_* maps are cleared in the source scope. enum transfer_type_t { SIGNALS = 1, VARIABLES = 2, COMPONENTS = 4, ALL = 0xffff }; diff --git a/vhdlpp/subprogram.h b/vhdlpp/subprogram.h index 7b4bcceee..d06f82461 100644 --- a/vhdlpp/subprogram.h +++ b/vhdlpp/subprogram.h @@ -55,6 +55,7 @@ class SubprogramBody : public LineInfo, public ScopeBase { void dump(std::ostream&fd) const; const SubprogramHeader*header() const { return header_; } + bool is_subprogram() const { return true; } private: std::list*statements_; diff --git a/vhdlpp/vsignal.cc b/vhdlpp/vsignal.cc index 5065356e0..5d5eca4ff 100644 --- a/vhdlpp/vsignal.cc +++ b/vhdlpp/vsignal.cc @@ -21,6 +21,7 @@ # include "vsignal.h" # include "expression.h" +# include "scope.h" # include "vtype.h" # include "std_types.h" # include @@ -79,6 +80,8 @@ int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope, bool initialize) { int errors = 0; + out << (!scope->is_subprogram() ? "static " : "automatic "); + VType::decl_t decl; type_elaborate_(decl); decl.reg_flag = true;