diff options
author | Zachary Snow <zach@zachjs.com> | 2022-05-30 16:45:39 -0400 |
---|---|---|
committer | Zachary Snow <zach@zachjs.com> | 2022-05-30 16:45:39 -0400 |
commit | a650d9079fa4732a6d118f2764d5abc2522a6b37 (patch) | |
tree | 5d4e92924a37dd9f358692d98180e43d71d6d95c /frontends | |
parent | cea7e85d607304faf36779757df14b4445fe1cfe (diff) | |
download | yosys-a650d9079fa4732a6d118f2764d5abc2522a6b37.tar.gz yosys-a650d9079fa4732a6d118f2764d5abc2522a6b37.tar.bz2 yosys-a650d9079fa4732a6d118f2764d5abc2522a6b37.zip |
verilog: fix width/sign detection for functions
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/ast/genrtlil.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc index a569c5ae2..d81c53dfb 100644 --- a/frontends/ast/genrtlil.cc +++ b/frontends/ast/genrtlil.cc @@ -1095,8 +1095,9 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun if (current_scope.count(str)) { // This width detection is needed for function calls which are - // unelaborated, which currently only applies to calls to recursive - // functions reached by unevaluated ternary branches. + // unelaborated, which currently applies to calls to functions + // reached via unevaluated ternary branches or used in case or case + // item expressions. const AstNode *func = current_scope.at(str); if (func->type != AST_FUNCTION) log_file_error(filename, location.first_line, "Function call to %s resolved to something that isn't a function!\n", RTLIL::unescape_id(str).c_str()); @@ -1107,8 +1108,8 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun break; } log_assert(wire && wire->type == AST_WIRE); - sign_hint = wire->is_signed; - width_hint = 1; + sign_hint &= wire->is_signed; + int result_width = 1; if (!wire->children.empty()) { log_assert(wire->children.size() == 1); @@ -1121,10 +1122,11 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun if (left->type != AST_CONSTANT || right->type != AST_CONSTANT) log_file_error(filename, location.first_line, "Function %s has non-constant width!", RTLIL::unescape_id(str).c_str()); - width_hint = abs(int(left->asInt(true) - right->asInt(true))); + result_width = abs(int(left->asInt(true) - right->asInt(true))); delete left; delete right; } + width_hint = max(width_hint, result_width); break; } YS_FALLTHROUGH |