3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-05-25 19:36:21 +00:00

Fixup sign.

This commit is contained in:
nella 2026-05-12 15:53:14 +02:00 committed by nella
parent ad912bc787
commit 52baeaef74
3 changed files with 26 additions and 6 deletions

View file

@ -1876,10 +1876,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 {
bool is_signed = child->is_signed;
if (!is_signed && !child->children.empty() && child->children[0] && child->children[0]->type == AST_CONSTANT)
is_signed = child->children[0]->is_signed;
is_signed = is_signed || ((it->second.flags & RTLIL::CONST_FLAG_SIGNED) != 0);
bool is_signed = child->is_signed || ((it->second.flags & RTLIL::CONST_FLAG_SIGNED) != 0);
child->children[0] = AstNode::mkconst_bits(loc, it->second.to_bits(), is_signed, (it->second.flags & RTLIL::CONST_FLAG_UNSIZED) != 0);
}
rewritten.insert(it->first);

View file

@ -41,6 +41,13 @@ struct setunset_t
if (!RTLIL::SigSpec::parse(sig_value, nullptr, set_value))
log_cmd_error("Can't decode value '%s'!\n", set_value);
value = sig_value.as_const();
if (!set_value.empty() && set_value.find('\'') == std::string::npos) {
size_t start = (set_value[0] == '-' || set_value[0] == '+') ? 1 : 0;
if (start < set_value.size() && std::all_of(set_value.begin() + start, set_value.end(), ::isdigit)) {
value.flags |= RTLIL::CONST_FLAG_SIGNED;
}
}
}
}
};

View file

@ -985,7 +985,15 @@ struct HierarchyPass : public Pass {
SigSpec sig_value;
if (!RTLIL::SigSpec::parse(sig_value, NULL, para.second))
log_cmd_error("Can't decode value '%s'!\n", para.second);
top_parameters[RTLIL::escape_id(para.first)] = sig_value.as_const();
RTLIL::Const c = sig_value.as_const();
if (!para.second.empty() && para.second.find('\'') == std::string::npos) {
size_t start = (para.second[0] == '-' || para.second[0] == '+') ? 1 : 0;
if (start < para.second.size() && std::all_of(para.second.begin() + start, para.second.end(), ::isdigit))
c.flags |= RTLIL::CONST_FLAG_SIGNED;
}
top_parameters[RTLIL::escape_id(para.first)] = c;
}
}
@ -1073,7 +1081,15 @@ struct HierarchyPass : public Pass {
SigSpec sig_value;
if (!RTLIL::SigSpec::parse(sig_value, NULL, para.second))
log_cmd_error("Can't decode value '%s'!\n", para.second);
top_parameters[RTLIL::escape_id(para.first)] = sig_value.as_const();
RTLIL::Const c = sig_value.as_const();
if (!para.second.empty() && para.second.find('\'') == std::string::npos) {
size_t start = (para.second[0] == '-' || para.second[0] == '+') ? 1 : 0;
if (start < para.second.size() && std::all_of(para.second.begin() + start, para.second.end(), ::isdigit))
c.flags |= RTLIL::CONST_FLAG_SIGNED;
}
top_parameters[RTLIL::escape_id(para.first)] = c;
}
top_mod = design->module(top_mod->derive(design, top_parameters));