diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-08-04 15:08:35 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-08-04 15:40:07 +0200 |
commit | ebbbe7fc8360ca0bd8f840d3df1b77ab2fb569b6 (patch) | |
tree | 8d7dd71f161543176cbf1d784d98da389d9b53b2 | |
parent | c7f99be3be828606cafc7d35b3612f5344065736 (diff) | |
download | yosys-ebbbe7fc8360ca0bd8f840d3df1b77ab2fb569b6.tar.gz yosys-ebbbe7fc8360ca0bd8f840d3df1b77ab2fb569b6.tar.bz2 yosys-ebbbe7fc8360ca0bd8f840d3df1b77ab2fb569b6.zip |
Added RTLIL::IdString::in(...)
-rw-r--r-- | kernel/rtlil.h | 23 | ||||
-rw-r--r-- | passes/cmds/wreduce.cc | 7 |
2 files changed, 21 insertions, 9 deletions
diff --git a/kernel/rtlil.h b/kernel/rtlil.h index ab15024e0..8dfcbcaa0 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -170,20 +170,20 @@ namespace RTLIL return std::string(global_id_storage_.at(index_)); } - bool operator<(const IdString &rhs) const { + bool operator<(IdString rhs) const { return index_ < rhs.index_; } - bool operator==(const IdString &rhs) const { return index_ == rhs.index_; } - bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; } + bool operator==(IdString rhs) const { return index_ == rhs.index_; } + bool operator!=(IdString rhs) const { return index_ != rhs.index_; } // The methods below are just convinience functions for better compatibility with std::string. bool operator==(const std::string &rhs) const { return str() == rhs; } bool operator!=(const std::string &rhs) const { return str() != rhs; } - bool operator==(const char *rhs) const { return str() == rhs; } - bool operator!=(const char *rhs) const { return str() != rhs; } + bool operator==(const char *rhs) const { return strcmp(c_str(), rhs) == 0; } + bool operator!=(const char *rhs) const { return strcmp(c_str(), rhs) != 0; } char operator[](size_t i) const { const char *p = c_str(); @@ -220,6 +220,19 @@ namespace RTLIL return (a == nullptr || b == nullptr) ? (a < b) : (a->name < b->name); } }; + + // often one needs to check if a given IdString is part of a list (for example a list + // of cell types). the following functions helps with that. + + template<typename T, typename... Args> + bool in(T first, Args... rest) { + return in(first) || in(rest...); + } + + bool in(IdString rhs) { return *this == rhs; } + bool in(const char *rhs) { return *this == rhs; } + bool in(const std::string &rhs) { return *this == rhs; } + bool in(const std::set<IdString> &rhs) { return rhs.count(*this) != 0; } }; static inline std::string escape_id(std::string str) { diff --git a/passes/cmds/wreduce.cc b/passes/cmds/wreduce.cc index bd0b315e7..9cef14f48 100644 --- a/passes/cmds/wreduce.cc +++ b/passes/cmds/wreduce.cc @@ -109,10 +109,10 @@ struct WreduceWorker void run_cell(Cell *cell) { - if (config->supported_cell_types.count(cell->type) == 0) + if (!cell->type.in(config->supported_cell_types)) return; - if (cell->type == ID("$shl") || cell->type == ID("$shr") || cell->type == ID("$sshl") || cell->type == ID("$sshr")) + if (cell->type.in("$shl", "$shr", "$sshl", "$sshr")) cell->setParam("\\B_SIGNED", false); if (cell->hasParam("\\A_SIGNED")) @@ -135,8 +135,7 @@ struct WreduceWorker bits_removed++; } - if (cell->type == ID("$pos") || cell->type == ID("$bu0") || cell->type == ID("$add") || cell->type == ID("$mul") || - cell->type == ID("$and") || cell->type == ID("$or") || cell->type == ID("$xor")) + if (cell->type.in("$pos", "$bu0", "$add", "$mul", "$and", "$or", "$xor")) { bool is_signed = cell->getParam("\\A_SIGNED").as_bool(); |