summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-08-02 16:03:18 +0200
committerClifford Wolf <clifford@clifford.at>2014-08-02 18:14:21 +0200
commit768eb846c4473040dc07bf62ce631c8a21474ae8 (patch)
tree9f5b1c860360b0bdd488cc668d80d44c84aca822 /kernel
parent08392aad8f8e7c5bbcfa010c19786b1f318028b6 (diff)
More bugfixes related to new RTLIL::IdString
Diffstat (limited to 'kernel')
-rw-r--r--kernel/log.cc17
-rw-r--r--kernel/rtlil.h29
-rw-r--r--kernel/yosys.cc2
3 files changed, 31 insertions, 17 deletions
diff --git a/kernel/log.cc b/kernel/log.cc
index 9cabc6a8..01f6207e 100644
--- a/kernel/log.cc
+++ b/kernel/log.cc
@@ -90,22 +90,25 @@ void logv(const char *format, va_list ap)
void logv_header(const char *format, va_list ap)
{
+ bool pop_errfile = false;
+
log("\n");
if (header_count.size() > 0)
header_count.back()++;
+
+ if (int(header_count.size()) <= log_verbose_level && log_errfile != NULL) {
+ log_files.push_back(log_errfile);
+ pop_errfile = true;
+ }
+
for (int c : header_count)
log("%d.", c);
log(" ");
logv(format, ap);
log_flush();
- if (int(header_count.size()) <= log_verbose_level && log_errfile != NULL) {
- for (int c : header_count)
- fprintf(log_errfile, "%d.", c);
- fprintf(log_errfile, " ");
- vfprintf(log_errfile, format, ap);
- fflush(log_errfile);
- }
+ if (pop_errfile)
+ log_files.pop_back();
}
void logv_error(const char *format, va_list ap)
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 7b989385..6529603e 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -126,11 +126,14 @@ namespace RTLIL
static inline void put_reference(int idx)
{
+ log_assert(global_refcount_storage_.at(idx) > 0);
+
if (--global_refcount_storage_.at(idx) != 0)
return;
global_id_index_.erase(global_id_storage_.at(idx));
free(global_id_storage_.at(idx));
+ global_id_storage_.at(idx) = nullptr;
global_free_idx_list_.push_back(idx);
}
@@ -191,7 +194,7 @@ namespace RTLIL
}
std::string substr(size_t pos = 0, size_t len = std::string::npos) const {
- if (len == std::string::npos)
+ if (len == std::string::npos || len >= strlen(c_str() + pos))
return std::string(c_str() + pos);
else
return std::string(c_str() + pos, len);
@@ -208,6 +211,16 @@ namespace RTLIL
void clear() {
*this = IdString();
}
+
+ // The following is a helper key_compare class. Instead of for example std::set<Cell*>
+ // use std::set<Cell*, IdString::compare_ptr_by_name<Cell>> if the order of cells in the
+ // set has an influence on the algorithm.
+
+ template<typename T> struct compare_ptr_by_name {
+ bool operator()(const T *a, const T *b) {
+ return (a == nullptr || b == nullptr) ? (a < b) : (a->name < b->name);
+ }
+ };
};
static inline std::string escape_id(std::string str) {
@@ -222,18 +235,12 @@ namespace RTLIL
return str;
}
- static inline const char *id2cstr(const 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(const RTLIL::IdString &str) {
- return id2cstr(str.str());
+ return log_id(str);
}
template <typename T> struct sort_by_name {
@@ -833,7 +840,11 @@ struct RTLIL::SigBit
SigBit(const RTLIL::SigSpec &sig);
bool operator <(const RTLIL::SigBit &other) const {
- return (wire != other.wire) ? (wire < other.wire) : wire ? (offset < other.offset) : (data < other.data);
+ if (wire == other.wire)
+ return wire ? (offset < other.offset) : (data < other.data);
+ if (wire != nullptr && other.wire != nullptr)
+ return wire->name < other.wire->name;
+ return wire < other.wire;
}
bool operator ==(const RTLIL::SigBit &other) const {
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index b5873d18..dff31db0 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -122,7 +122,7 @@ const char *create_prompt(RTLIL::Design *design, int recursion_counter)
str += stringf("(%d) ", recursion_counter);
str += "yosys";
if (!design->selected_active_module.empty())
- str += stringf(" [%s]", RTLIL::id2cstr(design->selected_active_module));
+ str += stringf(" [%s]", RTLIL::unescape_id(design->selected_active_module).c_str());
if (!design->selection_stack.empty() && !design->selection_stack.back().full_selection) {
if (design->selected_active_module.empty())
str += "*";