Correct vector sizes for bit select
This commit is contained in:
parent
a0dbb1aa5d
commit
bd5cc96956
|
|
@ -157,22 +157,23 @@ static vhdl_expr *translate_binary(ivl_expr_t e)
|
||||||
int lwidth = lhs->get_type()->get_width();
|
int lwidth = lhs->get_type()->get_width();
|
||||||
int rwidth = rhs->get_type()->get_width();
|
int rwidth = rhs->get_type()->get_width();
|
||||||
|
|
||||||
|
std::cout << "opwidth = " << ivl_expr_width(e)
|
||||||
|
<< " lwidth = " << lwidth
|
||||||
|
<< " rwidth = " << rwidth << std::endl;
|
||||||
|
|
||||||
// May need to resize the left or right hand side
|
// May need to resize the left or right hand side
|
||||||
int opwidth;
|
/*if (lwidth < rwidth) {
|
||||||
if (lwidth < rwidth) {
|
lhs = lhs->cast(rhs->get_type());
|
||||||
rhs = rhs->cast(lhs->get_type());
|
|
||||||
opwidth = lwidth;
|
|
||||||
}
|
}
|
||||||
else if (rwidth < lwidth) {
|
else if (rwidth < lwidth) {
|
||||||
lhs = lhs->cast(rhs->get_type());
|
rhs = rhs->cast(lhs->get_type());
|
||||||
opwidth = rwidth;
|
}*/
|
||||||
}
|
|
||||||
else
|
int result_width = ivl_expr_width(e);
|
||||||
opwidth = lwidth;
|
|
||||||
|
|
||||||
// For === and !== we need to compare std_logic_vectors
|
// For === and !== we need to compare std_logic_vectors
|
||||||
// rather than signeds
|
// rather than signeds
|
||||||
vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR, opwidth-1, 0);
|
vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR, result_width-1, 0);
|
||||||
bool vectorop =
|
bool vectorop =
|
||||||
(lhs->get_type()->get_name() == VHDL_TYPE_SIGNED
|
(lhs->get_type()->get_name() == VHDL_TYPE_SIGNED
|
||||||
|| lhs->get_type()->get_name() == VHDL_TYPE_UNSIGNED) &&
|
|| lhs->get_type()->get_name() == VHDL_TYPE_UNSIGNED) &&
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,6 @@ static vhdl_expr *part_select_base(vhdl_scope *scope, ivl_lpm_t lpm)
|
||||||
|
|
||||||
static vhdl_expr *draw_part_select_vp_lpm(vhdl_scope *scope, ivl_lpm_t lpm)
|
static vhdl_expr *draw_part_select_vp_lpm(vhdl_scope *scope, ivl_lpm_t lpm)
|
||||||
{
|
{
|
||||||
std::cout << "Part select vp" << std::endl;
|
|
||||||
|
|
||||||
vhdl_var_ref *selfrom = nexus_to_var_ref(scope, ivl_lpm_data(lpm, 0));
|
vhdl_var_ref *selfrom = nexus_to_var_ref(scope, ivl_lpm_data(lpm, 0));
|
||||||
if (NULL == selfrom)
|
if (NULL == selfrom)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -167,8 +165,6 @@ static vhdl_expr *draw_sign_extend_lpm(vhdl_scope *scope, ivl_lpm_t lpm)
|
||||||
|
|
||||||
vhdl_expr *lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
vhdl_expr *lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
||||||
{
|
{
|
||||||
std::cout << "LPM type " << ivl_lpm_type(lpm) << std::endl;
|
|
||||||
|
|
||||||
switch (ivl_lpm_type(lpm)) {
|
switch (ivl_lpm_type(lpm)) {
|
||||||
case IVL_LPM_ADD:
|
case IVL_LPM_ADD:
|
||||||
return draw_binop_lpm(scope, lpm, VHDL_BINOP_ADD);
|
return draw_binop_lpm(scope, lpm, VHDL_BINOP_ADD);
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,6 @@ static vhdl_expr *nexus_to_const(ivl_nexus_t nexus)
|
||||||
static vhdl_expr *nexus_to_expr(vhdl_scope *arch_scope, ivl_nexus_t nexus,
|
static vhdl_expr *nexus_to_expr(vhdl_scope *arch_scope, ivl_nexus_t nexus,
|
||||||
ivl_signal_t ignore = NULL)
|
ivl_signal_t ignore = NULL)
|
||||||
{
|
{
|
||||||
std::cout << "nexus_to_expr " << ivl_nexus_name(nexus) << std::endl;
|
|
||||||
|
|
||||||
int nptrs = ivl_nexus_ptrs(nexus);
|
int nptrs = ivl_nexus_ptrs(nexus);
|
||||||
for (int i = 0; i < nptrs; i++) {
|
for (int i = 0; i < nptrs; i++) {
|
||||||
ivl_nexus_ptr_t nexus_ptr = ivl_nexus_ptr(nexus, i);
|
ivl_nexus_ptr_t nexus_ptr = ivl_nexus_ptr(nexus, i);
|
||||||
|
|
@ -89,7 +87,6 @@ static vhdl_expr *nexus_to_expr(vhdl_scope *arch_scope, ivl_nexus_t nexus,
|
||||||
return translate_logic(arch_scope, log);
|
return translate_logic(arch_scope, log);
|
||||||
}
|
}
|
||||||
else if ((lpm = ivl_nexus_ptr_lpm(nexus_ptr))) {
|
else if ((lpm = ivl_nexus_ptr_lpm(nexus_ptr))) {
|
||||||
std::cout << "LPM to expr" << std::endl;
|
|
||||||
vhdl_expr *e = lpm_to_expr(arch_scope, lpm);
|
vhdl_expr *e = lpm_to_expr(arch_scope, lpm);
|
||||||
if (e)
|
if (e)
|
||||||
return e;
|
return e;
|
||||||
|
|
@ -254,7 +251,8 @@ static void declare_signals(vhdl_entity *ent, ivl_scope_t scope)
|
||||||
ivl_signal_t sig = ivl_scope_sig(scope, i);
|
ivl_signal_t sig = ivl_scope_sig(scope, i);
|
||||||
remember_signal(sig, ent->get_arch()->get_scope());
|
remember_signal(sig, ent->get_arch()->get_scope());
|
||||||
|
|
||||||
vhdl_type *sig_type = get_signal_type(sig);
|
vhdl_type *sig_type =
|
||||||
|
vhdl_type::type_for(ivl_signal_width(sig), ivl_signal_signed(sig) != 0);
|
||||||
|
|
||||||
std::string name = make_safe_name(sig);
|
std::string name = make_safe_name(sig);
|
||||||
rename_signal(sig, name);
|
rename_signal(sig, name);
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ vhdl_expr *vhdl_expr::resize(int newwidth)
|
||||||
else if (type_->get_name() == VHDL_TYPE_UNSIGNED)
|
else if (type_->get_name() == VHDL_TYPE_UNSIGNED)
|
||||||
rtype = vhdl_type::nunsigned(newwidth);
|
rtype = vhdl_type::nunsigned(newwidth);
|
||||||
else
|
else
|
||||||
assert(false); // Doesn't make sense to resize non-vector type
|
return this; // Doesn't make sense to resize non-vector type
|
||||||
|
|
||||||
vhdl_fcall *resize = new vhdl_fcall("Resize", rtype);
|
vhdl_fcall *resize = new vhdl_fcall("Resize", rtype);
|
||||||
resize->add_expr(this);
|
resize->add_expr(this);
|
||||||
|
|
|
||||||
|
|
@ -48,14 +48,14 @@ vhdl_type *vhdl_type::integer()
|
||||||
return new vhdl_type(VHDL_TYPE_INTEGER);
|
return new vhdl_type(VHDL_TYPE_INTEGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
vhdl_type *vhdl_type::nunsigned(int width)
|
vhdl_type *vhdl_type::nunsigned(int width, int lsb)
|
||||||
{
|
{
|
||||||
return new vhdl_type(VHDL_TYPE_UNSIGNED, width-1, 0);
|
return new vhdl_type(VHDL_TYPE_UNSIGNED, width-1+lsb, lsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
vhdl_type *vhdl_type::nsigned(int width)
|
vhdl_type *vhdl_type::nsigned(int width, int lsb)
|
||||||
{
|
{
|
||||||
return new vhdl_type(VHDL_TYPE_SIGNED, width-1, 0);
|
return new vhdl_type(VHDL_TYPE_SIGNED, width-1+lsb, lsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
vhdl_type *vhdl_type::time()
|
vhdl_type *vhdl_type::time()
|
||||||
|
|
@ -122,12 +122,12 @@ vhdl_type *vhdl_type::std_logic_vector(int msb, int lsb)
|
||||||
return new vhdl_type(VHDL_TYPE_STD_LOGIC_VECTOR, msb, lsb);
|
return new vhdl_type(VHDL_TYPE_STD_LOGIC_VECTOR, msb, lsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
vhdl_type *vhdl_type::type_for(int width, bool issigned)
|
vhdl_type *vhdl_type::type_for(int width, bool issigned, int lsb)
|
||||||
{
|
{
|
||||||
if (width == 0)
|
if (width == 1)
|
||||||
return vhdl_type::std_logic();
|
return vhdl_type::std_logic();
|
||||||
else if (issigned)
|
else if (issigned)
|
||||||
return vhdl_type::nsigned(width);
|
return vhdl_type::nsigned(width, lsb);
|
||||||
else
|
else
|
||||||
return vhdl_type::nunsigned(width);
|
return vhdl_type::nunsigned(width, lsb);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,13 @@ public:
|
||||||
static vhdl_type *string();
|
static vhdl_type *string();
|
||||||
static vhdl_type *line();
|
static vhdl_type *line();
|
||||||
static vhdl_type *std_logic_vector(int msb, int lsb);
|
static vhdl_type *std_logic_vector(int msb, int lsb);
|
||||||
static vhdl_type *nunsigned(int width);
|
static vhdl_type *nunsigned(int width, int lsb=0);
|
||||||
static vhdl_type *nsigned(int width);
|
static vhdl_type *nsigned(int width, int lsb=0);
|
||||||
static vhdl_type *integer();
|
static vhdl_type *integer();
|
||||||
static vhdl_type *boolean();
|
static vhdl_type *boolean();
|
||||||
static vhdl_type *time();
|
static vhdl_type *time();
|
||||||
|
|
||||||
static vhdl_type *type_for(int width, bool issigned);
|
static vhdl_type *type_for(int width, bool issigned, int lsb=0);
|
||||||
protected:
|
protected:
|
||||||
vhdl_type_name_t name_;
|
vhdl_type_name_t name_;
|
||||||
int msb_, lsb_;
|
int msb_, lsb_;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue