Convert `if (foo) ..' to `if foo = '1' then ..'
This commit is contained in:
parent
8fe2211e2b
commit
0df3eabe26
|
|
@ -420,11 +420,21 @@ vhdl_expr::~vhdl_expr()
|
||||||
*/
|
*/
|
||||||
vhdl_expr *vhdl_expr::cast(const vhdl_type *to)
|
vhdl_expr *vhdl_expr::cast(const vhdl_type *to)
|
||||||
{
|
{
|
||||||
vhdl_fcall *conv =
|
if (to->get_name() == type_->get_name())
|
||||||
new vhdl_fcall(to->get_string().c_str(), new vhdl_type(*to));
|
return this;
|
||||||
conv->add_expr(this);
|
else if (to->get_name() == VHDL_TYPE_BOOLEAN) {
|
||||||
|
// '1' is true all else are false
|
||||||
return conv;
|
vhdl_const_bit *one = new vhdl_const_bit('1');
|
||||||
|
return new vhdl_binop_expr
|
||||||
|
(this, VHDL_BINOP_EQ, one, vhdl_type::boolean());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vhdl_fcall *conv =
|
||||||
|
new vhdl_fcall(to->get_string().c_str(), new vhdl_type(*to));
|
||||||
|
conv->add_expr(this);
|
||||||
|
|
||||||
|
return conv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vhdl_expr_list::add_expr(vhdl_expr *e)
|
void vhdl_expr_list::add_expr(vhdl_expr *e)
|
||||||
|
|
@ -572,6 +582,13 @@ void vhdl_assert_stmt::emit(std::ofstream &of, int level) const
|
||||||
of << " report \"" << reason_ << "\" severity failure;";
|
of << " report \"" << reason_ << "\" severity failure;";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vhdl_if_stmt::vhdl_if_stmt(vhdl_expr *test)
|
||||||
|
{
|
||||||
|
// Need to ensure that the expression is Boolean
|
||||||
|
vhdl_type boolean(VHDL_TYPE_BOOLEAN);
|
||||||
|
test_ = test->cast(&boolean);
|
||||||
|
}
|
||||||
|
|
||||||
vhdl_if_stmt::~vhdl_if_stmt()
|
vhdl_if_stmt::~vhdl_if_stmt()
|
||||||
{
|
{
|
||||||
delete test_;
|
delete test_;
|
||||||
|
|
@ -640,6 +657,9 @@ void vhdl_binop_expr::emit(std::ofstream &of, int level) const
|
||||||
case VHDL_BINOP_OR:
|
case VHDL_BINOP_OR:
|
||||||
of << " or ";
|
of << " or ";
|
||||||
break;
|
break;
|
||||||
|
case VHDL_BINOP_EQ:
|
||||||
|
of << " = ";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*it)->emit(of, level);
|
(*it)->emit(of, level);
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ private:
|
||||||
enum vhdl_binop_t {
|
enum vhdl_binop_t {
|
||||||
VHDL_BINOP_AND,
|
VHDL_BINOP_AND,
|
||||||
VHDL_BINOP_OR,
|
VHDL_BINOP_OR,
|
||||||
|
VHDL_BINOP_EQ,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -278,8 +279,7 @@ private:
|
||||||
|
|
||||||
class vhdl_if_stmt : public vhdl_seq_stmt {
|
class vhdl_if_stmt : public vhdl_seq_stmt {
|
||||||
public:
|
public:
|
||||||
vhdl_if_stmt(vhdl_expr *test)
|
vhdl_if_stmt(vhdl_expr *test);
|
||||||
: test_(test) {}
|
|
||||||
~vhdl_if_stmt();
|
~vhdl_if_stmt();
|
||||||
|
|
||||||
stmt_container *get_then_container() { return &then_part_; }
|
stmt_container *get_then_container() { return &then_part_; }
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ std::string vhdl_type::get_string() const
|
||||||
return std::string("File");
|
return std::string("File");
|
||||||
case VHDL_TYPE_INTEGER:
|
case VHDL_TYPE_INTEGER:
|
||||||
return std::string("Integer");
|
return std::string("Integer");
|
||||||
|
case VHDL_TYPE_BOOLEAN:
|
||||||
|
return std::string("Boolean");
|
||||||
default:
|
default:
|
||||||
return std::string("BadType");
|
return std::string("BadType");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue