2010-11-03 04:16:42 +01:00
|
|
|
/*
|
2024-12-28 19:08:06 +01:00
|
|
|
* Copyright (c) 2010-2024 Stephen Williams (steve@icarus.com)
|
2010-11-03 04:16:42 +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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-11-03 04:16:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "netenum.h"
|
2010-11-21 00:09:32 +01:00
|
|
|
# include "compiler.h"
|
2010-11-07 18:58:00 +01:00
|
|
|
# include <cassert>
|
2010-11-03 04:16:42 +01:00
|
|
|
|
2012-09-30 00:13:45 +02:00
|
|
|
using namespace std;
|
|
|
|
|
|
2022-03-15 08:24:33 +01:00
|
|
|
netenum_t::netenum_t(ivl_type_t btype, size_t name_count, bool integer_flag)
|
|
|
|
|
: base_type_(btype), integer_flag_(integer_flag), names_(name_count),
|
|
|
|
|
bits_(name_count)
|
2010-11-03 04:16:42 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
netenum_t::~netenum_t()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-16 02:16:05 +02:00
|
|
|
bool netenum_t::get_signed() const
|
|
|
|
|
{
|
2022-03-15 08:24:33 +01:00
|
|
|
return base_type_->get_signed();
|
2012-09-16 02:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-01 02:07:46 +01:00
|
|
|
bool netenum_t::get_isint() const
|
|
|
|
|
{
|
|
|
|
|
return integer_flag_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 00:25:14 +01:00
|
|
|
/*
|
|
|
|
|
* Enumerations are by definition always packed.
|
|
|
|
|
*/
|
|
|
|
|
bool netenum_t::packed() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 02:27:48 +02:00
|
|
|
long netenum_t::packed_width() const
|
|
|
|
|
{
|
2022-03-15 08:24:33 +01:00
|
|
|
return base_type_->packed_width();
|
2012-08-20 02:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-06 15:24:20 +01:00
|
|
|
netranges_t netenum_t::slice_dimensions() const
|
2012-09-30 00:13:45 +02:00
|
|
|
{
|
2022-03-15 08:24:33 +01:00
|
|
|
return base_type_->slice_dimensions();
|
2012-09-30 00:13:45 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-21 00:09:32 +01:00
|
|
|
bool netenum_t::insert_name(size_t name_idx, perm_string name, const verinum&val)
|
2010-11-03 04:16:42 +01:00
|
|
|
{
|
2010-11-06 03:49:28 +01:00
|
|
|
std::pair<std::map<perm_string,verinum>::iterator, bool> res;
|
|
|
|
|
|
2024-12-28 19:08:06 +01:00
|
|
|
assert(val.has_len() && packed_width() >= 0 &&
|
|
|
|
|
val.len() == (unsigned long)packed_width());
|
2010-11-07 18:58:00 +01:00
|
|
|
|
2010-11-21 00:09:32 +01:00
|
|
|
// Insert a map of the name to the value. This also gets a
|
|
|
|
|
// flag that returns true if the name is unique, or false
|
|
|
|
|
// otherwise.
|
2010-11-06 03:49:28 +01:00
|
|
|
res = names_map_.insert( make_pair(name,val) );
|
2010-11-21 00:09:32 +01:00
|
|
|
|
|
|
|
|
assert(name_idx < names_.size() && names_[name_idx] == 0);
|
|
|
|
|
names_[name_idx] = name;
|
2010-11-06 03:49:28 +01:00
|
|
|
|
|
|
|
|
return res.second;
|
2010-11-03 04:16:42 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:03:21 +02:00
|
|
|
void netenum_t::insert_name_close(void)
|
|
|
|
|
{
|
|
|
|
|
for (size_t idx = 0 ; idx < names_.size() ; idx += 1) {
|
2014-11-01 04:07:22 +01:00
|
|
|
// If we failed to elaborate the name then skip this step.
|
|
|
|
|
if (names_[idx].nil()) continue;
|
|
|
|
|
|
2013-04-15 03:03:21 +02:00
|
|
|
netenum_t::iterator cur = names_map_.find(names_[idx]);
|
|
|
|
|
|
|
|
|
|
vector<char>str (cur->second.len() + 1);
|
|
|
|
|
for (unsigned bit = 0 ; bit < cur->second.len() ; bit += 1) {
|
|
|
|
|
switch (cur->second.get(bit)) {
|
|
|
|
|
case verinum::V0:
|
|
|
|
|
str[bit] = '0';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::V1:
|
|
|
|
|
str[bit] = '1';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::Vx:
|
|
|
|
|
str[bit] = 'x';
|
|
|
|
|
break;
|
|
|
|
|
case verinum::Vz:
|
|
|
|
|
str[bit] = 'z';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bits_[idx] = bits_strings.make(&str[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-03 04:16:42 +01:00
|
|
|
netenum_t::iterator netenum_t::find_name(perm_string name) const
|
|
|
|
|
{
|
2010-11-06 03:49:28 +01:00
|
|
|
return names_map_.find(name);
|
2010-11-03 04:16:42 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-30 04:34:23 +02:00
|
|
|
/*
|
|
|
|
|
* Check to see if the given value is already in the enumeration mapping.
|
|
|
|
|
*/
|
|
|
|
|
perm_string netenum_t::find_value(const verinum&val) const
|
|
|
|
|
{
|
|
|
|
|
perm_string res;
|
|
|
|
|
for(netenum_t::iterator cur = names_map_.begin();
|
2011-10-13 04:03:09 +02:00
|
|
|
cur != names_map_.end(); ++ cur) {
|
2011-09-30 04:34:23 +02:00
|
|
|
if (cur->second == val) {
|
|
|
|
|
res = cur->first;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-03 04:16:42 +01:00
|
|
|
netenum_t::iterator netenum_t::end_name() const
|
|
|
|
|
{
|
2010-11-06 03:49:28 +01:00
|
|
|
return names_map_.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
netenum_t::iterator netenum_t::first_name() const
|
|
|
|
|
{
|
|
|
|
|
return names_map_.find(names_.front());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
netenum_t::iterator netenum_t::last_name() const
|
|
|
|
|
{
|
|
|
|
|
return names_map_.find(names_.back());
|
2010-11-03 04:16:42 +01:00
|
|
|
}
|
2010-11-21 00:09:32 +01:00
|
|
|
|
|
|
|
|
perm_string netenum_t::name_at(size_t idx) const
|
|
|
|
|
{
|
|
|
|
|
assert(idx < names_.size());
|
|
|
|
|
return names_[idx];
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:03:21 +02:00
|
|
|
perm_string netenum_t::bits_at(size_t idx) const
|
2010-11-21 00:09:32 +01:00
|
|
|
{
|
|
|
|
|
return bits_[idx];
|
|
|
|
|
}
|
2014-11-04 23:55:40 +01:00
|
|
|
|
|
|
|
|
bool netenum_t::matches(const netenum_t*other) const
|
|
|
|
|
{
|
2022-03-19 15:03:53 +01:00
|
|
|
return this == other;
|
2014-11-04 23:55:40 +01:00
|
|
|
}
|