vhdlpp: Fixed automatic variables initalization in subprograms.

This commit is contained in:
Maciej Suminski 2016-03-22 15:49:51 +01:00
parent 4c82352229
commit b7d263462c
4 changed files with 10 additions and 10 deletions

View File

@ -49,7 +49,7 @@ class SubprogramBody : public LineInfo, public ScopeBase {
int emit(ostream&out, Entity*ent, ScopeBase*scope); int emit(ostream&out, Entity*ent, ScopeBase*scope);
// Emit body as it would show up in a package. // 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 write_to_stream(std::ostream&fd) const;
void dump(std::ostream&fd) const; void dump(std::ostream&fd) const;

View File

@ -26,7 +26,7 @@
using namespace std; using namespace std;
int SubprogramBody::emit_package(ostream&fd) const int SubprogramBody::emit_package(ostream&fd)
{ {
int errors = 0; int errors = 0;
@ -34,7 +34,7 @@ int SubprogramBody::emit_package(ostream&fd) const
; cur != new_variables_.end() ; ++cur) { ; cur != new_variables_.end() ; ++cur) {
// Enable reg_flag for variables // Enable reg_flag for variables
cur->second->count_ref_sequ(); 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) // 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()) { if(const Expression*init = var->peek_init_expr()) {
fd << cur->first << " = "; fd << cur->first << " = ";
init->emit(fd, NULL, NULL); init->emit(fd, NULL, this);
fd << "; // automatic function emulation" << endl; fd << "; // automatic function emulation" << endl;
} }
} }

View File

@ -49,7 +49,7 @@ void SigVarBase::type_elaborate_(VType::decl_t&decl)
decl.type = type_; 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; int errors = 0;
@ -63,7 +63,7 @@ int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope)
errors += decl.emit(out, peek_name()); errors += decl.emit(out, peek_name());
const Expression*init_expr = peek_init_expr(); const Expression*init_expr = peek_init_expr();
if (init_expr) { if (initialize && init_expr) {
/* Emit initialization value for wires as a weak assignment */ /* Emit initialization value for wires as a weak assignment */
if(!decl.reg_flag && !type->type_match(&primitive_REAL)) if(!decl.reg_flag && !type->type_match(&primitive_REAL))
out << ";" << endl << "/*init*/ assign (weak1, weak0) " << peek_name(); out << ";" << endl << "/*init*/ assign (weak1, weak0) " << peek_name();
@ -75,7 +75,7 @@ int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope)
return errors; 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; int errors = 0;
@ -85,7 +85,7 @@ int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope)
errors += decl.emit(out, peek_name()); errors += decl.emit(out, peek_name());
const Expression*init_expr = peek_init_expr(); const Expression*init_expr = peek_init_expr();
if (init_expr) { if (initialize && init_expr) {
out << " = "; out << " = ";
init_expr->emit(out, ent, scope); init_expr->emit(out, ent, scope);
} }

View File

@ -70,7 +70,7 @@ class Signal : public SigVarBase {
public: public:
Signal(perm_string name, const VType*type, Expression*init_expr); 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 { class Variable : public SigVarBase {
@ -78,7 +78,7 @@ class Variable : public SigVarBase {
public: public:
Variable(perm_string name, const VType*type, Expression*init_expr = NULL); 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); void write_to_stream(std::ostream&fd);
}; };