summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.cc32
-rw-r--r--kernel/rtlil.h14
2 files changed, 39 insertions, 7 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 5bfb33a2..bd1a9aee 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -28,9 +28,15 @@
int RTLIL::autoidx = 1;
-RTLIL::Const::Const(std::string str) : str(str)
+RTLIL::Const::Const()
{
- for (size_t i = 0; i < str.size(); i++) {
+ flags = RTLIL::CONST_FLAG_NONE;
+}
+
+RTLIL::Const::Const(std::string str)
+{
+ flags = RTLIL::CONST_FLAG_STRING;
+ for (int i = str.size()-1; i >= 0; i--) {
unsigned char ch = str[i];
for (int j = 0; j < 8; j++) {
bits.push_back((ch & 1) != 0 ? RTLIL::S1 : RTLIL::S0);
@@ -41,6 +47,7 @@ RTLIL::Const::Const(std::string str) : str(str)
RTLIL::Const::Const(int val, int width)
{
+ flags = RTLIL::CONST_FLAG_NONE;
for (int i = 0; i < width; i++) {
bits.push_back((val & 1) != 0 ? RTLIL::S1 : RTLIL::S0);
val = val >> 1;
@@ -49,6 +56,7 @@ RTLIL::Const::Const(int val, int width)
RTLIL::Const::Const(RTLIL::State bit, int width)
{
+ flags = RTLIL::CONST_FLAG_NONE;
for (int i = 0; i < width; i++)
bits.push_back(bit);
}
@@ -105,6 +113,23 @@ std::string RTLIL::Const::as_string() const
return ret;
}
+std::string RTLIL::Const::decode_string() const
+{
+ std::string string;
+ std::vector <char> string_chars;
+ for (int i = 0; i < int (bits.size()); i += 8) {
+ char ch = 0;
+ for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
+ if (bits[i + j] == RTLIL::State::S1)
+ ch |= 1 << j;
+ if (ch != 0)
+ string_chars.push_back(ch);
+ }
+ for (int i = int (string_chars.size()) - 1; i >= 0; i--)
+ string += string_chars[i];
+ return string;
+}
+
bool RTLIL::Selection::selected_module(RTLIL::IdString mod_name) const
{
if (full_selection)
@@ -965,7 +990,6 @@ void RTLIL::SigSpec::expand()
{
std::vector<RTLIL::SigChunk> new_chunks;
for (size_t i = 0; i < chunks.size(); i++) {
- assert(chunks[i].data.str.empty());
for (int j = 0; j < chunks[i].width; j++)
new_chunks.push_back(chunks[i].extract(j, 1));
}
@@ -1323,13 +1347,11 @@ void RTLIL::SigSpec::check() const
if (chunk.wire == NULL) {
assert(chunk.offset == 0);
assert(chunk.data.bits.size() == (size_t)chunk.width);
- assert(chunk.data.str.size() == 0 || chunk.data.str.size()*8 == chunk.data.bits.size());
} else {
assert(chunk.offset >= 0);
assert(chunk.width >= 0);
assert(chunk.offset + chunk.width <= chunk.wire->width);
assert(chunk.data.bits.size() == 0);
- assert(chunk.data.str.size() == 0);
}
w += chunk.width;
}
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 5873c369..f00a51a2 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -38,6 +38,7 @@ namespace RTLIL
Sa = 4, // don't care (used only in cases)
Sm = 5 // marker (used internally by some passes)
};
+
enum SyncType {
ST0 = 0, // level sensitive: 0
ST1 = 1, // level sensitive: 1
@@ -48,6 +49,13 @@ namespace RTLIL
STi = 6 // init
};
+ enum ConstFlags {
+ CONST_FLAG_NONE = 0,
+ CONST_FLAG_STRING = 1,
+ CONST_FLAG_SIGNED = 2, // unused -- to be used for parameters
+ CONST_FLAG_REAL = 4 // unused -- to be used for parameters
+ };
+
extern int autoidx;
struct Const;
@@ -181,9 +189,10 @@ namespace RTLIL
};
struct RTLIL::Const {
- std::string str;
+ int flags;
std::vector<RTLIL::State> bits;
- Const(std::string str = std::string());
+ Const();
+ Const(std::string str);
Const(int val, int width = 32);
Const(RTLIL::State bit, int width = 1);
Const(std::vector<RTLIL::State> bits) : bits(bits) { };
@@ -193,6 +202,7 @@ struct RTLIL::Const {
bool as_bool() const;
int as_int() const;
std::string as_string() const;
+ std::string decode_string() const;
};
struct RTLIL::Selection {