2 * Copyright (c) 1998-2007 Stephen Williams <steve@icarus.com>
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
36 bool PExpr::is_the_same(const PExpr
*that
) const
38 return typeid(this) == typeid(that
);
41 bool PExpr::is_constant(Module
*) const
46 NetNet
* PExpr::elaborate_lnet(Design
*des
, NetScope
*) const
48 cerr
<< get_fileline() << ": error: expression not valid in assign l-value: "
53 NetNet
* PExpr::elaborate_bi_net(Design
*des
, NetScope
*) const
55 cerr
<< get_fileline() << ": error: "
56 << "expression not valid as argument to inout port: "
61 PEBinary::PEBinary(char op
, PExpr
*l
, PExpr
*r
)
62 : op_(op
), left_(l
), right_(r
)
70 bool PEBinary::is_constant(Module
*mod
) const
72 return left_
->is_constant(mod
) && right_
->is_constant(mod
);
75 PEBComp::PEBComp(char op
, PExpr
*l
, PExpr
*r
)
84 PEBShift::PEBShift(char op
, PExpr
*l
, PExpr
*r
)
93 PECallFunction::PECallFunction(const pform_name_t
&n
, const svector
<PExpr
*> &parms
)
94 : path_(n
), parms_(parms
)
98 static pform_name_t
pn_from_ps(perm_string n
)
100 name_component_t
tmp_name (n
);
102 tmp
.push_back(tmp_name
);
106 PECallFunction::PECallFunction(perm_string n
, const svector
<PExpr
*>&parms
)
107 : path_(pn_from_ps(n
)), parms_(parms
)
111 PECallFunction::PECallFunction(perm_string n
)
112 : path_(pn_from_ps(n
))
116 PECallFunction::~PECallFunction()
120 PEConcat::PEConcat(const svector
<PExpr
*>&p
, PExpr
*r
)
121 : parms_(p
), repeat_(r
)
125 bool PEConcat::is_constant(Module
*mod
) const
127 bool constant
= repeat_
? repeat_
->is_constant(mod
) : true;
128 for (unsigned i
= 0; constant
&& i
< parms_
.count(); ++i
) {
129 constant
= constant
&& parms_
[i
]->is_constant(mod
);
134 PEConcat::~PEConcat()
139 PEEvent::PEEvent(PEEvent::edge_t t
, PExpr
*e
)
148 PEEvent::edge_t
PEEvent::type() const
153 PExpr
* PEEvent::expr() const
158 PEFNumber::PEFNumber(verireal
*v
)
163 PEFNumber::~PEFNumber()
168 const verireal
& PEFNumber::value() const
173 bool PEFNumber::is_constant(Module
*) const
178 PEIdent::PEIdent(const pform_name_t
&that
)
183 PEIdent::PEIdent(perm_string s
)
185 path_
.push_back(name_component_t(s
));
193 * An identifier can be in a constant expression if (and only if) it is
194 * a parameter or genvar.
196 * NOTE: This test does not work if the name is hierarchical!
198 bool PEIdent::is_constant(Module
*mod
) const
200 if (mod
== 0) return false;
203 perm_string tmp
= path_
.back().name
;
205 { map
<perm_string
,Module::param_expr_t
>::const_iterator cur
;
206 cur
= mod
->parameters
.find(tmp
);
207 if (cur
!= mod
->parameters
.end()) return true;
210 { map
<perm_string
,Module::param_expr_t
>::const_iterator cur
;
211 cur
= mod
->localparams
.find(tmp
);
212 if (cur
!= mod
->localparams
.end()) return true;
215 { map
<perm_string
,LineInfo
*>::const_iterator cur
;
216 cur
= mod
->genvars
.find(tmp
);
217 if (cur
!= mod
->genvars
.end()) return true;
223 PENumber::PENumber(verinum
*vp
)
229 PENumber::~PENumber()
234 const verinum
& PENumber::value() const
239 bool PENumber::is_the_same(const PExpr
*that
) const
241 const PENumber
*obj
= dynamic_cast<const PENumber
*>(that
);
245 return *value_
== *obj
->value_
;
248 bool PENumber::is_constant(Module
*) const
253 PEString::PEString(char*s
)
258 PEString::~PEString()
263 string
PEString::value() const
268 bool PEString::is_constant(Module
*) const
273 PETernary::PETernary(PExpr
*e
, PExpr
*t
, PExpr
*f
)
274 : expr_(e
), tru_(t
), fal_(f
)
278 PETernary::~PETernary()
282 bool PETernary::is_constant(Module
*m
) const
284 return expr_
->is_constant(m
)
285 && tru_
->is_constant(m
)
286 && fal_
->is_constant(m
);
289 PEUnary::PEUnary(char op
, PExpr
*ex
)
298 bool PEUnary::is_constant(Module
*m
) const
300 return expr_
->is_constant(m
);