From 93e95cf065c3a6c304f828ac3b13faaa93430a11 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 20 Mar 2024 21:46:53 +0000 Subject: [PATCH] VHPI discovery in for-generate broken since 7dd41. Fixes #868 --- src/vhpi/vhpi-model.c | 41 ++++++++++++++++++++++++++++++++++++++--- test/vhpi/vhpi10.c | 19 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/vhpi/vhpi-model.c b/src/vhpi/vhpi-model.c index 0b70f6e7..35f36fef 100644 --- a/src/vhpi/vhpi-model.c +++ b/src/vhpi/vhpi-model.c @@ -1847,6 +1847,14 @@ vhpiHandleT vhpi_handle(vhpiOneToOneT type, vhpiHandleT referenceHandle) return handle_for(&(sn->Suffix->decl.object)); } + case vhpiParamDecl: + { + c_forGenerate *g = cast_forGenerate(obj); + if (g == NULL) + return NULL; + + return handle_for(&(g->ParamDecl->objDecl.decl.object)); + } case DEPRECATED_vhpiReturnTypeMark: case DEPRECATED_vhpiName: case DEPRECATED_vhpiTypeMark: @@ -1855,8 +1863,9 @@ vhpiHandleT vhpi_handle(vhpiOneToOneT type, vhpiHandleT referenceHandle) "not implemented in vhpi_handle", vhpi_one_to_one_str(type)); return NULL; default: - fatal_trace("relationship %s not supported in vhpi_handle", - vhpi_one_to_one_str(type)); + vhpi_error(vhpiInternal, &(obj->loc), "relationship %s not supported in " + "vhpi_handle", vhpi_one_to_one_str(type)); + return NULL; } } @@ -2233,6 +2242,15 @@ vhpiIntT vhpi_get(vhpiIntPropertyT property, vhpiHandleT handle) return s->IsSeqStmt; } + case vhpiGenerateIndexP: + { + c_forGenerate *g = is_forGenerate(obj); + if (g == NULL) + goto missing_property; + + return g->GenerateIndex; + } + default: vhpi_error(vhpiFailure, &(obj->loc), "unsupported property %s in " "vhpi_get", vhpi_property_str(property)); @@ -3395,7 +3413,7 @@ static void build_signalDecl(tree_t decl, c_abstractRegion *region) APUSH(region->decls, &(s->objDecl.decl.object)); } -static void build_constDecl(tree_t decl, c_abstractRegion *region) +static c_constDecl *build_constDecl(tree_t decl, c_abstractRegion *region) { c_constDecl *cd = new_object(sizeof(c_constDecl), vhpiConstDeclK); init_objDecl(&(cd->objDecl), decl, region); @@ -3403,6 +3421,7 @@ static void build_constDecl(tree_t decl, c_abstractRegion *region) cd->IsDeferred = !tree_has_value(decl); APUSH(region->decls, &(cd->objDecl.decl.object)); + return cd; } static c_abstractRegion *build_blockStmt(tree_t t, c_abstractRegion *region) @@ -3442,6 +3461,15 @@ static c_abstractRegion *build_forGenerate(tree_t t, c_abstractRegion *region) init_abstractRegion(&(g->region), t); init_stmt(&(g->stmt), t); + assert(tree_generics(t) == 1); + assert(tree_genmaps(t) == 1); + + tree_t index = tree_value(tree_genmap(t, 0)); + g->GenerateIndex = assume_int(index); + + tree_t g0 = tree_generic(t, 0); + g->ParamDecl = build_constDecl(g0, &(g->region)); + APUSH(region->InternalRegions, &(g->region.object)); APUSH(region->stmts, &(g->region.object)); @@ -3495,6 +3523,12 @@ static void vhpi_lazy_component(c_abstractRegion *r) vhpi_build_stmts(inner, r); } +static void vhpi_lazy_for_generate(c_abstractRegion *r) +{ + vhpi_build_decls(r->tree, r); + vhpi_build_stmts(r->tree, r); +} + static void vhpi_build_stmts(tree_t container, c_abstractRegion *region) { const int nstmts = tree_stmts(container); @@ -3522,6 +3556,7 @@ static void vhpi_build_stmts(tree_t container, c_abstractRegion *region) break; case T_FOR_GENERATE: r = build_forGenerate(s, region); + r->lazyfn = vhpi_lazy_for_generate; break; default: continue; diff --git a/test/vhpi/vhpi10.c b/test/vhpi/vhpi10.c index 0a403067..c51ff790 100644 --- a/test/vhpi/vhpi10.c +++ b/test/vhpi/vhpi10.c @@ -118,10 +118,22 @@ static void start_of_sim(const vhpiCbDataT *cb_data) check_error(); fail_if(genblk1 == NULL); fail_unless(vhpi_get(vhpiKindP, genblk1) == vhpiForGenerateK); + fail_unless(vhpi_get(vhpiGenerateIndexP, genblk1) == 1); vhpi_printf("genblk1 CaseName is %s", (char *)vhpi_get_str(vhpiCaseNameP, genblk1)); //fail_unless(strcmp((char *)vhpi_get_str(vhpiCaseNameP, genblk1), "ForGen1(1)") == 0); + vhpiHandleT genblk1_i = vhpi_handle_by_name("I", genblk1); + check_error(); + fail_if(genblk1_i == NULL); + fail_unless(vhpi_get(vhpiKindP, genblk1_i) == vhpiConstDeclK); + fail_unless(vhpi_handle(vhpiParamDecl, genblk1) == genblk1_i); + + vhpiHandleT genblk1_s = vhpi_handle_by_name("S", genblk1); + check_error(); + fail_if(genblk1_s == NULL); + fail_unless(vhpi_get(vhpiKindP, genblk1_s) == vhpiSigDeclK); + vhpiValueT value = { .format = vhpiObjTypeVal }; @@ -132,6 +144,13 @@ static void start_of_sim(const vhpiCbDataT *cb_data) fail_unless(value.value.intg == 42); fail_unless(value.numElems == 1); + vhpi_get_value(genblk1_i, &value); + check_error(); + fail_unless(value.format == vhpiIntVal); + vhpi_printf("value=%d", value.value.intg); + fail_unless(value.value.intg == 1); + fail_unless(value.numElems == 1); + value.format = vhpiObjTypeVal; vhpi_get_value(c0, &value); check_error(); -- 2.39.2