Collect required packages as compilation progresses
This commit is contained in:
parent
82aca1b02e
commit
fe80da362c
|
|
@ -25,10 +25,22 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate VHDL for the $display system task.
|
* 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)
|
static int draw_stask_display(vhdl_process *proc, ivl_statement_t stmt)
|
||||||
{
|
{
|
||||||
|
require_package("std.textio");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,18 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
static int g_errors = 0; // Total number of errors encountered
|
static int g_errors = 0; // Total number of errors encountered
|
||||||
|
|
||||||
static entity_list_t g_entities; // All entities to emit
|
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.
|
* Called when an unrecoverable problem is encountered.
|
||||||
*/
|
*/
|
||||||
|
|
@ -71,6 +78,21 @@ void remember_entity(vhdl_entity* ent)
|
||||||
g_entities.push_back(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)
|
extern "C" int target_design(ivl_design_t des)
|
||||||
{
|
{
|
||||||
ivl_scope_t *roots;
|
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");
|
const char *ofname = ivl_design_flag(des, "-o");
|
||||||
std::ofstream outfile(ofname);
|
std::ofstream outfile(ofname);
|
||||||
|
|
||||||
entity_list_t::const_iterator it;
|
// Write all the required packages (and libraries?)
|
||||||
for (it = g_entities.begin(); it != g_entities.end(); ++it)
|
//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);
|
(*it)->emit(outfile);
|
||||||
|
|
||||||
outfile.close();
|
outfile.close();
|
||||||
|
|
||||||
// Clean up
|
// 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);
|
delete (*it);
|
||||||
g_entities.clear();
|
g_entities.clear();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ int draw_stmt(vhdl_process *proc, ivl_statement_t stmt);
|
||||||
|
|
||||||
void remember_entity(vhdl_entity *ent);
|
void remember_entity(vhdl_entity *ent);
|
||||||
vhdl_entity *find_entity(const std::string &tname);
|
vhdl_entity *find_entity(const std::string &tname);
|
||||||
|
void require_package(const char *name);
|
||||||
|
|
||||||
#endif /* #ifndef INC_VHDL_TARGET_H */
|
#endif /* #ifndef INC_VHDL_TARGET_H */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue