aboutsummaryrefslogtreecommitdiffstats
path: root/frontends/ast
diff options
context:
space:
mode:
authorZachary Snow <zach@zachjs.com>2021-03-03 14:36:19 -0500
committerZachary Snow <zachary.j.snow@gmail.com>2021-03-06 15:20:34 -0500
commitb1a8e73a609d3065f1caf7a230529443b54295bc (patch)
treee682f44ba07bf036005113e0dc5def403e8dc163 /frontends/ast
parentd245e2bae59d18eb641aa6b324eef1bbbfa13c38 (diff)
downloadyosys-b1a8e73a609d3065f1caf7a230529443b54295bc.tar.gz
yosys-b1a8e73a609d3065f1caf7a230529443b54295bc.tar.bz2
yosys-b1a8e73a609d3065f1caf7a230529443b54295bc.zip
sv: fix some edge cases for unbased unsized literals
- Fix explicit size cast of unbased unsized literals - Fix unbased unsized literal bound directly to port - Output `is_unsized` flag in `dumpAst`
Diffstat (limited to 'frontends/ast')
-rw-r--r--frontends/ast/ast.cc2
-rw-r--r--frontends/ast/simplify.cc22
2 files changed, 23 insertions, 1 deletions
diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc
index 57552d86c..88e6aa1c9 100644
--- a/frontends/ast/ast.cc
+++ b/frontends/ast/ast.cc
@@ -317,6 +317,8 @@ void AstNode::dumpAst(FILE *f, std::string indent) const
fprintf(f, " reg");
if (is_signed)
fprintf(f, " signed");
+ if (is_unsized)
+ fprintf(f, " unsized");
if (basic_prep)
fprintf(f, " basic_prep");
if (lookahead)
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index 5c4dd290f..e7f897b3c 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -915,6 +915,22 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
}
}
+ if (type == AST_ARGUMENT)
+ {
+ if (children.size() == 1 && children[0]->type == AST_CONSTANT)
+ {
+ // HACK: For port bindings using unbased unsized literals, mark them
+ // signed so they sign-extend. The hierarchy will still incorrectly
+ // generate a warning complaining about resizing the expression.
+ // This also doesn't handle the complex of something like a ternary
+ // expression bound to a port, where the actual size of the port is
+ // needed to resolve the expression correctly.
+ AstNode *arg = children[0];
+ if (arg->is_unsized)
+ arg->is_signed = true;
+ }
+ }
+
int backup_width_hint = width_hint;
bool backup_sign_hint = sign_hint;
@@ -3773,7 +3789,11 @@ replace_fcall_later:;
case AST_CAST_SIZE:
if (children.at(0)->type == AST_CONSTANT && children.at(1)->type == AST_CONSTANT) {
int width = children[0]->bitsAsConst().as_int();
- RTLIL::Const val = children[1]->bitsAsConst(width);
+ RTLIL::Const val;
+ if (children[1]->is_unsized)
+ val = children[1]->bitsAsUnsizedConst(width);
+ else
+ val = children[1]->bitsAsConst(width);
newNode = mkconst_bits(val.bits, children[1]->is_signed);
}
break;