From 12e223713100605e01c0565aeb9aa40a5b4e4f35 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 7 Jun 2008 14:21:50 +0100 Subject: [PATCH] Add Type'Image cast to $display parameters --- tgt-vhdl/stmt.cc | 22 ++++++++++++++++++---- tgt-vhdl/vhdl_element.hh | 12 +++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index c42110707..a19dc8610 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -23,6 +23,7 @@ #include #include #include +#include /* * 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(" "); diff --git a/tgt-vhdl/vhdl_element.hh b/tgt-vhdl/vhdl_element.hh index 0b15c7362..e9788c7d2 100644 --- a/tgt-vhdl/vhdl_element.hh +++ b/tgt-vhdl/vhdl_element.hh @@ -51,7 +51,12 @@ typedef std::list 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_; };