mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-12 20:18:20 +00:00
Improve ConstEval error handling for non-eval cell types
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
ab97eddee9
commit
e90195b737
|
@ -257,7 +257,7 @@ struct CellTypes
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static RTLIL::Const eval(RTLIL::IdString type, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
|
static RTLIL::Const eval(RTLIL::IdString type, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len, bool *errp = nullptr)
|
||||||
{
|
{
|
||||||
if (type == "$sshr" && !signed1)
|
if (type == "$sshr" && !signed1)
|
||||||
type = "$shr";
|
type = "$shr";
|
||||||
|
@ -329,10 +329,15 @@ struct CellTypes
|
||||||
if (type == "$_ORNOT_")
|
if (type == "$_ORNOT_")
|
||||||
return const_or(arg1, eval_not(arg2), false, false, 1);
|
return const_or(arg1, eval_not(arg2), false, false, 1);
|
||||||
|
|
||||||
|
if (errp != nullptr) {
|
||||||
|
*errp = true;
|
||||||
|
return State::Sm;
|
||||||
|
}
|
||||||
|
|
||||||
log_abort();
|
log_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2)
|
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool *errp = nullptr)
|
||||||
{
|
{
|
||||||
if (cell->type == "$slice") {
|
if (cell->type == "$slice") {
|
||||||
RTLIL::Const ret;
|
RTLIL::Const ret;
|
||||||
|
@ -415,10 +420,10 @@ struct CellTypes
|
||||||
bool signed_a = cell->parameters.count("\\A_SIGNED") > 0 && cell->parameters["\\A_SIGNED"].as_bool();
|
bool signed_a = cell->parameters.count("\\A_SIGNED") > 0 && cell->parameters["\\A_SIGNED"].as_bool();
|
||||||
bool signed_b = cell->parameters.count("\\B_SIGNED") > 0 && cell->parameters["\\B_SIGNED"].as_bool();
|
bool signed_b = cell->parameters.count("\\B_SIGNED") > 0 && cell->parameters["\\B_SIGNED"].as_bool();
|
||||||
int result_len = cell->parameters.count("\\Y_WIDTH") > 0 ? cell->parameters["\\Y_WIDTH"].as_int() : -1;
|
int result_len = cell->parameters.count("\\Y_WIDTH") > 0 ? cell->parameters["\\Y_WIDTH"].as_int() : -1;
|
||||||
return eval(cell->type, arg1, arg2, signed_a, signed_b, result_len);
|
return eval(cell->type, arg1, arg2, signed_a, signed_b, result_len, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, const RTLIL::Const &arg3)
|
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, const RTLIL::Const &arg3, bool *errp = nullptr)
|
||||||
{
|
{
|
||||||
if (cell->type.in("$mux", "$pmux", "$_MUX_")) {
|
if (cell->type.in("$mux", "$pmux", "$_MUX_")) {
|
||||||
RTLIL::Const ret = arg1;
|
RTLIL::Const ret = arg1;
|
||||||
|
@ -436,10 +441,10 @@ struct CellTypes
|
||||||
return eval_not(const_and(const_or(arg1, arg2, false, false, 1), arg3, false, false, 1));
|
return eval_not(const_and(const_or(arg1, arg2, false, false, 1), arg3, false, false, 1));
|
||||||
|
|
||||||
log_assert(arg3.bits.size() == 0);
|
log_assert(arg3.bits.size() == 0);
|
||||||
return eval(cell, arg1, arg2);
|
return eval(cell, arg1, arg2, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, const RTLIL::Const &arg3, const RTLIL::Const &arg4)
|
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, const RTLIL::Const &arg3, const RTLIL::Const &arg4, bool *errp = nullptr)
|
||||||
{
|
{
|
||||||
if (cell->type == "$_AOI4_")
|
if (cell->type == "$_AOI4_")
|
||||||
return eval_not(const_or(const_and(arg1, arg2, false, false, 1), const_and(arg3, arg4, false, false, 1), false, false, 1));
|
return eval_not(const_or(const_and(arg1, arg2, false, false, 1), const_and(arg3, arg4, false, false, 1), false, false, 1));
|
||||||
|
@ -447,7 +452,7 @@ struct CellTypes
|
||||||
return eval_not(const_and(const_or(arg1, arg2, false, false, 1), const_and(arg3, arg4, false, false, 1), false, false, 1));
|
return eval_not(const_and(const_or(arg1, arg2, false, false, 1), const_and(arg3, arg4, false, false, 1), false, false, 1));
|
||||||
|
|
||||||
log_assert(arg4.bits.size() == 0);
|
log_assert(arg4.bits.size() == 0);
|
||||||
return eval(cell, arg1, arg2, arg3);
|
return eval(cell, arg1, arg2, arg3, errp);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -321,8 +321,13 @@ struct ConstEval
|
||||||
if (sig_d.size() > 0 && !eval(sig_d, undef, cell))
|
if (sig_d.size() > 0 && !eval(sig_d, undef, cell))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
set(sig_y, CellTypes::eval(cell, sig_a.as_const(), sig_b.as_const(),
|
bool eval_err = false;
|
||||||
sig_c.as_const(), sig_d.as_const()));
|
RTLIL::Const eval_ret = CellTypes::eval(cell, sig_a.as_const(), sig_b.as_const(), sig_c.as_const(), sig_d.as_const(), &eval_err);
|
||||||
|
|
||||||
|
if (eval_err)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
set(sig_y, eval_ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue