Skip to content

Commit

Permalink
Support case expression lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Jun 15, 1999
1 parent e699787 commit fabb146
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 39 deletions.
11 changes: 0 additions & 11 deletions README.txt
Expand Up @@ -223,11 +223,6 @@ IVL is in development - as such it still only supports a (growing) subset
of verilog. Below is a description of some of the currently unsupported
verilog features.

- Lvalue bit ranges, i.e. values being assigned to. Examples:

regval [3:1] = 3'b0;
regval [7:0] = 8'b0;

- The "?" operator. Example: count = val ? 1 : 0;

- Ranges within parameter definitions:
Expand Down Expand Up @@ -267,12 +262,6 @@ verilog features.

- Bit ranges within IF. Example: if (a[2:3]) do = 1;

- List of targets for case statement:
Example:
case (a) // Not Okay - 1, 2, and 3 must be separate lines.
1, 2, 3: $write("selected 1, 2, 3 (Not Ok)\n");
endcase

- Forever key word.

- Repeat key word.
Expand Down
9 changes: 5 additions & 4 deletions Statement.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: Statement.cc,v 1.8 1999/06/13 23:51:16 steve Exp $"
#ident "$Id: Statement.cc,v 1.9 1999/06/15 05:38:39 steve Exp $"
#endif

# include "Statement.h"
Expand Down Expand Up @@ -89,10 +89,8 @@ PCase::PCase(PExpr*ex, svector<PCase::Item*>*l)
PCase::~PCase()
{
delete expr_;
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
if ((*items_)[idx]->expr) delete (*items_)[idx]->expr;
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1)
if ((*items_)[idx]->stat) delete (*items_)[idx]->stat;
}

delete[]items_;
}
Expand All @@ -117,6 +115,9 @@ PWhile::~PWhile()

/*
* $Log: Statement.cc,v $
* Revision 1.9 1999/06/15 05:38:39 steve
* Support case expression lists.
*
* Revision 1.8 1999/06/13 23:51:16 steve
* l-value part select for procedural assignments.
*
Expand Down
7 changes: 5 additions & 2 deletions Statement.h
Expand Up @@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: Statement.h,v 1.10 1999/06/13 23:51:16 steve Exp $"
#ident "$Id: Statement.h,v 1.11 1999/06/15 05:38:39 steve Exp $"
#endif

# include <string>
Expand Down Expand Up @@ -180,7 +180,7 @@ class PCase : public Statement {

public:
struct Item {
PExpr*expr;
svector<PExpr*>expr;
Statement*stat;
};

Expand Down Expand Up @@ -301,6 +301,9 @@ class PWhile : public Statement {

/*
* $Log: Statement.h,v $
* Revision 1.11 1999/06/15 05:38:39 steve
* Support case expression lists.
*
* Revision 1.10 1999/06/13 23:51:16 steve
* l-value part select for procedural assignments.
*
Expand Down
57 changes: 48 additions & 9 deletions elaborate.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: elaborate.cc,v 1.44 1999/06/15 03:44:53 steve Exp $"
#ident "$Id: elaborate.cc,v 1.45 1999/06/15 05:38:39 steve Exp $"
#endif

/*
Expand Down Expand Up @@ -1224,6 +1224,9 @@ NetProc* PBlock::elaborate(Design*des, const string&path) const
return cur;
}

/*
* Elaborate a case statement.
*/
NetProc* PCase::elaborate(Design*des, const string&path) const
{
NetExpr*expr = expr_->elaborate_expr(des, path);
Expand All @@ -1233,18 +1236,51 @@ NetProc* PCase::elaborate(Design*des, const string&path) const
return 0;
}

NetCase*res = new NetCase(expr, items_->count());
unsigned icount = 0;
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
PCase::Item*cur = (*items_)[idx];

if (cur->expr.count() == 0)
icount += 1;
else
icount += cur->expr.count();
}

NetCase*res = new NetCase(expr, icount);

unsigned inum = 0;
for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
NetExpr*gu = 0;
NetProc*st = 0;
if ((*items_)[idx]->expr)
gu = (*items_)[idx]->expr->elaborate_expr(des, path);

