diff --git a/elab_expr.cc b/elab_expr.cc index 673afb19b..13d4d6459 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1923,6 +1923,23 @@ NetExpr* PECallFunction::elaborate_base_(Design*des, NetScope*scope, NetScope*ds bool need_const = NEED_CONST & flags; + // If this is a constant expression, it is possible that we + // are being elaborated before the function definition. If + // that's the case, try to elaborate the function as a const + // function. + if (need_const && ! def->proc()) { + if (debug_elaborate) { + cerr << get_fileline() << ": PECallFunction::elaborate_base_: " + << "Try to elaborate " << scope_path(dscope) + << " as constant function." << endl; + } + dscope->set_elab_stage(2); + dscope->need_const_func(true); + const PFunction*pfunc = dscope->func_pform(); + ivl_assert(*this, pfunc); + pfunc->elaborate(des, dscope); + } + unsigned parms_count = parms_.size(); if ((parms_count == 1) && (parms_[0] == 0)) parms_count = 0; diff --git a/net_func_eval.cc b/net_func_eval.cc index f5bef42c4..db2dd2260 100644 --- a/net_func_eval.cc +++ b/net_func_eval.cc @@ -87,11 +87,22 @@ NetExpr* NetFuncDef::evaluate_function(const LineInfo&loc, const std::vectorevaluate_function_find_locals(loc, context_map); + if (debug_eval_tree && statement_==0) { + cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: " + << "Function " << scope_path(scope_) + << " has no statement?" << endl; + } + // Perform the evaluation. Note that if there were errors // when compiling the function definition, we may not have // a valid statement. bool flag = statement_ && statement_->evaluate_function(loc, context_map); + if (debug_eval_tree && !flag) { + cerr << loc.get_fileline() << ": NetFuncDef::evaluate_function: " + << "Cannot evaluate " << scope_path(scope_) << "." << endl; + } + // Extract the result... ptr = context_map.find(scope_->basename()); NetExpr*res = ptr->second.value;