Collect required packages as compilation progresses

This commit is contained in:
Nick Gasson 2008-06-03 19:14:47 +01:00
parent 82aca1b02e
commit fe80da362c
3 changed files with 50 additions and 4 deletions

View File

@ -25,10 +25,22 @@
/*
* Generate VHDL for the $display system task.
* TODO: How is this going to work??
* This is implemented using the functions in std.textio. Each
* parameter is written to a line variable in the process and
* then the line is written to the special variable `Output'
* (which represents the console). Subsequent $displays will use
* the same line variable.
*
* It's possible, although quite unlikely, that there will be
* name collision with an existing variable called
* `Verilog_Display_Line' - do something about this? It's also
* possible for there to be a name collision with the special
* variable `Output'.
*/
static int draw_stask_display(vhdl_process *proc, ivl_statement_t stmt)
{
require_package("std.textio");
return 0;
}

View File

@ -27,11 +27,18 @@
#include <cstdio>
#include <cassert>
#include <cstring>
#include <list>
static int g_errors = 0; // Total number of errors encountered
static entity_list_t g_entities; // All entities to emit
typedef std::string package_name_t;
typedef std::list<package_name_t> require_list_t;
static require_list_t g_requires; // External packages required
/*
* Called when an unrecoverable problem is encountered.
*/
@ -71,6 +78,21 @@ void remember_entity(vhdl_entity* ent)
g_entities.push_back(ent);
}
/*
* Add a package to the list of packages that should be
* use-ed at the start of the program.
*/
void require_package(const char *name)
{
package_name_t pname(name);
require_list_t::iterator it;
for (it = g_requires.begin(); it != g_requires.end(); ++it) {
if (*it == pname)
return;
}
g_requires.push_back(pname);
}
extern "C" int target_design(ivl_design_t des)
{
ivl_scope_t *roots;
@ -86,14 +108,25 @@ extern "C" int target_design(ivl_design_t des)
const char *ofname = ivl_design_flag(des, "-o");
std::ofstream outfile(ofname);
entity_list_t::const_iterator it;
for (it = g_entities.begin(); it != g_entities.end(); ++it)
// Write all the required packages (and libraries?)
//outfile << "library ieee;" << std::endl;
for (require_list_t::iterator it = g_requires.begin();
it != g_requires.end();
++it)
outfile << "use " << *it << ".all;" << std::endl;
outfile << std::endl;
for (entity_list_t::iterator it = g_entities.begin();
it != g_entities.end();
++it)
(*it)->emit(outfile);
outfile.close();
// Clean up
for (it = g_entities.begin(); it != g_entities.end(); ++it)
for (entity_list_t::iterator it = g_entities.begin();
it != g_entities.end();
++it)
delete (*it);
g_entities.clear();

View File

@ -16,6 +16,7 @@ int draw_stmt(vhdl_process *proc, ivl_statement_t stmt);
void remember_entity(vhdl_entity *ent);
vhdl_entity *find_entity(const std::string &tname);
void require_package(const char *name);
#endif /* #ifndef INC_VHDL_TARGET_H */