From 338a0eb11a8a009c59d4bde7c2e195990f22f37c Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 2 Oct 2014 14:09:27 -0700 Subject: [PATCH] Get $root scope tasks/fuctions down to the ivl_target API. --- emit.cc | 6 +++++ ivl_target_priv.h | 1 + net_design.cc | 11 ++++++++ netlist.h | 1 + t-dll-api.cc | 6 ++++- t-dll.cc | 65 +++++++++++++++++++++++++++++++++++------------ tgt-stub/stub.c | 6 +++++ 7 files changed, 79 insertions(+), 17 deletions(-) diff --git a/emit.cc b/emit.cc index fe6880156..bd46fc5c4 100644 --- a/emit.cc +++ b/emit.cc @@ -504,6 +504,12 @@ int Design::emit(struct target_t*tgt) const if (tgt->start_design(this) == false) return -2; + for (map::const_iterator scope = root_tasks_.begin() + ; scope != root_tasks_.end() ; ++ scope) { + scope->first->emit_scope(tgt); + scope->first->emit_defs(tgt); + } + // enumerate package scopes for (map::const_iterator scope = packages_.begin() ; scope != packages_.end() ; ++ scope) { diff --git a/ivl_target_priv.h b/ivl_target_priv.h index c5316e1b5..489d801eb 100644 --- a/ivl_target_priv.h +++ b/ivl_target_priv.h @@ -52,6 +52,7 @@ struct ivl_design_s { // Keep arrays of root scopes. std::map classes; + std::map root_tasks; std::vector packages; std::vector roots; diff --git a/net_design.cc b/net_design.cc index 9bea1d6d9..dc0a7ecbc 100644 --- a/net_design.cc +++ b/net_design.cc @@ -169,6 +169,17 @@ list Design::find_package_scopes() const return res; } +list Design::find_roottask_scopes() const +{ + listres; + for (map::const_iterator cur = root_tasks_.begin() + ; cur != root_tasks_.end() ; ++ cur) { + res.push_back (cur->first); + } + + return res; +} + /* * This method locates a scope in the design, given its rooted * hierarchical name. Each component of the key is used to scan one diff --git a/netlist.h b/netlist.h index 66e36201b..d3700a80a 100644 --- a/netlist.h +++ b/netlist.h @@ -4815,6 +4815,7 @@ class Design : public Definitions { // Tasks NetScope* find_task(NetScope*scope, const pform_name_t&name); void add_root_task(NetScope*tscope, PTaskFunc*tf); + std::list find_roottask_scopes(void) const; // Find a class in the $root scope. void add_class(netclass_t*cl, PClass*pclass); diff --git a/t-dll-api.cc b/t-dll-api.cc index 3dd1055d2..31389cba5 100644 --- a/t-dll-api.cc +++ b/t-dll-api.cc @@ -84,7 +84,11 @@ extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes, assert (nscopes && scopes); if (des->root_scope_list.size() == 0) { size_t fill = 0; - des->root_scope_list.resize(des->packages.size() + des->roots.size() + des->classes.size()); + des->root_scope_list.resize(des->root_tasks.size() + des->packages.size() + des->roots.size() + des->classes.size()); + for (map::iterator idx = des->root_tasks.begin() + ; idx != des->root_tasks.end() ; ++ idx) + des->root_scope_list[fill++] = idx->second; + for (map::iterator idx = des->classes.begin() ; idx != des->classes.end() ; ++ idx) des->root_scope_list[fill++] = idx->second; diff --git a/t-dll.cc b/t-dll.cc index 054558c63..f9854e793 100644 --- a/t-dll.cc +++ b/t-dll.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2014 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it @@ -261,6 +261,12 @@ ivl_scope_t dll_target::find_scope(ivl_design_s &des, const NetScope*cur) return tmp; } + if (cur->type()==NetScope::TASK || cur->type()==NetScope::FUNC) { + map::const_iterator idx = des.root_tasks.find(cur); + if (idx != des.root_tasks.end()) + return idx->second; + } + for (unsigned idx = 0; idx < des.roots.size(); idx += 1) { assert(des.roots[idx]); ivl_scope_t scope = find_scope_from_root(des.roots[idx], cur); @@ -605,6 +611,13 @@ void dll_target::add_root(const NetScope *s) root_->lpm_ = 0; root_->def = 0; make_scope_parameters(root_, s); + root_->tname_ = root_->name_; + root_->time_precision = s->time_precision(); + root_->time_units = s->time_unit(); + root_->nattr = s->attr_cnt(); + root_->attr = fill_in_attributes(s); + root_->is_auto = 0; + root_->is_cell = s->is_cell(); switch (s->type()) { case NetScope::PACKAGE: root_->type_ = IVL_SCT_PACKAGE; @@ -615,16 +628,25 @@ void dll_target::add_root(const NetScope *s) case NetScope::CLASS: root_->type_ = IVL_SCT_CLASS; break; + case NetScope::TASK: { + const NetTaskDef*def = s->task_def(); + if (def == 0) { + cerr << "?:?" << ": internal error: " + << "task " << root_->name_ + << " has no definition." << endl; + } + assert(def); + root_->type_ = IVL_SCT_TASK; + root_->tname_ = def->scope()->basename(); + break; + } + break; + case NetScope::FUNC: + root_->type_ = IVL_SCT_FUNCTION; + break; default: assert(0); } - root_->tname_ = root_->name_; - root_->time_precision = s->time_precision(); - root_->time_units = s->time_unit(); - root_->nattr = s->attr_cnt(); - root_->attr = fill_in_attributes(s); - root_->is_auto = 0; - root_->is_cell = s->is_cell(); switch (s->type()) { case NetScope::MODULE: @@ -650,6 +672,11 @@ void dll_target::add_root(const NetScope *s) des_.classes[s] = root_; break; + case NetScope::TASK: + case NetScope::FUNC: + des_.root_tasks[s] = root_; + break; + default: assert(0); break; @@ -691,16 +718,22 @@ bool dll_target::start_design(const Design*des) } assert(idx == des_.disciplines.size()); - list package_scopes = des->find_package_scopes(); - for (list::const_iterator scop = package_scopes.begin() - ; scop != package_scopes.end(); ++ scop ) { - add_root(*scop); + list scope_list = des->find_roottask_scopes(); + for (list::const_iterator cur = scope_list.begin() + ; cur != scope_list.end() ; ++ cur) { + add_root(*cur); } - list root_scopes = des->find_root_scopes(); - for (list::const_iterator scop = root_scopes.begin() - ; scop != root_scopes.end(); ++ scop ) { - add_root(*scop); + scope_list = des->find_package_scopes(); + for (list::const_iterator cur = scope_list.begin() + ; cur != scope_list.end(); ++ cur ) { + add_root(*cur); + } + + scope_list = des->find_root_scopes(); + for (list::const_iterator cur = scope_list.begin() + ; cur != scope_list.end(); ++ cur ) { + add_root(*cur); } target_ = (target_design_f)ivl_dlsym(dll_, LU "target_design" TU); diff --git a/tgt-stub/stub.c b/tgt-stub/stub.c index 353952718..358b2efa6 100644 --- a/tgt-stub/stub.c +++ b/tgt-stub/stub.c @@ -1797,6 +1797,12 @@ int target_design(ivl_design_t des) ivl_scope_t cur = root_scopes[idx]; switch (ivl_scope_type(cur)) { + case IVL_SCT_TASK: + fprintf(out, "task = %s\n", ivl_scope_name(cur)); + break; + case IVL_SCT_FUNCTION: + fprintf(out, "function = %s\n", ivl_scope_name(cur)); + break; case IVL_SCT_CLASS: fprintf(out, "class = %s\n", ivl_scope_name(cur)); break;