Skip to content

Commit a7d59f5

Browse files
committed
allow declaring multiple regs within a single statement
1 parent 4a548c4 commit a7d59f5

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

test/verilogTests.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,22 @@ class Testes_verilog : public CppUnit::TestFixture
9696
{"rbx", 32, 0},
9797
{"r_flag", 20, 0},
9898
{"r_extra_flag", 3, 0},
99-
{"number_signed", 64, 1}
99+
{"number_signed", 64, 1},
100+
{"r_0", 1, 0},
101+
{"r_1", 1, 0},
102+
{"r_2", 1, 0},
103+
{"r_3", 1, 0},
104+
{"r_4", 1, 0},
105+
{"r_5", 1, 0},
106+
{"r_6", 1, 0},
107+
{"r_7", 1, 0}
100108
};
101109

102110
Evento* q = new_empty_event();
103111
Module* circuit = load_module("./verilog_sample_src/reg.v", &q);
104112

105113
CPPUNIT_ASSERT( circuit );
106-
CPPUNIT_ASSERT( circuit->listaReg.total == 12 );
114+
CPPUNIT_ASSERT_EQUAL( (int)regs_info.size(), circuit->listaReg.total );
107115

108116
for ( int i=0 ; i < circuit->listaReg.total ; i++ )
109117
{
@@ -281,6 +289,7 @@ class Testes_verilog : public CppUnit::TestFixture
281289
"./verilog_sample_src/badverilog_44.v",
282290
"./verilog_sample_src/badverilog_45.v",
283291
"./verilog_sample_src/badverilog_46.v",
292+
"./verilog_sample_src/badverilog_46a.v",
284293
"./verilog_sample_src/badverilog_47.v",
285294
"./verilog_sample_src/badverilog_48.v",
286295
"./verilog_sample_src/badverilog_49.v",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
// invalid code
3+
4+
module bad_reg;
5+
6+
reg a,

test/verilog_sample_src/reg.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ reg [EXTRA_FLAGS_END:EXTRA_FLAGS_START] r_extra_flag;
2828

2929
reg signed [63:0] number_signed;
3030

31+
reg r_0, r_1, r_2, r_3, r_4, r_5, r_6, r_7;
32+
33+
// There are 20 registers in this module
34+
3135
endmodule

verilog.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,9 @@ VerilogError load_reg(Token** it, ListaToken* identifiers, ListaToken* list_para
845845
if (t->classe == KW_SIGNED) {
846846
is_signed = 1;
847847

848-
avanca(&t);
849-
if (!t)
848+
if (!avanca(&t)) {
850849
goto load_reg_bad_eof;
850+
}
851851
}
852852

853853
// range specification
@@ -869,6 +869,8 @@ VerilogError load_reg(Token** it, ListaToken* identifiers, ListaToken* list_para
869869
break;
870870
}
871871

872+
load_reg_identifier_list:
873+
872874
if (!isIdentificador(t)) {
873875
show_error_msg("Identificador nao foi encontrado",
874876
t->linha, t->coluna, "um identificador", t->valor);
@@ -889,9 +891,16 @@ VerilogError load_reg(Token** it, ListaToken* identifiers, ListaToken* list_para
889891
if (!avanca(&t))
890892
goto load_reg_bad_eof;
891893

894+
if (t->classe == SYM_COMMA) {
895+
if (!avanca(&t)) {
896+
goto load_reg_bad_eof;
897+
}
898+
goto load_reg_identifier_list;
899+
}
900+
892901
if (t->classe != SYM_SEMICOLON) {
893902
show_error_msg("Simbolo esperado nao foi encontrado",
894-
t->linha, t->coluna, ";", t->valor);
903+
t->linha, t->coluna, ",' ou ';", t->valor);
895904
goto load_reg_bad_token;
896905
}
897906

0 commit comments

Comments
 (0)