diff options
author | Clifford Wolf <clifford@clifford.at> | 2019-04-22 08:51:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-22 08:51:34 +0200 |
commit | b40af877f3107150f8b648397ae4007d15406dac (patch) | |
tree | 5b47f0808c45eda1980848e9d175ee2d61413806 /frontends | |
parent | a98b1718142a85f8c66b23494ce5532783f93ac4 (diff) | |
parent | 5855024cccfbcb1919e3225f519bc9f0421c4056 (diff) | |
download | yosys-b40af877f3107150f8b648397ae4007d15406dac.tar.gz yosys-b40af877f3107150f8b648397ae4007d15406dac.tar.bz2 yosys-b40af877f3107150f8b648397ae4007d15406dac.zip |
Merge pull request #909 from zachjs/master
support repeat loops with constant repeat counts outside of constant functions
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/ast/simplify.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 63b71b800..76da5a97c 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -1030,7 +1030,26 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, log_file_error(filename, linenum, "While loops are only allowed in constant functions!\n"); if (type == AST_REPEAT) - log_file_error(filename, linenum, "Repeat loops are only allowed in constant functions!\n"); + { + AstNode *count = children[0]; + AstNode *body = children[1]; + + // eval count expression + while (count->simplify(true, false, false, stage, 32, true, false)) { } + + if (count->type != AST_CONSTANT) + log_file_error(filename, linenum, "Repeat loops outside must have constant repeat counts!\n"); + + // convert to a block with the body repeated n times + type = AST_BLOCK; + children.clear(); + for (int i = 0; i < count->bitsAsConst().as_int(); i++) + children.insert(children.begin(), body->clone()); + + delete count; + delete body; + did_something = true; + } // unroll for loops and generate-for blocks if ((type == AST_GENFOR || type == AST_FOR) && children.size() != 0) |