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);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert the inputs of a logic gate to a binary expression.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Translate all the primitive logic gates into concurrent
|
* Translate all the primitive logic gates into concurrent
|
||||||
* signal assignments.
|
* signal assignments.
|
||||||
|
|
|
||||||
|
|
@ -471,29 +471,47 @@ void vhdl_unaryop_expr::emit(std::ofstream &of, int level) const
|
||||||
operand_->emit(of, level);
|
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()
|
vhdl_binop_expr::~vhdl_binop_expr()
|
||||||
{
|
{
|
||||||
delete left_;
|
delete_children<vhdl_expr>(operands_);
|
||||||
delete right_;
|
}
|
||||||
|
|
||||||
|
void vhdl_binop_expr::add_expr(vhdl_expr *e)
|
||||||
|
{
|
||||||
|
operands_.push_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vhdl_binop_expr::emit(std::ofstream &of, int level) const
|
void vhdl_binop_expr::emit(std::ofstream &of, int level) const
|
||||||
{
|
{
|
||||||
// Expressions are fully parenthesized to remove any
|
// Expressions are fully parenthesized to remove any
|
||||||
// ambiguity in the output
|
// ambiguity in the output
|
||||||
|
|
||||||
of << "(";
|
of << "(";
|
||||||
right_->emit(of, level);
|
|
||||||
|
|
||||||
switch (op_) {
|
assert(operands_.size() > 0);
|
||||||
case VHDL_BINOP_AND:
|
std::list<vhdl_expr*>::const_iterator it = operands_.begin();
|
||||||
of << " and ";
|
|
||||||
break;
|
do {
|
||||||
case VHDL_BINOP_OR:
|
(*it)->emit(of, level);
|
||||||
of << " or ";
|
|
||||||
break;
|
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 << ")";
|
of << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,16 +58,24 @@ enum vhdl_binop_t {
|
||||||
VHDL_BINOP_OR,
|
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 {
|
class vhdl_binop_expr : public vhdl_expr {
|
||||||
public:
|
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_binop_expr(vhdl_expr *left, vhdl_binop_t op,
|
||||||
vhdl_expr *right, vhdl_type *type)
|
vhdl_expr *right, vhdl_type *type);
|
||||||
: vhdl_expr(type), left_(left), right_(right), op_(op) {}
|
|
||||||
~vhdl_binop_expr();
|
~vhdl_binop_expr();
|
||||||
|
|
||||||
|
void add_expr(vhdl_expr *e);
|
||||||
void emit(std::ofstream &of, int level) const;
|
void emit(std::ofstream &of, int level) const;
|
||||||
private:
|
private:
|
||||||
vhdl_expr *left_, *right_;
|
std::list<vhdl_expr*> operands_;
|
||||||
vhdl_binop_t op_;
|
vhdl_binop_t op_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue