diff options
author | clairexen <claire@symbioticeda.com> | 2020-07-01 16:40:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 16:40:20 +0200 |
commit | 8ce4f8790ecf33f7df19e0fb54a749abe026831d (patch) | |
tree | 20d18b6f47cb74be76d91568cfc0e0f51a47f1dd /frontends/ast/genrtlil.cc | |
parent | b1707407a0912fe44ecf83f6f8e64b13a1c4daee (diff) | |
parent | 429d37ff41b5a058fdd0b70f23a55170a973c369 (diff) | |
download | yosys-8ce4f8790ecf33f7df19e0fb54a749abe026831d.tar.gz yosys-8ce4f8790ecf33f7df19e0fb54a749abe026831d.tar.bz2 yosys-8ce4f8790ecf33f7df19e0fb54a749abe026831d.zip |
Merge pull request #2179 from splhack/static-cast
Support SystemVerilog Static Cast
Diffstat (limited to 'frontends/ast/genrtlil.cc')
-rw-r--r-- | frontends/ast/genrtlil.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc index 9546558aa..e878d0dd2 100644 --- a/frontends/ast/genrtlil.cc +++ b/frontends/ast/genrtlil.cc @@ -814,6 +814,16 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun children.at(0)->detectSignWidthWorker(sub_width_hint, sign_hint); break; + case AST_CAST_SIZE: + while (children.at(0)->simplify(true, false, false, 1, -1, false, false)) { } + if (children.at(0)->type != AST_CONSTANT) + log_file_error(filename, location.first_line, "Static cast with non constant expression!\n"); + children.at(1)->detectSignWidthWorker(width_hint, sign_hint); + width_hint = children.at(0)->bitsAsConst().as_int(); + if (width_hint <= 0) + log_file_error(filename, location.first_line, "Static cast with zero or negative size!\n"); + break; + case AST_CONCAT: for (auto child : children) { sub_width_hint = 0; @@ -1289,6 +1299,20 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint) return sig; } + // changing the size of signal can be done directly using RTLIL::SigSpec + case AST_CAST_SIZE: { + RTLIL::SigSpec size = children[0]->genRTLIL(); + RTLIL::SigSpec sig = children[1]->genRTLIL(); + if (!size.is_fully_const()) + log_file_error(filename, location.first_line, "Static cast with non constant expression!\n"); + int width = size.as_int(); + if (width <= 0) + log_file_error(filename, location.first_line, "Static cast with zero or negative size!\n"); + sig.extend_u0(width, sign_hint); + is_signed = sign_hint; + return sig; + } + // concatenation of signals can be done directly using RTLIL::SigSpec case AST_CONCAT: { RTLIL::SigSpec sig; |