Add Type'Image cast to $display parameters

This commit is contained in:
Nick Gasson 2008-06-07 14:21:50 +01:00
parent 066a9b7a61
commit 12e2237131
2 changed files with 27 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#include <iostream>
#include <cstring>
#include <cassert>
#include <sstream>
/*
* Generate VHDL for the $display system task.
@ -60,11 +61,24 @@ static int draw_stask_display(vhdl_process *proc, ivl_statement_t stmt)
ivl_expr_t net = ivl_stmt_parm(stmt, i);
vhdl_expr *e = NULL;
if (net) {
// TODO: Need to add a call to Type'Image for types not
// supported by std.textio
e = translate_expr(net);
if (NULL == e)
vhdl_expr *base = translate_expr(net);
if (NULL == base)
return 1;
// Need to add a call to Type'Image for types not
// supported by std.textio
if (base->get_type()->get_name() != "String") {
std::string name(base->get_type()->get_name());
name += "'Image";
vhdl_fcall *cast
= new vhdl_fcall(name.c_str(), vhdl_scalar_type::string());
cast->add_expr(base);
e = cast;
}
else
e = base;
}
else
e = new vhdl_const_string(" ");

View File

@ -51,7 +51,12 @@ typedef std::list<vhdl_element*> element_list_t;
class vhdl_type : public vhdl_element {
public:
vhdl_type(const char *name) : name_(name) {}
virtual ~vhdl_type() {}
const std::string &get_name() const { return name_; }
protected:
std::string name_;
};
/*
@ -61,7 +66,8 @@ public:
*/
class vhdl_scalar_type : public vhdl_type {
public:
vhdl_scalar_type(const char *name) : name_(name) {}
vhdl_scalar_type(const char *name)
: vhdl_type(name) {}
void emit(std::ofstream &of, int level) const;
@ -69,14 +75,14 @@ public:
static vhdl_scalar_type *std_logic();
static vhdl_scalar_type *string();
static vhdl_scalar_type *line();
private:
std::string name_;
};
class vhdl_expr : public vhdl_element {
public:
vhdl_expr(vhdl_type* type) : type_(type) {}
virtual ~vhdl_expr();
const vhdl_type *get_type() const { return type_; }
private:
vhdl_type *type_;
};