Assignment to arrays
This commit is contained in:
parent
1d3ac6bc1f
commit
2a791bfb38
|
|
@ -117,6 +117,8 @@ static vhdl_expr *make_assign_rhs(ivl_signal_t sig, vhdl_scope *scope,
|
||||||
|
|
||||||
if (base == NULL)
|
if (base == NULL)
|
||||||
return rhs->cast(decl->get_type());
|
return rhs->cast(decl->get_type());
|
||||||
|
else if (decl->get_type()->get_name() == VHDL_TYPE_ARRAY)
|
||||||
|
return rhs->cast(decl->get_type()->get_base());
|
||||||
else {
|
else {
|
||||||
// Doesn't make sense to part select on something that's
|
// Doesn't make sense to part select on something that's
|
||||||
// not a vector
|
// not a vector
|
||||||
|
|
@ -142,8 +144,12 @@ static vhdl_var_ref *make_assign_lhs(ivl_signal_t sig, vhdl_scope *scope,
|
||||||
|
|
||||||
vhdl_type *ltype = new vhdl_type(*decl->get_type());
|
vhdl_type *ltype = new vhdl_type(*decl->get_type());
|
||||||
vhdl_var_ref *lval_ref = new vhdl_var_ref(signame.c_str(), ltype);
|
vhdl_var_ref *lval_ref = new vhdl_var_ref(signame.c_str(), ltype);
|
||||||
if (base)
|
if (base) {
|
||||||
lval_ref->set_slice(base, lval_width - 1);
|
if (decl->get_type()->get_name() == VHDL_TYPE_ARRAY)
|
||||||
|
lval_ref->set_slice(base, 0);
|
||||||
|
else
|
||||||
|
lval_ref->set_slice(base, lval_width - 1);
|
||||||
|
}
|
||||||
|
|
||||||
return lval_ref;
|
return lval_ref;
|
||||||
}
|
}
|
||||||
|
|
@ -167,6 +173,8 @@ static T *make_assignment(vhdl_procedural *proc, stmt_container *container,
|
||||||
|
|
||||||
vhdl_expr *base = NULL;
|
vhdl_expr *base = NULL;
|
||||||
ivl_expr_t e_off = ivl_lval_part_off(lval);
|
ivl_expr_t e_off = ivl_lval_part_off(lval);
|
||||||
|
if (NULL == e_off)
|
||||||
|
e_off = ivl_lval_idx(lval);
|
||||||
if (e_off) {
|
if (e_off) {
|
||||||
if ((base = translate_expr(e_off)) == NULL)
|
if ((base = translate_expr(e_off)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -239,7 +247,9 @@ static T *make_assignment(vhdl_procedural *proc, stmt_container *container,
|
||||||
// internal signals not ports
|
// internal signals not ports
|
||||||
if (proc->get_scope()->initializing()
|
if (proc->get_scope()->initializing()
|
||||||
&& ivl_signal_port(sig) == IVL_SIP_NONE
|
&& ivl_signal_port(sig) == IVL_SIP_NONE
|
||||||
&& !decl->has_initial() && rhs->constant()) {
|
&& !decl->has_initial()
|
||||||
|
&& rhs->constant()
|
||||||
|
&& decl->get_type()->get_name() != VHDL_TYPE_ARRAY) {
|
||||||
|
|
||||||
// If this assignment is not in the top-level container
|
// If this assignment is not in the top-level container
|
||||||
// it will not be made on all paths through the code
|
// it will not be made on all paths through the code
|
||||||
|
|
|
||||||
|
|
@ -507,22 +507,27 @@ vhdl_var_ref::~vhdl_var_ref()
|
||||||
void vhdl_var_ref::set_slice(vhdl_expr *s, int w)
|
void vhdl_var_ref::set_slice(vhdl_expr *s, int w)
|
||||||
{
|
{
|
||||||
assert(type_);
|
assert(type_);
|
||||||
|
|
||||||
vhdl_type_name_t tname = type_->get_name();
|
|
||||||
assert(tname == VHDL_TYPE_UNSIGNED || tname == VHDL_TYPE_SIGNED);
|
|
||||||
|
|
||||||
slice_ = s;
|
slice_ = s;
|
||||||
slice_width_ = w;
|
slice_width_ = w;
|
||||||
|
|
||||||
|
vhdl_type_name_t tname = type_->get_name();
|
||||||
|
if (tname == VHDL_TYPE_ARRAY) {
|
||||||
|
type_ = new vhdl_type(*type_->get_base());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(tname == VHDL_TYPE_UNSIGNED || tname == VHDL_TYPE_SIGNED);
|
||||||
|
|
||||||
if (type_)
|
if (type_)
|
||||||
delete type_;
|
delete type_;
|
||||||
|
|
||||||
if (w > 0)
|
if (w > 0)
|
||||||
type_ = new vhdl_type(tname, w);
|
type_ = new vhdl_type(tname, w);
|
||||||
else
|
else
|
||||||
type_ = vhdl_type::std_logic();
|
type_ = vhdl_type::std_logic();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vhdl_var_ref::emit(std::ostream &of, int level) const
|
void vhdl_var_ref::emit(std::ostream &of, int level) const
|
||||||
{
|
{
|
||||||
of << name_;
|
of << name_;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue