vhdlpp: Workaround to make subprograms work as if they were automatic.

This commit is contained in:
Maciej Suminski 2016-03-15 16:03:56 +01:00
parent d6ef813a20
commit 97e31ec9fa
3 changed files with 18 additions and 7 deletions

View File

@ -32,9 +32,21 @@ int SubprogramBody::emit_package(ostream&fd) const
for (map<perm_string,Variable*>::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<perm_string,Variable*>::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_) {

View File

@ -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);

View File

@ -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_;