Implement the ivl_target ivl_scope_child functions.

These are a more convenient way of iterating through child scopes.
This commit is contained in:
Stephen Williams 2013-07-18 19:24:47 -07:00
parent d2034a6458
commit 01b81e0dbc
5 changed files with 26 additions and 0 deletions

View File

@ -197,6 +197,8 @@ ivl_scope_attr_cnt
ivl_scope_attr_val
ivl_scope_basename
ivl_scope_children
ivl_scope_child
ivl_scope_childs
ivl_scope_class
ivl_scope_classes
ivl_scope_def

View File

@ -20,6 +20,7 @@
*/
# include <inttypes.h>
# include <stddef.h>
/* Re the _CLASS define: clang++ wants this to be class to match the
* definition, but clang (the C) compiler needs it to be a struct
@ -1678,6 +1679,11 @@ extern unsigned ivl_parameter_lineno(ivl_parameter_t net);
* If the scope has no children, this method will return 0 and
* otherwise do nothing.
*
* ivl_scope_childs
* ivl_scope_child
* This is an alternative way of getting at the childs scopes of a
* given scope.
*
* ivl_scope_def
* Task definition scopes carry a task definition, in the form of
* a statement. This method accesses that definition. The
@ -1779,6 +1785,8 @@ extern ivl_statement_t ivl_scope_def(ivl_scope_t net);
extern const char* ivl_scope_def_file(ivl_scope_t net);
extern unsigned ivl_scope_def_lineno(ivl_scope_t net);
extern size_t ivl_scope_childs(ivl_scope_t net);
extern ivl_scope_t ivl_scope_child(ivl_scope_t net, size_t idx);
extern unsigned ivl_scope_classes(ivl_scope_t net);
extern ivl_type_t ivl_scope_class(ivl_scope_t net, unsigned idx);
extern unsigned ivl_scope_enumerates(ivl_scope_t net);

View File

@ -1919,6 +1919,18 @@ extern "C" int ivl_scope_children(ivl_scope_t net,
return 0;
}
extern "C" size_t ivl_scope_childs(ivl_scope_t net)
{
assert(net->child.size() == net->children.size());
return net->child.size();
}
extern "C" ivl_scope_t ivl_scope_child(ivl_scope_t net, size_t idx)
{
assert(net && idx < net->child.size());
return net->child[idx];
}
extern "C" ivl_type_t ivl_scope_class(ivl_scope_t net, unsigned idx)
{
assert(idx < net->classes.size());

View File

@ -2363,6 +2363,7 @@ void dll_target::scope(const NetScope*net)
scop->parent = find_scope(des_, net->parent());
assert(scop->parent);
scop->parent->children[net->fullname()] = scop;
scop->parent->child .push_back(scop);
scop->nlog_ = 0;
scop->log_ = 0;
scop->nevent_ = 0;

View File

@ -639,6 +639,9 @@ struct ivl_process_s {
struct ivl_scope_s {
ivl_scope_t parent;
std::map<hname_t,ivl_scope_t> children;
// This is just like the children map above, but in vector
// form for convenient access.
std::vector<ivl_scope_t> child;
perm_string name_;
perm_string tname_;