From 6d0edcf58af6804d967e3ed6b94f338e3e464e94 Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 30 Dec 1999 19:06:14 +0000 Subject: [PATCH] Support reg initial assignment syntax. --- parse.y | 8 +++++--- pform.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++-- pform.h | 7 ++++++- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/parse.y b/parse.y index 0bc08b90a..d47d933b0 100644 --- a/parse.y +++ b/parse.y @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: parse.y,v 1.76 1999/11/15 04:43:52 steve Exp $" +#ident "$Id: parse.y,v 1.77 1999/12/30 19:06:14 steve Exp $" #endif # include "parse_misc.h" @@ -1390,8 +1390,10 @@ register_variable } | IDENTIFIER '=' expression { pform_makewire(@1, $1, NetNet::REG); - yyerror(@2, "error: net declaration assignment to reg/integer not allowed."); - delete $3; + if (! pform_expression_is_constant($3)) + yyerror(@3, "error: register declaration assignment" + " value must be a constant expression."); + pform_make_reginit(@1, $1, $3); $$ = $1; } | IDENTIFIER '[' expression ':' expression ']' diff --git a/pform.cc b/pform.cc index dbaeb9735..9a8b021b3 100644 --- a/pform.cc +++ b/pform.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: pform.cc,v 1.48 1999/12/11 05:45:41 steve Exp $" +#ident "$Id: pform.cc,v 1.49 1999/12/30 19:06:14 steve Exp $" #endif # include "compiler.h" @@ -407,6 +407,46 @@ void pform_make_pgassign_list(svector*alist, } } +/* + * this function makes the initial assignment to a register as given + * in the source. It handles the case where a reg variable is assigned + * where it it declared: + * + * reg foo = ; + * + * This is equivilent to the combination of statements: + * + * reg foo; + * initital foo = ; + * + * and that is how it is parsed. This syntax is not part of the + * IEEE1364-1994 standard, but is approved by OVI as enhancement + * BTF-B14. + */ +void pform_make_reginit(const struct vlltype&li, + const string&name, PExpr*expr) +{ + const string sname = scoped_name(name); + PWire*cur = pform_cur_module->get_wire(sname); + if (cur == 0) { + VLerror(li, "internal error: reginit to non-register?"); + delete expr; + return; + } + + PEIdent*lval = new PEIdent(sname); + lval->set_file(li.text); + lval->set_lineno(li.first_line); + PAssign*ass = new PAssign(lval, expr); + ass->set_file(li.text); + ass->set_lineno(li.first_line); + PProcess*top = new PProcess(PProcess::PR_INITIAL, ass); + top->set_file(li.text); + top->set_lineno(li.first_line); + + pform_cur_module->add_behavior(top); +} + void pform_makewire(const vlltype&li, const string&nm, NetNet::Type type) { @@ -416,7 +456,7 @@ void pform_makewire(const vlltype&li, const string&nm, if (cur->get_wire_type() != NetNet::IMPLICIT) { strstream msg; msg << name << " previously defined at " << - cur->get_line() << "."; + cur->get_line() << "." << ends; VLerror(msg.str()); } else { bool rc = cur->set_wire_type(type); @@ -725,6 +765,9 @@ int pform_parse(const char*path, map&modules, /* * $Log: pform.cc,v $ + * Revision 1.49 1999/12/30 19:06:14 steve + * Support reg initial assignment syntax. + * * Revision 1.48 1999/12/11 05:45:41 steve * Fix support for attaching attributes to primitive gates. * diff --git a/pform.h b/pform.h index 82db4ab65..f9943b723 100644 --- a/pform.h +++ b/pform.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: pform.h,v 1.31 1999/09/10 05:02:09 steve Exp $" +#ident "$Id: pform.h,v 1.32 1999/12/30 19:06:14 steve Exp $" #endif # include "netlist.h" @@ -116,6 +116,8 @@ extern void pform_makewire(const struct vlltype&li, const string&name, NetNet::Type type = NetNet::IMPLICIT); extern void pform_makewire(const struct vlltype&li, const list*names, NetNet::Type type); +extern void pform_make_reginit(const struct vlltype&li, + const string&name, PExpr*expr); extern void pform_set_port_type(list*names, NetNet::PortType); extern void pform_set_net_range(list*names, const svector*); extern void pform_set_reg_idx(const string&name, PExpr*l, PExpr*r); @@ -174,6 +176,9 @@ extern void pform_dump(ostream&out, Module*mod); /* * $Log: pform.h,v $ + * Revision 1.32 1999/12/30 19:06:14 steve + * Support reg initial assignment syntax. + * * Revision 1.31 1999/09/10 05:02:09 steve * Handle integers at task parameters. *