My understanding is that: yes these are legal implicit casts that
subvert the strictness of enum typing.
This is not a new issue; enums have previously been permitted as fields
of packed struct, where the
same integral/bit-vector matching rule permits unchecked values to be
deposited in enum-type fields.
My impression of committee intent on this has been that strongly typed
enums are only "type-safe"
when kept in unpacked aggregations, and when no explicit cast
operations are used to produce
values of that type.
The question begged by this viewpoint is what the LRM requires when an
enum element or field
that's been abused by type-unsafe assignment is fetched
as an enum
value.
Is a compiler justified in thinking this value is confined to the
enumerated set of values?
The prude in me would not cut this abuser any slack - so if (say) case
labels were involved and
the case_expression fetched this enum, I'd be happy to presume that the
case is "full" if
its labels covered just the enumerated data values. In practice, this
attitude has
not been well-received, so the net effect has (so far) been that adding
enums to SV does not
improve synthesis "QoR" (smaller area or better timing). Formal
equivalence to
the obvious simulation semantics usually takes precedence. But given
the LRM's lax
treatment of this topic, no user should count on being indulged by
every implementation.
There is a clear analogy to unsafe casts in C, or the effects of
escaping to assembly language:
users must beware that they take on a far greater burden of proof than
if they'd avoided
the pretension of type-safety altogether. Perhaps there was a lobbyist
from the LINT tool
vendors at work here ;-)
Greg Jaxon
Disclaimer: this is just my personal take-away from committee
discussions...
Brad Pierce wrote:
2009 makes it legal to create packed arrays of enums. Is it legal to assign a data object of such a type with a value that is not a packed array of the same kind of enums?
In the following element-by-element assignment, the explicit cast is required
typedef enum logic {FALSE, TRUE} Boolean;
module test1
( input logic [5:0] in
, output Boolean [5:0] out
);
for (genvar I = 0; I < 6; I++) begin
assign out[I] = Boolean'(in[I]);
end
endmodule
But are both of the following assignments legal?
typedef enum logic {STOP, GO} NotBoolean;
module test2
( input logic [5:0] in1
, input NotBoolean [5:0] in2
, output Boolean [5:0] out1, out2
);
assign out1 = in1;
assign out2 = in2;
endmodule
-- Brad
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--
This message has been scanned for viruses and
dangerous content by
MailScanner, and is
believed to be clean.
Received on Fri Oct 2 12:28:47 2009