mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-15 02:21:17 +00:00
Merge pull request #5473 from YosysHQ/krys/unsized_params
Handle unsized params
This commit is contained in:
commit
529886f7fb
8 changed files with 72 additions and 12 deletions
|
|
@ -993,6 +993,8 @@ RTLIL::Const AstNode::asParaConst() const
|
|||
RTLIL::Const val = asAttrConst();
|
||||
if (is_signed)
|
||||
val.flags |= RTLIL::CONST_FLAG_SIGNED;
|
||||
if (is_unsized)
|
||||
val.flags |= RTLIL::CONST_FLAG_UNSIZED;
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
@ -1766,7 +1768,10 @@ static std::string serialize_param_value(const RTLIL::Const &val) {
|
|||
res.push_back('s');
|
||||
if (val.flags & RTLIL::ConstFlags::CONST_FLAG_REAL)
|
||||
res.push_back('r');
|
||||
res += stringf("%d", GetSize(val));
|
||||
if (val.flags & RTLIL::ConstFlags::CONST_FLAG_UNSIZED)
|
||||
res.push_back('u');
|
||||
else
|
||||
res += stringf("%d", GetSize(val));
|
||||
res.push_back('\'');
|
||||
res.append(val.as_string("?"));
|
||||
return res;
|
||||
|
|
@ -1860,7 +1865,7 @@ std::string AstModule::derive_common(RTLIL::Design *design, const dict<RTLIL::Id
|
|||
} else if ((it->second.flags & RTLIL::CONST_FLAG_STRING) != 0)
|
||||
child->children[0] = AstNode::mkconst_str(loc, it->second.decode_string());
|
||||
else
|
||||
child->children[0] = AstNode::mkconst_bits(loc, it->second.to_bits(), (it->second.flags & RTLIL::CONST_FLAG_SIGNED) != 0);
|
||||
child->children[0] = AstNode::mkconst_bits(loc, it->second.to_bits(), (it->second.flags & RTLIL::CONST_FLAG_SIGNED) != 0, (it->second.flags & RTLIL::CONST_FLAG_UNSIZED) != 0);
|
||||
rewritten.insert(it->first);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2265,9 +2265,13 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
|
|||
}
|
||||
if (children[0]->type == AST_CONSTANT) {
|
||||
if (width != int(children[0]->bits.size())) {
|
||||
RTLIL::SigSpec sig(children[0]->bits);
|
||||
sig.extend_u0(width, children[0]->is_signed);
|
||||
children[0] = mkconst_bits(location, sig.as_const().to_bits(), is_signed);
|
||||
RTLIL::Const val;
|
||||
if (children[0]->is_unsized) {
|
||||
val = children[0]->bitsAsUnsizedConst(width);
|
||||
} else {
|
||||
val = children[0]->bitsAsConst(width);
|
||||
}
|
||||
children[0] = mkconst_bits(location, val.to_bits(), is_signed);
|
||||
fixup_hierarchy_flags();
|
||||
}
|
||||
children[0]->is_signed = is_signed;
|
||||
|
|
|
|||
|
|
@ -567,10 +567,13 @@ struct RTLILFrontendWorker {
|
|||
if (try_parse_keyword("parameter")) {
|
||||
bool is_signed = false;
|
||||
bool is_real = false;
|
||||
bool is_unsized = false;
|
||||
if (try_parse_keyword("signed")) {
|
||||
is_signed = true;
|
||||
} else if (try_parse_keyword("real")) {
|
||||
is_real = true;
|
||||
} else if (try_parse_keyword("unsized")) {
|
||||
is_unsized = true;
|
||||
}
|
||||
RTLIL::IdString param_name = parse_id();
|
||||
RTLIL::Const val = parse_const();
|
||||
|
|
@ -578,6 +581,8 @@ struct RTLILFrontendWorker {
|
|||
val.flags |= RTLIL::CONST_FLAG_SIGNED;
|
||||
if (is_real)
|
||||
val.flags |= RTLIL::CONST_FLAG_REAL;
|
||||
if (is_unsized)
|
||||
val.flags |= RTLIL::CONST_FLAG_UNSIZED;
|
||||
cell->parameters.insert({std::move(param_name), std::move(val)});
|
||||
expect_eol();
|
||||
} else if (try_parse_keyword("connect")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue