From 0b2bea03e4386c91369310c8463fa742bd259fdf Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 12 Dec 2023 11:27:15 -0500 Subject: [PATCH] vhpi: Support types from package instances Search declarations as well as statements so we can find package instances. This allows VHPI to use signals which have types defined in package instances. Signed-off-by: Sean Anderson --- src/vhpi/vhpi-model.c | 7 +++++++ test/regress/testlist.txt | 2 +- test/regress/vhpi10.vhd | 8 ++++++++ test/vhpi/vhpi10.c | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/vhpi/vhpi-model.c b/src/vhpi/vhpi-model.c index 91d3e6a68..3cf2f1e7f 100644 --- a/src/vhpi/vhpi-model.c +++ b/src/vhpi/vhpi-model.c @@ -3183,6 +3183,13 @@ static c_typeDecl *build_typeDecl(type_t type, c_vhpiObject *obj) next = s; } + const int ndecls = tree_decls(unit); + for (int i = 0; next == NULL && i < ndecls; i++) { + tree_t d = tree_decl(unit, i); + if (tree_ident(d) == b) + next = d; + } + if (next == NULL) fatal_trace("cannot find %s within %s", istr(b), istr(tree_ident(unit))); diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 41308fcbf..8b3f6f501 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -867,7 +867,7 @@ ieee14 normal,gold ieee15 fail,gold issue752 shell predef5 normal,2008 -vhpi10 normal,vhpi +vhpi10 normal,vhpi,2008 bounds40 fail,gold bounds41 fail,gold ieee16 normal diff --git a/test/regress/vhpi10.vhd b/test/regress/vhpi10.vhd index a0316a3e4..917547a7c 100644 --- a/test/regress/vhpi10.vhd +++ b/test/regress/vhpi10.vhd @@ -1,3 +1,8 @@ +package counter is + generic (MAX: bit_vector); + subtype counter_t is bit_vector(MAX'range); +end; + entity sub is generic ( g0 : integer; g1 : string ); @@ -37,6 +42,9 @@ architecture test of vhpi10 is generic ( g0 : integer; g1 : string ); port ( p0 : bit_vector ); end component; + + package pkg is new work.counter generic map (MAX => 10D"999"); + signal s0: pkg.counter_t; begin b0: block is diff --git a/test/vhpi/vhpi10.c b/test/vhpi/vhpi10.c index 00d730222..0a4030674 100644 --- a/test/vhpi/vhpi10.c +++ b/test/vhpi/vhpi10.c @@ -46,6 +46,11 @@ static void start_of_sim(const vhpiCbDataT *cb_data) fail_unless(vhpi_scan(it2) == NULL); vhpi_release_handle(it2); + vhpiHandleT s0 = vhpi_handle_by_name("s0", root); + check_error(); + fail_if(s0 == NULL); + fail_unless(vhpi_get(vhpiKindP, s0) == vhpiSigDeclK); + vhpiHandleT b0 = vhpi_handle_by_name("b0", root); check_error(); fail_if(b0 == NULL);