Handle while loops.

This commit is contained in:
steve 1998-11-11 03:13:04 +00:00
parent d27f260bc1
commit 6b2fa19429
5 changed files with 56 additions and 7 deletions

View File

@ -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.

View File

@ -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 <string>
@ -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,

View File

@ -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<Module*>&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,

View File

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

View File

@ -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,