2000-09-23 07:15:07 +02:00
|
|
|
/*
|
2021-11-04 17:12:04 +01:00
|
|
|
* Copyright (c) 2000-2021 Stephen Williams (steve@icarus.com)
|
2000-09-23 07:15:07 +02: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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-09-23 07:15:07 +02:00
|
|
|
*/
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
|
|
|
|
|
|
|
|
|
# include <iostream>
|
|
|
|
|
|
2008-01-05 00:23:47 +01:00
|
|
|
# include <cstring>
|
2000-09-23 07:15:07 +02:00
|
|
|
# include "t-dll.h"
|
|
|
|
|
# include "netlist.h"
|
2012-12-10 02:59:16 +01:00
|
|
|
# include "netclass.h"
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cassert>
|
|
|
|
|
# include <cstdlib>
|
2010-10-24 00:52:56 +02:00
|
|
|
# include "ivl_alloc.h"
|
2013-03-15 04:08:32 +01:00
|
|
|
# include "ivl_assert.h"
|
2000-09-23 07:15:07 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
2003-01-26 22:15:58 +01:00
|
|
|
/*
|
|
|
|
|
* This is a little convenience function for converting a NetExpr
|
2003-01-30 17:23:07 +01:00
|
|
|
* expression type to the expression type used by ivl_expr_t objects.
|
2003-01-26 22:15:58 +01:00
|
|
|
*/
|
|
|
|
|
static ivl_variable_type_t get_expr_type(const NetExpr*net)
|
|
|
|
|
{
|
2005-07-11 18:56:50 +02:00
|
|
|
return net->expr_type();
|
2003-01-26 22:15:58 +01:00
|
|
|
}
|
|
|
|
|
|
2000-09-30 04:18:15 +02:00
|
|
|
/*
|
|
|
|
|
* These methods implement the expression scan that generates the
|
|
|
|
|
* ivl_expr_t representing the expression. Each method leaves the
|
|
|
|
|
* expr_ member filled with the ivl_expr_t that represents it. Each
|
|
|
|
|
* method expects that the expr_ member empty (0) when it starts.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-05-30 00:05:54 +02:00
|
|
|
/*
|
|
|
|
|
* This function takes an expression in the expr_ member that is
|
|
|
|
|
* already built up, and adds a subtraction of the given constant.
|
|
|
|
|
*/
|
|
|
|
|
void dll_target::sub_off_from_expr_(long off)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ != 0);
|
|
|
|
|
|
|
|
|
|
char*bits;
|
|
|
|
|
ivl_expr_t tmpc = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
tmpc->type_ = IVL_EX_NUMBER;
|
2003-01-26 22:15:58 +01:00
|
|
|
tmpc->value_ = IVL_VT_VECTOR;
|
2012-10-01 03:03:10 +02:00
|
|
|
tmpc->net_type= 0;
|
2002-05-30 00:05:54 +02:00
|
|
|
tmpc->width_ = expr_->width_;
|
|
|
|
|
tmpc->signed_ = expr_->signed_;
|
2010-03-06 04:36:54 +01:00
|
|
|
tmpc->sized_ = 1;
|
2002-05-30 00:05:54 +02:00
|
|
|
tmpc->u_.number_.bits_ = bits = (char*)malloc(tmpc->width_);
|
|
|
|
|
for (unsigned idx = 0 ; idx < tmpc->width_ ; idx += 1) {
|
|
|
|
|
bits[idx] = (off & 1)? '1' : '0';
|
|
|
|
|
off >>= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 06:27:03 +01:00
|
|
|
/* Now make the subtracter (x-4 in the above example)
|
2002-05-30 00:05:54 +02:00
|
|
|
that has as input A the index expression and input B
|
|
|
|
|
the constant to subtract. */
|
|
|
|
|
ivl_expr_t tmps = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
tmps->type_ = IVL_EX_BINARY;
|
2003-01-26 22:15:58 +01:00
|
|
|
tmps->value_ = IVL_VT_VECTOR;
|
2012-10-01 03:03:10 +02:00
|
|
|
tmps->net_type= 0;
|
2002-05-30 00:05:54 +02:00
|
|
|
tmps->width_ = tmpc->width_;
|
|
|
|
|
tmps->signed_ = tmpc->signed_;
|
2010-03-06 04:36:54 +01:00
|
|
|
tmps->sized_ = 1;
|
2002-05-30 00:05:54 +02:00
|
|
|
tmps->u_.binary_.op_ = '-';
|
|
|
|
|
tmps->u_.binary_.lef_ = expr_;
|
|
|
|
|
tmps->u_.binary_.rig_ = tmpc;
|
|
|
|
|
|
|
|
|
|
/* Replace (x) with (x-off) */
|
|
|
|
|
expr_ = tmps;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-16 22:39:12 +02:00
|
|
|
void dll_target::mul_expr_by_const_(long val)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ != 0);
|
|
|
|
|
|
|
|
|
|
char*bits;
|
|
|
|
|
ivl_expr_t tmpc = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
tmpc->type_ = IVL_EX_NUMBER;
|
2003-01-26 22:15:58 +01:00
|
|
|
tmpc->value_ = IVL_VT_VECTOR;
|
2012-10-01 03:03:10 +02:00
|
|
|
tmpc->net_type= 0;
|
2002-06-16 22:39:12 +02:00
|
|
|
tmpc->width_ = expr_->width_;
|
|
|
|
|
tmpc->signed_ = expr_->signed_;
|
2010-03-06 04:36:54 +01:00
|
|
|
tmpc->sized_ = 1;
|
2002-06-16 22:39:12 +02:00
|
|
|
tmpc->u_.number_.bits_ = bits = (char*)malloc(tmpc->width_);
|
|
|
|
|
for (unsigned idx = 0 ; idx < tmpc->width_ ; idx += 1) {
|
|
|
|
|
bits[idx] = (val & 1)? '1' : '0';
|
|
|
|
|
val >>= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 06:27:03 +01:00
|
|
|
/* Now make the subtracter (x-4 in the above example)
|
2002-06-16 22:39:12 +02:00
|
|
|
that has as input A the index expression and input B
|
|
|
|
|
the constant to subtract. */
|
|
|
|
|
ivl_expr_t tmps = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
tmps->type_ = IVL_EX_BINARY;
|
2003-01-26 22:15:58 +01:00
|
|
|
tmps->value_ = IVL_VT_VECTOR;
|
2012-10-01 03:03:10 +02:00
|
|
|
tmpc->net_type= 0;
|
2002-06-16 22:39:12 +02:00
|
|
|
tmps->width_ = tmpc->width_;
|
|
|
|
|
tmps->signed_ = tmpc->signed_;
|
2010-03-06 04:36:54 +01:00
|
|
|
tmps->sized_ = 1;
|
2002-06-16 22:39:12 +02:00
|
|
|
tmps->u_.binary_.op_ = '*';
|
|
|
|
|
tmps->u_.binary_.lef_ = expr_;
|
|
|
|
|
tmps->u_.binary_.rig_ = tmpc;
|
|
|
|
|
|
|
|
|
|
/* Replace (x) with (x*valf) */
|
|
|
|
|
expr_ = tmps;
|
|
|
|
|
}
|
2000-09-30 04:18:15 +02:00
|
|
|
|
2002-10-23 03:45:24 +02:00
|
|
|
ivl_expr_t dll_target::expr_from_value_(const verinum&val)
|
|
|
|
|
{
|
|
|
|
|
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
unsigned idx;
|
|
|
|
|
char*bits;
|
|
|
|
|
expr->type_ = IVL_EX_NUMBER;
|
2003-01-26 22:15:58 +01:00
|
|
|
expr->value_= IVL_VT_VECTOR;
|
2012-10-01 03:03:10 +02:00
|
|
|
expr->net_type=0;
|
2002-10-23 03:45:24 +02:00
|
|
|
expr->width_= val.len();
|
|
|
|
|
expr->signed_ = val.has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr->sized_= 1;
|
2003-02-02 01:19:27 +01:00
|
|
|
expr->u_.number_.bits_ = bits = (char*)malloc(expr->width_ + 1);
|
2002-10-23 03:45:24 +02:00
|
|
|
for (idx = 0 ; idx < expr->width_ ; idx += 1)
|
|
|
|
|
switch (val.get(idx)) {
|
|
|
|
|
case verinum::V0:
|
|
|
|
|
bits[idx] = '0';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::V1:
|
|
|
|
|
bits[idx] = '1';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::Vx:
|
|
|
|
|
bits[idx] = 'x';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::Vz:
|
|
|
|
|
bits[idx] = 'z';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-02 01:19:27 +01:00
|
|
|
bits[expr->width_] = 0;
|
|
|
|
|
|
2002-10-23 03:45:24 +02:00
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-31 03:01:41 +02:00
|
|
|
void dll_target::expr_access_func(const NetEAccess*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
2008-08-05 05:54:05 +02:00
|
|
|
// Make a stub Branch Access Function expression node.
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->type_ = IVL_EX_BACCESS;
|
|
|
|
|
expr_->value_ = IVL_VT_REAL;
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2008-08-05 05:54:05 +02:00
|
|
|
expr_->width_ = 1;
|
|
|
|
|
expr_->signed_= 1;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_ = 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2008-11-12 05:41:14 +01:00
|
|
|
|
|
|
|
|
expr_->u_.branch_.branch = net->get_branch()->target_obj();
|
|
|
|
|
expr_->u_.branch_.nature = net->get_nature();
|
2008-07-31 03:01:41 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-10 05:15:10 +02:00
|
|
|
void dll_target::expr_array_pattern(const NetEArrayPattern*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
ivl_expr_t expr_tmp = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_tmp->type_ = IVL_EX_ARRAY_PATTERN;
|
|
|
|
|
expr_tmp->value_= net->expr_type();
|
|
|
|
|
expr_tmp->net_type = net->net_type();
|
|
|
|
|
expr_tmp->width_ = 1;
|
|
|
|
|
expr_tmp->signed_ = 0;
|
|
|
|
|
expr_tmp->sized_ = 0;
|
|
|
|
|
FILE_NAME(expr_tmp, net);
|
|
|
|
|
|
|
|
|
|
expr_tmp->u_.array_pattern_.parms = net->item_size();
|
|
|
|
|
expr_tmp->u_.array_pattern_.parm = new ivl_expr_t [net->item_size()];
|
|
|
|
|
|
|
|
|
|
for (size_t idx = 0 ; idx < net->item_size() ; idx += 1) {
|
|
|
|
|
const NetExpr*tmp = net->item(idx);
|
|
|
|
|
tmp->expr_scan(this);
|
|
|
|
|
expr_tmp->u_.array_pattern_.parm[idx] = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expr_ = expr_tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-30 04:18:15 +02:00
|
|
|
void dll_target::expr_binary(const NetEBinary*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
net->left()->expr_scan(this);
|
|
|
|
|
ivl_expr_t left = expr_;
|
|
|
|
|
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
net->right()->expr_scan(this);
|
|
|
|
|
ivl_expr_t rght = expr_;
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr_->type_ = IVL_EX_BINARY;
|
2003-01-26 22:15:58 +01:00
|
|
|
expr_->value_= get_expr_type(net);
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2000-09-30 04:18:15 +02:00
|
|
|
expr_->width_= net->expr_width();
|
2001-04-05 03:12:27 +02:00
|
|
|
expr_->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_= 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2000-09-30 04:18:15 +02:00
|
|
|
|
|
|
|
|
expr_->u_.binary_.op_ = net->op();
|
|
|
|
|
expr_->u_.binary_.lef_ = left;
|
|
|
|
|
expr_->u_.binary_.rig_ = rght;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-28 19:55:03 +02:00
|
|
|
void dll_target::expr_concat(const NetEConcat*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
2000-10-29 00:32:34 +02:00
|
|
|
ivl_expr_t cur = new struct ivl_expr_s;
|
|
|
|
|
assert(cur);
|
2000-10-28 19:55:03 +02:00
|
|
|
|
2003-01-26 22:15:58 +01:00
|
|
|
cur->type_ = IVL_EX_CONCAT;
|
2012-06-25 00:33:40 +02:00
|
|
|
cur->value_ = net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
cur->net_type=0;
|
2003-01-26 22:15:58 +01:00
|
|
|
cur->width_ = net->expr_width();
|
2009-07-24 18:52:48 +02:00
|
|
|
cur->signed_ = net->has_sign() ? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
cur->sized_ = 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(cur, net);
|
2000-10-29 00:32:34 +02:00
|
|
|
|
|
|
|
|
cur->u_.concat_.rept = net->repeat();
|
|
|
|
|
cur->u_.concat_.parms = net->nparms();
|
|
|
|
|
cur->u_.concat_.parm = new ivl_expr_t [net->nparms()];
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < net->nparms() ; idx += 1) {
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
net->parm(idx)->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
cur->u_.concat_.parm[idx] = expr_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expr_ = cur;
|
2000-10-28 19:55:03 +02:00
|
|
|
}
|
|
|
|
|
|
2000-09-23 07:15:07 +02:00
|
|
|
void dll_target::expr_const(const NetEConst*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
2005-09-14 04:53:13 +02:00
|
|
|
expr_->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2008-09-05 23:44:02 +02:00
|
|
|
FILE_NAME(expr_, net);
|
2000-09-23 07:15:07 +02:00
|
|
|
|
|
|
|
|
if (net->value().is_string()) {
|
|
|
|
|
expr_->type_ = IVL_EX_STRING;
|
2000-09-24 04:21:53 +02:00
|
|
|
expr_->width_= net->expr_width();
|
2000-09-23 07:15:07 +02:00
|
|
|
expr_->u_.string_.value_ =strdup(net->value().as_string().c_str());
|
|
|
|
|
|
|
|
|
|
} else {
|
2000-09-26 02:30:07 +02:00
|
|
|
verinum val = net->value();
|
|
|
|
|
unsigned idx;
|
|
|
|
|
char*bits;
|
2000-09-23 07:15:07 +02:00
|
|
|
expr_->type_ = IVL_EX_NUMBER;
|
2000-09-24 04:21:53 +02:00
|
|
|
expr_->width_= net->expr_width();
|
2001-12-31 01:08:14 +01:00
|
|
|
expr_->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_= net->has_width()? 1 : 0;
|
2000-09-26 02:30:07 +02:00
|
|
|
expr_->u_.number_.bits_ = bits = (char*)malloc(expr_->width_);
|
|
|
|
|
for (idx = 0 ; idx < expr_->width_ ; idx += 1)
|
|
|
|
|
switch (val.get(idx)) {
|
|
|
|
|
case verinum::V0:
|
|
|
|
|
bits[idx] = '0';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::V1:
|
|
|
|
|
bits[idx] = '1';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::Vx:
|
|
|
|
|
bits[idx] = 'x';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::Vz:
|
|
|
|
|
bits[idx] = 'z';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2000-09-23 07:15:07 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 00:40:53 +01:00
|
|
|
void dll_target::expr_param(const NetEConstParam*net)
|
|
|
|
|
{
|
2008-10-20 19:06:04 +02:00
|
|
|
ivl_scope_t scop = find_scope(des_, net->scope());
|
|
|
|
|
ivl_parameter_t par = scope_find_param(scop, net->name());
|
2003-03-11 00:40:53 +01:00
|
|
|
|
2009-01-16 20:03:03 +01:00
|
|
|
if (par == 0) {
|
|
|
|
|
cerr << net->get_fileline() << ": internal error: "
|
|
|
|
|
<< "Parameter " << net->name() << " missing from "
|
|
|
|
|
<< ivl_scope_name(scop) << endl;
|
|
|
|
|
}
|
|
|
|
|
assert(par);
|
2011-02-26 23:59:52 +01:00
|
|
|
expr_const(net);
|
|
|
|
|
expr_->u_.string_.parameter = par;
|
2009-01-16 20:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dll_target::expr_rparam(const NetECRealParam*net)
|
|
|
|
|
{
|
|
|
|
|
ivl_scope_t scop = find_scope(des_, net->scope());
|
|
|
|
|
ivl_parameter_t par = scope_find_param(scop, net->name());
|
|
|
|
|
|
2003-03-11 00:40:53 +01:00
|
|
|
if (par == 0) {
|
2007-12-20 18:31:01 +01:00
|
|
|
cerr << net->get_fileline() << ": internal error: "
|
2003-03-11 00:40:53 +01:00
|
|
|
<< "Parameter " << net->name() << " missing from "
|
2008-10-20 19:06:04 +02:00
|
|
|
<< ivl_scope_name(scop) << endl;
|
2003-03-11 00:40:53 +01:00
|
|
|
}
|
|
|
|
|
assert(par);
|
|
|
|
|
assert(par->value);
|
|
|
|
|
expr_ = par->value;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-26 22:15:58 +01:00
|
|
|
void dll_target::expr_creal(const NetECReal*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->width_ = net->expr_width();
|
|
|
|
|
expr_->signed_ = 1;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_ = 1;
|
2003-01-26 22:15:58 +01:00
|
|
|
expr_->type_ = IVL_EX_REALNUM;
|
2008-09-05 23:44:02 +02:00
|
|
|
FILE_NAME(expr_, net);
|
2003-01-26 22:15:58 +01:00
|
|
|
expr_->value_= IVL_VT_REAL;
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2003-01-26 22:15:58 +01:00
|
|
|
expr_->u_.real_.value = net->value().as_double();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 01:11:40 +02:00
|
|
|
void dll_target::expr_last(const NetELast*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
ivl_expr_t expr = new struct ivl_expr_s;
|
|
|
|
|
expr->type_ = IVL_EX_SFUNC;
|
|
|
|
|
expr->value_ = IVL_VT_LOGIC;
|
|
|
|
|
expr->width_ = 32;
|
|
|
|
|
expr->signed_ = 1;
|
|
|
|
|
expr->sized_ = 1;
|
|
|
|
|
expr->net_type = 0;
|
|
|
|
|
FILE_NAME(expr, net);
|
|
|
|
|
|
|
|
|
|
expr->u_.sfunc_.name_ = "$high";
|
|
|
|
|
|
|
|
|
|
ivl_signal_t sig = find_signal(des_, net->sig());
|
|
|
|
|
|
|
|
|
|
ivl_expr_t esig = new struct ivl_expr_s;
|
|
|
|
|
esig->type_ = IVL_EX_SIGNAL;
|
|
|
|
|
esig->value_ = IVL_VT_DARRAY;
|
|
|
|
|
esig->net_type= sig->net_type;
|
|
|
|
|
esig->width_ = 1;
|
2015-01-08 19:03:30 +01:00
|
|
|
esig->signed_ = sig->net_type->get_signed()? 1 : 0;
|
2014-08-17 01:11:40 +02:00
|
|
|
FILE_NAME(esig, net);
|
|
|
|
|
esig->u_.signal_.word = 0;
|
|
|
|
|
esig->u_.signal_.sig = sig;
|
|
|
|
|
|
|
|
|
|
expr->u_.sfunc_.parms = 1;
|
|
|
|
|
expr->u_.sfunc_.parm = new ivl_expr_t[1];
|
|
|
|
|
expr->u_.sfunc_.parm[0] = esig;
|
|
|
|
|
|
|
|
|
|
expr_ = expr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-17 18:20:13 +01:00
|
|
|
void dll_target::expr_new(const NetENew*net)
|
|
|
|
|
{
|
2012-11-18 01:44:25 +01:00
|
|
|
ivl_expr_t size = 0;
|
2013-10-14 02:54:39 +02:00
|
|
|
ivl_expr_t init_val = 0;
|
|
|
|
|
|
2012-11-18 01:44:25 +01:00
|
|
|
if (net->size_expr()) {
|
|
|
|
|
net->size_expr()->expr_scan(this);
|
|
|
|
|
size = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 02:54:39 +02:00
|
|
|
if (net->init_expr()) {
|
|
|
|
|
net->init_expr()->expr_scan(this);
|
|
|
|
|
init_val = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-17 18:20:13 +01:00
|
|
|
assert(expr_ == 0);
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->width_ = net->expr_width();
|
|
|
|
|
expr_->signed_ = 0;
|
|
|
|
|
expr_->sized_ = 1;
|
|
|
|
|
expr_->type_ = IVL_EX_NEW;
|
|
|
|
|
FILE_NAME(expr_, net);
|
2012-11-18 01:44:25 +01:00
|
|
|
expr_->value_ = net->expr_type(); // May be IVL_VT_DARRAY or _CLASS
|
2012-11-17 18:20:13 +01:00
|
|
|
expr_->net_type= net->get_type();
|
2012-11-18 01:44:25 +01:00
|
|
|
expr_->u_.new_.size = size;
|
2013-10-14 02:54:39 +02:00
|
|
|
expr_->u_.new_.init_val = init_val;
|
2012-11-17 18:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
2012-11-12 02:42:31 +01:00
|
|
|
void dll_target::expr_null(const NetENull*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->width_ = net->expr_width();
|
|
|
|
|
expr_->signed_ = 0;
|
|
|
|
|
expr_->sized_ = 1;
|
|
|
|
|
expr_->type_ = IVL_EX_NULL;
|
|
|
|
|
FILE_NAME(expr_, net);
|
|
|
|
|
expr_->value_ = IVL_VT_CLASS;
|
|
|
|
|
expr_->net_type= 0;
|
|
|
|
|
}
|
2012-11-17 18:20:13 +01:00
|
|
|
|
2012-11-25 19:13:05 +01:00
|
|
|
void dll_target::expr_property(const NetEProperty*net)
|
|
|
|
|
{
|
2014-09-12 22:07:34 +02:00
|
|
|
ivl_expr_t index = 0;
|
|
|
|
|
if (const NetExpr*index_expr = net->get_index()) {
|
|
|
|
|
index_expr->expr_scan(this);
|
|
|
|
|
index = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
2012-11-25 19:13:05 +01:00
|
|
|
assert(expr_ == 0);
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->width_ = net->expr_width();
|
|
|
|
|
expr_->signed_ = net->has_sign();
|
|
|
|
|
expr_->sized_ = 1;
|
|
|
|
|
expr_->type_ = IVL_EX_PROPERTY;
|
|
|
|
|
FILE_NAME(expr_, net);
|
|
|
|
|
expr_->value_ = net->expr_type();
|
|
|
|
|
expr_->net_type= net->net_type();
|
|
|
|
|
expr_->u_.property_.sig = find_signal(des_, net->get_sig());
|
2012-12-10 02:59:16 +01:00
|
|
|
expr_->u_.property_.prop_idx = net->property_idx();
|
2014-09-12 22:07:34 +02:00
|
|
|
expr_->u_.property_.index = index;
|
2012-11-25 19:13:05 +01:00
|
|
|
}
|
|
|
|
|
|
2003-04-22 06:48:29 +02:00
|
|
|
void dll_target::expr_event(const NetEEvent*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr_->type_ = IVL_EX_EVENT;
|
2009-09-07 19:55:44 +02:00
|
|
|
FILE_NAME(expr_, net);
|
2003-04-22 06:48:29 +02:00
|
|
|
expr_->value_= IVL_VT_VOID;
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2003-04-22 06:48:29 +02:00
|
|
|
|
|
|
|
|
/* Locate the event by name. Save the ivl_event_t in the
|
|
|
|
|
expression so that the generator can find it easily. */
|
|
|
|
|
const NetEvent*ev = net->event();
|
|
|
|
|
ivl_scope_t ev_scope = lookup_scope_(ev->scope());
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < ev_scope->nevent_ ; idx += 1) {
|
|
|
|
|
const char*ename = ivl_event_basename(ev_scope->event_[idx]);
|
|
|
|
|
if (strcmp(ev->name(), ename) == 0) {
|
|
|
|
|
expr_->u_.event_.event = ev_scope->event_[idx];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-02 02:28:35 +02:00
|
|
|
void dll_target::expr_scope(const NetEScope*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr_->type_ = IVL_EX_SCOPE;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2003-01-26 22:15:58 +01:00
|
|
|
expr_->value_= IVL_VT_VOID;
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2001-04-02 02:28:35 +02:00
|
|
|
expr_->u_.scope_.scope = lookup_scope_(net->scope());
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 04:54:13 +02:00
|
|
|
void dll_target::expr_scopy(const NetEShallowCopy*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
net->expr_scan_oper1(this);
|
|
|
|
|
ivl_expr_t expr1 = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
|
|
|
|
|
net->expr_scan_oper2(this);
|
|
|
|
|
ivl_expr_t expr2 = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->type_ = IVL_EX_SHALLOWCOPY;
|
|
|
|
|
FILE_NAME(expr_, net);
|
|
|
|
|
expr_->value_ = net->expr_type();
|
|
|
|
|
expr_->net_type = net->net_type();
|
|
|
|
|
|
|
|
|
|
expr_->u_.shallow_.dest = expr1;
|
|
|
|
|
expr_->u_.shallow_.src = expr2;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-21 00:09:32 +01:00
|
|
|
void dll_target::expr_netenum(const NetENetenum*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr_->type_ = IVL_EX_ENUMTYPE;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2010-11-21 00:09:32 +01:00
|
|
|
expr_->value_= IVL_VT_VOID;
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2010-11-21 00:09:32 +01:00
|
|
|
expr_->u_.enumtype_.type = net->netenum();
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 01:52:41 +01:00
|
|
|
void dll_target::expr_select(const NetESelect*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
net->sub_expr()->expr_scan(this);
|
2011-02-23 18:15:36 +01:00
|
|
|
ivl_expr_t expr = expr_;
|
2002-01-28 01:52:41 +01:00
|
|
|
|
|
|
|
|
expr_ = 0;
|
2003-07-26 05:34:42 +02:00
|
|
|
if (net->select())
|
|
|
|
|
net->select()->expr_scan(this);
|
|
|
|
|
|
2011-02-23 18:15:36 +01:00
|
|
|
ivl_expr_t base = expr_;
|
2002-01-28 01:52:41 +01:00
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr_->type_ = IVL_EX_SELECT;
|
2012-10-08 05:29:24 +02:00
|
|
|
expr_->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2002-01-28 01:52:41 +01:00
|
|
|
expr_->width_= net->expr_width();
|
|
|
|
|
expr_->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_= 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2002-01-28 01:52:41 +01:00
|
|
|
|
2011-02-23 18:15:36 +01:00
|
|
|
expr_->u_.select_.sel_type_ = net->select_type();
|
|
|
|
|
expr_->u_.select_.expr_ = expr;
|
|
|
|
|
expr_->u_.select_.base_ = base;
|
2002-01-28 01:52:41 +01:00
|
|
|
}
|
|
|
|
|
|
2000-10-05 07:03:01 +02:00
|
|
|
void dll_target::expr_sfunc(const NetESFunc*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
2001-07-07 22:20:10 +02:00
|
|
|
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
2000-10-05 07:03:01 +02:00
|
|
|
|
2001-07-07 22:20:10 +02:00
|
|
|
expr->type_ = IVL_EX_SFUNC;
|
2005-07-11 18:56:50 +02:00
|
|
|
expr->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr->net_type=net->net_type();
|
2001-07-07 22:20:10 +02:00
|
|
|
expr->width_= net->expr_width();
|
2004-06-17 18:06:18 +02:00
|
|
|
expr->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr->sized_= 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr, net);
|
2003-03-01 07:25:30 +01:00
|
|
|
/* system function names are lex_strings strings. */
|
|
|
|
|
expr->u_.sfunc_.name_ = net->name();
|
2001-07-07 22:20:10 +02:00
|
|
|
|
|
|
|
|
unsigned cnt = net->nparms();
|
|
|
|
|
expr->u_.sfunc_.parms = cnt;
|
|
|
|
|
expr->u_.sfunc_.parm = new ivl_expr_t[cnt];
|
|
|
|
|
|
|
|
|
|
/* make up the parameter expressions. */
|
|
|
|
|
for (unsigned idx = 0 ; idx < cnt ; idx += 1) {
|
|
|
|
|
net->parm(idx)->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
expr->u_.sfunc_.parm[idx] = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expr_ = expr;
|
2000-10-05 07:03:01 +02:00
|
|
|
}
|
|
|
|
|
|
2001-05-17 06:37:02 +02:00
|
|
|
void dll_target::expr_ternary(const NetETernary*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr->type_ = IVL_EX_TERNARY;
|
2007-02-14 06:59:46 +01:00
|
|
|
expr->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr->net_type=0;
|
2001-05-17 06:37:02 +02:00
|
|
|
expr->width_ = net->expr_width();
|
|
|
|
|
expr->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr->sized_ = 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr, net);
|
2001-05-17 06:37:02 +02:00
|
|
|
|
|
|
|
|
net->cond_expr()->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
expr->u_.ternary_.cond = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
|
|
|
|
|
net->true_expr()->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
expr->u_.ternary_.true_e = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
|
|
|
|
|
net->false_expr()->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
expr->u_.ternary_.false_e = expr_;
|
|
|
|
|
|
|
|
|
|
expr_ = expr;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
void dll_target::expr_signal(const NetESignal*net)
|
|
|
|
|
{
|
2007-01-16 06:44:14 +01:00
|
|
|
ivl_signal_t sig = find_signal(des_, net->sig());
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
2007-01-16 06:44:14 +01:00
|
|
|
/* If there is a word expression, generate it. */
|
|
|
|
|
ivl_expr_t word_expr = 0;
|
|
|
|
|
if (const NetExpr*word = net->word_index()) {
|
|
|
|
|
word->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
word_expr = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr_->type_ = IVL_EX_SIGNAL;
|
2005-07-11 18:56:50 +02:00
|
|
|
expr_->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2000-09-24 04:21:53 +02:00
|
|
|
expr_->width_= net->expr_width();
|
2001-04-05 03:12:27 +02:00
|
|
|
expr_->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_= 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2007-01-16 06:44:14 +01:00
|
|
|
expr_->u_.signal_.word = word_expr;
|
|
|
|
|
expr_->u_.signal_.sig = sig;
|
|
|
|
|
|
|
|
|
|
/* Make account for the special case that this is a reference
|
|
|
|
|
to an array as a whole. We detect this case by noting that
|
2009-03-31 03:28:16 +02:00
|
|
|
this is an array (more than 0 array dimensions) and that
|
|
|
|
|
there is no word select expression. For this case, we have
|
|
|
|
|
an IVL_EX_ARRAY expression instead of a SIGNAL expression. */
|
|
|
|
|
if (sig->array_dimensions_ > 0 && word_expr == 0) {
|
2007-01-16 06:44:14 +01:00
|
|
|
expr_->type_ = IVL_EX_ARRAY;
|
|
|
|
|
expr_->width_ = 0; // Doesn't make much sense for arrays.
|
|
|
|
|
}
|
2001-07-22 02:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
2000-09-24 04:21:53 +02:00
|
|
|
|
2001-04-06 04:28:02 +02:00
|
|
|
void dll_target::expr_ufunc(const NetEUFunc*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
ivl_expr_t expr = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
|
|
|
|
|
expr->type_ = IVL_EX_UFUNC;
|
2005-07-13 06:51:36 +02:00
|
|
|
expr->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr->net_type=0;
|
2001-04-06 04:28:02 +02:00
|
|
|
expr->width_= net->expr_width();
|
|
|
|
|
expr->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr->sized_= 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr, net);
|
2001-04-06 04:28:02 +02:00
|
|
|
|
|
|
|
|
expr->u_.ufunc_.def = lookup_scope_(net->func());
|
2014-09-07 01:26:08 +02:00
|
|
|
if (expr->u_.ufunc_.def == 0) {
|
|
|
|
|
cerr << net->get_fileline() << ": internal error: "
|
|
|
|
|
<< "dll_target::expr_ufunc: "
|
|
|
|
|
<< "Unable to match scope " << scope_path(net->func()) << endl;
|
|
|
|
|
}
|
2013-03-15 04:08:32 +01:00
|
|
|
ivl_assert(*net, expr->u_.ufunc_.def);
|
|
|
|
|
ivl_assert(*net, expr->u_.ufunc_.def->type_ == IVL_SCT_FUNCTION);
|
2001-04-06 04:28:02 +02:00
|
|
|
|
|
|
|
|
unsigned cnt = net->parm_count();
|
|
|
|
|
expr->u_.ufunc_.parms = cnt;
|
|
|
|
|
expr->u_.ufunc_.parm = new ivl_expr_t[cnt];
|
|
|
|
|
|
|
|
|
|
/* make up the parameter expressions. */
|
|
|
|
|
for (unsigned idx = 0 ; idx < cnt ; idx += 1) {
|
|
|
|
|
net->parm(idx)->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
expr->u_.ufunc_.parm[idx] = expr_;
|
|
|
|
|
expr_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expr_ = expr;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-29 04:52:39 +02:00
|
|
|
void dll_target::expr_unary(const NetEUnary*net)
|
|
|
|
|
{
|
|
|
|
|
assert(expr_ == 0);
|
|
|
|
|
|
|
|
|
|
net->expr()->expr_scan(this);
|
|
|
|
|
assert(expr_);
|
|
|
|
|
|
|
|
|
|
ivl_expr_t sub = expr_;
|
|
|
|
|
|
|
|
|
|
expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s));
|
|
|
|
|
expr_->type_ = IVL_EX_UNARY;
|
2007-02-20 06:58:36 +01:00
|
|
|
expr_->value_= net->expr_type();
|
2012-10-01 03:03:10 +02:00
|
|
|
expr_->net_type=0;
|
2002-04-14 04:56:19 +02:00
|
|
|
expr_->width_ = net->expr_width();
|
|
|
|
|
expr_->signed_ = net->has_sign()? 1 : 0;
|
2010-03-06 04:36:54 +01:00
|
|
|
expr_->sized_ = 1;
|
2011-02-07 04:47:11 +01:00
|
|
|
FILE_NAME(expr_, net);
|
2001-03-29 04:52:39 +02:00
|
|
|
expr_->u_.unary_.op_ = net->op();
|
|
|
|
|
expr_->u_.unary_.sub_ = sub;
|
|
|
|
|
}
|