aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/hashlib.h24
-rw-r--r--kernel/rtlil.cc14
-rw-r--r--kernel/rtlil.h3
3 files changed, 33 insertions, 8 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h
index 996bda38e..97fadea0e 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);
@@ -961,7 +961,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 +1033,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 8af941c85..2aefe30b1 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -1389,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_)
@@ -1508,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);
@@ -2618,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 f3b1c9ae7..11c45bbec 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -1091,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;