Shift operators working correctly
This commit is contained in:
parent
d5cdb91d55
commit
c9ace14c40
|
|
@ -127,6 +127,17 @@ static vhdl_expr *translate_relation(vhdl_expr *lhs, vhdl_expr *rhs,
|
|||
return new vhdl_binop_expr(lhs, op, r_cast, vhdl_type::boolean());
|
||||
}
|
||||
|
||||
static vhdl_expr *translate_shift(vhdl_expr *lhs, vhdl_expr *rhs,
|
||||
vhdl_binop_t op)
|
||||
{
|
||||
// The RHS must be an integer
|
||||
vhdl_type integer(VHDL_TYPE_INTEGER);
|
||||
vhdl_expr *r_cast = rhs->cast(&integer);
|
||||
|
||||
vhdl_type *rtype = new vhdl_type(*lhs->get_type());
|
||||
return new vhdl_binop_expr(lhs, op, r_cast, rtype);
|
||||
}
|
||||
|
||||
static vhdl_expr *translate_binary(ivl_expr_t e)
|
||||
{
|
||||
vhdl_expr *lhs = translate_expr(ivl_expr_oper1(e));
|
||||
|
|
@ -176,9 +187,9 @@ static vhdl_expr *translate_binary(ivl_expr_t e)
|
|||
case '>':
|
||||
return translate_relation(lhs, rhs, VHDL_BINOP_GT);
|
||||
case 'l':
|
||||
return translate_numeric(lhs, rhs, VHDL_BINOP_SL);
|
||||
return translate_shift(lhs, rhs, VHDL_BINOP_SL);
|
||||
case 'r':
|
||||
return translate_numeric(lhs, rhs, VHDL_BINOP_SR);
|
||||
return translate_shift(lhs, rhs, VHDL_BINOP_SR);
|
||||
default:
|
||||
error("No translation for binary opcode '%c'\n",
|
||||
ivl_expr_opcode(e));
|
||||
|
|
|
|||
|
|
@ -585,7 +585,7 @@ void vhdl_assign_stmt::emit(std::ofstream &of, int level) const
|
|||
}
|
||||
|
||||
vhdl_const_bits::vhdl_const_bits(const char *value, int width)
|
||||
: vhdl_expr(vhdl_type::nsigned(width), true)
|
||||
: vhdl_expr(vhdl_type::nsigned(width), true), qualified_(false)
|
||||
{
|
||||
// Can't rely on value being NULL-terminated
|
||||
while (width--)
|
||||
|
|
@ -604,20 +604,39 @@ vhdl_expr *vhdl_const_bits::cast(const vhdl_type *to)
|
|||
|
||||
return new vhdl_const_bit(lsb);
|
||||
}
|
||||
else if (to->get_name() == VHDL_TYPE_STD_LOGIC_VECTOR) {
|
||||
// Don't need to do anything
|
||||
return this;
|
||||
}
|
||||
else if (to->get_name() == VHDL_TYPE_SIGNED
|
||||
|| to->get_name() == VHDL_TYPE_UNSIGNED) {
|
||||
// Might need to drop some bits (but not extend?)
|
||||
assert(to->get_width() <= get_type()->get_width());
|
||||
|
||||
value_.resize(to->get_width());
|
||||
return this;
|
||||
}
|
||||
else if (to->get_name() == VHDL_TYPE_INTEGER) {
|
||||
// Need to explicitly qualify the type (or the VHDL
|
||||
// compiler gets confused between signed/unsigned)
|
||||
qualified_ = true;
|
||||
|
||||
return vhdl_expr::cast(to);
|
||||
}
|
||||
else
|
||||
return vhdl_expr::cast(to);
|
||||
}
|
||||
|
||||
void vhdl_const_bits::emit(std::ofstream &of, int level) const
|
||||
{
|
||||
of << "signed'(\"";
|
||||
of << (qualified_ ? "signed'(\"" : "\"");
|
||||
|
||||
// The bits appear to be in reverse order
|
||||
std::string::const_reverse_iterator it;
|
||||
for (it = value_.rbegin(); it != value_.rend(); ++it)
|
||||
of << vl_to_vhdl_bit(*it);
|
||||
|
||||
of << "\")";
|
||||
of << (qualified_ ? "\")" : "\"");
|
||||
}
|
||||
|
||||
void vhdl_const_bit::emit(std::ofstream &of, int level) const
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ public:
|
|||
vhdl_expr *cast(const vhdl_type *to);
|
||||
private:
|
||||
std::string value_;
|
||||
bool qualified_;
|
||||
};
|
||||
|
||||
class vhdl_const_bit : public vhdl_expr {
|
||||
|
|
|
|||
Loading…
Reference in New Issue