1998-11-04 00:28:49 +01:00
|
|
|
/*
|
2000-02-23 03:56:53 +01:00
|
|
|
* Copyright (c) 1998-1999 Stephen Williams <steve@icarus.com>
|
1998-11-04 00:28:49 +01:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2000-02-23 03:56:53 +01:00
|
|
|
#if !defined(WINNT) && !defined(macintosh)
|
2001-11-08 06:15:50 +01:00
|
|
|
#ident "$Id: PExpr.cc,v 1.27 2001/11/08 05:15:50 steve Exp $"
|
1998-11-04 00:28:49 +01:00
|
|
|
#endif
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
|
|
|
|
|
|
|
|
|
# include <iostream>
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
# include "PExpr.h"
|
1999-05-16 07:08:42 +02:00
|
|
|
# include "Module.h"
|
1998-11-11 01:01:51 +01:00
|
|
|
# include <typeinfo>
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PExpr::PExpr()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
PExpr::~PExpr()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-11 01:01:51 +01:00
|
|
|
bool PExpr::is_the_same(const PExpr*that) const
|
|
|
|
|
{
|
|
|
|
|
return typeid(this) == typeid(that);
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-16 07:08:42 +02:00
|
|
|
bool PExpr::is_constant(Module*) const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-08 06:15:50 +01:00
|
|
|
NetNet* PExpr::elaborate_net(Design*des, NetScope*scope, unsigned,
|
1999-09-15 06:17:52 +02:00
|
|
|
unsigned long,
|
|
|
|
|
unsigned long,
|
2000-05-07 06:37:55 +02:00
|
|
|
unsigned long,
|
|
|
|
|
Link::strength_t,
|
|
|
|
|
Link::strength_t) const
|
1999-09-15 06:17:52 +02:00
|
|
|
{
|
1999-12-31 18:38:37 +01:00
|
|
|
cerr << get_line() << ": error: Unable to elaborate `"
|
|
|
|
|
<< *this << "' as gates." << endl;
|
1999-09-15 06:17:52 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 05:26:46 +01:00
|
|
|
NetNet* PExpr::elaborate_lnet(Design*des, NetScope*) const
|
1999-09-15 06:17:52 +02:00
|
|
|
{
|
1999-12-31 18:38:37 +01:00
|
|
|
cerr << get_line() << ": error: expression not valid in assign l-value: "
|
1999-09-15 06:17:52 +02:00
|
|
|
<< *this << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-06 07:11:55 +01:00
|
|
|
PEBinary::PEBinary(char op, PExpr*l, PExpr*r)
|
|
|
|
|
: op_(op), left_(l), right_(r)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEBinary::~PEBinary()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-16 05:13:29 +02:00
|
|
|
bool PEBinary::is_constant(Module*mod) const
|
|
|
|
|
{
|
|
|
|
|
return left_->is_constant(mod) && right_->is_constant(mod);
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 05:37:58 +02:00
|
|
|
PECallFunction::PECallFunction(const char*n, const svector<PExpr *> &parms)
|
1999-09-25 04:57:29 +02:00
|
|
|
: name_(n), parms_(parms)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 05:37:58 +02:00
|
|
|
PECallFunction::PECallFunction(const char*n)
|
|
|
|
|
: name_(n)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-25 04:57:29 +02:00
|
|
|
PECallFunction::~PECallFunction()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PEConcat::PEConcat(const svector<PExpr*>&p, PExpr*r)
|
|
|
|
|
: parms_(p), repeat_(r)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-22 04:05:20 +02:00
|
|
|
bool PEConcat::is_constant(Module *mod) const
|
|
|
|
|
{
|
1999-09-16 06:18:15 +02:00
|
|
|
bool constant = repeat_? repeat_->is_constant(mod) : true;
|
1999-07-22 04:05:20 +02:00
|
|
|
for (unsigned i = 0; constant && i < parms_.count(); ++i) {
|
|
|
|
|
constant = constant && parms_[i]->is_constant(mod);
|
|
|
|
|
}
|
|
|
|
|
return constant;
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-10 06:03:52 +02:00
|
|
|
PEConcat::~PEConcat()
|
|
|
|
|
{
|
|
|
|
|
delete repeat_;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PEEvent::PEEvent(PEEvent::edge_t t, PExpr*e)
|
2000-04-01 21:31:57 +02:00
|
|
|
: type_(t), expr_(e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEEvent::~PEEvent()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PEEvent::edge_t PEEvent::type() const
|
2000-04-01 21:31:57 +02:00
|
|
|
{
|
|
|
|
|
return type_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PExpr* PEEvent::expr() const
|
|
|
|
|
{
|
|
|
|
|
return expr_;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-10 23:01:35 +01:00
|
|
|
PEFNumber::PEFNumber(verireal*v)
|
|
|
|
|
: value_(v)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEFNumber::~PEFNumber()
|
|
|
|
|
{
|
|
|
|
|
delete value_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const verireal& PEFNumber::value() const
|
|
|
|
|
{
|
|
|
|
|
return *value_;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 00:04:55 +01:00
|
|
|
bool PEFNumber::is_constant(Module*) const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PEIdent::PEIdent(const string&s)
|
|
|
|
|
: text_(s), msb_(0), lsb_(0), idx_(0)
|
2000-04-01 21:31:57 +02:00
|
|
|
{
|
2000-04-12 06:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEIdent::~PEIdent()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string PEIdent::name() const
|
|
|
|
|
{
|
|
|
|
|
return text_;
|
2000-04-01 21:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
1999-05-16 07:08:42 +02:00
|
|
|
/*
|
|
|
|
|
* An identifier can be in a constant expresion if (and only if) it is
|
|
|
|
|
* a parameter.
|
|
|
|
|
*/
|
|
|
|
|
bool PEIdent::is_constant(Module*mod) const
|
|
|
|
|
{
|
2000-03-12 19:22:11 +01:00
|
|
|
map<string,PExpr*>::const_iterator cur;
|
2001-01-12 05:31:27 +01:00
|
|
|
if (mod == 0) return false;
|
2000-03-12 19:22:11 +01:00
|
|
|
|
|
|
|
|
cur = mod->parameters.find(text_);
|
|
|
|
|
if (cur != mod->parameters.end()) return true;
|
|
|
|
|
|
|
|
|
|
cur = mod->localparams.find(text_);
|
|
|
|
|
if (cur != mod->localparams.end()) return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
1999-05-16 07:08:42 +02:00
|
|
|
}
|
|
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PENumber::PENumber(verinum*vp)
|
|
|
|
|
: value_(vp)
|
|
|
|
|
{
|
|
|
|
|
assert(vp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PENumber::~PENumber()
|
|
|
|
|
{
|
|
|
|
|
delete value_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const verinum& PENumber::value() const
|
|
|
|
|
{
|
|
|
|
|
return *value_;
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-11 01:01:51 +01:00
|
|
|
bool PENumber::is_the_same(const PExpr*that) const
|
|
|
|
|
{
|
|
|
|
|
const PENumber*obj = dynamic_cast<const PENumber*>(that);
|
|
|
|
|
if (obj == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return *value_ == *obj->value_;
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-16 07:08:42 +02:00
|
|
|
bool PENumber::is_constant(Module*) const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-12 06:23:57 +02:00
|
|
|
PEString::PEString(const string&s)
|
|
|
|
|
: text_(s)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEString::~PEString()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string PEString::value() const
|
|
|
|
|
{
|
|
|
|
|
return text_;
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-16 07:08:42 +02:00
|
|
|
bool PEString::is_constant(Module*) const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-17 21:50:59 +02:00
|
|
|
PETernary::PETernary(PExpr*e, PExpr*t, PExpr*f)
|
|
|
|
|
: expr_(e), tru_(t), fal_(f)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-10 06:03:52 +02:00
|
|
|
PETernary::~PETernary()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-16 20:03:30 +01:00
|
|
|
bool PETernary::is_constant(Module*m) const
|
1999-07-17 21:50:59 +02:00
|
|
|
{
|
2000-12-16 20:03:30 +01:00
|
|
|
return expr_->is_constant(m)
|
|
|
|
|
&& tru_->is_constant(m)
|
|
|
|
|
&& fal_->is_constant(m);
|
1999-07-17 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
2000-06-30 17:50:20 +02:00
|
|
|
PEUnary::PEUnary(char op, PExpr*ex)
|
|
|
|
|
: op_(op), expr_(ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEUnary::~PEUnary()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PEUnary::is_constant(Module*m) const
|
|
|
|
|
{
|
|
|
|
|
return expr_->is_constant(m);
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
/*
|
|
|
|
|
* $Log: PExpr.cc,v $
|
2001-11-08 06:15:50 +01:00
|
|
|
* Revision 1.27 2001/11/08 05:15:50 steve
|
|
|
|
|
* Remove string paths from PExpr elaboration.
|
|
|
|
|
*
|
2001-11-07 05:26:46 +01:00
|
|
|
* Revision 1.26 2001/11/07 04:26:46 steve
|
|
|
|
|
* elaborate_lnet uses scope instead of string path.
|
|
|
|
|
*
|
2001-11-06 07:11:55 +01:00
|
|
|
* Revision 1.25 2001/11/06 06:11:55 steve
|
|
|
|
|
* Support more real arithmetic in delay constants.
|
|
|
|
|
*
|
2001-07-25 05:10:48 +02:00
|
|
|
* Revision 1.24 2001/07/25 03:10:48 steve
|
|
|
|
|
* Create a config.h.in file to hold all the config
|
|
|
|
|
* junk, and support gcc 3.0. (Stephan Boettcher)
|
|
|
|
|
*
|
2001-01-15 00:04:55 +01:00
|
|
|
* Revision 1.23 2001/01/14 23:04:55 steve
|
|
|
|
|
* Generalize the evaluation of floating point delays, and
|
|
|
|
|
* get it working with delay assignment statements.
|
|
|
|
|
*
|
|
|
|
|
* Allow parameters to be referenced by hierarchical name.
|
|
|
|
|
*
|
2001-01-12 05:31:27 +01:00
|
|
|
* Revision 1.22 2001/01/12 04:31:27 steve
|
|
|
|
|
* Handle error idents in constants not in any scope (PR#97)
|
|
|
|
|
*
|
2000-12-16 20:03:30 +01:00
|
|
|
* Revision 1.21 2000/12/16 19:03:30 steve
|
|
|
|
|
* Evaluate <= and ?: in parameter expressions (PR#81)
|
|
|
|
|
*
|
2000-12-10 23:01:35 +01:00
|
|
|
* Revision 1.20 2000/12/10 22:01:35 steve
|
|
|
|
|
* Support decimal constants in behavioral delays.
|
|
|
|
|
*
|
2000-06-30 17:50:20 +02:00
|
|
|
* Revision 1.19 2000/06/30 15:50:20 steve
|
|
|
|
|
* Allow unary operators in constant expressions.
|
|
|
|
|
*
|
2000-05-07 06:37:55 +02:00
|
|
|
* Revision 1.18 2000/05/07 04:37:55 steve
|
|
|
|
|
* Carry strength values from Verilog source to the
|
|
|
|
|
* pform and netlist for gates.
|
|
|
|
|
*
|
|
|
|
|
* Change vvm constants to use the driver_t to drive
|
|
|
|
|
* a constant value. This works better if there are
|
|
|
|
|
* multiple drivers on a signal.
|
|
|
|
|
*
|
2000-05-04 05:37:58 +02:00
|
|
|
* Revision 1.17 2000/05/04 03:37:58 steve
|
|
|
|
|
* Add infrastructure for system functions, move
|
|
|
|
|
* $time to that structure and add $random.
|
|
|
|
|
*
|
2000-04-12 06:23:57 +02:00
|
|
|
* Revision 1.16 2000/04/12 04:23:57 steve
|
|
|
|
|
* Named events really should be expressed with PEIdent
|
|
|
|
|
* objects in the pform,
|
|
|
|
|
*
|
|
|
|
|
* Handle named events within the mix of net events
|
|
|
|
|
* and edges. As a unified lot they get caught together.
|
|
|
|
|
* wait statements are broken into more complex statements
|
|
|
|
|
* that include a conditional.
|
|
|
|
|
*
|
|
|
|
|
* Do not generate NetPEvent or NetNEvent objects in
|
|
|
|
|
* elaboration. NetEvent, NetEvWait and NetEvProbe
|
|
|
|
|
* take over those functions in the netlist.
|
|
|
|
|
*
|
2000-04-01 21:31:57 +02:00
|
|
|
* Revision 1.15 2000/04/01 19:31:57 steve
|
|
|
|
|
* Named events as far as the pform.
|
|
|
|
|
*
|
2000-03-12 19:22:11 +01:00
|
|
|
* Revision 1.14 2000/03/12 18:22:11 steve
|
|
|
|
|
* Binary and unary operators in parameter expressions.
|
|
|
|
|
*
|
2000-02-23 03:56:53 +01:00
|
|
|
* Revision 1.13 2000/02/23 02:56:53 steve
|
|
|
|
|
* Macintosh compilers do not support ident.
|
|
|
|
|
*
|
1999-12-31 18:38:37 +01:00
|
|
|
* Revision 1.12 1999/12/31 17:38:37 steve
|
|
|
|
|
* Standardize some of the error messages.
|
|
|
|
|
*
|
1999-10-31 05:11:27 +01:00
|
|
|
* Revision 1.11 1999/10/31 04:11:27 steve
|
|
|
|
|
* Add to netlist links pin name and instance number,
|
|
|
|
|
* and arrange in vvm for pin connections by name
|
|
|
|
|
* and instance number.
|
|
|
|
|
*
|
1999-09-25 04:57:29 +02:00
|
|
|
* Revision 1.10 1999/09/25 02:57:29 steve
|
|
|
|
|
* Parse system function calls.
|
|
|
|
|
*
|
1999-09-16 06:18:15 +02:00
|
|
|
* Revision 1.9 1999/09/16 04:18:15 steve
|
|
|
|
|
* elaborate concatenation repeats.
|
|
|
|
|
*
|
1999-09-15 06:17:52 +02:00
|
|
|
* Revision 1.8 1999/09/15 04:17:52 steve
|
|
|
|
|
* separate assign lval elaboration for error checking.
|
|
|
|
|
*
|
1999-07-22 04:05:20 +02:00
|
|
|
* Revision 1.7 1999/07/22 02:05:20 steve
|
|
|
|
|
* is_constant method for PEConcat.
|
|
|
|
|
*
|
1999-07-17 21:50:59 +02:00
|
|
|
* Revision 1.6 1999/07/17 19:50:59 steve
|
|
|
|
|
* netlist support for ternary operator.
|
|
|
|
|
*
|
1999-06-16 05:13:29 +02:00
|
|
|
* Revision 1.5 1999/06/16 03:13:29 steve
|
|
|
|
|
* More syntax parse with sorry stubs.
|
|
|
|
|
*
|
1999-06-10 06:03:52 +02:00
|
|
|
* Revision 1.4 1999/06/10 04:03:52 steve
|
|
|
|
|
* Add support for the Ternary operator,
|
|
|
|
|
* Add support for repeat concatenation,
|
|
|
|
|
* Correct some seg faults cause by elaboration
|
|
|
|
|
* errors,
|
|
|
|
|
* Parse the casex anc casez statements.
|
|
|
|
|
*
|
1999-05-16 07:08:42 +02:00
|
|
|
* Revision 1.3 1999/05/16 05:08:42 steve
|
|
|
|
|
* Redo constant expression detection to happen
|
|
|
|
|
* after parsing.
|
|
|
|
|
*
|
|
|
|
|
* Parse more operators and expressions.
|
|
|
|
|
*
|
1998-11-11 01:01:51 +01:00
|
|
|
* Revision 1.2 1998/11/11 00:01:51 steve
|
|
|
|
|
* Check net ranges in declarations.
|
|
|
|
|
*
|
1998-11-04 00:28:49 +01:00
|
|
|
* Revision 1.1 1998/11/03 23:28:53 steve
|
|
|
|
|
* Introduce verilog to CVS.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|