iverilog/tgt-vhdl/process.cc

96 lines
3.4 KiB
C++
Raw Normal View History

/*
* VHDL code generation for processes.
*
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "vhdl_target.h"
#include "vhdl_element.hh"
#include <iostream>
#include <cassert>
#include <sstream>
/*
* Convert a Verilog process to VHDL and add it to the architecture
* of the given entity.
*/
static int generate_vhdl_process(vhdl_entity *ent, ivl_process_t proc)
{
// Create a new process and store it in the entity's
// architecture. This needs to be done first or the
// parent link won't be valid (and draw_stmt needs this
// to add information to the architecture)
vhdl_process *vhdl_proc = new vhdl_process();
ent->get_arch()->add_stmt(vhdl_proc);
// If this is an initial process, push signal initialisation
// into the declarations
vhdl_proc->get_scope()->set_initializing
(ivl_process_type(proc) == IVL_PR_INITIAL);
2008-06-03 19:26:36 +02:00
ivl_statement_t stmt = ivl_process_stmt(proc);
2008-06-11 15:11:37 +02:00
int rc = draw_stmt(vhdl_proc, vhdl_proc->get_container(), stmt);
2008-06-03 19:26:36 +02:00
if (rc != 0)
return rc;
// Initial processes are translated to VHDL processes with
// no sensitivity list and and indefinite wait statement at
// the end
2008-06-13 15:17:24 +02:00
// 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();
2008-06-11 15:11:37 +02:00
vhdl_proc->get_container()->add_stmt(wait);
}
// Add a comment indicating where it came from
ivl_scope_t scope = ivl_process_scope(proc);
const char *type = ivl_process_type(proc) == IVL_PR_INITIAL
? "initial" : "always";
std::ostringstream ss;
2008-06-02 21:24:25 +02:00
ss << "Generated from " << type << " process in ";
ss << ivl_scope_tname(scope);
vhdl_proc->set_comment(ss.str());
return 0;
}
int draw_process(ivl_process_t proc, void *cd)
{
ivl_scope_t scope = ivl_process_scope(proc);
const char *scope_name = ivl_scope_name(scope);
// A process should occur in a module scope, therefore it
// should have already been assigned a VHDL entity
assert(ivl_scope_type(scope) == IVL_SCT_MODULE);
vhdl_entity *ent = find_entity(ivl_scope_tname(scope));
assert(ent != NULL);
2008-06-09 13:40:59 +02:00
// If the scope this process belongs to is the same as the
// VHDL entity was generated from, then create a VHDL process
// from this Verilog process. This ensures that each process
// is translated at most once, no matter how many times it
// appears in the hierarchy.
2008-06-04 22:07:50 +02:00
if (ent->get_derived_from() == scope_name)
return generate_vhdl_process(ent, proc);
2008-06-04 22:07:50 +02:00
else
return 0;
}