Allow n-ary expressions
This commit is contained in:
parent
aa91186119
commit
3b5d56e087
|
|
@ -53,6 +53,10 @@ static vhdl_var_ref *nexus_to_var_ref(vhdl_arch *arch, ivl_nexus_t nexus)
|
|||
assert(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert the inputs of a logic gate to a binary expression.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Translate all the primitive logic gates into concurrent
|
||||
* signal assignments.
|
||||
|
|
|
|||
|
|
@ -471,29 +471,47 @@ void vhdl_unaryop_expr::emit(std::ofstream &of, int level) const
|
|||
operand_->emit(of, level);
|
||||
}
|
||||
|
||||
vhdl_binop_expr::vhdl_binop_expr(vhdl_expr *left, vhdl_binop_t op,
|
||||
vhdl_expr *right, vhdl_type *type)
|
||||
: vhdl_expr(type), op_(op)
|
||||
{
|
||||
add_expr(left);
|
||||
add_expr(right);
|
||||
}
|
||||
|
||||
vhdl_binop_expr::~vhdl_binop_expr()
|
||||
{
|
||||
delete left_;
|
||||
delete right_;
|
||||
delete_children<vhdl_expr>(operands_);
|
||||
}
|
||||
|
||||
void vhdl_binop_expr::add_expr(vhdl_expr *e)
|
||||
{
|
||||
operands_.push_back(e);
|
||||
}
|
||||
|
||||
void vhdl_binop_expr::emit(std::ofstream &of, int level) const
|
||||
{
|
||||
// Expressions are fully parenthesized to remove any
|
||||
// ambiguity in the output
|
||||
|
||||
of << "(";
|
||||
right_->emit(of, level);
|
||||
|
||||
switch (op_) {
|
||||
case VHDL_BINOP_AND:
|
||||
of << " and ";
|
||||
break;
|
||||
case VHDL_BINOP_OR:
|
||||
of << " or ";
|
||||
break;
|
||||
}
|
||||
assert(operands_.size() > 0);
|
||||
std::list<vhdl_expr*>::const_iterator it = operands_.begin();
|
||||
|
||||
do {
|
||||
(*it)->emit(of, level);
|
||||
|
||||
switch (op_) {
|
||||
case VHDL_BINOP_AND:
|
||||
of << " and ";
|
||||
break;
|
||||
case VHDL_BINOP_OR:
|
||||
of << " or ";
|
||||
break;
|
||||
}
|
||||
} while (++it != operands_.end());
|
||||
|
||||
right_->emit(of, level);
|
||||
of << ")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,24 @@ enum vhdl_binop_t {
|
|||
VHDL_BINOP_OR,
|
||||
};
|
||||
|
||||
/*
|
||||
* A binary expression contains a list of operands rather
|
||||
* than just two: this is to model n-input gates and the
|
||||
* like. A second constructor is provided to handle the
|
||||
* common case of a true binary expression.
|
||||
*/
|
||||
class vhdl_binop_expr : public vhdl_expr {
|
||||
public:
|
||||
vhdl_binop_expr(vhdl_binop_t op, vhdl_type *type)
|
||||
: vhdl_expr(type), op_(op) {}
|
||||
vhdl_binop_expr(vhdl_expr *left, vhdl_binop_t op,
|
||||
vhdl_expr *right, vhdl_type *type)
|
||||
: vhdl_expr(type), left_(left), right_(right), op_(op) {}
|
||||
vhdl_expr *right, vhdl_type *type);
|
||||
~vhdl_binop_expr();
|
||||
|
||||
void add_expr(vhdl_expr *e);
|
||||
void emit(std::ofstream &of, int level) const;
|
||||
private:
|
||||
vhdl_expr *left_, *right_;
|
||||
std::list<vhdl_expr*> operands_;
|
||||
vhdl_binop_t op_;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue