Skip to content

Commit e1da548

Browse files
committed
SystemVerilog: type parameter ports
This adds support for SystemVerilog type parameter ports (1800-2017 6.20.3).
1 parent 1876bfd commit e1da548

11 files changed

+90
-22
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# EBMC 5.9
22

3+
* SystemVerilog: type parameter ports
34
* SystemVerilog: fix for type parameters
45
* SMV: word constants
56
* SMV: IVAR declarations

regression/verilog/modules/parameter_ports4.desc

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
type_parameter_port1.sv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
type_parameter_port2.sv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module sub #(parameter type T = int)();
2+
3+
var T my_var;
4+
5+
endmodule
6+
7+
module main;
8+
9+
sub #(.T(byte)) submodule();
10+
11+
p1: assert final ($bits(submodule.my_var) == 8);
12+
13+
endmodule // main
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
type_parameter_port3.sv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module sub #(type T = int)();
2+
3+
var T my_var;
4+
5+
endmodule
6+
7+
module main;
8+
9+
sub #(byte) submodule();
10+
11+
p1: assert final ($bits(submodule.my_var) == 8);
12+
13+
endmodule // main

src/verilog/parser.y

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,8 @@ list_of_variable_identifiers:
19851985
parameter_port_declaration:
19861986
TOK_PARAMETER data_type_or_implicit param_assignment
19871987
{ init($$, ID_decl); stack_expr($$).type() = std::move(stack_type($2)); mto($$, $3); }
1988+
| TOK_PARAMETER TOK_TYPE type_assignment
1989+
{ init($$, ID_decl); stack_expr($$).type() = typet{ID_type}; mto($$, $3); }
19881990
| TOK_LOCALPARAM data_type_or_implicit param_assignment
19891991
{ init($$, ID_decl); stack_expr($$).type() = std::move(stack_type($2)); mto($$, $3); }
19901992
| data_type param_assignment
@@ -2028,7 +2030,7 @@ list_of_type_assignments:
20282030
;
20292031

20302032
type_assignment: param_identifier '=' data_type
2031-
{ init($$, ID_parameter);
2033+
{ init($$, ID_declarator);
20322034
auto base_name = stack_expr($1).id();
20332035
stack_expr($$).set(ID_identifier, base_name);
20342036
stack_expr($$).set(ID_base_name, base_name);
@@ -3161,11 +3163,23 @@ named_parameter_assignment_brace:
31613163
{ $$=$1; mto($$, $3); }
31623164
;
31633165

3164-
ordered_parameter_assignment:
3165-
expression;
3166+
ordered_parameter_assignment: param_expression
3167+
;
3168+
3169+
param_expression:
3170+
expression
3171+
| data_type
3172+
{ init($$, ID_type); stack_expr($$).type() = stack_type($1); }
3173+
;
3174+
3175+
param_expression_opt:
3176+
/* empty */
3177+
{ init($$, ID_nil); }
3178+
| param_expression
3179+
;
31663180

31673181
named_parameter_assignment:
3168-
'.' parameter_identifier '(' expression_opt ')'
3182+
'.' parameter_identifier '(' param_expression_opt ')'
31693183
{ init($$, ID_named_parameter_assignment);
31703184
stack_expr($$).add(ID_parameter).swap(stack_expr($2));
31713185
stack_expr($$).add(ID_value).swap(stack_expr($4));

src/verilog/verilog_parameterize_module.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,17 @@ irep_idt verilog_typecheckt::parameterize_module(
245245

246246
if(pv.is_not_nil())
247247
{
248-
mp_integer i;
249-
if(to_integer_non_constant(pv, i))
248+
if(pv.id() == ID_type)
250249
{
251-
throw errort().with_location(pv.source_location())
252-
<< "parameter value expected to be constant, but got `"
253-
<< to_string(pv) << "'";
250+
suffix += "some_type";
254251
}
255-
else
252+
else if(pv.id() == ID_constant)
253+
{
254+
mp_integer i = numeric_cast_v<mp_integer>(to_constant_expr(pv));
256255
suffix += integer2string(i);
256+
}
257+
else
258+
DATA_INVARIANT(false, "parameter value expected to be type or constant");
257259
}
258260
}
259261

0 commit comments

Comments
 (0)