Sean Anderson [Sun, 11 Jun 2023 15:02:42 +0000 (11:02 -0400)]
vhpi: Support char and string values
The native format for character types is vhpiCharVal. Similarly, the
native format for 1-d character arrays is vhpiStrVal. Use these formats
instead of the short enum formats. Note that vhpiStrVals are
nul-terminated, and the terminator is not included in the numElems (but
it is included in bufSize).
Nick Gasson [Sat, 17 Jun 2023 15:19:07 +0000 (16:19 +0100)]
Rework determination of most recently analysed architecture
Avoid using timestamps as well as loading every architecture and instead
establish a total order over all architectures in a library with a new
_sequence file.
Sean Anderson [Sun, 11 Jun 2023 03:54:26 +0000 (23:54 -0400)]
vhpi: Fix use-after-free when removing callbacks (part 2)
I made a first attempt at this back in commit a21a360e ("vhpi: Fix
use-after-free when removing callbacks"), but I didn't fix the global or
value callbacks. These can also have use-after-frees, which can be
triggered consistently with a pair of "mutually-removing" callbacks.
They are set up so that they trigger on the next cycle, and they try to
remove themselves. This fails without the fixes in this commit.
The main approach is to give rt_watch_t the same treatment that
c_callback got: adding a flag to free the watch after the callback
completes. Global callbacks are a bit simpler, and can mostly be treated
like timeout callbacks; if we don't find anything to remove, the
callback must be currently-enqueued, so we shouldn't free it.
Fixes: d6e523a4 ("vhpi: Free callbacks in remove")
Sean Anderson [Sat, 10 Jun 2023 23:04:30 +0000 (19:04 -0400)]
vhpi: Fix incorrect range calculation
Null ranges have zero length. Detect them properly by basing the
direvction of the range on IsUp instead of whether LeftBound >
RightBound. The comparison in init_indexedName can stay the same since
it is guarded by build_indexedNames.
Fixes: 2052a42f ("vhpi: Rework size calculation") Fixes: 9416eb6e ("vhpi: Add support for IndexedNames")
Sean Anderson [Sat, 10 Jun 2023 21:06:48 +0000 (17:06 -0400)]
vhpi: Fix NULL-pointer dereference in vhpi_get_by_name
strtok_r returns NULL when there are no more tokens in the string. When
passed a name matching scope's name, but without a colon or period, we
call strtok_r twice, getting NULL the second time. Because the name
matches the region, fix this by returning the region.
Sean Anderson [Mon, 29 May 2023 21:39:41 +0000 (17:39 -0400)]
vhpi: Add support for getting/putting IndexedNames
This allows getting/putting nested arrays, and individual elements of an
array. The final index calculation is done lazily, although this
could be done eagerly by moving it to init_indexedName.
The tests for indexednames and the various enum types are extended now
that it is easier to access them.
Sean Anderson [Mon, 29 May 2023 21:49:14 +0000 (17:49 -0400)]
vhpi: Fix vhpi_get_value with EnumVecVal format
The Logic, SmallEnum, and Enum formats were not treated consistently.
Sometimes the wrong value type was used to store signals, and the
variable signal size of Enum was not handled properly. The correct
relationships for these types may be seen in the following table:
Format Value type Signal size
================ ============== ===========
vhpiLogicVal vhpiEnumT 8
vhpiSmallEnumVal vhpiSmallEnumT 8
vhpiEnumVal vhpiEnumT variable
In order to handle the variable size of Enum, we need to use FOR_ALL_SIZES
from model.c. Move it to util.h, and rename a conflicting macro with a
similar purpose. This also adds support for getting SmallEnumVecs.
This adds a test for the Vec versions of these formats; the non-vec
versions will be tested when indexedName get/put support is added.
Sean Anderson [Mon, 29 May 2023 21:04:52 +0000 (17:04 -0400)]
vhpi: Add support for IndexedNames
IndexedNames (e.g. `a(0)` or `a(2, 3)`) are necessary to access elements
of nested or multidimensional arrays (which have too many dimensions for
vhpiLogicVecVal) or to set individual elements of single-dimensional
arrays. Add basic support for these objects.
Although objDecls are names too, they also include the decl properties
which we don't want. Therefore, we use a separate hierarchy for
exprs/names. For future work, it might be nice to use the object
framework (tree_t, type_t, etc) for VHPI as well.
IndexedNames are created lazily. This is useful for nested arrays. For
example, a signal like
type a is array(0 to 9) of std_logic_vector(31 downto 0);
signal b: a;
might only be accessed like `b(0)` and never like `b(2)(3)`.
The encoding of prefixedName varies slightly from the UML. To reuse the
above example, while the UML says that the prefix of `b(0)` is `b`,
we set prefix as NULL in this situation, using simpleName instead. This
makes it easier to walk nested prefixes, since we don't have to compare
prefix to simpleName.
To populate IndexedNames, we must iterate over all constraints on the
array, and create `c_indexedName`s for each. One option here would be to
pass BaseIndex to init_indexedName. However, this would require decoding
the BaseIndex into indices for each constraint. Indead, I chose to pass
the indices directly, and create BaseIndex from them. I think this is
easier, because it doesn't involve any division.
Sean Anderson [Mon, 29 May 2023 20:11:56 +0000 (16:11 -0400)]
vhpi: Rework size calculation
IndexedNames represent a subset of the elements in a signal. Their size
is dependent on their type. In preparation for adding IndexedName
support, rework the size calculation to be based on the type of the
object instead of the width of the backing signal.
Sean Anderson [Mon, 29 May 2023 19:45:06 +0000 (15:45 -0400)]
vhpi: Support constraints
Add support for range constraints on arrays and subtypes. I think the
from/to on unconstrained ranges should reflect the from/to of the
underlying type, but I have left that out for now. Currently no
properties are supported, but that will change soon.
Sean Anderson [Mon, 29 May 2023 19:23:07 +0000 (15:23 -0400)]
vhpi: Add support for subtypes
Add very basic support for subtypes. This is just enough to place them
in the type hierarchy, and not much else. Array subtypes are always
created as arrayTypeDecls, since this will let us expose the element
subtype properly.
Sean Anderson [Mon, 29 May 2023 23:02:31 +0000 (19:02 -0400)]
vhpi: Pass type directly to init_typeDecl
Anonymous types can't be looked up by their ident, so the decl is for
their base type instead. Pass the type directly instead of using
tree_type to ensure the type matches what it represents.
Sean Anderson [Mon, 29 May 2023 18:36:17 +0000 (14:36 -0400)]
vhpi: Move iterator initialization to init_iterator
In preparation for merging the logic in vhpi_iterator with
vhpi_handle_for_index, split off iterator initialization into its own
function. This replaces new_iterator so we can avoid a memory
allocation if possible in vhpi_handle_for_index.
Sean Anderson [Mon, 29 May 2023 17:09:37 +0000 (13:09 -0400)]
vhpi: Move BaseType to c_typeDecl
Each Type has a BaseType. Except for subtypes, the BaseType is the Type
itself. In preparation for adding subTypeDecls, move BaseType to
typeDecl. This allows us to calculate the BaseType when necessary,
removing the need to have a redundant BaseType reference.