From adb4be5c75da64eecd3fabe1e2ce53131e5adaf8 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 18 Apr 2021 09:47:21 +0100 Subject: [PATCH] Don't return packages when iterating over root modules (issue #496) The code assumed all handles stored in vpip_root_table were modules. This is true for traditional Verilog, but not so for SystemVerilog. Whilst here, also add support for iterating over packages. (cherry picked from commit 3167b2ed2497b434a2e0e5bcd8af85c77864d86a) --- vvp/vpi_priv.cc | 4 +++- vvp/vpi_priv.h | 2 +- vvp/vpi_scope.cc | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 42d301a50..d8648b2cd 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -1239,7 +1239,9 @@ static vpiHandle vpi_iterate_global(int type) { switch (type) { case vpiModule: - return vpip_make_root_iterator(); + // fallthrough + case vpiPackage: + return vpip_make_root_iterator(type); case vpiUdpDefn: return vpip_make_udp_iterator(); diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 1d9bccfce..4da000127 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -329,7 +329,7 @@ extern void vpip_attach_to_current_scope(vpiHandle obj); extern __vpiScope* vpip_peek_context_scope(void); extern unsigned vpip_add_item_to_context(automatic_hooks_s*item, __vpiScope*scope); -extern vpiHandle vpip_make_root_iterator(void); +extern vpiHandle vpip_make_root_iterator(int type_code); extern void vpip_make_root_iterator(class __vpiHandle**&table, unsigned&ntable); diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index 746fb4d72..ba17b127a 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2020 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2021 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -35,10 +35,11 @@ using namespace std; static vector vpip_root_table; -vpiHandle vpip_make_root_iterator(void) +static vpiHandle make_subset_iterator_(int type_code, vector&table); + +vpiHandle vpip_make_root_iterator(int type_code) { - return vpip_make_iterator(vpip_root_table.size(), - &vpip_root_table[0], false); + return make_subset_iterator_(type_code, vpip_root_table); } void vpip_make_root_iterator(__vpiHandle**&table, unsigned&ntable) @@ -291,22 +292,22 @@ static int compare_types(int code, int type) return 0; } -static vpiHandle module_iter_subset(int code, __vpiScope*ref) +static vpiHandle make_subset_iterator_(int type_code, vector&table) { unsigned mcnt = 0, ncnt = 0; vpiHandle*args; - for (unsigned idx = 0 ; idx < ref->intern.size() ; idx += 1) - if (compare_types(code, ref->intern[idx]->get_type_code())) + for (unsigned idx = 0; idx < table.size(); idx += 1) + if (compare_types(type_code, table[idx]->get_type_code())) mcnt += 1; if (mcnt == 0) return 0; args = (vpiHandle*)calloc(mcnt, sizeof(vpiHandle)); - for (unsigned idx = 0 ; idx < ref->intern.size() ; idx += 1) - if (compare_types(code, ref->intern[idx]->get_type_code())) - args[ncnt++] = ref->intern[idx]; + for (unsigned idx = 0; idx < table.size(); idx += 1) + if (compare_types(type_code, table[idx]->get_type_code())) + args[ncnt++] = table[idx]; assert(ncnt == mcnt); @@ -324,7 +325,7 @@ static vpiHandle module_iter(int code, vpiHandle obj) __vpiScope*ref = dynamic_cast<__vpiScope*>(obj); assert(ref); - return module_iter_subset(code, ref); + return make_subset_iterator_(code, ref->intern); }