From b80401e1eee08b5bbef39eaa89cfee951cb85949 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Mon, 11 Mar 2013 19:46:00 +0000 Subject: [PATCH] Improved error reporting for constant user functions. --- elab_expr.cc | 13 +++++++++++-- net_func_eval.cc | 7 +------ netlist.h | 3 +++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index 5f3183ae0..9a0345054 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1280,6 +1280,16 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope, NetESFunc*fun = new NetESFunc(name, expr_type_, expr_width_, nparms); fun->set_line(*this); + if (!fun->is_built_in()) { + if (scope->need_const_func()) { + cerr << get_fileline() << ": error: " << name + << " is not a built-in function, so cannot" + << " be used in a constant function." << endl; + des->errors += 1; + } + scope->is_const_func(false); + } + /* Now run through the expected parameters. If we find that there are missing parameters, print an error message. @@ -1785,7 +1795,7 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope, // fully elaborated. If this is the case, elaborate it now. This // ensures we know whether or not it is a constant function. if (dscope->elab_stage() < 3) { - dscope->need_const_func(need_const); + dscope->need_const_func(need_const || scope->need_const_func()); const PFunction*pfunc = dscope->func_pform(); ivl_assert(*this, pfunc); pfunc->elaborate(des, dscope); @@ -1797,7 +1807,6 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope, "a constant function must be a constant function " "local to the current module." << endl; des->errors += 1; - return 0; } scope->is_const_func(false); } diff --git a/net_func_eval.cc b/net_func_eval.cc index a9d281754..472de4aa5 100644 --- a/net_func_eval.cc +++ b/net_func_eval.cc @@ -487,12 +487,7 @@ NetExpr* NetESFunc::evaluate_function(const LineInfo&loc, map&context_map) const { ID id = built_in_id_(); - if (id == NOT_BUILT_IN) { - cerr << get_fileline() << ": error: " << name_ - << " is not a built-in function, so cannot" - << " be used in a constant function." << endl; - return 0; - } + ivl_assert(*this, id != NOT_BUILT_IN); NetExpr*val0 = 0; NetExpr*val1 = 0; diff --git a/netlist.h b/netlist.h index b0628cc6e..2ec36da49 100644 --- a/netlist.h +++ b/netlist.h @@ -4066,6 +4066,9 @@ class NetESFunc : public NetExpr { NetExpr* evaluate_min_max_(ID id, const NetExpr*arg0, const NetExpr*arg1) const; + public: + bool is_built_in() const { return built_in_id_() != NOT_BUILT_IN; }; + private: // not implemented NetESFunc(const NetESFunc&); NetESFunc& operator= (const NetESFunc&);