ivl: String to vector casting.

This commit is contained in:
Maciej Suminski 2014-11-06 10:04:21 +01:00
parent 103828577b
commit b12e00d875
2 changed files with 23 additions and 1 deletions

View File

@ -2445,7 +2445,7 @@ unsigned PECastType::test_width(Design*des, NetScope*scope, width_mode_t&wid)
else if(const netstring_t*use_string = dynamic_cast<const netstring_t*> (t)) {
expr_type_ = use_string->base_type();
expr_width_ = 1;
expr_width_ = 8;
signed_flag_= false;
}
@ -2487,6 +2487,20 @@ NetExpr* PECastType::elaborate_expr(Design*des, NetScope*scope,
return cast_to_int2(expr, expr_width_);
}
if(const vector_type_t*vec = dynamic_cast<const vector_type_t*>(target_))
{
switch(vec->base_type) {
case IVL_VT_BOOL:
return cast_to_int2(expr, expr_width_);
case IVL_VT_LOGIC:
return cast_to_int4(expr, expr_width_);
default:
break; /* Suppress warnings */
}
}
cerr << get_fileline() << "sorry: I don't know how to cast expression." << endl;
ivl_assert(*this, false);

View File

@ -593,6 +593,14 @@ static int show_stmt_assign_vector(ivl_statement_t net)
fprintf(vvp_out, " %%cvt/vr %u, %u;\n", res.base, res.wid);
} else if (ivl_expr_value(rval) == IVL_VT_STRING) {
/* Special case: vector to string casting */
ivl_lval_t lval = ivl_stmt_lval(net, 0);
fprintf(vvp_out, " %%vpi_call %u %u \"$ivl_string_method$to_vec\", v%p_0, v%p_0 {0 0};\n",
ivl_file_table_index(ivl_stmt_file(net)), ivl_stmt_lineno(net),
ivl_expr_signal(rval), ivl_lval_sig(lval));
return 0;
} else {
res = draw_eval_expr(rval, 0);
}