mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 17:15:33 +00:00
Preparations for RTLIL::IdString redesign: cleanup of existing code
This commit is contained in:
parent
75ffd1643c
commit
14412e6c95
12 changed files with 71 additions and 32 deletions
|
@ -29,7 +29,7 @@
|
|||
|
||||
struct CellTypes
|
||||
{
|
||||
std::set<std::string> cell_types;
|
||||
std::set<RTLIL::IdString> cell_types;
|
||||
std::vector<const RTLIL::Design*> designs;
|
||||
|
||||
CellTypes()
|
||||
|
@ -168,7 +168,7 @@ struct CellTypes
|
|||
designs.clear();
|
||||
}
|
||||
|
||||
bool cell_known(std::string type)
|
||||
bool cell_known(RTLIL::IdString type)
|
||||
{
|
||||
if (cell_types.count(type) > 0)
|
||||
return true;
|
||||
|
@ -178,7 +178,7 @@ struct CellTypes
|
|||
return false;
|
||||
}
|
||||
|
||||
bool cell_output(std::string type, std::string port)
|
||||
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
|
||||
{
|
||||
if (cell_types.count(type) == 0) {
|
||||
for (auto design : designs)
|
||||
|
@ -201,7 +201,7 @@ struct CellTypes
|
|||
return false;
|
||||
}
|
||||
|
||||
bool cell_input(std::string type, std::string port)
|
||||
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
|
||||
{
|
||||
if (cell_types.count(type) == 0) {
|
||||
for (auto design : designs)
|
||||
|
@ -219,7 +219,7 @@ struct CellTypes
|
|||
return false;
|
||||
}
|
||||
|
||||
static RTLIL::Const eval(std::string type, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
|
||||
static RTLIL::Const eval(RTLIL::IdString type, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
|
||||
{
|
||||
if (type == "$sshr" && !signed1)
|
||||
type = "$shr";
|
||||
|
|
|
@ -203,12 +203,12 @@ const char *log_signal(const RTLIL::SigSpec &sig, bool autoint)
|
|||
return string_buf.back().c_str();
|
||||
}
|
||||
|
||||
const char *log_id(std::string str)
|
||||
const char *log_id(RTLIL::IdString str)
|
||||
{
|
||||
if (str.size() > 1 && str[0] == '\\' && str[1] != '$')
|
||||
string_buf.push_back(str.substr(1));
|
||||
else
|
||||
string_buf.push_back(str);
|
||||
string_buf.push_back(str.str());
|
||||
return string_buf.back().c_str();
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ void log_reset_stack();
|
|||
void log_flush();
|
||||
|
||||
const char *log_signal(const RTLIL::SigSpec &sig, bool autoint = true);
|
||||
const char *log_id(std::string id);
|
||||
const char *log_id(RTLIL::IdString id);
|
||||
|
||||
template<typename T> static inline const char *log_id(T *obj) {
|
||||
return log_id(obj->name);
|
||||
|
|
|
@ -72,9 +72,7 @@ namespace RTLIL
|
|||
|
||||
typedef std::pair<SigSpec, SigSpec> SigSig;
|
||||
|
||||
#ifdef NDEBUG
|
||||
typedef std::string IdString;
|
||||
#else
|
||||
#if 1
|
||||
struct IdString : public std::string {
|
||||
IdString() { }
|
||||
IdString(std::string str) : std::string(str) {
|
||||
|
@ -100,30 +98,70 @@ namespace RTLIL
|
|||
void check() const {
|
||||
log_assert(empty() || (size() >= 2 && (at(0) == '$' || at(0) == '\\')));
|
||||
}
|
||||
const std::string& str() const {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
#else
|
||||
struct IdString {
|
||||
IdString();
|
||||
IdString(const char *str);
|
||||
IdString(const IdString &str);
|
||||
IdString(const std::string &str);
|
||||
|
||||
void operator=(const char *rhs);
|
||||
void operator=(const IdString &rhs);
|
||||
void operator=(const std::string &rhs);
|
||||
|
||||
operator const char*() const;
|
||||
const std::string& str() const;
|
||||
|
||||
bool operator<(const IdString &rhs) const;
|
||||
bool operator==(const IdString &rhs) const;
|
||||
bool operator!=(const IdString &rhs) const;
|
||||
bool operator==(const char *rhs) const;
|
||||
bool operator!=(const char *rhs) const;
|
||||
std::string operator+(const char *other) const;
|
||||
|
||||
std::string::const_iterator begin() const;
|
||||
std::string::const_iterator end() const;
|
||||
char at(int i) const;
|
||||
const char*c_str() const;
|
||||
size_t find(char c) const;
|
||||
std::string substr(size_t pos = 0, size_t len = std::string::npos) const;
|
||||
size_t size() const;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static IdString escape_id(std::string str) __attribute__((unused));
|
||||
static IdString escape_id(std::string str) {
|
||||
static inline std::string escape_id(std::string str) {
|
||||
if (str.size() > 0 && str[0] != '\\' && str[0] != '$')
|
||||
return "\\" + str;
|
||||
return str;
|
||||
}
|
||||
|
||||
static std::string unescape_id(std::string str) __attribute__((unused));
|
||||
static std::string unescape_id(std::string str) {
|
||||
static inline std::string unescape_id(std::string str) {
|
||||
if (str.size() > 1 && str[0] == '\\' && str[1] != '$')
|
||||
return str.substr(1);
|
||||
return str;
|
||||
}
|
||||
|
||||
static const char *id2cstr(std::string str) __attribute__((unused));
|
||||
static const char *id2cstr(std::string str) {
|
||||
static inline const char *id2cstr(std::string str) {
|
||||
if (str.size() > 1 && str[0] == '\\' && str[1] != '$')
|
||||
return str.c_str() + 1;
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
static inline std::string unescape_id(RTLIL::IdString str) {
|
||||
return unescape_id(str.str());
|
||||
}
|
||||
|
||||
static inline const char *id2cstr(RTLIL::IdString str) {
|
||||
return id2cstr(str.str());
|
||||
}
|
||||
|
||||
template <typename T> struct sort_by_name {
|
||||
bool operator()(T *a, T *b) const {
|
||||
return a->name < b->name;
|
||||
|
|
|
@ -445,7 +445,7 @@ static char *readline_obj_generator(const char *text, int state)
|
|||
{
|
||||
for (auto &it : design->modules_)
|
||||
if (RTLIL::unescape_id(it.first).substr(0, len) == text)
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first.c_str())));
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
|
||||
}
|
||||
else
|
||||
if (design->modules_.count(design->selected_active_module) > 0)
|
||||
|
@ -454,19 +454,19 @@ static char *readline_obj_generator(const char *text, int state)
|
|||
|
||||
for (auto &it : module->wires_)
|
||||
if (RTLIL::unescape_id(it.first).substr(0, len) == text)
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first.c_str())));
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
|
||||
|
||||
for (auto &it : module->memories)
|
||||
if (RTLIL::unescape_id(it.first).substr(0, len) == text)
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first.c_str())));
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
|
||||
|
||||
for (auto &it : module->cells_)
|
||||
if (RTLIL::unescape_id(it.first).substr(0, len) == text)
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first.c_str())));
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
|
||||
|
||||
for (auto &it : module->processes)
|
||||
if (RTLIL::unescape_id(it.first).substr(0, len) == text)
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first.c_str())));
|
||||
obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
|
||||
}
|
||||
|
||||
std::sort(obj_names.begin(), obj_names.end());
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
YOSYS_NAMESPACE_BEGIN
|
||||
|
||||
namespace RTLIL {
|
||||
struct IdString;
|
||||
struct SigSpec;
|
||||
struct Wire;
|
||||
struct Cell;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue