A
Allan Herriman
Guest
Hi,
I'm trying to do something equivalent to the following:
generic g : boolean;
....
constant c : some_type := expression1 when g else expression2;
This is something I want to do a lot in both synthesisable and non-
synthesisable designs. Usually I end up writing an 8 line function to do
something that I ought be able to do in a single line.
For example, in Verilog 2001 I would write this as
localparam c = g ? expression1 : expression2;
(Questions below)
I found this in the '08 standard:
[§ 6.4.2.2]
constant_declaration ::=
constant identifier_list : subtype_indication [ := expression ] ;
[§ 9.1]
expression ::=
condition_operator primary
| logical_expression
[§ 9.1]
primary ::=
name
| literal
| aggregate
| function_call
| qualified_expression
| type_conversion
| allocator
| ( expression )
Unfortunately, "expression" doesn't ever lead to
"conditional_expressions".
[§ 10.5.3]
conditional_expressions ::=
expression when condition
{ else expression when condition }
[ else expression ]
Questions:
Q1: Am I reading the standard correctly and we can't (in 2008) use
conditional expressions in constant initialisers?
Q2: Is there some simple and effective way of doing what I'm trying to do?
Q3: If not, how do we go about fixing this?
Thanks,
Allan
I'm trying to do something equivalent to the following:
generic g : boolean;
....
constant c : some_type := expression1 when g else expression2;
This is something I want to do a lot in both synthesisable and non-
synthesisable designs. Usually I end up writing an 8 line function to do
something that I ought be able to do in a single line.
For example, in Verilog 2001 I would write this as
localparam c = g ? expression1 : expression2;
(Questions below)
I found this in the '08 standard:
[§ 6.4.2.2]
constant_declaration ::=
constant identifier_list : subtype_indication [ := expression ] ;
[§ 9.1]
expression ::=
condition_operator primary
| logical_expression
[§ 9.1]
primary ::=
name
| literal
| aggregate
| function_call
| qualified_expression
| type_conversion
| allocator
| ( expression )
Unfortunately, "expression" doesn't ever lead to
"conditional_expressions".
[§ 10.5.3]
conditional_expressions ::=
expression when condition
{ else expression when condition }
[ else expression ]
Questions:
Q1: Am I reading the standard correctly and we can't (in 2008) use
conditional expressions in constant initialisers?
Q2: Is there some simple and effective way of doing what I'm trying to do?
Q3: If not, how do we go about fixing this?
Thanks,
Allan