2008-06-03 19:26:36 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL code generation for statements.
|
|
|
|
|
*
|
|
|
|
|
* 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 <iostream>
|
2008-06-03 19:44:17 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generate VHDL for the $display system task.
|
2008-06-03 20:14:47 +02:00
|
|
|
* 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'
|
2008-06-03 20:46:10 +02:00
|
|
|
* (which represents the console). Subsequent $displays will
|
|
|
|
|
* use the same line variable.
|
2008-06-03 20:14:47 +02:00
|
|
|
*
|
|
|
|
|
* It's possible, although quite unlikely, that there will be
|
|
|
|
|
* name collision with an existing variable called
|
2008-06-03 20:46:10 +02:00
|
|
|
* `Verilog_Display_Line' -- do something about this?
|
|
|
|
|
* It's also possible for there to be a name collision with
|
|
|
|
|
* the special variable `Output'.
|
2008-06-03 19:44:17 +02:00
|
|
|
*/
|
|
|
|
|
static int draw_stask_display(vhdl_process *proc, ivl_statement_t stmt)
|
|
|
|
|
{
|
2008-06-03 20:14:47 +02:00
|
|
|
require_package("std.textio");
|
2008-06-03 20:46:10 +02:00
|
|
|
|
|
|
|
|
const char *display_line = "Verilog_Display_Line";
|
|
|
|
|
|
|
|
|
|
if (!proc->have_declared_var(display_line)) {
|
|
|
|
|
vhdl_type *line_type = new vhdl_scalar_type("Line");
|
|
|
|
|
vhdl_var_decl *line_var =
|
|
|
|
|
new vhdl_var_decl(display_line, line_type);
|
|
|
|
|
line_var->set_comment("For generating $display output");
|
|
|
|
|
proc->add_decl(line_var);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Write the data into the line
|
|
|
|
|
|
2008-06-04 14:27:42 +02:00
|
|
|
// Write_Line(Output, Verilog_Display_Line)
|
|
|
|
|
vhdl_var_ref *output_ref = new vhdl_var_ref("Output");
|
|
|
|
|
vhdl_var_ref *line_ref = new vhdl_var_ref(display_line);
|
|
|
|
|
vhdl_pcall_stmt *write_line = new vhdl_pcall_stmt("Write_Line");
|
|
|
|
|
write_line->add_expr(output_ref);
|
|
|
|
|
write_line->add_expr(line_ref);
|
|
|
|
|
proc->add_stmt(write_line);
|
2008-06-03 20:14:47 +02:00
|
|
|
|
2008-06-03 19:44:17 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generate VHDL for system tasks (like $display). Not all of
|
|
|
|
|
* these are supported.
|
|
|
|
|
*/
|
|
|
|
|
static int draw_stask(vhdl_process *proc, ivl_statement_t stmt)
|
|
|
|
|
{
|
|
|
|
|
const char *name = ivl_stmt_name(stmt);
|
|
|
|
|
|
|
|
|
|
std::cout << "IVL_ST_STASK " << name << std::endl;
|
|
|
|
|
|
|
|
|
|
if (strcmp(name, "$display") == 0)
|
|
|
|
|
return draw_stask_display(proc, stmt);
|
|
|
|
|
else {
|
|
|
|
|
error("No VHDL translation for system task %s", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-03 19:26:36 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generate VHDL statements for the given Verilog statement and
|
|
|
|
|
* add them to the given VHDL process.
|
|
|
|
|
*/
|
|
|
|
|
int draw_stmt(vhdl_process *proc, ivl_statement_t stmt)
|
|
|
|
|
{
|
2008-06-03 19:44:17 +02:00
|
|
|
switch (ivl_statement_type(stmt)) {
|
|
|
|
|
case IVL_ST_STASK:
|
|
|
|
|
return draw_stask(proc, stmt);
|
|
|
|
|
default:
|
|
|
|
|
error("No VHDL translation for statement at %s:%d (type = %d)",
|
|
|
|
|
ivl_stmt_file(stmt), ivl_stmt_lineno(stmt),
|
|
|
|
|
ivl_statement_type(stmt));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-06-03 19:26:36 +02:00
|
|
|
}
|