steveicarus / iverilog

Icarus Verilog
https://steveicarus.github.io/iverilog/
GNU General Public License v2.0
2.79k stars 520 forks source link

Repeat literal array element syntax in system verilog is not yet supported #742

Open pbreuer opened 2 years ago

pbreuer commented 2 years ago

This evokes syntax error as shown (both iverilog 11.0 and 12.0, with -g1800-2005 and without):

assign ws3 = KPU_Test_types::array_of_5_Tup2_220_cons ( { 3'd0 , { KPU_Test_types::array_of_4_logic_vector_90_to_lv ( '{ 4{ <----- error signalled here 90'b0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx } } ) } } , c$ws4_case_alt );

If I replace 4{ foo } by `{ foo,foo,foo,foo } then all is well.

The 1800-2005 standard says the code syntax is correct:

3.7 Array literals ... int n[1:2][1:3] = '{'{0,1,2},'{3{4}}}; ... replicate operators can be nested. The inner pair of braces in a replication is removed. A replication expression only operates within one dimension. int n[1:2][1:6] = '{ 2{ '{ 3{4, 5} } } }; // same as '{ '{4,5,4,5,4,5}, '{4,5,4,5,4,5} }

I was hoping to check system verilog (2005) code produced by Clash. That the line is generated is why the example is ugly!

Can you fix this in the parser? If you point me at your parser spec I can likely do that if it helps.

Regards

PTB

pbreuer commented 2 years ago

I had a look at parse.y. It seems to be assignment_pattern, but I may be wrong. That is '{ expression (, expression)* } | '{ }. If it is that, one would add a clause for number '{ expression } I don't know what the attribitute calculation would be. Maybe

{ std::list<PExpr>tmp = new std::list<PExpr*>; tmp->push_back($3); for (int i = 1; i < atoi($1.text); i++) tmp->push_back(new std::($3)); FILE_NAME(tmp, @1); $$ = tmp; }

Pardon my nonexistent C++. Something like that. But you probably will want to make a new term construct in the abstract data type of syntax trees for "repeated n times". That's more than a one liner.