2000-03-08 05:36:53 +01:00
|
|
|
/*
|
2008-02-27 20:34:51 +01:00
|
|
|
* Copyright (c) 2000-2008 Stephen Williams (steve@icarus.com)
|
2000-03-08 05:36:53 +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"
|
|
|
|
|
|
2000-03-08 05:36:53 +01:00
|
|
|
# include "PExpr.h"
|
2004-02-20 07:22:56 +01:00
|
|
|
# include "compiler.h"
|
2001-01-15 00:04:55 +01:00
|
|
|
# include "util.h"
|
2007-06-02 05:42:12 +02:00
|
|
|
# include "netmisc.h"
|
2000-03-08 05:36:53 +01:00
|
|
|
|
2008-01-05 00:23:47 +01:00
|
|
|
# include <cstdlib>
|
2001-07-25 05:10:48 +02:00
|
|
|
# include <iostream>
|
2007-07-22 02:47:37 +02:00
|
|
|
# include "ivl_assert.h"
|
2001-07-25 05:10:48 +02:00
|
|
|
|
2000-03-08 05:36:53 +01:00
|
|
|
NetExpr*PExpr::elaborate_pexpr(Design*des, NetScope*sc) const
|
|
|
|
|
{
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: invalid parameter expression: "
|
2000-03-08 05:36:53 +01:00
|
|
|
<< *this << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-12 19:22:11 +01:00
|
|
|
/*
|
|
|
|
|
* Binary operators have sub-expressions that must be elaborated as
|
|
|
|
|
* parameter expressions. If either of them fail, then give up. Once
|
|
|
|
|
* they are taken care of, make the base object just as in any other
|
|
|
|
|
* expression.
|
|
|
|
|
*/
|
|
|
|
|
NetExpr*PEBinary::elaborate_pexpr (Design*des, NetScope*scope) const
|
|
|
|
|
{
|
|
|
|
|
NetExpr*lp = left_->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*rp = right_->elaborate_pexpr(des, scope);
|
|
|
|
|
if ((lp == 0) || (rp == 0)) {
|
|
|
|
|
delete lp;
|
|
|
|
|
delete rp;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 20:23:24 +02:00
|
|
|
NetExpr*tmp = elaborate_expr_base_(des, lp, rp, -2);
|
2000-03-12 19:22:11 +01:00
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-30 03:34:44 +01:00
|
|
|
NetExpr*PEBComp::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
|
|
|
|
NetExpr*lp = left_->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*rp = right_->elaborate_pexpr(des, scope);
|
|
|
|
|
if ((lp == 0) || (rp == 0)) {
|
|
|
|
|
delete lp;
|
|
|
|
|
delete rp;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suppress_binary_operand_sign_if_needed_(lp, rp);
|
|
|
|
|
|
|
|
|
|
NetEBComp*tmp = new NetEBComp(op_, lp, rp);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
bool flag = tmp->set_width(1);
|
|
|
|
|
if (flag == false) {
|
|
|
|
|
cerr << get_fileline() << ": internal error: "
|
|
|
|
|
"expression bit width of comparison != 1." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-30 04:31:26 +01:00
|
|
|
NetExpr*PEBLogic::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
|
|
|
|
NetExpr*lp = left_->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*rp = right_->elaborate_pexpr(des, scope);
|
|
|
|
|
if ((lp == 0) || (rp == 0)) {
|
|
|
|
|
delete lp;
|
|
|
|
|
delete rp;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetEBLogic*tmp = new NetEBLogic(op_, lp, rp);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
bool flag = tmp->set_width(1);
|
|
|
|
|
if (flag == false) {
|
|
|
|
|
cerr << get_fileline() << ": internal error: "
|
|
|
|
|
"expression bit width of comparison != 1." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-13 07:22:16 +02:00
|
|
|
/*
|
|
|
|
|
* Event though parameters are not generally sized, parameter
|
|
|
|
|
* expressions can include concatenation expressions. This requires
|
|
|
|
|
* that the subexpressions all have well-defined size (in spite of
|
|
|
|
|
* being in a parameter expression) in order to get a defined
|
2003-01-27 06:09:17 +01:00
|
|
|
* value. The sub-expressions themselves must also be value parameter
|
2000-06-13 07:22:16 +02:00
|
|
|
* expressions.
|
|
|
|
|
*/
|
|
|
|
|
NetEConcat* PEConcat::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
2002-05-05 23:11:49 +02:00
|
|
|
NetExpr* repeat = 0;
|
2000-06-13 07:22:16 +02:00
|
|
|
|
|
|
|
|
/* If there is a repeat expression, then evaluate the constant
|
2002-05-05 23:11:49 +02:00
|
|
|
value and set the repeat count. */
|
2000-06-13 07:22:16 +02:00
|
|
|
if (repeat_) {
|
2002-05-05 23:11:49 +02:00
|
|
|
repeat = repeat_->elaborate_pexpr(des, scope);
|
|
|
|
|
if (repeat == 0) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: "
|
2000-06-13 07:22:16 +02:00
|
|
|
"concatenation repeat expression cannot be evaluated."
|
|
|
|
|
<< endl;
|
|
|
|
|
des->errors += 1;
|
2008-03-08 03:51:50 +01:00
|
|
|
return 0;
|
2000-06-13 07:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
2002-05-05 23:11:49 +02:00
|
|
|
/* continue on even if the repeat expression doesn't
|
|
|
|
|
work, as we can find more errors. */
|
2000-06-13 07:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make the empty concat expression. */
|
|
|
|
|
NetEConcat*tmp = new NetEConcat(parms_.count(), repeat);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
|
|
|
|
|
/* Elaborate all the operands and attach them to the concat
|
|
|
|
|
node. Use the elaborate_pexpr method instead of the
|
|
|
|
|
elaborate_expr method. */
|
|
|
|
|
for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1) {
|
|
|
|
|
assert(parms_[idx]);
|
|
|
|
|
NetExpr*ex = parms_[idx]->elaborate_pexpr(des, scope);
|
|
|
|
|
if (ex == 0) continue;
|
2001-10-07 05:38:08 +02:00
|
|
|
|
2000-06-13 07:22:16 +02:00
|
|
|
ex->set_line(*parms_[idx]);
|
2001-10-07 05:38:08 +02:00
|
|
|
|
2002-05-06 04:30:27 +02:00
|
|
|
if (dynamic_cast<NetEParam*>(ex)) {
|
|
|
|
|
|
|
|
|
|
/* If this parameter is a NetEParam, then put off
|
|
|
|
|
the width check for later. */
|
|
|
|
|
|
|
|
|
|
} else if (! ex->has_width()) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << ex->get_fileline() << ": error: operand of "
|
2001-10-07 05:38:08 +02:00
|
|
|
<< "concatenation has indefinite width: "
|
|
|
|
|
<< *ex << endl;
|
|
|
|
|
des->errors += 1;
|
2008-03-08 03:51:50 +01:00
|
|
|
delete tmp;
|
|
|
|
|
return 0;
|
2001-10-07 05:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
2000-06-13 07:22:16 +02:00
|
|
|
tmp->set(idx, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 00:04:55 +01:00
|
|
|
NetExpr*PEFNumber::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
2006-06-02 06:48:49 +02:00
|
|
|
return elaborate_expr(des, scope, -1, false);
|
2001-01-15 00:04:55 +01:00
|
|
|
}
|
|
|
|
|
|
2000-03-12 05:35:22 +01:00
|
|
|
/*
|
|
|
|
|
* Parameter expressions may reference other parameters, but only in
|
|
|
|
|
* the current scope. Preserve the parameter reference in the
|
|
|
|
|
* parameter expression I'm generating, instead of evaluating it now,
|
|
|
|
|
* because the referenced parameter may yet be overridden.
|
|
|
|
|
*/
|
|
|
|
|
NetExpr*PEIdent::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
2008-10-13 18:51:05 +02:00
|
|
|
pform_name_t oldpath = path_;
|
2007-05-24 06:07:11 +02:00
|
|
|
name_component_t name_tail = path_.back();
|
2008-10-13 18:51:05 +02:00
|
|
|
oldpath.pop_back();
|
2001-01-15 00:04:55 +01:00
|
|
|
|
|
|
|
|
NetScope*pscope = scope;
|
2007-06-02 05:42:12 +02:00
|
|
|
if (path_.size() > 0) {
|
2008-10-13 18:51:05 +02:00
|
|
|
list<hname_t> tmp = eval_scope_path(des, scope, oldpath);
|
2007-06-02 05:42:12 +02:00
|
|
|
pscope = des->find_scope(scope, tmp);
|
|
|
|
|
}
|
2001-01-15 00:04:55 +01:00
|
|
|
|
2005-11-27 06:56:20 +01:00
|
|
|
const NetExpr*ex_msb;
|
|
|
|
|
const NetExpr*ex_lsb;
|
2007-07-22 02:47:37 +02:00
|
|
|
const NetExpr*ex = 0;
|
|
|
|
|
// Look up the parameter name in the current scope. If the
|
|
|
|
|
// name is not found in the pscope, look in containing scopes,
|
|
|
|
|
// but do not go outside the containing module instance.
|
|
|
|
|
for (;;) {
|
|
|
|
|
ex = pscope->get_parameter(name_tail.name, ex_msb, ex_lsb);
|
|
|
|
|
if (ex != 0)
|
|
|
|
|
break;
|
|
|
|
|
if (pscope->type() == NetScope::MODULE)
|
|
|
|
|
break;
|
|
|
|
|
pscope = pscope->parent();
|
|
|
|
|
ivl_assert(*this, pscope);
|
|
|
|
|
}
|
2000-03-12 05:35:22 +01:00
|
|
|
if (ex == 0) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": error: identifier ``" << name_tail.name <<
|
2007-06-02 05:42:12 +02:00
|
|
|
"'' is not a parameter in "<< scope_path(scope)<< "." << endl;
|
2000-03-12 05:35:22 +01:00
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
NetExpr*res = new NetEParam(des, pscope, name_tail.name);
|
2003-05-30 04:55:32 +02:00
|
|
|
res->set_line(*this);
|
2002-12-05 03:14:33 +01:00
|
|
|
assert(res);
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
index_component_t::ctype_t use_sel = index_component_t::SEL_NONE;
|
|
|
|
|
if (!name_tail.index.empty())
|
|
|
|
|
use_sel = name_tail.index.back().sel;
|
|
|
|
|
|
|
|
|
|
switch (use_sel) {
|
|
|
|
|
case index_component_t::SEL_NONE:
|
|
|
|
|
break;
|
2008-03-08 03:51:50 +01:00
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
default:
|
|
|
|
|
case index_component_t::SEL_PART:
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << get_fileline() << ": sorry: Cannot part select "
|
2008-03-08 03:51:50 +01:00
|
|
|
"bits of parameters." << endl;
|
2002-01-28 01:52:41 +01:00
|
|
|
des->errors += 1;
|
2008-03-08 03:51:50 +01:00
|
|
|
delete res;
|
|
|
|
|
return 0;
|
2002-12-05 03:14:33 +01:00
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
case index_component_t::SEL_BIT:
|
2002-12-05 03:14:33 +01:00
|
|
|
|
|
|
|
|
/* We have here a bit select. Insert a NetESelect node
|
|
|
|
|
to handle it. */
|
2007-05-24 06:07:11 +02:00
|
|
|
NetExpr*tmp = name_tail.index.back().msb->elaborate_pexpr(des, scope);
|
2008-03-08 03:51:50 +01:00
|
|
|
if (tmp == 0) {
|
|
|
|
|
delete res;
|
|
|
|
|
return 0;
|
2002-12-05 03:14:33 +01:00
|
|
|
}
|
2008-04-09 05:42:42 +02:00
|
|
|
if (debug_elaborate)
|
|
|
|
|
cerr << get_fileline() << ": debug: "
|
|
|
|
|
<< "Bit select [" << *tmp << "]"
|
|
|
|
|
<< " in parameter expression." << endl;
|
|
|
|
|
|
2008-03-08 03:51:50 +01:00
|
|
|
res = new NetESelect(res, tmp, 1);
|
|
|
|
|
res->set_line(*this);
|
2007-05-24 06:07:11 +02:00
|
|
|
break;
|
2002-01-28 01:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
2000-03-12 05:35:22 +01:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-08 05:36:53 +01:00
|
|
|
/*
|
|
|
|
|
* Simple numbers can be elaborated by the elaborate_expr method.
|
|
|
|
|
*/
|
|
|
|
|
NetExpr*PENumber::elaborate_pexpr(Design*des, NetScope*sc) const
|
|
|
|
|
{
|
2006-06-02 06:48:49 +02:00
|
|
|
return elaborate_expr(des, sc, -1, false);
|
2000-03-08 05:36:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-01 04:31:39 +02:00
|
|
|
NetEConst* PEString::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
2006-06-02 06:48:49 +02:00
|
|
|
return elaborate_expr(des, scope, -1, false);
|
2000-06-01 04:31:39 +02:00
|
|
|
}
|
|
|
|
|
|
2000-12-16 20:03:30 +01:00
|
|
|
NetETernary* PETernary::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
|
|
|
|
NetExpr*c = expr_->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*t = tru_->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*f = fal_->elaborate_pexpr(des, scope);
|
2008-03-08 03:51:50 +01:00
|
|
|
if (c == 0 || t == 0 || f == 0) return 0;
|
2008-02-27 20:34:51 +01:00
|
|
|
|
|
|
|
|
NetETernary*tmp = new NetETernary(c, t, f);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
return tmp;
|
2000-12-16 20:03:30 +01:00
|
|
|
}
|
|
|
|
|
|
2000-03-12 19:22:11 +01:00
|
|
|
NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const
|
|
|
|
|
{
|
|
|
|
|
NetExpr*ip = expr_->elaborate_pexpr(des, scope);
|
|
|
|
|
if (ip == 0) return 0;
|
|
|
|
|
|
|
|
|
|
/* Should we evaluate expressions ahead of time,
|
|
|
|
|
* just like in PEBinary::elaborate_expr() ?
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
NetEUnary*tmp;
|
|
|
|
|
switch (op_) {
|
|
|
|
|
default:
|
|
|
|
|
tmp = new NetEUnary(op_, ip);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
break;
|
2008-03-08 03:51:50 +01:00
|
|
|
|
2000-03-12 19:22:11 +01:00
|
|
|
case '~':
|
|
|
|
|
tmp = new NetEUBits(op_, ip);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
break;
|
2008-03-08 03:51:50 +01:00
|
|
|
|
2001-01-02 05:21:13 +01:00
|
|
|
case '!': // Logical NOT
|
|
|
|
|
case '&': // Reduction AND
|
|
|
|
|
case '|': // Reduction OR
|
|
|
|
|
case '^': // Reduction XOR
|
|
|
|
|
case 'A': // Reduction NAND (~&)
|
|
|
|
|
case 'N': // Reduction NOR (~|)
|
|
|
|
|
case 'X': // Reduction NXOR (~^)
|
|
|
|
|
tmp = new NetEUReduce(op_, ip);
|
|
|
|
|
tmp->set_line(*this);
|
|
|
|
|
break;
|
2000-03-12 19:22:11 +01:00
|
|
|
}
|
2008-03-08 03:51:50 +01:00
|
|
|
|
2000-03-12 19:22:11 +01:00
|
|
|
return tmp;
|
|
|
|
|
}
|
2008-07-31 23:05:27 +02:00
|
|
|
|
|
|
|
|
NetExpr* PECallFunction::elaborate_pexpr(Design*des, NetScope*scope) const
|
|
|
|
|
{
|
2008-08-30 06:11:44 +02:00
|
|
|
/* Only $clog2 and the builtin mathematical functions can
|
|
|
|
|
* be a constant system function. */
|
2008-10-02 05:35:26 +02:00
|
|
|
perm_string nm = peek_tail_name(path_);
|
|
|
|
|
if (nm[0] == '$' && (generation_flag >= GN_VER2005 ||
|
|
|
|
|
gn_icarus_misc_flag || gn_verilog_ams_flag)) {
|
|
|
|
|
if (nm == "$clog2" ||
|
|
|
|
|
nm == "$ln" ||
|
|
|
|
|
nm == "$log10" ||
|
|
|
|
|
nm == "$exp" ||
|
|
|
|
|
nm == "$sqrt" ||
|
|
|
|
|
nm == "$floor" ||
|
|
|
|
|
nm == "$ceil" ||
|
|
|
|
|
nm == "$sin" ||
|
|
|
|
|
nm == "$cos" ||
|
|
|
|
|
nm == "$tan" ||
|
|
|
|
|
nm == "$asin" ||
|
|
|
|
|
nm == "$acos" ||
|
|
|
|
|
nm == "$atan" ||
|
|
|
|
|
nm == "$sinh" ||
|
|
|
|
|
nm == "$cosh" ||
|
|
|
|
|
nm == "$tanh" ||
|
|
|
|
|
nm == "$asinh" ||
|
|
|
|
|
nm == "$acosh" ||
|
|
|
|
|
nm == "$atanh") {
|
2008-08-30 04:03:34 +02:00
|
|
|
if (parms_.size() != 1 || parms_[0] == 0) {
|
2008-10-02 05:35:26 +02:00
|
|
|
cerr << get_fileline() << ": error: " << nm
|
2008-08-30 06:11:44 +02:00
|
|
|
<< " takes a single argument." << endl;
|
2008-07-31 23:05:27 +02:00
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
NetExpr*arg = parms_[0]->elaborate_pexpr(des, scope);
|
2008-08-30 06:11:44 +02:00
|
|
|
if (arg == 0) return 0;
|
2008-10-02 05:35:26 +02:00
|
|
|
NetESFunc*rtn;
|
|
|
|
|
if (nm == "$clog2") {
|
|
|
|
|
rtn = new NetESFunc(nm, IVL_VT_BOOL, integer_width, 1);
|
2008-08-30 06:11:44 +02:00
|
|
|
} else {
|
2008-10-02 05:35:26 +02:00
|
|
|
rtn = new NetESFunc(nm, IVL_VT_REAL, 1, 1);
|
2008-08-30 06:11:44 +02:00
|
|
|
}
|
2008-10-02 05:35:26 +02:00
|
|
|
rtn->set_line(*this);
|
|
|
|
|
rtn->cast_signed(true);
|
|
|
|
|
rtn->parm(0, arg);
|
|
|
|
|
return rtn;
|
2008-08-30 06:11:44 +02:00
|
|
|
}
|
|
|
|
|
|
2008-10-02 05:35:26 +02:00
|
|
|
if (nm == "$pow" ||
|
|
|
|
|
nm == "$atan2" ||
|
|
|
|
|
nm == "$hypot") {
|
2008-08-30 06:11:44 +02:00
|
|
|
if (parms_.size() != 2 || parms_[0] == 0 || parms_[1] == 0) {
|
2008-10-02 05:35:26 +02:00
|
|
|
cerr << get_fileline() << ": error: " << nm
|
2008-08-30 06:11:44 +02:00
|
|
|
<< " takes two arguments." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
NetExpr*arg0 = parms_[0]->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*arg1 = parms_[1]->elaborate_pexpr(des, scope);
|
|
|
|
|
if (arg0 == 0 || arg1 == 0) return 0;
|
2008-10-02 05:35:26 +02:00
|
|
|
NetESFunc*rtn = new NetESFunc(nm, IVL_VT_REAL, 1, 2);
|
|
|
|
|
rtn->set_line(*this);
|
|
|
|
|
rtn->cast_signed(true);
|
|
|
|
|
rtn->parm(0, arg0);
|
|
|
|
|
rtn->parm(1, arg1);
|
|
|
|
|
return rtn;
|
2008-08-30 06:11:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* These are only available with verilog-ams or icarus-misc. */
|
|
|
|
|
if ((gn_icarus_misc_flag || gn_verilog_ams_flag) &&
|
2008-10-02 05:35:26 +02:00
|
|
|
(nm == "$log" || nm == "$abs")) {
|
2008-08-30 06:11:44 +02:00
|
|
|
if (parms_.size() != 1 || parms_[0] == 0) {
|
2008-10-02 05:35:26 +02:00
|
|
|
cerr << get_fileline() << ": error: " << nm
|
2008-08-30 06:11:44 +02:00
|
|
|
<< " takes a single argument." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
NetExpr*arg = parms_[0]->elaborate_pexpr(des, scope);
|
|
|
|
|
if (arg == 0) return 0;
|
2008-10-02 05:35:26 +02:00
|
|
|
NetESFunc*rtn;
|
|
|
|
|
if (nm == "$log") {
|
|
|
|
|
rtn = new NetESFunc(nm, IVL_VT_REAL, 1, 1);
|
2008-08-30 06:11:44 +02:00
|
|
|
} else {
|
2008-10-02 05:35:26 +02:00
|
|
|
/* This can return either a real or an arbitrary
|
|
|
|
|
* width vector, so set things to fail if this
|
|
|
|
|
* does not get replaced with a constant during
|
|
|
|
|
* elaboration. */
|
|
|
|
|
rtn = new NetESFunc(nm, IVL_VT_NO_TYPE, 0, 1);
|
2008-07-31 23:05:27 +02:00
|
|
|
}
|
2008-10-02 05:35:26 +02:00
|
|
|
rtn->set_line(*this);
|
|
|
|
|
rtn->cast_signed(true);
|
|
|
|
|
rtn->parm(0, arg);
|
|
|
|
|
return rtn;
|
2008-07-31 23:05:27 +02:00
|
|
|
}
|
2008-08-30 06:11:44 +02:00
|
|
|
if ((gn_icarus_misc_flag || gn_verilog_ams_flag) &&
|
2008-10-02 05:35:26 +02:00
|
|
|
(nm == "$min" || nm == "$max")) {
|
2008-08-30 06:11:44 +02:00
|
|
|
if (parms_.size() != 2 || parms_[0] == 0 || parms_[1] == 0) {
|
2008-10-02 05:35:26 +02:00
|
|
|
cerr << get_fileline() << ": error: " << nm
|
2008-08-30 06:11:44 +02:00
|
|
|
<< " takes two arguments." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
NetExpr*arg0 = parms_[0]->elaborate_pexpr(des, scope);
|
|
|
|
|
NetExpr*arg1 = parms_[1]->elaborate_pexpr(des, scope);
|
|
|
|
|
if (arg0 == 0 || arg1 == 0) return 0;
|
2008-10-02 05:35:26 +02:00
|
|
|
/* See $log above for why this has no type or width. */
|
|
|
|
|
NetESFunc*rtn = new NetESFunc(nm, IVL_VT_NO_TYPE, 0, 2);
|
|
|
|
|
rtn->set_line(*this);
|
|
|
|
|
rtn->cast_signed(true);
|
|
|
|
|
rtn->parm(0, arg0);
|
|
|
|
|
rtn->parm(1, arg1);
|
|
|
|
|
return rtn;
|
2008-08-30 06:11:44 +02:00
|
|
|
}
|
2008-07-31 23:05:27 +02:00
|
|
|
|
|
|
|
|
cerr << get_fileline() << ": error: this is not a constant "
|
|
|
|
|
"system function (" << *this << ")." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Constant user function code goes here. */
|
|
|
|
|
cerr << get_fileline() << ": sorry: constant user functions are not "
|
|
|
|
|
"currently supported." << endl;
|
|
|
|
|
des->errors += 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|