ice40: split out cells_map.v into ff_map.v
[yosys.git] / kernel / rtlil.cc
index dc368ead5021b20766c9df6ce831b21016436fce..196e301b6c04e20fd449f197cf0cafd96467f230 100644 (file)
@@ -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;
 }
@@ -1383,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_)
@@ -1502,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);
@@ -2612,7 +2619,15 @@ void RTLIL::Cell::setParam(RTLIL::IdString paramname, RTLIL::Const value)
 
 const RTLIL::Const &RTLIL::Cell::getParam(RTLIL::IdString paramname) const
 {
-       return parameters.at(paramname);
+       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);
+       }
+       throw std::out_of_range("Cell::getParam()");
 }
 
 void RTLIL::Cell::sort()