Convert std_logic to Boolean in loop tests
This commit is contained in:
parent
ba462eb8b7
commit
8b32096e2a
|
|
@ -168,6 +168,8 @@ vhdl_expr *vhdl_const_bit::cast(const vhdl_type *to)
|
||||||
{
|
{
|
||||||
if (to->get_name() == VHDL_TYPE_INTEGER)
|
if (to->get_name() == VHDL_TYPE_INTEGER)
|
||||||
return new vhdl_const_int(bit_ == '1' ? 1 : 0);
|
return new vhdl_const_int(bit_ == '1' ? 1 : 0);
|
||||||
|
else if (to->get_name() == VHDL_TYPE_BOOLEAN)
|
||||||
|
return new vhdl_const_bool(bit_ == '1');
|
||||||
else
|
else
|
||||||
return vhdl_expr::cast(to);
|
return vhdl_expr::cast(to);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -551,6 +551,11 @@ int draw_while(vhdl_procedural *proc, stmt_container *container,
|
||||||
if (NULL == test)
|
if (NULL == test)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// The test must be a Boolean (and std_logic and (un)signed types
|
||||||
|
// must be explicitly cast unlike in Verilog)
|
||||||
|
vhdl_type boolean(VHDL_TYPE_BOOLEAN);
|
||||||
|
test = test->cast(&boolean);
|
||||||
|
|
||||||
vhdl_while_stmt *loop = new vhdl_while_stmt(test);
|
vhdl_while_stmt *loop = new vhdl_while_stmt(test);
|
||||||
container->add_stmt(loop);
|
container->add_stmt(loop);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -567,6 +567,11 @@ void vhdl_const_int::emit(std::ostream &of, int level) const
|
||||||
of << value_;
|
of << value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vhdl_const_bool::emit(std::ostream &of, int level) const
|
||||||
|
{
|
||||||
|
of << (value_ ? "True" : "False");
|
||||||
|
}
|
||||||
|
|
||||||
void vhdl_const_time::emit(std::ostream &of, int level) const
|
void vhdl_const_time::emit(std::ostream &of, int level) const
|
||||||
{
|
{
|
||||||
of << value_;
|
of << value_;
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,15 @@ private:
|
||||||
int64_t value_;
|
int64_t value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class vhdl_const_bool : public vhdl_expr {
|
||||||
|
public:
|
||||||
|
vhdl_const_bool(bool value)
|
||||||
|
: vhdl_expr(vhdl_type::boolean(), true), value_(value) {}
|
||||||
|
void emit(std::ostream &of, int level) const;
|
||||||
|
private:
|
||||||
|
bool value_;
|
||||||
|
};
|
||||||
|
|
||||||
class vhdl_expr_list : public vhdl_element {
|
class vhdl_expr_list : public vhdl_element {
|
||||||
public:
|
public:
|
||||||
~vhdl_expr_list();
|
~vhdl_expr_list();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue