Parse OR of event expressions.

This commit is contained in:
steve 1999-04-29 02:16:26 +00:00
parent f01cbc6a57
commit ce49708442
6 changed files with 224 additions and 38 deletions

25
PExpr.h
View File

@ -1,7 +1,7 @@
#ifndef __PExpr_H
#define __PExpr_H
/*
* Copyright (c) 1998 Stephen Williams <steve@icarus.com>
* Copyright (c) 1998-1999 Stephen Williams <steve@icarus.com>
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -19,10 +19,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: PExpr.h,v 1.5 1999/04/19 01:59:36 steve Exp $"
#ident "$Id: PExpr.h,v 1.6 1999/04/29 02:16:26 steve Exp $"
#endif
# include <string>
# include "netlist.h"
# include "verinum.h"
# include "LineInfo.h"
@ -60,6 +61,23 @@ class PExpr : public LineInfo {
ostream& operator << (ostream&, const PExpr&);
class PEEvent : public PExpr {
public:
PEEvent(NetPEvent::Type t, PExpr*e)
: type_(t), expr_(e)
{ }
NetPEvent::Type type() const { return type_; }
PExpr* expr() const { return expr_; }
virtual void dump(ostream&) const;
private:
NetPEvent::Type type_;
PExpr*expr_;
};
class PEIdent : public PExpr {
public:
@ -151,6 +169,9 @@ class PEBinary : public PExpr {
/*
* $Log: PExpr.h,v $
* Revision 1.6 1999/04/29 02:16:26 steve
* Parse OR of event expressions.
*
* Revision 1.5 1999/04/19 01:59:36 steve
* Add memories to the parse and elaboration phases.
*

View File

@ -19,12 +19,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: Statement.h,v 1.6 1999/02/03 04:20:11 steve Exp $"
#ident "$Id: Statement.h,v 1.7 1999/04/29 02:16:26 steve Exp $"
#endif
# include <string>
# include <list>
# include "netlist.h"
# include "svector.h"
# include "PExpr.h"
# include "LineInfo.h"
class PExpr;
class Statement;
@ -212,8 +213,11 @@ class PEventStatement : public Statement {
public:
PEventStatement(NetPEvent::Type t, PExpr*ee)
: type_(t), expr_(ee), statement_(0) { }
PEventStatement(const svector<PEEvent*>&ee)
: expr_(ee), statement_(0) { }
PEventStatement(PEEvent*ee)
: expr_(1), statement_(0) { expr_[0] = ee; }
void set_statement(Statement*st) { statement_ = st; }
@ -221,8 +225,7 @@ class PEventStatement : public Statement {
virtual NetProc* elaborate(Design*des, const string&path) const;
private:
NetPEvent::Type type_;
PExpr*expr_;
svector<PEEvent*>expr_;
Statement*statement_;
};
@ -273,6 +276,9 @@ class PWhile : public Statement {
/*
* $Log: Statement.h,v $
* Revision 1.7 1999/04/29 02:16:26 steve
* Parse OR of event expressions.
*
* Revision 1.6 1999/02/03 04:20:11 steve
* Parse and elaborate the Verilog CASE statement.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998 Stephen Williams (steve@icarus.com)
* Copyright (c) 1998-1999 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -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.20 1999/04/25 00:44:10 steve Exp $"
#ident "$Id: elaborate.cc,v 1.21 1999/04/29 02:16:26 steve Exp $"
#endif
/*
@ -882,12 +882,20 @@ NetProc* PEventStatement::elaborate(Design*des, const string&path) const
return 0;
}
NetPEvent*ev = new NetPEvent(des->local_symbol(path), type_, enet);
if (expr_.count() != 1) {
cerr << get_line() << ": Sorry, unable to elaborate event "
"OR expressions." << endl;
des->errors += 1;
return 0;
}
NetNet*expr = expr_->elaborate_net(des, path);
NetPEvent*ev = new NetPEvent(des->local_symbol(path),
expr_[0]->type(), enet);
NetNet*expr = expr_[0]->expr()->elaborate_net(des, path);
if (expr == 0) {
cerr << get_line() << ": Failed to elaborate expression: ";
expr_->dump(cerr);
expr_[0]->dump(cerr);
cerr << endl;
delete ev;
return 0;
@ -1043,6 +1051,9 @@ Design* elaborate(const map<string,Module*>&modules,
/*
* $Log: elaborate.cc,v $
* Revision 1.21 1999/04/29 02:16:26 steve
* Parse OR of event expressions.
*
* Revision 1.20 1999/04/25 00:44:10 steve
* Core handles subsignal expressions.
*

59
parse.y
View File

@ -1,7 +1,7 @@
%{
/*
* Copyright (c) 1998 Stephen Williams (steve@icarus.com)
* Copyright (c) 1998-1999 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -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.17 1999/04/19 01:59:37 steve Exp $"
#ident "$Id: parse.y,v 1.18 1999/04/29 02:16:26 steve Exp $"
#endif
# include "parse_misc.h"
@ -43,6 +43,8 @@ extern void lex_end_table();
PExpr*expr;
list<PExpr*>*exprs;
svector<PEEvent*>*event_expr;
NetNet::Type nettype;
PGBuiltin::Type gatetype;
NetNet::PortType porttype;
@ -107,7 +109,8 @@ extern void lex_end_table();
%type <gatetype> gatetype
%type <porttype> port_type
%type <event_statement> event_control event_expression
%type <event_expr> event_expression
%type <event_statement> event_control
%type <statement> statement statement_opt
%type <statement_list> statement_list
@ -224,16 +227,48 @@ event_control
$$ = 0;
}
| '@' '(' event_expression ')'
{ $$ = $3;
{ PEventStatement*tmp = new PEventStatement(*$3);
tmp->set_file(@1.text);
tmp->set_lineno(@1.first_line);
delete $3;
$$ = tmp;
}
| '@' '(' error ')'
{ yyerror(@1, "Malformed event control expression.");
$$ = 0;
}
;
event_expression
: K_posedge expression
{ $$ = new PEventStatement(NetPEvent::POSEDGE, $2);
{ PEEvent*tmp = new PEEvent(NetPEvent::POSEDGE, $2);
tmp->set_file(@1.text);
tmp->set_lineno(@1.first_line);
svector<PEEvent*>*tl = new svector<PEEvent*>(1);
(*tl)[0] = tmp;
$$ = tl;
}
| K_negedge expression
{ $$ = new PEventStatement(NetPEvent::NEGEDGE, $2);
{ PEEvent*tmp = new PEEvent(NetPEvent::NEGEDGE, $2);
tmp->set_file(@1.text);
tmp->set_lineno(@1.first_line);
svector<PEEvent*>*tl = new svector<PEEvent*>(1);
(*tl)[0] = tmp;
$$ = tl;
}
| expression
{ PEEvent*tmp = new PEEvent(NetPEvent::ANYEDGE, $1);
tmp->set_file(@1.text);
tmp->set_lineno(@1.first_line);
svector<PEEvent*>*tl = new svector<PEEvent*>(1);
(*tl)[0] = tmp;
$$ = tl;
}
| event_expression K_or event_expression
{ svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
delete $1;
delete $3;
$$ = tmp;
}
;
@ -721,8 +756,13 @@ statement
}
| event_control statement_opt
{ PEventStatement*tmp = $1;
tmp->set_statement($2);
$$ = tmp;
if (tmp == 0) {
yyerror(@1, "Invalid event control.");
$$ = 0;
} else {
tmp->set_statement($2);
$$ = tmp;
}
}
| lvalue '=' expression ';'
{ Statement*tmp = pform_make_assignment($1, $3);
@ -736,7 +776,8 @@ statement
}
| K_wait '(' expression ')' statement_opt
{ PEventStatement*tmp;
tmp = new PEventStatement(NetPEvent::POSITIVE, $3);
PEEvent*etmp = new PEEvent(NetPEvent::POSITIVE, $3);
tmp = new PEventStatement(etmp);
tmp->set_statement($5);
$$ = tmp;
}

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.12 1999/04/19 01:59:37 steve Exp $"
#ident "$Id: pform_dump.cc,v 1.13 1999/04/29 02:16:26 steve Exp $"
#endif
/*
@ -42,6 +42,24 @@ void PExpr::dump(ostream&out) const
out << typeid(*this).name();
}
void PEEvent::dump(ostream&out) const
{
switch (type_) {
case NetPEvent::ANYEDGE:
break;
case NetPEvent::POSEDGE:
out << "posedge ";
break;
case NetPEvent::NEGEDGE:
out << "negedge ";
break;
case NetPEvent::POSITIVE:
out << "positive ";
break;
}
out << *expr_;
}
void PENumber::dump(ostream&out) const
{
out << value();
@ -286,21 +304,13 @@ void PDelayStatement::dump(ostream&out, unsigned ind) const
void PEventStatement::dump(ostream&out, unsigned ind) const
{
out << setw(ind) << "" << "@(";
switch (type_) {
case NetPEvent::ANYEDGE:
break;
case NetPEvent::POSEDGE:
out << "posedge ";
break;
case NetPEvent::NEGEDGE:
out << "negedge ";
break;
case NetPEvent::POSITIVE:
out << "positive ";
break;
}
out << *expr_ << ")";
out << setw(ind) << "" << "@(" << *(expr_[0]);
if (expr_.count() > 1)
for (unsigned idx = 1 ; idx < expr_.count() ; idx += 1)
out << " or " << *(expr_[idx]);
out << ")";
if (statement_) {
out << endl;
@ -424,6 +434,9 @@ void PUdp::dump(ostream&out) const
/*
* $Log: pform_dump.cc,v $
* Revision 1.13 1999/04/29 02:16:26 steve
* Parse OR of event expressions.
*
* Revision 1.12 1999/04/19 01:59:37 steve
* Add memories to the parse and elaboration phases.
*

94
svector.h Normal file
View File

@ -0,0 +1,94 @@
#ifndef __svector_H
#define __svector_H
/*
* Copyright (c) 1999 Picture Elements, Inc.
* Stephen Williams (steve@picturel.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version. In order to redistribute the software in
* binary form, you will need a Picture Elements Binary Software
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
* ---
* You should also have recieved a copy of the Picture Elements
* Binary Software License offer along with the source. This offer
* allows you to obtain the right to redistribute the software in
* binary (compiled) form. If you have not received it, contact
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
*/
#if !defined(WINNT)
#ident "$Id: svector.h,v 1.1 1999/04/29 02:16:26 steve Exp $"
#endif
# include <assert.h>
/*
* This is a way simplified vector class that cannot grow or shrink,
* and is really only able to handle values. It is intended to be
* lighter weight then the STL list class.
*/
template <class TYPE> class svector {
public:
svector(unsigned size) : nitems_(size), items_(new TYPE[size])
{ for (unsigned idx = 0 ; idx < size ; idx += 1)
items_[idx] = 0;
}
svector(const svector<TYPE>&that)
: nitems_(that.nitems_), items_(new TYPE[nitems_])
{ for (unsigned idx = 0 ; idx < that.nitems_ ; idx += 1)
items_[idx] = that[idx];
}
svector(const svector<TYPE>&l, const svector<TYPE>&r)
: nitems_(l.nitems_ + r.nitems_), items_(new TYPE[nitems_])
{ for (unsigned idx = 0 ; idx < l.nitems_ ; idx += 1)
items_[idx] = l[idx];
for (unsigned idx = 0 ; idx < r.nitems_ ; idx += 1)
items_[l.nitems_+idx] = r[idx];
}
~svector() { delete[]items_; }
unsigned count() const { return nitems_; }
TYPE&operator[] (unsigned idx)
{ assert(idx < nitems_);
return items_[idx];
}
TYPE operator[] (unsigned idx) const
{ assert(idx < nitems_);
return items_[idx];
}
private:
unsigned nitems_;
TYPE* items_;
private: // not implemented
svector<TYPE>& operator= (const svector<TYPE>&);
};
/*
* $Log: svector.h,v $
* Revision 1.1 1999/04/29 02:16:26 steve
* Parse OR of event expressions.
*
*/
#endif