From 4dffd97d28c45a9186648ece4912116a4263662e Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 8 Apr 2013 18:12:54 -0700 Subject: [PATCH] Handle tasks in packages. --- Statement.cc | 15 +++++++++++++-- Statement.h | 3 +++ elaborate.cc | 8 +++++++- parse.y | 10 ++++------ pform.cc | 28 ++++++++++++++++++++++++++++ pform.h | 6 +++++- pform_package.cc | 7 +++++++ 7 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Statement.cc b/Statement.cc index 54e9ad1b1..79d63fb63 100644 --- a/Statement.cc +++ b/Statement.cc @@ -127,7 +127,18 @@ void PBlock::set_statement(const vector&st) } PCallTask::PCallTask(const pform_name_t&n, const list&p) -: path_(n), parms_(p.size()) +: package_(0), path_(n), parms_(p.size()) +{ + list::const_iterator cur = p.begin(); + for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) { + parms_[idx] = *cur; + ++cur; + } + assert(cur == p.end()); +} + +PCallTask::PCallTask(PPackage*pkg, const pform_name_t&n, const list&p) +: package_(pkg), path_(n), parms_(p.size()) { list::const_iterator cur = p.begin(); for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) { @@ -138,7 +149,7 @@ PCallTask::PCallTask(const pform_name_t&n, const list&p) } PCallTask::PCallTask(perm_string n, const list&p) -: parms_(p.size()) +: package_(0), parms_(p.size()) { list::const_iterator cur = p.begin(); for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) { diff --git a/Statement.h b/Statement.h index c96d7706a..43f299443 100644 --- a/Statement.h +++ b/Statement.h @@ -31,6 +31,7 @@ # include "HName.h" # include "LineInfo.h" class PExpr; +class PPackage; class Statement; class PEventStatement; class Design; @@ -198,6 +199,7 @@ class PBlock : public PScope, public Statement { class PCallTask : public Statement { public: + explicit PCallTask(PPackage*pkg, const pform_name_t&n, const list&parms); explicit PCallTask(const pform_name_t&n, const list&parms); explicit PCallTask(perm_string n, const list&parms); ~PCallTask(); @@ -217,6 +219,7 @@ class PCallTask : public Statement { NetProc*elaborate_build_call_(Design*des, NetScope*scope, NetScope*task, NetExpr*use_this) const; + PPackage*package_; pform_name_t path_; vector parms_; }; diff --git a/elaborate.cc b/elaborate.cc index ffff583bb..d9637b34e 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -3206,7 +3206,13 @@ NetProc* PCallTask::elaborate_usr(Design*des, NetScope*scope) const return 0; } - NetScope*task = des->find_task(scope, path_); + NetScope*pscope = scope; + if (package_) { + pscope = des->find_package(package_->pscope_name()); + ivl_assert(*this, pscope); + } + + NetScope*task = des->find_task(pscope, path_); if (task == 0) { // For SystemVerilog this may be a few other things. if (gn_system_verilog()) { diff --git a/parse.y b/parse.y index f287c149d..88f8dcbef 100644 --- a/parse.y +++ b/parse.y @@ -1412,6 +1412,7 @@ package_item /* IEEE1800-2005 A.1.10 */ | K_localparam param_type localparam_assign_list ';' | type_declaration | function_declaration + | task_declaration | data_declaration ; @@ -5725,8 +5726,7 @@ statement_item /* This is roughly statement_item in the LRM */ } | hierarchy_identifier '(' expression_list_with_nuls ')' ';' - { PCallTask*tmp = new PCallTask(*$1, *$3); - FILE_NAME(tmp, @1); + { PCallTask*tmp = pform_make_call_task(@1, *$1, *$3); delete $1; delete $3; $$ = tmp; @@ -5760,8 +5760,7 @@ statement_item /* This is roughly statement_item in the LRM */ | hierarchy_identifier ';' { listpt; - PCallTask*tmp = new PCallTask(*$1, pt); - FILE_NAME(tmp, @1); + PCallTask*tmp = pform_make_call_task(@1, *$1, pt); delete $1; $$ = tmp; } @@ -5769,8 +5768,7 @@ statement_item /* This is roughly statement_item in the LRM */ | hierarchy_identifier '(' error ')' ';' { yyerror(@3, "error: Syntax error in task arguments."); listpt; - PCallTask*tmp = new PCallTask(*$1, pt); - FILE_NAME(tmp, @1); + PCallTask*tmp = pform_make_call_task(@1, *$1, pt); delete $1; $$ = tmp; } diff --git a/pform.cc b/pform.cc index 223196769..696a31821 100644 --- a/pform.cc +++ b/pform.cc @@ -580,6 +580,34 @@ PECallFunction* pform_make_call_function(const struct vlltype&loc, return tmp; } +PCallTask* pform_make_call_task(const struct vlltype&loc, + const pform_name_t&name, + const list&parms) +{ + PCallTask*tmp = 0; + + do { + if (name.size() != 1) + break; + + perm_string use_name = peek_tail_name(name); + + map::iterator cur_pkg; + cur_pkg = lexical_scope->imports.find(use_name); + if (cur_pkg == lexical_scope->imports.end()) + break; + + tmp = new PCallTask(cur_pkg->second, name, parms); + } while (0); + + if (tmp == 0) { + tmp = new PCallTask(name, parms); + } + + FILE_NAME(tmp, loc); + return tmp; +} + static void pform_put_behavior_in_scope(PProcess*pp) { lexical_scope->behaviors.push_back(pp); diff --git a/pform.h b/pform.h index e6fe173a5..20d039bc7 100644 --- a/pform.h +++ b/pform.h @@ -279,7 +279,11 @@ extern void pform_set_typedef(perm_string name, data_type_t*data_type); */ extern PECallFunction* pform_make_call_function(const struct vlltype&loc, const pform_name_t&name, - const list&parms); + const std::list&parms); +extern PCallTask* pform_make_call_task(const struct vlltype&loc, + const pform_name_t&name, + const std::list&parms); + /* * The makewire functions announce to the pform code new wires. These diff --git a/pform_package.cc b/pform_package.cc index 52e6c896b..d8ebdf8ff 100644 --- a/pform_package.cc +++ b/pform_package.cc @@ -105,6 +105,13 @@ void pform_package_import(const struct vlltype&, PPackage*pkg, const char*ident) return; } + map::const_iterator ttcur; + ttcur = pkg->tasks.find(use_ident); + if (ttcur != pkg->tasks.end()) { + scope->imports[ttcur->first] = pkg; + return; + } + map::const_iterator wcur; wcur = pkg->wires.find(use_ident); if (wcur != pkg->wires.end()) {