Skip to content

Commit

Permalink
Fix select from non-variable-reference error (pr2281519)
Browse files Browse the repository at this point in the history
VHDL can't select bits from arbitrary expression so sometimes
translating IVL_EX_SELECT would fail. This is easily fixed by
replacing the select with a shift in this instance (and the
resizing)
  • Loading branch information
nickg authored and steveicarus committed Nov 16, 2008
1 parent fe199a7 commit 1d4ade8
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tgt-vhdl/expr.cc
Expand Up @@ -451,20 +451,26 @@ static vhdl_expr *translate_select(ivl_expr_t e)
return NULL;

ivl_expr_t o2 = ivl_expr_oper2(e);
if (o2) {
vhdl_var_ref *from_var_ref = dynamic_cast<vhdl_var_ref*>(from);
if (NULL == from_var_ref) {
error("Can only select from variable reference");
return NULL;
}

if (o2) {
vhdl_expr *base = translate_expr(ivl_expr_oper2(e));
if (NULL == base)
return NULL;

vhdl_type integer(VHDL_TYPE_INTEGER);
from_var_ref->set_slice(base->cast(&integer), ivl_expr_width(e) - 1);
return from_var_ref;
vhdl_var_ref *from_var_ref = dynamic_cast<vhdl_var_ref*>(from);
if (NULL == from_var_ref) {
// We can't directly select bits from something that's not
// a variable reference in VHDL, but we can emulate the
// effect with a shift and a resize
return new vhdl_binop_expr(from, VHDL_BINOP_SR, base->to_integer(),
new vhdl_type(*from->get_type()));
}
else {
// We can use the more idomatic VHDL slice notation on a
// single variable reference
vhdl_type integer(VHDL_TYPE_INTEGER);
from_var_ref->set_slice(base->cast(&integer), ivl_expr_width(e) - 1);
return from_var_ref;
}
}
else
return from->resize(ivl_expr_width(e));
Expand Down Expand Up @@ -634,7 +640,7 @@ vhdl_expr *translate_expr(ivl_expr_t e)
{
assert(e);
ivl_expr_type_t type = ivl_expr_type(e);

switch (type) {
case IVL_EX_STRING:
return translate_string(e);
Expand Down

0 comments on commit 1d4ade8

Please sign in to comment.