aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/hashlib.h58
-rw-r--r--kernel/rtlil.cc53
-rw-r--r--kernel/rtlil.h16
3 files changed, 98 insertions, 29 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h
index 996bda38e..592d6e577 100644
--- a/kernel/hashlib.h
+++ b/kernel/hashlib.h
@@ -569,7 +569,7 @@ public:
return entries[i].udata.second;
}
- T at(const K &key, const T &defval) const
+ const T& at(const K &key, const T &defval) const
{
int hash = do_hash(key);
int i = do_lookup(key, hash);
@@ -642,6 +642,7 @@ protected:
entry_t() { }
entry_t(const K &udata, int next) : udata(udata), next(next) { }
+ entry_t(K &&udata, int next) : udata(std::move(udata)), next(next) { }
};
std::vector<int> hashtable;
@@ -745,11 +746,24 @@ protected:
int do_insert(const K &value, int &hash)
{
if (hashtable.empty()) {
- entries.push_back(entry_t(value, -1));
+ entries.emplace_back(value, -1);
do_rehash();
hash = do_hash(value);
} else {
- entries.push_back(entry_t(value, hashtable[hash]));
+ entries.emplace_back(value, hashtable[hash]);
+ hashtable[hash] = entries.size() - 1;
+ }
+ return entries.size() - 1;
+ }
+
+ int do_insert(K &&rvalue, int &hash)
+ {
+ if (hashtable.empty()) {
+ entries.emplace_back(std::forward<K>(rvalue), -1);
+ do_rehash();
+ hash = do_hash(rvalue);
+ } else {
+ entries.emplace_back(std::forward<K>(rvalue), hashtable[hash]);
hashtable[hash] = entries.size() - 1;
}
return entries.size() - 1;
@@ -847,6 +861,22 @@ public:
return std::pair<iterator, bool>(iterator(this, i), true);
}
+ std::pair<iterator, bool> insert(K &&rvalue)
+ {
+ int hash = do_hash(rvalue);
+ int i = do_lookup(rvalue, hash);
+ if (i >= 0)
+ return std::pair<iterator, bool>(iterator(this, i), false);
+ i = do_insert(std::forward<K>(rvalue), hash);
+ return std::pair<iterator, bool>(iterator(this, i), true);
+ }
+
+ template<typename... Args>
+ std::pair<iterator, bool> emplace(Args&&... args)
+ {
+ return insert(K(std::forward<Args>(args)...));
+ }
+
int erase(const K &key)
{
int hash = do_hash(key);
@@ -961,7 +991,21 @@ class idict
pool<K, OPS> database;
public:
- typedef typename pool<K, OPS>::const_iterator const_iterator;
+ class const_iterator : public std::iterator<std::forward_iterator_tag, K>
+ {
+ friend class idict;
+ protected:
+ const idict &container;
+ int index;
+ const_iterator(const idict &container, int index) : container(container), index(index) { }
+ public:
+ const_iterator() { }
+ const_iterator operator++() { index++; return *this; }
+ bool operator==(const const_iterator &other) const { return index == other.index; }
+ bool operator!=(const const_iterator &other) const { return index != other.index; }
+ const K &operator*() const { return container[index]; }
+ const K *operator->() const { return &container[index]; }
+ };
int operator()(const K &key)
{
@@ -1019,9 +1063,9 @@ public:
bool empty() const { return database.empty(); }
void clear() { database.clear(); }
- const_iterator begin() const { return database.begin(); }
- const_iterator element(int n) const { return database.element(n); }
- const_iterator end() const { return database.end(); }
+ const_iterator begin() const { return const_iterator(*this, offset); }
+ const_iterator element(int n) const { return const_iterator(*this, n); }
+ const_iterator end() const { return const_iterator(*this, offset + size()); }
};
template<typename K, typename OPS>
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 6996a02c4..2aefe30b1 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -273,6 +273,11 @@ bool RTLIL::Const::is_fully_undef() const
return true;
}
+bool RTLIL::AttrObject::has_attribute(RTLIL::IdString id) const
+{
+ return attributes.count(id);
+}
+
void RTLIL::AttrObject::set_bool_attribute(RTLIL::IdString id, bool value)
{
if (value)
@@ -289,6 +294,23 @@ bool RTLIL::AttrObject::get_bool_attribute(RTLIL::IdString id) const
return it->second.as_bool();
}
+void RTLIL::AttrObject::set_string_attribute(RTLIL::IdString id, string value)
+{
+ if (value.empty())
+ attributes.erase(id);
+ else
+ attributes[id] = value;
+}
+
+string RTLIL::AttrObject::get_string_attribute(RTLIL::IdString id) const
+{
+ std::string value;
+ const auto it = attributes.find(id);
+ if (it != attributes.end())
+ value = it->second.decode_string();
+ return value;
+}
+
void RTLIL::AttrObject::set_strpool_attribute(RTLIL::IdString id, const pool<string> &data)
{
string attrval;
@@ -317,23 +339,6 @@ pool<string> RTLIL::AttrObject::get_strpool_attribute(RTLIL::IdString id) const
return data;
}
-void RTLIL::AttrObject::set_src_attribute(const std::string &src)
-{
- if (src.empty())
- attributes.erase(ID::src);
- else
- attributes[ID::src] = src;
-}
-
-std::string RTLIL::AttrObject::get_src_attribute() const
-{
- std::string src;
- const auto it = attributes.find(ID::src);
- if (it != attributes.end())
- src = it->second.decode_string();
- return src;
-}
-
bool RTLIL::Selection::selected_module(RTLIL::IdString mod_name) const
{
if (full_selection)
@@ -1384,7 +1389,7 @@ void RTLIL::Module::sort()
{
wires_.sort(sort_by_id_str());
cells_.sort(sort_by_id_str());
- avail_parameters.sort(sort_by_id_str());
+ parameter_default_values.sort(sort_by_id_str());
memories.sort(sort_by_id_str());
processes.sort(sort_by_id_str());
for (auto &it : cells_)
@@ -1503,6 +1508,7 @@ void RTLIL::Module::cloneInto(RTLIL::Module *new_mod) const
log_assert(new_mod->refcount_cells_ == 0);
new_mod->avail_parameters = avail_parameters;
+ new_mod->parameter_default_values = parameter_default_values;
for (auto &conn : connections_)
new_mod->connect(conn);
@@ -2613,7 +2619,16 @@ void RTLIL::Cell::setParam(RTLIL::IdString paramname, RTLIL::Const value)
const RTLIL::Const &RTLIL::Cell::getParam(RTLIL::IdString paramname) const
{
- return parameters.at(paramname);
+ static const RTLIL::Const empty;
+ const auto &it = parameters.find(paramname);
+ if (it != parameters.end())
+ return it->second;
+ if (module && module->design) {
+ RTLIL::Module *m = module->design->module(type);
+ if (m)
+ return m->parameter_default_values.at(paramname, empty);
+ }
+ return empty;
}
void RTLIL::Cell::sort()
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 17f038e36..11c45bbec 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -656,6 +656,8 @@ struct RTLIL::AttrObject
{
dict<RTLIL::IdString, RTLIL::Const> attributes;
+ bool has_attribute(RTLIL::IdString id) const;
+
void set_bool_attribute(RTLIL::IdString id, bool value=true);
bool get_bool_attribute(RTLIL::IdString id) const;
@@ -663,12 +665,19 @@ struct RTLIL::AttrObject
return get_bool_attribute(ID::blackbox) || (!ignore_wb && get_bool_attribute(ID::whitebox));
}
+ void set_string_attribute(RTLIL::IdString id, string value);
+ string get_string_attribute(RTLIL::IdString id) const;
+
void set_strpool_attribute(RTLIL::IdString id, const pool<string> &data);
void add_strpool_attribute(RTLIL::IdString id, const pool<string> &data);
pool<string> get_strpool_attribute(RTLIL::IdString id) const;
- void set_src_attribute(const std::string &src);
- std::string get_src_attribute() const;
+ void set_src_attribute(const std::string &src) {
+ set_string_attribute(ID::src, src);
+ }
+ std::string get_src_attribute() const {
+ return get_string_attribute(ID::src);
+ }
};
struct RTLIL::SigChunk
@@ -1082,7 +1091,8 @@ public:
std::vector<RTLIL::SigSig> connections_;
RTLIL::IdString name;
- pool<RTLIL::IdString> avail_parameters;
+ idict<RTLIL::IdString> avail_parameters;
+ dict<RTLIL::IdString, RTLIL::Const> parameter_default_values;
dict<RTLIL::IdString, RTLIL::Memory*> memories;
dict<RTLIL::IdString, RTLIL::Process*> processes;