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.
This commit is contained in:
parent
d8cb29f6e0
commit
3167b2ed24
|
|
@ -1241,7 +1241,9 @@ static vpiHandle vpi_iterate_global(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case vpiModule:
|
case vpiModule:
|
||||||
return vpip_make_root_iterator();
|
// fallthrough
|
||||||
|
case vpiPackage:
|
||||||
|
return vpip_make_root_iterator(type);
|
||||||
|
|
||||||
case vpiUdpDefn:
|
case vpiUdpDefn:
|
||||||
return vpip_make_udp_iterator();
|
return vpip_make_udp_iterator();
|
||||||
|
|
|
||||||
|
|
@ -329,7 +329,7 @@ extern void vpip_attach_to_current_scope(vpiHandle obj);
|
||||||
extern __vpiScope* vpip_peek_context_scope(void);
|
extern __vpiScope* vpip_peek_context_scope(void);
|
||||||
extern unsigned vpip_add_item_to_context(automatic_hooks_s*item,
|
extern unsigned vpip_add_item_to_context(automatic_hooks_s*item,
|
||||||
__vpiScope*scope);
|
__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,
|
extern void vpip_make_root_iterator(class __vpiHandle**&table,
|
||||||
unsigned&ntable);
|
unsigned&ntable);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -35,10 +35,11 @@ using namespace std;
|
||||||
|
|
||||||
static vector<vpiHandle> vpip_root_table;
|
static vector<vpiHandle> vpip_root_table;
|
||||||
|
|
||||||
vpiHandle vpip_make_root_iterator(void)
|
static vpiHandle make_subset_iterator_(int type_code, vector<vpiHandle>&table);
|
||||||
|
|
||||||
|
vpiHandle vpip_make_root_iterator(int type_code)
|
||||||
{
|
{
|
||||||
return vpip_make_iterator(vpip_root_table.size(),
|
return make_subset_iterator_(type_code, vpip_root_table);
|
||||||
&vpip_root_table[0], false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vpip_make_root_iterator(__vpiHandle**&table, unsigned&ntable)
|
void vpip_make_root_iterator(__vpiHandle**&table, unsigned&ntable)
|
||||||
|
|
@ -291,22 +292,22 @@ static int compare_types(int code, int type)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static vpiHandle module_iter_subset(int code, __vpiScope*ref)
|
static vpiHandle make_subset_iterator_(int type_code, vector<vpiHandle>&table)
|
||||||
{
|
{
|
||||||
unsigned mcnt = 0, ncnt = 0;
|
unsigned mcnt = 0, ncnt = 0;
|
||||||
vpiHandle*args;
|
vpiHandle*args;
|
||||||
|
|
||||||
for (unsigned idx = 0 ; idx < ref->intern.size() ; idx += 1)
|
for (unsigned idx = 0; idx < table.size(); idx += 1)
|
||||||
if (compare_types(code, ref->intern[idx]->get_type_code()))
|
if (compare_types(type_code, table[idx]->get_type_code()))
|
||||||
mcnt += 1;
|
mcnt += 1;
|
||||||
|
|
||||||
if (mcnt == 0)
|
if (mcnt == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
args = (vpiHandle*)calloc(mcnt, sizeof(vpiHandle));
|
args = (vpiHandle*)calloc(mcnt, sizeof(vpiHandle));
|
||||||
for (unsigned idx = 0 ; idx < ref->intern.size() ; idx += 1)
|
for (unsigned idx = 0; idx < table.size(); idx += 1)
|
||||||
if (compare_types(code, ref->intern[idx]->get_type_code()))
|
if (compare_types(type_code, table[idx]->get_type_code()))
|
||||||
args[ncnt++] = ref->intern[idx];
|
args[ncnt++] = table[idx];
|
||||||
|
|
||||||
assert(ncnt == mcnt);
|
assert(ncnt == mcnt);
|
||||||
|
|
||||||
|
|
@ -324,7 +325,7 @@ static vpiHandle module_iter(int code, vpiHandle obj)
|
||||||
__vpiScope*ref = dynamic_cast<__vpiScope*>(obj);
|
__vpiScope*ref = dynamic_cast<__vpiScope*>(obj);
|
||||||
assert(ref);
|
assert(ref);
|
||||||
|
|
||||||
return module_iter_subset(code, ref);
|
return make_subset_iterator_(code, ref->intern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue