From dd30c1b39d2f872f719c6f9b7a48a009a0744817 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 4 Jun 2008 13:27:42 +0100 Subject: [PATCH] Support procedure call generation for $display --- tgt-vhdl/stmt.cc | 8 +++++++- tgt-vhdl/vhdl_element.cc | 37 +++++++++++++++++++++++++++++++++ tgt-vhdl/vhdl_element.hh | 44 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index 2ee58bfc6..d05e6209b 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -53,7 +53,13 @@ static int draw_stask_display(vhdl_process *proc, ivl_statement_t stmt) // TODO: Write the data into the line - // TODO: Write_Line(Output, Verilog_Display_Line) + // 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); return 0; } diff --git a/tgt-vhdl/vhdl_element.cc b/tgt-vhdl/vhdl_element.cc index f5f7d5f90..7f9ce9b4c 100644 --- a/tgt-vhdl/vhdl_element.cc +++ b/tgt-vhdl/vhdl_element.cc @@ -283,3 +283,40 @@ void vhdl_var_decl::emit(std::ofstream &of, int level) const of << ";"; emit_comment(of, level, true); } + +void vhdl_expr_list::add_expr(vhdl_expr *e) +{ + exprs_.push_back(e); +} + +vhdl_expr_list::~vhdl_expr_list() +{ + delete_children(exprs_); +} + +void vhdl_expr_list::emit(std::ofstream &of, int level) const +{ + of << "("; + + int size = exprs_.size(); + std::list::const_iterator it; + for (it = exprs_.begin(); it != exprs_.end(); ++it) { + (*it)->emit(of, level); + if (--size > 0) + of << ", "; + } + + of << ")"; +} + +void vhdl_pcall_stmt::emit(std::ofstream &of, int level) const +{ + of << name_; + exprs_.emit(of, level); + of << ";"; +} + +void vhdl_var_ref::emit(std::ofstream &of, int level) const +{ + of << name_; +} diff --git a/tgt-vhdl/vhdl_element.hh b/tgt-vhdl/vhdl_element.hh index 3082aad76..ab0646597 100644 --- a/tgt-vhdl/vhdl_element.hh +++ b/tgt-vhdl/vhdl_element.hh @@ -65,6 +65,34 @@ private: std::string name_; }; +class vhdl_expr : public vhdl_element { +public: + virtual ~vhdl_expr() {} +}; + +/* + * A normal scalar variable reference. + */ +class vhdl_var_ref : public vhdl_expr { +public: + vhdl_var_ref(const char *name) : name_(name) {} + + void emit(std::ofstream &of, int level) const; +private: + std::string name_; +}; + +class vhdl_expr_list : public vhdl_element { +public: + ~vhdl_expr_list(); + + void emit(std::ofstream &of, int level) const; + void add_expr(vhdl_expr *e); +private: + std::list exprs_; +}; + + /* * A concurrent statement appears in architecture bodies but not * processes. @@ -98,6 +126,22 @@ public: }; +/* + * A procedure call. Which is a statement, unlike a function + * call which is an expression. + */ +class vhdl_pcall_stmt : public vhdl_seq_stmt { +public: + vhdl_pcall_stmt(const char *name) : name_(name) {} + + void emit(std::ofstream &of, int level) const; + void add_expr(vhdl_expr *e) { exprs_.add_expr(e); } +private: + std::string name_; + vhdl_expr_list exprs_; +}; + + /* * A declaration of some sort (variable, component, etc.). * Declarations have names, which is the identifier of the variable,