aboutsummaryrefslogtreecommitdiffstats
path: root/frontends/ast/simplify.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-12-05 13:26:17 +0100
committerClifford Wolf <clifford@clifford.at>2013-12-05 13:26:17 +0100
commit891e4b5b0d16a537e6d1ca0ecbc1ac3bafccecef (patch)
treed5517477feb4c2162fa59f7be6861bf4e9ef9261 /frontends/ast/simplify.cc
parente935bb6edacf46e84959a2e7befa413497420a9a (diff)
downloadyosys-891e4b5b0d16a537e6d1ca0ecbc1ac3bafccecef.tar.gz
yosys-891e4b5b0d16a537e6d1ca0ecbc1ac3bafccecef.tar.bz2
yosys-891e4b5b0d16a537e6d1ca0ecbc1ac3bafccecef.zip
Keep strings as strings in const ternary and concat
Diffstat (limited to 'frontends/ast/simplify.cc')
-rw-r--r--frontends/ast/simplify.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index fe4ff3f23..f6df0c170 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -1176,6 +1176,7 @@ skip_dynamic_range_lvalue_expansion:;
// perform const folding when activated
if (const_fold && newNode == NULL)
{
+ bool string_op;
std::vector<RTLIL::State> tmp_bits;
RTLIL::Const (*const_func)(const RTLIL::Const&, const RTLIL::Const&, bool, bool, int);
RTLIL::Const dummy_arg;
@@ -1306,7 +1307,10 @@ skip_dynamic_range_lvalue_expansion:;
choice = children[2];
if (choice != NULL && choice->type == AST_CONSTANT) {
RTLIL::Const y = choice->bitsAsConst(width_hint, sign_hint);
- newNode = mkconst_bits(y.bits, sign_hint);
+ if (choice->is_string && y.bits.size() % 8 == 0 && sign_hint == false)
+ newNode = mkconst_str(y.bits);
+ else
+ newNode = mkconst_bits(y.bits, sign_hint);
} else if (children[1]->type == AST_CONSTANT && children[2]->type == AST_CONSTANT) {
RTLIL::Const a = children[1]->bitsAsConst(width_hint, sign_hint);
RTLIL::Const b = children[2]->bitsAsConst(width_hint, sign_hint);
@@ -1319,19 +1323,22 @@ skip_dynamic_range_lvalue_expansion:;
}
break;
case AST_CONCAT:
+ string_op = !children.empty();
for (auto it = children.begin(); it != children.end(); it++) {
if ((*it)->type != AST_CONSTANT)
goto not_const;
+ if (!(*it)->is_string)
+ string_op = false;
tmp_bits.insert(tmp_bits.end(), (*it)->bits.begin(), (*it)->bits.end());
}
- newNode = mkconst_bits(tmp_bits, false);
+ newNode = string_op ? mkconst_str(tmp_bits) : mkconst_bits(tmp_bits, false);
break;
case AST_REPLICATE:
if (children.at(0)->type != AST_CONSTANT || children.at(1)->type != AST_CONSTANT)
goto not_const;
for (int i = 0; i < children[0]->bitsAsConst().as_int(); i++)
tmp_bits.insert(tmp_bits.end(), children.at(1)->bits.begin(), children.at(1)->bits.end());
- newNode = mkconst_bits(tmp_bits, false);
+ newNode = children.at(1)->is_string ? mkconst_str(tmp_bits) : mkconst_bits(tmp_bits, false);
break;
default:
not_const: