From b67db338f58644c5a56c1d9586ee21fac29ecb70 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 28 Dec 2023 19:17:14 +0000 Subject: [PATCH] Implement vhpiIsNullP and vhpiIsDiscreteP for ranges --- src/vhpi/vhpi-model.c | 32 +++++++++++++++++++++++++------- test/vhpi/vhpi9.c | 2 ++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/vhpi/vhpi-model.c b/src/vhpi/vhpi-model.c index 3cf2f1e7..452b32ba 100644 --- a/src/vhpi/vhpi-model.c +++ b/src/vhpi/vhpi-model.c @@ -855,9 +855,12 @@ static void init_enumLiteral(c_enumLiteral *el, tree_t t, c_enumTypeDecl *Type) el->Position = tree_pos(t); } -static void init_range(c_range *r, vhpiBooleanT IsUp) +static void init_range(c_range *r, vhpiBooleanT IsUp, vhpiBooleanT IsNull, + vhpiBooleanT IsDiscrete) { r->IsUp = IsUp; + r->IsNull = IsNull; + r->IsDiscrete = IsDiscrete; r->LeftExpr = NULL; r->RightExpr = NULL; } @@ -2117,12 +2120,19 @@ vhpiIntT vhpi_get(vhpiIntPropertyT property, vhpiHandleT handle) } case vhpiIsUpP: + case vhpiIsNullP: + case vhpiIsDiscreteP: { c_range *r = is_range(obj); if (r == NULL) goto missing_property; - return r->IsUp; + if (property == vhpiIsUpP) + return r->IsUp; + else if (property == vhpiIsNullP) + return r->IsNull; + else + return r->IsDiscrete; } case vhpiStaticnessP: @@ -2973,11 +2983,16 @@ static c_expr *build_expr(tree_t t) static c_physRange *build_phys_range(tree_t t) { + const int64_t left = assume_int(tree_left(t)); + const int64_t right = assume_int(tree_right(t)); + const range_kind_t dir = tree_subkind(t) == RANGE_TO; + const bool null = dir == RANGE_TO ? left > right : right > left; + c_physRange *pr = new_object(sizeof(c_physRange), vhpiPhysRangeK); - init_range(&(pr->range), tree_subkind(t) == RANGE_TO); + init_range(&(pr->range), dir, null, true); - pr->PhysLeftBound = vhpi_phys_from_native(assume_int(tree_left(t))); - pr->PhysRightBound = vhpi_phys_from_native(assume_int(tree_right(t))); + pr->PhysLeftBound = vhpi_phys_from_native(left); + pr->PhysRightBound = vhpi_phys_from_native(right); return pr; } @@ -3020,8 +3035,10 @@ static c_intRange *build_int_range(tree_t r, type_t parent, int dim, } } + const bool null = dir == RANGE_TO ? left > right : right > left; + c_intRange *ir = new_object(sizeof(c_intRange), vhpiIntRangeK); - init_range(&(ir->range), dir == RANGE_TO); + init_range(&(ir->range), dir == RANGE_TO, null, true); ir->LeftBound = vhpi_int_from_native(left); ir->RightBound = vhpi_int_from_native(right); @@ -3107,9 +3124,10 @@ static c_typeDecl *build_dynamicSubtype(c_typeDecl *base, void *ptr, const int64_t left = bounds[i].left; const int64_t right = ffi_array_right(bounds[i].left, bounds[i].length); + const bool null = dir == RANGE_TO ? left > right : right > left; c_intRange *ir = new_object(sizeof(c_intRange), vhpiIntRangeK); - init_range(&(ir->range), dir == RANGE_TO); + init_range(&(ir->range), dir == RANGE_TO, null, true); ir->LeftBound = vhpi_int_from_native(left); ir->RightBound = vhpi_int_from_native(right); diff --git a/test/vhpi/vhpi9.c b/test/vhpi/vhpi9.c index ddf3ffca..0f4feb75 100644 --- a/test/vhpi/vhpi9.c +++ b/test/vhpi/vhpi9.c @@ -96,6 +96,8 @@ static void end_of_init(const vhpiCbDataT *cb_data) fail_unless(vhpi_get(vhpiLeftBoundP, s3f_range) == 1); fail_unless(vhpi_get(vhpiRightBoundP, s3f_range) == 4); fail_unless(vhpi_get(vhpiIsUpP, s3f_range)); + fail_if(vhpi_get(vhpiIsNullP, s3f_range)); + fail_unless(vhpi_get(vhpiIsDiscreteP, s3f_range)); vhpiHandleT s3g = vhpi_handle_by_name("s3.g", root); check_error(); -- 2.39.2