Improved error reporting for constant user functions.

This commit is contained in:
Martin Whitaker 2013-03-11 19:46:00 +00:00 committed by Stephen Williams
parent 1bcd3a97ad
commit b80401e1ee
3 changed files with 15 additions and 8 deletions

View File

@ -1280,6 +1280,16 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope,
NetESFunc*fun = new NetESFunc(name, expr_type_, expr_width_, nparms); NetESFunc*fun = new NetESFunc(name, expr_type_, expr_width_, nparms);
fun->set_line(*this); 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 /* Now run through the expected parameters. If we find that
there are missing parameters, print an error message. 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 // fully elaborated. If this is the case, elaborate it now. This
// ensures we know whether or not it is a constant function. // ensures we know whether or not it is a constant function.
if (dscope->elab_stage() < 3) { 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(); const PFunction*pfunc = dscope->func_pform();
ivl_assert(*this, pfunc); ivl_assert(*this, pfunc);
pfunc->elaborate(des, dscope); pfunc->elaborate(des, dscope);
@ -1797,7 +1807,6 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope,
"a constant function must be a constant function " "a constant function must be a constant function "
"local to the current module." << endl; "local to the current module." << endl;
des->errors += 1; des->errors += 1;
return 0;
} }
scope->is_const_func(false); scope->is_const_func(false);
} }

View File

@ -487,12 +487,7 @@ NetExpr* NetESFunc::evaluate_function(const LineInfo&loc,
map<perm_string,NetExpr*>&context_map) const map<perm_string,NetExpr*>&context_map) const
{ {
ID id = built_in_id_(); ID id = built_in_id_();
if (id == NOT_BUILT_IN) { ivl_assert(*this, 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;
}
NetExpr*val0 = 0; NetExpr*val0 = 0;
NetExpr*val1 = 0; NetExpr*val1 = 0;

View File

@ -4066,6 +4066,9 @@ class NetESFunc : public NetExpr {
NetExpr* evaluate_min_max_(ID id, const NetExpr*arg0, NetExpr* evaluate_min_max_(ID id, const NetExpr*arg0,
const NetExpr*arg1) const; const NetExpr*arg1) const;
public:
bool is_built_in() const { return built_in_id_() != NOT_BUILT_IN; };
private: // not implemented private: // not implemented
NetESFunc(const NetESFunc&); NetESFunc(const NetESFunc&);
NetESFunc& operator= (const NetESFunc&); NetESFunc& operator= (const NetESFunc&);