From a3df37b851eee3555d1fd12eb0e77baae95b3cf8 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 25 Jun 2008 17:29:09 +0100 Subject: [PATCH] Initial code to generate function calls Also catch a few null-pointer issues --- tgt-vhdl/expr.cc | 27 +++++++++++++++++++++++++++ tgt-vhdl/vhdl_syntax.cc | 6 ++++++ tgt-vhdl/vhdl_syntax.hh | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tgt-vhdl/expr.cc b/tgt-vhdl/expr.cc index e861b4a7f..75d94147f 100644 --- a/tgt-vhdl/expr.cc +++ b/tgt-vhdl/expr.cc @@ -203,6 +203,31 @@ vhdl_expr *translate_select(ivl_expr_t e) return from->resize(ivl_expr_width(e)); } +vhdl_expr *translate_ufunc(ivl_expr_t e) +{ + ivl_scope_t defscope = ivl_expr_def(e); + ivl_scope_t parentscope = ivl_scope_parent(defscope); + assert(ivl_scope_type(parentscope) == IVL_SCT_MODULE); + + // A function is always declared in a module, which should have + // a corresponding entity by this point: so we can get type + // information, etc. from the declaration + vhdl_entity *parent_ent = find_entity(ivl_scope_tname(parentscope)); + assert(parent_ent); + + const char *funcname = ivl_scope_tname(defscope); + + vhdl_decl *fdecl = + parent_ent->get_arch()->get_scope()->get_decl(funcname); + assert(fdecl); + + vhdl_type *rettype = new vhdl_type(*fdecl->get_type()); + + vhdl_fcall *fcall = new vhdl_fcall(funcname, rettype); + + return fcall; +} + /* * Generate a VHDL expression from a Verilog expression. */ @@ -224,6 +249,8 @@ vhdl_expr *translate_expr(ivl_expr_t e) return translate_binary(e); case IVL_EX_SELECT: return translate_select(e); + case IVL_EX_UFUNC: + return translate_ufunc(e); default: error("No VHDL translation for expression at %s:%d (type = %d)", ivl_expr_file(e), ivl_expr_lineno(e), type); diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 89f15749e..921f15964 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -305,6 +305,12 @@ vhdl_decl::~vhdl_decl() delete initial_; } +const vhdl_type *vhdl_decl::get_type() const +{ + assert(type_); + return type_; +} + void vhdl_decl::set_initial(vhdl_expr *initial) { if (initial_ != NULL) diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index 428996412..742a38f5d 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -414,7 +414,7 @@ public: virtual ~vhdl_decl(); const std::string &get_name() const { return name_; } - const vhdl_type *get_type() const { return type_; } + const vhdl_type *get_type() const; void set_initial(vhdl_expr *initial); bool has_initial() const { return initial_ != NULL; } protected: