aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2022-08-08 16:13:33 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2022-08-08 16:13:33 +0200
commit6c65ca4e50cc6712d9293b9630afdf67af89ef61 (patch)
tree972797adf263e9ecf3dc4e6b10310c629df30274 /kernel
parent2b1aeb44d98f4aafc73a66cdd02092571d725ee4 (diff)
downloadyosys-6c65ca4e50cc6712d9293b9630afdf67af89ef61.tar.gz
yosys-6c65ca4e50cc6712d9293b9630afdf67af89ef61.tar.bz2
yosys-6c65ca4e50cc6712d9293b9630afdf67af89ef61.zip
Encode filename unprintable chars
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index ff5bdf2d7..db175d7e9 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -440,6 +440,21 @@ namespace RTLIL
}
};
+ static inline std::string encode_filename(const std::string &filename)
+ {
+ std::stringstream val;
+ if (!std::any_of(filename.begin(), filename.end(), [](char c) {
+ return static_cast<unsigned char>(c) < 33 || static_cast<unsigned char>(c) > 126;
+ })) return filename;
+ for (unsigned char const c : filename) {
+ if (c < 33 || c > 126)
+ val << stringf("$%02x", c);
+ else
+ val << c;
+ }
+ return val.str();
+ }
+
// see calc.cc for the implementation of this functions
RTLIL::Const const_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
RTLIL::Const const_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);