Added RTLIL::SigSpec::to_sigbit_map()

This commit is contained in:
Clifford Wolf 2014-08-14 23:14:47 +02:00
parent c83b990458
commit 978a933b6a
3 changed files with 20 additions and 11 deletions

View File

@ -400,10 +400,7 @@ struct AST_INTERNAL::ProcessGenerator
case AST_ASSIGN_EQ: case AST_ASSIGN_EQ:
case AST_ASSIGN_LE: case AST_ASSIGN_LE:
{ {
std::map<RTLIL::SigBit, RTLIL::SigBit> new_subst_rvalue_map; std::map<RTLIL::SigBit, RTLIL::SigBit> new_subst_rvalue_map = subst_rvalue_from.to_sigbit_map(subst_rvalue_to);
for (int i = 0; i < SIZE(subst_rvalue_to); i++)
new_subst_rvalue_map[subst_rvalue_from[i]] = subst_rvalue_to[i];
RTLIL::SigSpec unmapped_lvalue = ast->children[0]->genRTLIL(), lvalue = unmapped_lvalue; RTLIL::SigSpec unmapped_lvalue = ast->children[0]->genRTLIL(), lvalue = unmapped_lvalue;
RTLIL::SigSpec rvalue = ast->children[1]->genWidthRTLIL(lvalue.size(), &new_subst_rvalue_map); RTLIL::SigSpec rvalue = ast->children[1]->genWidthRTLIL(lvalue.size(), &new_subst_rvalue_map);
lvalue.replace(subst_lvalue_from, subst_lvalue_to); lvalue.replace(subst_lvalue_from, subst_lvalue_to);
@ -421,10 +418,7 @@ struct AST_INTERNAL::ProcessGenerator
case AST_CASE: case AST_CASE:
{ {
std::map<RTLIL::SigBit, RTLIL::SigBit> new_subst_rvalue_map; std::map<RTLIL::SigBit, RTLIL::SigBit> new_subst_rvalue_map = subst_rvalue_from.to_sigbit_map(subst_rvalue_to);
for (int i = 0; i < SIZE(subst_rvalue_to); i++)
new_subst_rvalue_map[subst_rvalue_from[i]] = subst_rvalue_to[i];
RTLIL::SwitchRule *sw = new RTLIL::SwitchRule; RTLIL::SwitchRule *sw = new RTLIL::SwitchRule;
sw->signal = ast->children[0]->genWidthRTLIL(-1, &new_subst_rvalue_map); sw->signal = ast->children[0]->genWidthRTLIL(-1, &new_subst_rvalue_map);
current_case->switches.push_back(sw); current_case->switches.push_back(sw);
@ -478,9 +472,7 @@ struct AST_INTERNAL::ProcessGenerator
else if (node->type == AST_BLOCK) else if (node->type == AST_BLOCK)
processAst(node); processAst(node);
else { else {
std::map<RTLIL::SigBit, RTLIL::SigBit> new_subst_rvalue_map; std::map<RTLIL::SigBit, RTLIL::SigBit> new_subst_rvalue_map = subst_rvalue_from.to_sigbit_map(subst_rvalue_to);
for (int i = 0; i < SIZE(subst_rvalue_to); i++)
new_subst_rvalue_map[subst_rvalue_from[i]] = subst_rvalue_to[i];
current_case->compare.push_back(node->genWidthRTLIL(sw->signal.size(), &new_subst_rvalue_map)); current_case->compare.push_back(node->genWidthRTLIL(sw->signal.size(), &new_subst_rvalue_map));
} }
} }

View File

@ -2687,6 +2687,22 @@ std::vector<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_vector() const
return bits_; return bits_;
} }
std::map<RTLIL::SigBit, RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_map(const RTLIL::SigSpec &other) const
{
cover("kernel.rtlil.sigspec.to_sigbit_map");
unpack();
other.unpack();
log_assert(width_ == other.width_);
std::map<RTLIL::SigBit, RTLIL::SigBit> new_map;
for (int i = 0; i < width_; i++)
new_map[bits_[i]] = other.bits_[i];
return new_map;
}
RTLIL::SigBit RTLIL::SigSpec::to_single_sigbit() const RTLIL::SigBit RTLIL::SigSpec::to_single_sigbit() const
{ {
cover("kernel.rtlil.sigspec.to_single_sigbit"); cover("kernel.rtlil.sigspec.to_single_sigbit");

View File

@ -1020,6 +1020,7 @@ public:
std::set<RTLIL::SigBit> to_sigbit_set() const; std::set<RTLIL::SigBit> to_sigbit_set() const;
std::vector<RTLIL::SigBit> to_sigbit_vector() const; std::vector<RTLIL::SigBit> to_sigbit_vector() const;
std::map<RTLIL::SigBit, RTLIL::SigBit> to_sigbit_map(const RTLIL::SigSpec &other) const;
RTLIL::SigBit to_single_sigbit() const; RTLIL::SigBit to_single_sigbit() const;
static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);