- Adds support for C-style for-loop initializers
- Current implementation supports: for (x a = 1, y b = 2, ...)
- This patch extends support to: for (x a = 1, b = 2, ...)
- Adds unit test for new feature
This commit is contained in:
parent
292cc54768
commit
a24f61403a
|
|
@ -3701,13 +3701,16 @@ statement_item<nodep>: // IEEE: statement_item
|
||||||
;
|
;
|
||||||
|
|
||||||
statementFor<beginp>: // IEEE: part of statement
|
statementFor<beginp>: // IEEE: part of statement
|
||||||
yFOR '(' for_initialization expr ';' for_stepE ')' stmtBlock
|
yFOR beginForParen for_initialization expr ';' for_stepE ')' stmtBlock
|
||||||
{ $$ = new AstBegin{$1, "", $3, false, true};
|
{ $$ = new AstBegin{$1, "", $3, false, true};
|
||||||
$$->addStmtsp(new AstWhile{$1, $4, $8, $6}); }
|
$$->addStmtsp(new AstWhile{$1, $4, $8, $6}); }
|
||||||
| yFOR '(' for_initialization ';' for_stepE ')' stmtBlock
|
| yFOR beginForParen for_initialization ';' for_stepE ')' stmtBlock
|
||||||
{ $$ = new AstBegin{$1, "", $3, false, true};
|
{ $$ = new AstBegin{$1, "", $3, false, true};
|
||||||
$$->addStmtsp(new AstWhile{$1, new AstConst{$1, AstConst::BitTrue{}}, $7, $5}); }
|
$$->addStmtsp(new AstWhile{$1, new AstConst{$1, AstConst::BitTrue{}}, $7, $5}); }
|
||||||
;
|
;
|
||||||
|
beginForParen: // IEEE: Part of statement (for loop beginning paren)
|
||||||
|
'(' { VARRESET(); }
|
||||||
|
;
|
||||||
|
|
||||||
statementVerilatorPragmas<nodep>:
|
statementVerilatorPragmas<nodep>:
|
||||||
yVL_COVERAGE_BLOCK_OFF
|
yVL_COVERAGE_BLOCK_OFF
|
||||||
|
|
@ -3997,7 +4000,16 @@ for_initializationItem<nodep>: // IEEE: variable_assignment + for_varia
|
||||||
$$->addNext(new AstAssign{$4, new AstParseRef{$<fl>3, VParseRefExp::PX_TEXT, *$3}, $5}); }
|
$$->addNext(new AstAssign{$4, new AstParseRef{$<fl>3, VParseRefExp::PX_TEXT, *$3}, $5}); }
|
||||||
// // IEEE: variable_assignment
|
// // IEEE: variable_assignment
|
||||||
// // UNSUP variable_lvalue below
|
// // UNSUP variable_lvalue below
|
||||||
| varRefBase '=' expr { $$ = new AstAssign{$2, $1, $3}; }
|
| id/*newOrExisting*/ '=' expr
|
||||||
|
{ if (GRAMMARP->m_varDecl) {
|
||||||
|
AstVar* const varp = VARDONEA($<fl>1, *$1, nullptr, nullptr);
|
||||||
|
varp->lifetime(VLifetime::AUTOMATIC);
|
||||||
|
$$ = varp;
|
||||||
|
$$->addNext(new AstAssign{$2, new AstParseRef{$<fl>1, VParseRefExp::PX_TEXT, *$1}, $3});
|
||||||
|
} else {
|
||||||
|
$$ = new AstAssign{$2, new AstParseRef{$<fl>1, VParseRefExp::PX_TEXT, *$1}, $3};
|
||||||
|
}
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
for_stepE<nodep>: // IEEE: for_step + empty
|
for_stepE<nodep>: // IEEE: for_step + empty
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ module t (/*AUTOARG*/);
|
||||||
`checkc(7);
|
`checkc(7);
|
||||||
for (int a = 1, int b = 1; a < 3; a = a + 1, b = b + 1) begin c = c + 1 + a + b; end
|
for (int a = 1, int b = 1; a < 3; a = a + 1, b = b + 1) begin c = c + 1 + a + b; end
|
||||||
`checkc(8);
|
`checkc(8);
|
||||||
|
for (int a = 1, x = 1; a < 3; a = a + 1, x = x + 1) begin c = c + 1 + a + x; end
|
||||||
|
`checkc(8);
|
||||||
$write("*-* All Finished *-*\n");
|
$write("*-* All Finished *-*\n");
|
||||||
$finish;
|
$finish;
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue