Generate code for + and concat expressions.
This commit is contained in:
parent
4a058632b2
commit
7aa9bc9892
|
|
@ -17,7 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: eval_expr.c,v 1.5 2001/03/29 05:16:25 steve Exp $"
|
#ident "$Id: eval_expr.c,v 1.6 2001/03/31 02:00:44 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include "vvp_priv.h"
|
# include "vvp_priv.h"
|
||||||
|
|
@ -145,6 +145,27 @@ static struct vector_info draw_binary_expr_eq(ivl_expr_t exp)
|
||||||
return lv;
|
return lv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct vector_info draw_binary_expr_plus(ivl_expr_t exp, unsigned wid)
|
||||||
|
{
|
||||||
|
ivl_expr_t le = ivl_expr_oper1(exp);
|
||||||
|
ivl_expr_t re = ivl_expr_oper2(exp);
|
||||||
|
|
||||||
|
struct vector_info lv;
|
||||||
|
struct vector_info rv;
|
||||||
|
|
||||||
|
assert(ivl_expr_width(le) == wid);
|
||||||
|
assert(ivl_expr_width(re) == wid);
|
||||||
|
|
||||||
|
lv = draw_eval_expr_wid(le, wid);
|
||||||
|
rv = draw_eval_expr_wid(re, wid);
|
||||||
|
|
||||||
|
fprintf(vvp_out, " %%add %u, %u, %u;\n", lv.base, rv.base, wid);
|
||||||
|
|
||||||
|
clr_vector(rv);
|
||||||
|
|
||||||
|
return lv;
|
||||||
|
}
|
||||||
|
|
||||||
static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid)
|
static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid)
|
||||||
{
|
{
|
||||||
struct vector_info rv;
|
struct vector_info rv;
|
||||||
|
|
@ -158,13 +179,53 @@ static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid)
|
||||||
rv = draw_binary_expr_eq(exp);
|
rv = draw_binary_expr_eq(exp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '+':
|
||||||
|
rv = draw_binary_expr_plus(exp, wid);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
fprintf(stderr, "vvp.tgt error: unsupported binary (%c)\n",
|
||||||
|
ivl_expr_opcode(exp));
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct vector_info draw_concat_expr(ivl_expr_t exp, unsigned wid)
|
||||||
|
{
|
||||||
|
unsigned idx, off;
|
||||||
|
struct vector_info res;
|
||||||
|
|
||||||
|
assert(wid >= ivl_expr_width(exp));
|
||||||
|
|
||||||
|
res.base = allocate_vector(wid);
|
||||||
|
res.wid = wid;
|
||||||
|
|
||||||
|
idx = ivl_expr_parms(exp);
|
||||||
|
off = 0;
|
||||||
|
while (idx > 0) {
|
||||||
|
ivl_expr_t arg = ivl_expr_parm(exp, idx-1);
|
||||||
|
unsigned awid = ivl_expr_width(arg);
|
||||||
|
|
||||||
|
struct vector_info avec = draw_eval_expr_wid(arg, awid);
|
||||||
|
|
||||||
|
fprintf(vvp_out, " %%mov %u, %u, %u;\n", res.base+off,
|
||||||
|
avec.base, avec.wid);
|
||||||
|
clr_vector(avec);
|
||||||
|
|
||||||
|
idx -= 1;
|
||||||
|
off += awid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (off < wid) {
|
||||||
|
fprintf(vvp_out, " %%mov %u, 0, %u;\n",
|
||||||
|
res.base+off, wid-off);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A number in an expression is made up by copying constant bits into
|
* A number in an expression is made up by copying constant bits into
|
||||||
* the allocated vector.
|
* the allocated vector.
|
||||||
|
|
@ -299,8 +360,10 @@ struct vector_info draw_eval_expr_wid(ivl_expr_t exp, unsigned wid)
|
||||||
struct vector_info res;
|
struct vector_info res;
|
||||||
|
|
||||||
switch (ivl_expr_type(exp)) {
|
switch (ivl_expr_type(exp)) {
|
||||||
case IVL_EX_NONE:
|
|
||||||
default:
|
default:
|
||||||
|
fprintf(stderr, "vvp error: unhandled expr type: %u\n",
|
||||||
|
ivl_expr_type(exp));
|
||||||
|
case IVL_EX_NONE:
|
||||||
assert(0);
|
assert(0);
|
||||||
res.base = 0;
|
res.base = 0;
|
||||||
res.wid = 0;
|
res.wid = 0;
|
||||||
|
|
@ -310,6 +373,10 @@ struct vector_info draw_eval_expr_wid(ivl_expr_t exp, unsigned wid)
|
||||||
res = draw_binary_expr(exp, wid);
|
res = draw_binary_expr(exp, wid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case IVL_EX_CONCAT:
|
||||||
|
res = draw_concat_expr(exp, wid);
|
||||||
|
break;
|
||||||
|
|
||||||
case IVL_EX_NUMBER:
|
case IVL_EX_NUMBER:
|
||||||
res = draw_number_expr(exp, wid);
|
res = draw_number_expr(exp, wid);
|
||||||
break;
|
break;
|
||||||
|
|
@ -333,6 +400,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: eval_expr.c,v $
|
* $Log: eval_expr.c,v $
|
||||||
|
* Revision 1.6 2001/03/31 02:00:44 steve
|
||||||
|
* Generate code for + and concat expressions.
|
||||||
|
*
|
||||||
* Revision 1.5 2001/03/29 05:16:25 steve
|
* Revision 1.5 2001/03/29 05:16:25 steve
|
||||||
* Handle truncation/padding of numbers.
|
* Handle truncation/padding of numbers.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue