Refactor to use new pad_to_width/cast_to_width functions.
(cherry picked from commit 7f475d4210)
This commit is contained in:
parent
04ae07f03c
commit
8bd4e9d481
69
elab_expr.cc
69
elab_expr.cc
|
|
@ -675,10 +675,7 @@ NetExpr* PEBComp::elaborate_expr(Design*des, NetScope*scope,
|
||||||
NetExpr*tmp = new NetEBComp(op_, lp, rp);
|
NetExpr*tmp = new NetEBComp(op_, lp, rp);
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
|
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
return pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PEBLogic::test_width(Design*, NetScope*, width_mode_t&)
|
unsigned PEBLogic::test_width(Design*, NetScope*, width_mode_t&)
|
||||||
|
|
@ -716,10 +713,7 @@ NetExpr*PEBLogic::elaborate_expr(Design*des, NetScope*scope,
|
||||||
NetExpr*tmp = new NetEBLogic(op_, lp, rp);
|
NetExpr*tmp = new NetEBLogic(op_, lp, rp);
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
|
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
return pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PEBLeftWidth::test_width(Design*des, NetScope*scope, width_mode_t&mode)
|
unsigned PEBLeftWidth::test_width(Design*des, NetScope*scope, width_mode_t&mode)
|
||||||
|
|
@ -1035,8 +1029,7 @@ NetExpr*PEBShift::elaborate_expr_leaf(Design*des, NetExpr*lp, NetExpr*rp,
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
tmp = new NetESelect(lp, tmp, 1);
|
tmp = new NetESelect(lp, tmp, 1);
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
tmp = pad_to_width(tmp, expr_wid, true, *this);
|
||||||
tmp->cast_signed(true);
|
|
||||||
|
|
||||||
delete rp;
|
delete rp;
|
||||||
return tmp;
|
return tmp;
|
||||||
|
|
@ -1414,23 +1407,7 @@ NetExpr*PECallFunction::cast_to_width_(NetExpr*expr, unsigned wid) const
|
||||||
<< " from expr_width()=" << expr->expr_width() << endl;
|
<< " from expr_width()=" << expr->expr_width() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the expression is a const, then replace it with a new
|
return cast_to_width(expr, wid, signed_flag_, *this);
|
||||||
const. This is a more efficient result. */
|
|
||||||
if (NetEConst*tmp = dynamic_cast<NetEConst*>(expr)) {
|
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
if (wid != tmp->expr_width()) {
|
|
||||||
tmp = new NetEConst(verinum(tmp->value(), wid));
|
|
||||||
tmp->set_line(*this);
|
|
||||||
delete expr;
|
|
||||||
}
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetESelect*tmp = new NetESelect(expr, 0, wid);
|
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
tmp->set_line(*this);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -1606,10 +1583,7 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope,
|
||||||
if (missing_parms || parm_errors)
|
if (missing_parms || parm_errors)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
NetExpr*tmp = pad_to_width(fun, expr_wid, *this);
|
return pad_to_width(fun, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetExpr* PECallFunction::elaborate_access_func_(Design*des, NetScope*scope,
|
NetExpr* PECallFunction::elaborate_access_func_(Design*des, NetScope*scope,
|
||||||
|
|
@ -1666,10 +1640,7 @@ NetExpr* PECallFunction::elaborate_access_func_(Design*des, NetScope*scope,
|
||||||
NetExpr*tmp = new NetEAccess(branch, nature);
|
NetExpr*tmp = new NetEAccess(branch, nature);
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
|
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
return pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -2281,10 +2252,7 @@ NetExpr* PECallFunction::elaborate_base_(Design*des, NetScope*scope, NetScope*ds
|
||||||
if(res->darray_type())
|
if(res->darray_type())
|
||||||
return func;
|
return func;
|
||||||
|
|
||||||
NetExpr*tmp = pad_to_width(func, expr_wid, *this);
|
return pad_to_width(func, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << get_fileline() << ": internal error: Unable to locate "
|
cerr << get_fileline() << ": internal error: Unable to locate "
|
||||||
|
|
@ -2883,8 +2851,7 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetExpr*tmp = pad_to_width(concat, expr_wid, *this);
|
NetExpr*tmp = pad_to_width(concat, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
concat_depth -= 1;
|
concat_depth -= 1;
|
||||||
return tmp;
|
return tmp;
|
||||||
|
|
@ -3801,10 +3768,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
|
||||||
|
|
||||||
if (!tmp) return 0;
|
if (!tmp) return 0;
|
||||||
|
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
return pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the identifier names a signal (a register or wire)
|
// If the identifier names a signal (a register or wire)
|
||||||
|
|
@ -3840,10 +3804,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
|
||||||
<< ", tmp=" << *tmp << endl;
|
<< ", tmp=" << *tmp << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
return pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the identifier is a named event
|
// If the identifier is a named event
|
||||||
|
|
@ -3943,9 +3904,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
|
||||||
member_comp);
|
member_comp);
|
||||||
if (!tmp) return 0;
|
if (!tmp) return 0;
|
||||||
|
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
return pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
tmp->cast_signed(signed_flag_);
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->class_type() != 0) {
|
if (net->class_type() != 0) {
|
||||||
|
|
@ -4524,7 +4483,7 @@ NetExpr* PEIdent::elaborate_expr_param_(Design*des,
|
||||||
<< "Elaborate parameter <" << path_
|
<< "Elaborate parameter <" << path_
|
||||||
<< "> as enumeration constant." << *etmp << endl;
|
<< "> as enumeration constant." << *etmp << endl;
|
||||||
tmp = etmp->dup_expr();
|
tmp = etmp->dup_expr();
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
tmp = pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
perm_string name = peek_tail_name(path_);
|
perm_string name = peek_tail_name(path_);
|
||||||
|
|
@ -6114,7 +6073,7 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope,
|
||||||
}
|
}
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
}
|
}
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
tmp = pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '&': // Reduction AND
|
case '&': // Reduction AND
|
||||||
|
|
@ -6132,7 +6091,7 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope,
|
||||||
}
|
}
|
||||||
tmp = new NetEUReduce(op_, ip);
|
tmp = new NetEUReduce(op_, ip);
|
||||||
tmp->set_line(*this);
|
tmp->set_line(*this);
|
||||||
tmp = pad_to_width(tmp, expr_wid, *this);
|
tmp = pad_to_width(tmp, expr_wid, signed_flag_, *this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '~':
|
case '~':
|
||||||
|
|
|
||||||
15
netmisc.h
15
netmisc.h
|
|
@ -59,14 +59,6 @@ inline NetScope* symbol_search(const LineInfo*li,
|
||||||
return symbol_search(li, des, start, path, net, par, eve, ex1, ex2);
|
return symbol_search(li, des, start, path, net, par, eve, ex1, ex2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* This function transforms an expression by padding the high bits
|
|
||||||
* with V0 until the expression has the desired width. This may mean
|
|
||||||
* not transforming the expression at all, if it is already wide
|
|
||||||
* enough.
|
|
||||||
*/
|
|
||||||
extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid, const LineInfo&info);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function transforms an expression by either zero or sign extending
|
* This function transforms an expression by either zero or sign extending
|
||||||
* the high bits until the expression has the desired width. This may mean
|
* the high bits until the expression has the desired width. This may mean
|
||||||
|
|
@ -76,6 +68,13 @@ extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid, const LineInfo&info);
|
||||||
*/
|
*/
|
||||||
extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid, bool signed_flag,
|
extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid, bool signed_flag,
|
||||||
const LineInfo&info);
|
const LineInfo&info);
|
||||||
|
/*
|
||||||
|
* This version determines the extension method from the base expression type.
|
||||||
|
*/
|
||||||
|
inline NetExpr*pad_to_width(NetExpr*expr, unsigned wid, const LineInfo&info)
|
||||||
|
{
|
||||||
|
return pad_to_width(expr, wid, expr->has_sign(), info);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function transforms an expression by either zero or sign extending
|
* This function transforms an expression by either zero or sign extending
|
||||||
|
|
|
||||||
|
|
@ -24,33 +24,6 @@
|
||||||
# include "netmisc.h"
|
# include "netmisc.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This function transforms an expression by padding the high bits
|
|
||||||
* with V0 until the expression has the desired width. This may mean
|
|
||||||
* not transforming the expression at all, if it is already wide
|
|
||||||
* enough.
|
|
||||||
*/
|
|
||||||
NetExpr*pad_to_width(NetExpr*expr, unsigned wid, const LineInfo&info)
|
|
||||||
{
|
|
||||||
if (wid <= expr->expr_width())
|
|
||||||
return expr;
|
|
||||||
|
|
||||||
/* If the expression is a const, then replace it with a wider
|
|
||||||
const. This is a more efficient result. */
|
|
||||||
if (NetEConst*tmp = dynamic_cast<NetEConst*>(expr)) {
|
|
||||||
verinum oval = pad_to_width(tmp->value(), wid);
|
|
||||||
tmp = new NetEConst(oval);
|
|
||||||
tmp->set_line(info);
|
|
||||||
delete expr;
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetESelect*tmp = new NetESelect(expr, 0, wid);
|
|
||||||
tmp->set_line(info);
|
|
||||||
tmp->cast_signed(expr->has_sign());
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetExpr*pad_to_width(NetExpr*expr, unsigned wid, bool signed_flag,
|
NetExpr*pad_to_width(NetExpr*expr, unsigned wid, bool signed_flag,
|
||||||
const LineInfo&info)
|
const LineInfo&info)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue