From 6b2fa194292f8f34e484d471b2fed4453dfc8914 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 11 Nov 1998 03:13:04 +0000 Subject: [PATCH] Handle while loops. --- Statement.cc | 11 ++++++++++- Statement.h | 20 +++++++++++++++++++- elaborate.cc | 15 ++++++++++++++- parse.y | 6 +++--- pform_dump.cc | 11 ++++++++++- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Statement.cc b/Statement.cc index d85a16def..3ff826326 100644 --- a/Statement.cc +++ b/Statement.cc @@ -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.2 1998/11/07 17:05:05 steve Exp $" +#ident "$Id: Statement.cc,v 1.3 1998/11/11 03:13:04 steve Exp $" #endif # include "Statement.h" @@ -65,8 +65,17 @@ PCondit::~PCondit() } +PWhile::~PWhile() +{ + delete cond_; + delete statement_; +} + /* * $Log: Statement.cc,v $ + * Revision 1.3 1998/11/11 03:13:04 steve + * Handle while loops. + * * Revision 1.2 1998/11/07 17:05:05 steve * Handle procedural conditional, and some * of the conditional expressions. diff --git a/Statement.h b/Statement.h index 783823a41..eb9b79656 100644 --- a/Statement.h +++ b/Statement.h @@ -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.3 1998/11/09 18:55:33 steve Exp $" +#ident "$Id: Statement.h,v 1.4 1998/11/11 03:13:04 steve Exp $" #endif # include @@ -228,8 +228,26 @@ class PNoop : public Statement { PNoop() { } }; +class PWhile : public Statement { + + public: + PWhile(PExpr*e1, Statement*st) + : cond_(e1), statement_(st) { } + ~PWhile(); + + virtual NetProc* elaborate(Design*des, const string&path) const; + virtual void dump(ostream&out, unsigned ind) const; + + private: + PExpr*cond_; + Statement*statement_; +}; + /* * $Log: Statement.h,v $ + * Revision 1.4 1998/11/11 03:13:04 steve + * Handle while loops. + * * Revision 1.3 1998/11/09 18:55:33 steve * Add procedural while loops, * Parse procedural for loops, diff --git a/elaborate.cc b/elaborate.cc index ca981b64e..9c4ea2efc 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -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.3 1998/11/09 18:55:34 steve Exp $" +#ident "$Id: elaborate.cc,v 1.4 1998/11/11 03:13:04 steve Exp $" #endif /* @@ -612,6 +612,16 @@ NetProc* PForStatement::elaborate(Design*des, const string&path) const return top; } +/* + * The while loop is fairly directly represented in the netlist. + */ +NetProc* PWhile::elaborate(Design*des, const string&path) const +{ + NetWhile*loop = new NetWhile(cond_->elaborate_expr(des, path), + statement_->elaborate(des, path)); + return loop; +} + void Module::elaborate(Design*des, const string&path) const { // Get all the explicitly declared wires of the module and @@ -690,6 +700,9 @@ Design* elaborate(const list&modules, const string&root) /* * $Log: elaborate.cc,v $ + * Revision 1.4 1998/11/11 03:13:04 steve + * Handle while loops. + * * Revision 1.3 1998/11/09 18:55:34 steve * Add procedural while loops, * Parse procedural for loops, diff --git a/parse.y b/parse.y index 6ed8d0a51..260a24416 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.4 1998/11/11 00:01:51 steve Exp $" +#ident "$Id: parse.y,v 1.5 1998/11/11 03:13:04 steve Exp $" #endif # include "parse_misc.h" @@ -554,8 +554,8 @@ statement yyerror(@3, "Incomprehensible for loop."); } | K_while '(' expression ')' statement - { $$ = 0; - yyerror(@1, "Sorry, while loops not implemented."); + { PWhile*tmp = new PWhile($3, $5); + $$ = tmp; } | K_while '(' error ')' statement { $$ = 0; diff --git a/pform_dump.cc b/pform_dump.cc index 2904f138b..29af596b8 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -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.3 1998/11/09 18:55:34 steve Exp $" +#ident "$Id: pform_dump.cc,v 1.4 1998/11/11 03:13:04 steve Exp $" #endif /* @@ -271,6 +271,12 @@ void PForStatement::dump(ostream&out, unsigned ind) const statement_->dump(out, ind+3); } +void PWhile::dump(ostream&out, unsigned ind) const +{ + out << setw(ind) << "" << "while (" << *cond_ << ")" << endl; + statement_->dump(out, ind+3); +} + void PProcess::dump(ostream&out, unsigned ind) const { switch (type_) { @@ -323,6 +329,9 @@ void pform_dump(ostream&out, Module*mod) /* * $Log: pform_dump.cc,v $ + * Revision 1.4 1998/11/11 03:13:04 steve + * Handle while loops. + * * Revision 1.3 1998/11/09 18:55:34 steve * Add procedural while loops, * Parse procedural for loops,