2012-03-26 02:59:05 +02:00
|
|
|
/*
|
2013-07-28 22:23:17 +02:00
|
|
|
* Copyright (c) 2012-2013 Stephen Williams (steve@icarus.com)
|
2012-03-26 02:59:05 +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.
|
2012-03-26 02:59:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "nettypes.h"
|
|
|
|
|
# include <cassert>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2012-09-23 18:28:49 +02:00
|
|
|
ivl_type_s::~ivl_type_s()
|
2012-07-14 03:41:41 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:28:49 +02:00
|
|
|
long ivl_type_s::packed_width(void) const
|
2012-08-06 01:28:40 +02:00
|
|
|
{
|
2012-09-23 18:28:49 +02:00
|
|
|
return 1;
|
2012-08-06 01:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-30 00:13:45 +02:00
|
|
|
vector<netrange_t> ivl_type_s::slice_dimensions() const
|
|
|
|
|
{
|
|
|
|
|
return vector<netrange_t>();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:28:49 +02:00
|
|
|
ivl_variable_type_t ivl_type_s::base_type() const
|
2012-09-15 19:27:43 +02:00
|
|
|
{
|
|
|
|
|
return IVL_VT_NO_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 18:28:49 +02:00
|
|
|
bool ivl_type_s::get_signed() const
|
2012-09-16 02:16:05 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-29 23:48:42 +02:00
|
|
|
bool ivl_type_s::type_compatible(ivl_type_t that) const
|
|
|
|
|
{
|
|
|
|
|
if (this == that)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return test_compatibility(that);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ivl_type_s::test_compatibility(const ivl_type_s*that) const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-30 19:34:09 +02:00
|
|
|
netarray_t::~netarray_t()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ivl_variable_type_t netarray_t::base_type() const
|
|
|
|
|
{
|
|
|
|
|
return element_type_->base_type();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-30 00:13:45 +02:00
|
|
|
unsigned long netrange_width(const vector<netrange_t>&packed)
|
2012-03-26 02:59:05 +02:00
|
|
|
{
|
|
|
|
|
unsigned wid = 1;
|
2012-09-30 00:13:45 +02:00
|
|
|
for (vector<netrange_t>::const_iterator cur = packed.begin()
|
2012-03-26 02:59:05 +02:00
|
|
|
; cur != packed.end() ; ++cur) {
|
2012-07-14 03:41:41 +02:00
|
|
|
unsigned use_wid = cur->width();
|
2012-03-26 02:59:05 +02:00
|
|
|
wid *= use_wid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return wid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Given a netrange_t list (which represent packed dimensions) and a
|
|
|
|
|
* prefix of calculated index values, calculate the canonical offset
|
|
|
|
|
* and width of the resulting slice. In this case, the "sb" argument
|
|
|
|
|
* is an extra index of the prefix.
|
|
|
|
|
*/
|
2012-09-30 00:13:45 +02:00
|
|
|
bool prefix_to_slice(const std::vector<netrange_t>&dims,
|
2012-03-26 02:59:05 +02:00
|
|
|
const std::list<long>&prefix, long sb,
|
|
|
|
|
long&loff, unsigned long&lwid)
|
|
|
|
|
{
|
|
|
|
|
assert(prefix.size() < dims.size());
|
|
|
|
|
|
|
|
|
|
size_t acc_wid = 1;
|
2012-09-30 00:13:45 +02:00
|
|
|
vector<netrange_t>::const_iterator pcur = dims.end();
|
2012-03-26 02:59:05 +02:00
|
|
|
for (size_t idx = prefix.size()+1 ; idx < dims.size() ; idx += 1) {
|
|
|
|
|
-- pcur;
|
|
|
|
|
acc_wid *= pcur->width();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lwid = acc_wid;
|
|
|
|
|
|
|
|
|
|
-- pcur;
|
2012-07-14 03:41:41 +02:00
|
|
|
if (sb < pcur->get_msb() && sb < pcur->get_lsb())
|
2012-03-26 02:59:05 +02:00
|
|
|
return false;
|
2012-07-14 03:41:41 +02:00
|
|
|
if (sb > pcur->get_msb() && sb > pcur->get_lsb())
|
2012-03-26 02:59:05 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
long acc_off = 0;
|
2012-07-14 03:41:41 +02:00
|
|
|
if (pcur->get_msb() >= pcur->get_lsb())
|
|
|
|
|
acc_off += (sb - pcur->get_lsb()) * acc_wid;
|
2012-03-26 02:59:05 +02:00
|
|
|
else
|
2013-07-28 22:23:17 +02:00
|
|
|
acc_off += (pcur->get_lsb() - sb) * acc_wid;
|
2012-03-26 02:59:05 +02:00
|
|
|
|
2012-08-08 20:26:46 +02:00
|
|
|
if (prefix.empty()) {
|
2012-03-26 02:59:05 +02:00
|
|
|
loff = acc_off;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lwid *= pcur->width();
|
|
|
|
|
|
|
|
|
|
list<long>::const_iterator icur = prefix.end();
|
|
|
|
|
do {
|
|
|
|
|
-- pcur;
|
|
|
|
|
-- icur;
|
|
|
|
|
acc_wid *= pcur->width();
|
2012-07-14 03:41:41 +02:00
|
|
|
if (pcur->get_msb() >= pcur->get_lsb())
|
|
|
|
|
acc_off += (*icur - pcur->get_lsb()) * acc_wid;
|
2012-03-26 02:59:05 +02:00
|
|
|
else
|
2013-07-28 22:23:17 +02:00
|
|
|
acc_off += (pcur->get_lsb() - *icur) * acc_wid;
|
2012-03-26 02:59:05 +02:00
|
|
|
|
|
|
|
|
} while (icur != prefix.begin());
|
|
|
|
|
|
|
|
|
|
loff = acc_off;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|