Optimise away empty (VHDL) processes

This commit is contained in:
Nick Gasson 2008-06-13 14:17:24 +01:00
parent be3c4cf268
commit 9fbb449e06
3 changed files with 14 additions and 1 deletions

View File

@ -51,7 +51,11 @@ static int generate_vhdl_process(vhdl_entity *ent, ivl_process_t proc)
// Initial processes are translated to VHDL processes with
// no sensitivity list and and indefinite wait statement at
// the end
if (ivl_process_type(proc) == IVL_PR_INITIAL) {
// However, if no statements were added to the container
// by draw_stmt, don't bother adding a wait as `emit'
// will optimise the process out of the output
if (ivl_process_type(proc) == IVL_PR_INITIAL
&& !vhdl_proc->get_container()->empty()) {
vhdl_wait_stmt *wait = new vhdl_wait_stmt();
vhdl_proc->get_container()->add_stmt(wait);
}

View File

@ -218,6 +218,14 @@ bool vhdl_process::have_declared_var(const std::string &name) const
void vhdl_process::emit(std::ofstream &of, int level) const
{
// If there are no statements in the body, this process
// can't possibly do anything, so don't bother to emit it
if (stmts_.empty()) {
of << "-- Removed one empty process";
newline(of, level);
return;
}
emit_comment(of, level);
if (name_.size() > 0)
of << name_ << ": ";

View File

@ -215,6 +215,7 @@ public:
void add_stmt(vhdl_seq_stmt *stmt);
void emit(std::ofstream &of, int level) const;
bool empty() const { return stmts_.empty(); }
private:
std::list<vhdl_seq_stmt*> stmts_;
};