From ff7a1a1568e0d4773b160b631da0446673149091 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 16 Apr 2020 21:43:03 +0000 Subject: [PATCH 1/2] rtlil: add AttrObject::{get,set}_string_attribute. And make {get,set}_src_attribute use those functions. --- kernel/rtlil.cc | 34 +++++++++++++++++----------------- kernel/rtlil.h | 11 +++++++++-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 6996a02c4..9ecad056f 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -289,6 +289,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 &data) { string attrval; @@ -317,23 +334,6 @@ pool 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) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 17f038e36..fe9e21c31 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -663,12 +663,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 &data); void add_strpool_attribute(RTLIL::IdString id, const pool &data); pool 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 From b6f624b56bc3adee55743c4bd383414ea5b07c72 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 16 Apr 2020 21:49:49 +0000 Subject: [PATCH 2/2] rtlil: add AttrObject::has_attribute. --- kernel/rtlil.cc | 5 +++++ kernel/rtlil.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 9ecad056f..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) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index fe9e21c31..f3b1c9ae7 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -656,6 +656,8 @@ struct RTLIL::AttrObject { dict 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;