diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index 456f36be8..2589fc0c3 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -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; } diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 2d4d1e984..036c6e889 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -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;"; } diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index c87eea284..53ee27d94 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -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_; };