diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/hashlib.h | 72 | ||||
-rw-r--r-- | kernel/register.cc | 7 | ||||
-rw-r--r-- | kernel/rtlil.cc | 40 | ||||
-rw-r--r-- | kernel/rtlil.h | 13 |
4 files changed, 106 insertions, 26 deletions
diff --git a/kernel/hashlib.h b/kernel/hashlib.h index e7cb312ed..996bda38e 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -314,11 +314,11 @@ class dict int do_insert(const K &key, int &hash) { if (hashtable.empty()) { - entries.push_back(entry_t(std::pair<K, T>(key, T()), -1)); + entries.emplace_back(std::pair<K, T>(key, T()), -1); do_rehash(); hash = do_hash(key); } else { - entries.push_back(entry_t(std::pair<K, T>(key, T()), hashtable[hash])); + entries.emplace_back(std::pair<K, T>(key, T()), hashtable[hash]); hashtable[hash] = entries.size() - 1; } return entries.size() - 1; @@ -327,11 +327,25 @@ class dict int do_insert(const std::pair<K, T> &value, int &hash) { if (hashtable.empty()) { - entries.push_back(entry_t(value, -1)); + entries.emplace_back(value, -1); do_rehash(); hash = do_hash(value.first); } 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(std::pair<K, T> &&rvalue, int &hash) + { + if (hashtable.empty()) { + auto key = rvalue.first; + entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), -1); + do_rehash(); + hash = do_hash(key); + } else { + entries.emplace_back(std::forward<std::pair<K, T>>(rvalue), hashtable[hash]); hashtable[hash] = entries.size() - 1; } return entries.size() - 1; @@ -441,6 +455,56 @@ public: return std::pair<iterator, bool>(iterator(this, i), true); } + std::pair<iterator, bool> insert(std::pair<K, T> &&rvalue) + { + int hash = do_hash(rvalue.first); + int i = do_lookup(rvalue.first, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::forward<std::pair<K, T>>(rvalue), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + + std::pair<iterator, bool> emplace(K const &key, T const &value) + { + int hash = do_hash(key); + int i = do_lookup(key, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(key, value), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + + std::pair<iterator, bool> emplace(K const &key, T &&rvalue) + { + int hash = do_hash(key); + int i = do_lookup(key, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(key, std::forward<T>(rvalue)), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + + std::pair<iterator, bool> emplace(K &&rkey, T const &value) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward<K>(rkey), value), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + + std::pair<iterator, bool> emplace(K &&rkey, T &&rvalue) + { + int hash = do_hash(rkey); + int i = do_lookup(rkey, hash); + if (i >= 0) + return std::pair<iterator, bool>(iterator(this, i), false); + i = do_insert(std::make_pair(std::forward<K>(rkey), std::forward<T>(rvalue)), hash); + return std::pair<iterator, bool>(iterator(this, i), true); + } + int erase(const K &key) { int hash = do_hash(key); diff --git a/kernel/register.cc b/kernel/register.cc index af8c1b8e8..925d0d776 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -485,20 +485,21 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s cmd_error(args, argidx, "Extra filename argument in direct file mode."); filename = arg; + //Accommodate heredocs with EOT marker spaced out from "<<", e.g. "<< EOT" vs. "<<EOT" if (filename == "<<" && argidx+1 < args.size()) filename += args[++argidx]; if (filename.compare(0, 2, "<<") == 0) { - if (Frontend::current_script_file == NULL) - log_error("Unexpected here document '%s' outside of script!\n", filename.c_str()); if (filename.size() <= 2) log_error("Missing EOT marker in here document!\n"); std::string eot_marker = filename.substr(2); + if (Frontend::current_script_file == nullptr) + filename = "<stdin>"; last_here_document.clear(); while (1) { std::string buffer; char block[4096]; while (1) { - if (fgets(block, 4096, Frontend::current_script_file) == NULL) + if (fgets(block, 4096, Frontend::current_script_file == nullptr? stdin : Frontend::current_script_file) == nullptr) log_error("Unexpected end of file in here document '%s'!\n", filename.c_str()); buffer += block; if (buffer.size() > 0 && (buffer[buffer.size() - 1] == '\n' || buffer[buffer.size() - 1] == '\r')) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index dc368ead5..8af941c85 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) @@ -597,6 +602,7 @@ void RTLIL::Design::remove(RTLIL::Module *module) } log_assert(modules_.at(module->name) == module); + log_assert(refcount_modules_ == 0); modules_.erase(module->name); delete module; } diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 17f038e36..f3b1c9ae7 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 |