Skip to content

Commit fb82f4b

Browse files
authored
Merge pull request #407 from diffblue/ports7
Verilog: module ports may be arrays
2 parents a2d7bc9 + e53e01b commit fb82f4b

File tree

7 files changed

+71
-11
lines changed

7 files changed

+71
-11
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
ports7.v
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/verilog/modules/ports7.v

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Ports can be arrays.
2+
module sub(input [31:0] array [9:0]);
3+
4+
always assert p0: array[0] == 0;
5+
always assert p9: array[9] == 9;
6+
7+
endmodule
8+
9+
module main;
10+
reg [31:0] array [9:0];
11+
12+
initial begin
13+
integer i;
14+
for(i=0; i<10; i=i+1)
15+
array[i] = i;
16+
end
17+
18+
sub s(array);
19+
20+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
ports8.v
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/verilog/modules/ports8.v

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Ports can be arrays.
2+
module sub(output reg [31:0] array [9:0]);
3+
4+
wire some_floating_wire;
5+
6+
always @some_floating_wire begin
7+
integer i;
8+
for(i=0; i<10; i=i+1)
9+
array[i] = i;
10+
end
11+
12+
endmodule
13+
14+
module main;
15+
wire [31:0] array [9:0];
16+
17+
sub s(array);
18+
19+
always assert p0: array[0] == 0;
20+
always assert p9: array[9] == 9;
21+
22+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ IREP_ID_ONE(sva_s_until_with)
2727
IREP_ID_ONE(sva_overlapped_implication)
2828
IREP_ID_ONE(sva_non_overlapped_implication)
2929
IREP_ID_ONE(module_instance)
30-
IREP_ID_ONE(C_offset)
31-
IREP_ID_ONE(C_little_endian)
30+
IREP_ID_TWO(C_offset, #offset)
31+
IREP_ID_TWO(C_little_endian, #little_endian)
3232
IREP_ID_ONE(ports)
3333
IREP_ID_ONE(inst)
3434
IREP_ID_ONE(Verilog)

src/verilog/parser.y

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,23 +822,26 @@ ansi_port_declaration:
822822
;
823823

824824
module_port_input_declaration:
825-
TOK_INPUT net_port_type port_identifier
825+
TOK_INPUT net_port_type port_identifier unpacked_dimension_brace
826826
{ init($$, ID_decl);
827827
stack_expr($$).set(ID_class, ID_input);
828-
addswap($$, ID_type, $2);
828+
add_as_subtype(stack_type($4), stack_type($2));
829+
addswap($$, ID_type, $4);
829830
mto($$, $3); }
830831
;
831832

832833
module_port_output_declaration:
833-
TOK_OUTPUT net_port_type port_identifier
834+
TOK_OUTPUT net_port_type port_identifier unpacked_dimension_brace
834835
{ init($$, ID_decl);
835836
stack_expr($$).set(ID_class, ID_output);
836-
addswap($$, ID_type, $2);
837+
add_as_subtype(stack_type($4), stack_type($2));
838+
addswap($$, ID_type, $4);
837839
mto($$, $3); }
838-
| TOK_OUTPUT data_type port_identifier
840+
| TOK_OUTPUT data_type port_identifier unpacked_dimension_brace
839841
{ init($$, ID_decl);
840842
stack_expr($$).set(ID_class, ID_output_register);
841-
addswap($$, ID_type, $2);
843+
add_as_subtype(stack_type($4), stack_type($2));
844+
addswap($$, ID_type, $4);
842845
mto($$, $3); }
843846
;
844847

@@ -1092,10 +1095,11 @@ specparam_declaration:
10921095
// A.2.1.2 Port declarations
10931096

10941097
module_port_inout_declaration:
1095-
TOK_INOUT net_port_type port_identifier
1098+
TOK_INOUT net_port_type port_identifier unpacked_dimension_brace
10961099
{ init($$, ID_decl);
10971100
stack_expr($$).set(ID_class, ID_inout);
1098-
addswap($$, ID_type, $2);
1101+
add_as_subtype(stack_type($4), stack_type($2));
1102+
addswap($$, ID_type, $4);
10991103
mto($$, $3); }
11001104
;
11011105

src/verilog/verilog_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ array_typet verilog_typecheckt::array_type(
9292
else
9393
array_subtype=array_type(src_subtype, element_type);
9494

95-
const exprt final_size_expr = from_integer(size, natural_typet());
95+
const exprt final_size_expr = from_integer(size, integer_typet());
9696
array_typet result(array_subtype, final_size_expr);
9797
result.set(ID_offset, from_integer(offset, integer_typet()));
9898
result.set(ID_C_little_endian, little_endian);

0 commit comments

Comments
 (0)