Vl-constint
Representation for constant integer literals with no X or Z bits.
This is a product type introduced by defprod.
Fields
- origwidth — posp
- Subtle; generally should not be used; see below.
- value — natp
- The most important part of a constant integer. Even
immediately upon parsing the value has already been determined
and is available to you as an ordinary natural number.
- origtype — vl-exprtype-p
- Subtle; generally should not be used; see below.
- wasunsized — booleanp
- Set to t by the parser for unsized constants like 5
and 'b0101, but not for sized ones like 4'b0101.
Additional Requirements
The following invariant is enforced on the fields:
(< value (expt 2 origwidth))
Constant integers are produced from source code constructs like
5, 4'b0010, and 3'h0.
Note that the value of a constant integer is never negative. In Verilog
there are no negative literals; instead, an expression like -5 is
basically parsed the same as -(5), so the negative sign is not part of the
literal. See Section 3.5.1 of the Verilog-2005 standard.
The origwidth and origtype fields are subtle. They indicate the
original width and signedness of the literal as specified in the source
code, e.g., if the source code contains 8'sd 65, then the origwidth will
be 8 and the origtype will be :vl-signed. These fields are subtle because
expression-sizing generally alters the widths and types of
subexpressions, so these may not represent the final widths and types of these
constants in the context of the larger expression. Instead, the preferred way
to determine a constint's final width and sign is to inspect the vl-atom-p
that contains it.
We insist that 0 <= value <= 2^origwidth for every constant integer.
If our lexer encounters something ill-formed like 3'b 1111, it
emits a warning and truncates from the left, as required by Section 3.5.1 (page
10) of the Verilog-2005 standard.
Note that in Verilog, unsized integer constants like 5 or 'b101
have an implementation-dependent size of at least 32 bits. VL historically
tried to treat such numbers in an abstract way, saying they had "integer
size". But we eventually decided that this was too error-prone and we now
instead act like a 32-bit implementation even at the level of our lexer. This
conveniently makes the width of a constant integer just a positive number. On
the other hand, some expressions may produce different results on 32-bit
versus, say, 64-bit implementations. Because of this, we added the
wasunsized field so that we might later statically check for problematic
uses of unsized constants.
All constints are automatically created with hons. This is probably
pretty trivial, but it seems nice. For instance, the constant integers from
0-32 are probably used thousands of times throughout a design for bit-selects
and wire ranges, so sharing their memory may be useful.
Subtopics
- Vl-constint-fix
- Fixing function for vl-constint structures.
- Vl-constint-p
- Recognizer for vl-constint structures.
- Vl-constint-equiv
- Basic equivalence relation for vl-constint structures.
- Make-vl-constint
- Basic constructor macro for vl-constint structures.
- Vl-constint->origtype
- Get the origtype field from a vl-constint.
- Vl-constint->value
- Get the value field from a vl-constint.
- Vl-constint->wasunsized
- Get the wasunsized field from a vl-constint.
- Vl-constint->origwidth
- Get the origwidth field from a vl-constint.
- Change-vl-constint
- Modifying constructor for vl-constint structures.