1998-11-04 00:28:49 +01:00
|
|
|
/*
|
2007-12-20 18:31:01 +01:00
|
|
|
* Copyright (c) 1998-2007 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
|
|
|
|
|
*/
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-19 04:50:40 +01:00
|
|
|
NetNet* PExpr::elaborate_lnet(Design*des, NetScope*) const
|
1999-09-15 06:17:52 +02:00
|
|
|
{
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: expression not valid in assign l-value: "
|
1999-09-15 06:17:52 +02:00
|
|
|
<< *this << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-06 19:58:16 +02:00
|
|
|
NetNet* PExpr::elaborate_bi_net(Design*des, NetScope*) const
|
|
|
|
|
{
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: "
|
2005-08-06 19:58:16 +02:00
|
|
|
<< "expression not valid as argument to inout port: "
|
|
|
|
|
<< *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);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 06:44:49 +01:00
|
|
|
PEBComp::PEBComp(char op, PExpr*l, PExpr*r)
|
|
|
|
|
: PEBinary(op, l, r)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEBComp::~PEBComp()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEBShift::PEBShift(char op, PExpr*l, PExpr*r)
|
|
|
|
|
: PEBinary(op, l, r)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEBShift::~PEBShift()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
PECallFunction::PECallFunction(const pform_name_t&n, const svector<PExpr *> &parms)
|
2001-12-03 05:47:14 +01:00
|
|
|
: path_(n), parms_(parms)
|
1999-09-25 04:57:29 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
static pform_name_t pn_from_ps(perm_string n)
|
|
|
|
|
{
|
|
|
|
|
name_component_t tmp_name (n);
|
|
|
|
|
pform_name_t tmp;
|
|
|
|
|
tmp.push_back(tmp_name);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PECallFunction::PECallFunction(perm_string n, const svector<PExpr*>&parms)
|
|
|
|
|
: path_(pn_from_ps(n)), parms_(parms)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PECallFunction::PECallFunction(perm_string n)
|
|
|
|
|
: path_(pn_from_ps(n))
|
2000-05-04 05:37:58 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
PEIdent::PEIdent(const pform_name_t&that)
|
|
|
|
|
: path_(that)
|
2000-04-01 21:31:57 +02:00
|
|
|
{
|
2000-04-12 06:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
PEIdent::PEIdent(perm_string s)
|
2000-04-12 06:23:57 +02:00
|
|
|
{
|
2007-05-24 06:07:11 +02:00
|
|
|
path_.push_back(name_component_t(s));
|
2000-04-12 06:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
PEIdent::~PEIdent()
|
2000-04-12 06:23:57 +02:00
|
|
|
{
|
2000-04-01 21:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
1999-05-16 07:08:42 +02:00
|
|
|
/*
|
2003-01-27 06:09:17 +01:00
|
|
|
* An identifier can be in a constant expression if (and only if) it is
|
2008-05-06 05:56:50 +02:00
|
|
|
* a parameter or genvar.
|
2007-05-24 06:07:11 +02:00
|
|
|
*
|
|
|
|
|
* NOTE: This test does not work if the name is hierarchical!
|
1999-05-16 07:08:42 +02:00
|
|
|
*/
|
|
|
|
|
bool PEIdent::is_constant(Module*mod) const
|
|
|
|
|
{
|
2001-01-12 05:31:27 +01:00
|
|
|
if (mod == 0) return false;
|
2000-03-12 19:22:11 +01:00
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
/* */
|
|
|
|
|
perm_string tmp = path_.back().name;
|
2004-02-20 07:22:56 +01:00
|
|
|
|
|
|
|
|
{ map<perm_string,Module::param_expr_t>::const_iterator cur;
|
|
|
|
|
cur = mod->parameters.find(tmp);
|
2001-12-03 05:47:14 +01:00
|
|
|
if (cur != mod->parameters.end()) return true;
|
|
|
|
|
}
|
2000-03-12 19:22:11 +01:00
|
|
|
|
2004-02-20 07:22:56 +01:00
|
|
|
{ map<perm_string,Module::param_expr_t>::const_iterator cur;
|
|
|
|
|
cur = mod->localparams.find(tmp);
|
2001-12-03 05:47:14 +01:00
|
|
|
if (cur != mod->localparams.end()) return true;
|
|
|
|
|
}
|
2000-03-12 19:22:11 +01:00
|
|
|
|
2008-05-06 05:56:50 +02:00
|
|
|
{ map<perm_string,LineInfo*>::const_iterator cur;
|
|
|
|
|
cur = mod->genvars.find(tmp);
|
|
|
|
|
if (cur != mod->genvars.end()) return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-12 19:22:11 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-30 22:32:03 +01:00
|
|
|
PEString::PEString(char*s)
|
2000-04-12 06:23:57 +02:00
|
|
|
: text_(s)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEString::~PEString()
|
|
|
|
|
{
|
2001-12-30 22:32:03 +01:00
|
|
|
delete[]text_;
|
2000-04-12 06:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|