Tidy up code to generate default branch of case
This commit is contained in:
parent
1736cd9bc8
commit
19cbab78b2
|
|
@ -461,30 +461,27 @@ static int draw_case(vhdl_procedural *proc, stmt_container *container,
|
|||
|
||||
int nbranches = ivl_stmt_case_count(stmt);
|
||||
for (int i = 0; i < nbranches; i++) {
|
||||
vhdl_expr *when;
|
||||
stmt_container *container;
|
||||
ivl_expr_t net = ivl_stmt_case_expr(stmt, i);
|
||||
if (net) {
|
||||
when = translate_expr(net)->cast(test->get_type());
|
||||
vhdl_expr *when = translate_expr(net)->cast(test->get_type());
|
||||
if (NULL == when)
|
||||
return 1;
|
||||
|
||||
vhdl_case_branch *branch = new vhdl_case_branch(when);
|
||||
vhdlcase->add_branch(branch);
|
||||
container = branch->get_container();
|
||||
}
|
||||
else {
|
||||
when = new vhdl_var_ref("others", NULL);
|
||||
container = vhdlcase->get_others_container();
|
||||
have_others = true;
|
||||
}
|
||||
|
||||
vhdl_case_branch *branch = new vhdl_case_branch(when);
|
||||
vhdlcase->add_branch(branch);
|
||||
|
||||
draw_stmt(proc, branch->get_container(), ivl_stmt_case_stmt(stmt, i));
|
||||
draw_stmt(proc, container, ivl_stmt_case_stmt(stmt, i));
|
||||
}
|
||||
|
||||
if (!have_others) {
|
||||
vhdl_case_branch *others =
|
||||
new vhdl_case_branch(new vhdl_var_ref("others", NULL));
|
||||
others->get_container()->add_stmt(new vhdl_null_stmt());
|
||||
vhdlcase->add_branch(others);
|
||||
}
|
||||
if (!have_others)
|
||||
vhdlcase->get_others_container()->add_stmt(new vhdl_null_stmt());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -734,6 +734,11 @@ void vhdl_case_stmt::emit(std::ostream &of, int level) const
|
|||
case_branch_list_t::const_iterator it;
|
||||
for (it = branches_.begin(); it != branches_.end(); ++it)
|
||||
(*it)->emit(of, level);
|
||||
|
||||
if (!others_.empty()) {
|
||||
of << "when others =>";
|
||||
others_.emit(of, indent(level));
|
||||
}
|
||||
|
||||
of << "end case;";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,9 +367,11 @@ public:
|
|||
|
||||
void add_branch(vhdl_case_branch *b) { branches_.push_back(b); }
|
||||
void emit(std::ostream &of, int level) const;
|
||||
stmt_container *get_others_container() { return &others_; }
|
||||
private:
|
||||
vhdl_expr *test_;
|
||||
case_branch_list_t branches_;
|
||||
stmt_container others_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue