From 807fb2e5d1ee403cf58cf548733b87647d7cb8de Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sun, 27 Feb 2022 08:56:30 -0800 Subject: [PATCH] always_comb and friends handle void functions similar to tasks Void functions can be used in always_comb, but since the compiler uses the check_synth() method to generate some warnings, make sure that function is implemented for functions as well as tasks. --- elab_scope.cc | 5 +++-- netlist.cc | 17 +++++++++++++++-- netlist.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index 23a9a8ef4..371d16e72 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -692,7 +692,8 @@ static void elaborate_scope_func(Design*des, NetScope*scope, PFunction*task) if (debug_scopes) { cerr << task->get_fileline() << ": elaborate_scope_func: " - << "Elaborate task scope " << scope_path(task_scope) << endl; + << "Elaborate function scope " << scope_path(task_scope) + << endl; } task->elaborate_scope(des, task_scope); @@ -1589,7 +1590,7 @@ void PEvent::elaborate_scope(Design*, NetScope*scope) const void PFunction::elaborate_scope(Design*des, NetScope*scope) const { - assert(scope->type() == NetScope::FUNC); + ivl_assert(*this, scope->type() == NetScope::FUNC); // Save a reference to the pform representation of the function // in case we need to perform early elaboration. diff --git a/netlist.cc b/netlist.cc index 21a44faea..d8e467c2e 100644 --- a/netlist.cc +++ b/netlist.cc @@ -3502,7 +3502,14 @@ bool NetSTask::check_synth(ivl_process_type_t pr_type, return false; } -bool NetTaskDef::check_synth(ivl_process_type_t pr_type, +/* + * This function is called to make sure the task/function can be used + * in a context where it must be synthesizable, such as in an always_comb + * or always_ff. + * + * If this is a function, then the function must be void. + */ +bool NetBaseDef::check_synth(ivl_process_type_t pr_type, const NetScope* /* scope */) const { bool result = false; @@ -3522,7 +3529,13 @@ bool NetTaskDef::check_synth(ivl_process_type_t pr_type, bool NetUTask::check_synth(ivl_process_type_t pr_type, const NetScope* scope) const { - return task()->task_def()->check_synth(pr_type, scope); + const NetScope* task_scope = task(); + if (task_scope->type() == NetScope::FUNC) { + // This can happen if this a void function. + return task_scope->func_def()->check_synth(pr_type, scope); + } else { + return task_scope->task_def()->check_synth(pr_type, scope); + } } bool NetWhile::check_synth(ivl_process_type_t pr_type, diff --git a/netlist.h b/netlist.h index dd6b9dbb7..e99f0e167 100644 --- a/netlist.h +++ b/netlist.h @@ -867,6 +867,8 @@ class NetBaseDef { //const string& name() const; const NetProc*proc() const; + virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const; + private: NetScope*scope_; std::vectorports_; @@ -3867,7 +3869,6 @@ class NetTaskDef : public NetBaseDef { void dump(std::ostream&, unsigned) const; DelayType delay_type(bool print_delay=false) const; - virtual bool check_synth(ivl_process_type_t pr_type, const NetScope*scope) const; private: // not implemented NetTaskDef(const NetTaskDef&);