if ((*items_)[idx]->stat)
st = (*items_)[idx]->stat->elaborate(des, path);
assert(inum < icount);
PCase::Item*cur = (*items_)[idx];

res->set_case(idx, gu, st);
if (cur->expr.count() == 0) {
/* If there are no expressions, then this is the
default case. */
NetProc*st = 0;
if (cur->stat)
st = cur->stat->elaborate(des, path);

res->set_case(inum, 0, st);
inum += 1;

} else for (unsigned e = 0; e < cur->expr.count(); e += 1) {

/* If there are one or more expressions, then
iterate over the guard expressions, elaborating
a separate case for each. (Yes, the statement
will be elaborated again for each.) */
NetExpr*gu = 0;
NetProc*st = 0;
assert(cur->expr[e]);
gu = cur->expr[e]->elaborate_expr(des, path);

if (cur->stat)
st = cur->stat->elaborate(des, path);

res->set_case(inum, gu, st);
inum += 1;
}
}

return res;
Expand Down Expand Up @@ -1527,6 +1563,9 @@ Design* elaborate(const map<string,Module*>&modules,

/*
* $Log: elaborate.cc,v $
* Revision 1.45 1999/06/15 05:38:39 steve
* Support case expression lists.
*
* Revision 1.44 1999/06/15 03:44:53 steve
* Get rid of the STL vector template.
*
Expand Down
10 changes: 3 additions & 7 deletions parse.y
Expand Up @@ -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.41 1999/06/15 02:50:02 steve Exp $"
#ident "$Id: parse.y,v 1.42 1999/06/15 05:38:39 steve Exp $"
#endif

# include "parse_misc.h"
Expand Down Expand Up @@ -153,22 +153,18 @@ source_file
case_item
: expression_list ':' statement_opt
{ PCase::Item*tmp = new PCase::Item;
if ($1->count() > 1) {
yyerror(@1, "Sorry, case expression lists not supported.");
}
tmp->expr = (*$1)[0];
tmp->expr = *$1;
tmp->stat = $3;
delete $1;
$$ = tmp;
}
| K_default ':' statement_opt
{ PCase::Item*tmp = new PCase::Item;
tmp->expr = 0;
tmp->stat = $3;
$$ = tmp;
}
| K_default statement_opt
{ PCase::Item*tmp = new PCase::Item;
tmp->expr = 0;
tmp->stat = $2;
$$ = tmp;
}
Expand Down
24 changes: 18 additions & 6 deletions pform_dump.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: pform_dump.cc,v 1.21 1999/06/15 03:44:53 steve Exp $"
#ident "$Id: pform_dump.cc,v 1.22 1999/06/15 05:38:39 steve Exp $"
#endif

/*
Expand Down Expand Up @@ -310,14 +310,23 @@ void PCase::dump(ostream&out, unsigned ind) const
get_line() << " */" << endl;

for (unsigned idx = 0 ; idx < items_->count() ; idx += 1) {
if ((*items_)[idx]->expr)
out << setw(ind+2) << "" << *(*items_)[idx]->expr << ":";
else
PCase::Item*cur = (*items_)[idx];

if (cur->expr.count() == 0) {
out << setw(ind+2) << "" << "default:";

if ((*items_)[idx]->stat) {
} else {
out << setw(ind+2) << "" << *cur->expr[0];

for(unsigned e = 1 ; e < cur->expr.count() ; e += 1)
out << ", " << *cur->expr[e];

out << ":";
}

if (cur->stat) {
out << endl;
(*items_)[idx]->stat->dump(out, ind+6);
cur->stat->dump(out, ind+6);
} else {
out << " ;" << endl;
}
Expand Down Expand Up @@ -480,6 +489,9 @@ void PUdp::dump(ostream&out) const

/*
* $Log: pform_dump.cc,v $
* Revision 1.22 1999/06/15 05:38:39 steve
* Support case expression lists.
*
* Revision 1.21 1999/06/15 03:44:53 steve
* Get rid of the STL vector template.
*
Expand Down

0 comments on commit fabb146

Please sign in to comment.