From 9faaf5f817d1d495ad84a3543e7c24f7d1e7597e Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 5 Oct 2010 20:00:16 +0100 Subject: [PATCH] Add VHDL report statement Not output yet, but will be used to replace std.textio implementation of $display. Conflicts: tgt-vhdl/vhdl_syntax.cc --- tgt-vhdl/vhdl_syntax.cc | 36 ++++++++++++++++++++++++++++++++++-- tgt-vhdl/vhdl_syntax.hh | 31 ++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 44f112fd2..ba881f9fb 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -788,10 +788,42 @@ void vhdl_cassign_stmt::emit(std::ostream &of, int level) const of << ";"; } +vhdl_report_stmt::vhdl_report_stmt(vhdl_expr *text, + vhdl_severity_t severity) + : severity_(severity), + text_(text) +{ + +} + +void vhdl_report_stmt::emit(ostream& of, int level) const +{ + of << "report "; + text_->emit(of, level); + + if (severity_ != SEVERITY_NOTE) { + const char *levels[] = { "note", "warning", "error", "failure" }; + of << " severity " << levels[severity_]; + } + + of << ";"; +} + +void vhdl_report_stmt::find_vars(vhdl_var_set_t& read, vhdl_var_set_t& write) +{ + text_->find_vars(read); +} + +vhdl_assert_stmt::vhdl_assert_stmt(const char *reason) + : vhdl_report_stmt(new vhdl_const_string(reason), SEVERITY_FAILURE) +{ + +} + void vhdl_assert_stmt::emit(std::ostream &of, int level) const { - of << "assert false"; // TODO: Allow arbitrary expression - of << " report \"" << reason_ << "\" severity failure;"; + of << "assert false "; // TODO: Allow arbitrary expression + vhdl_report_stmt::emit(of, level); } vhdl_if_stmt::vhdl_if_stmt(vhdl_expr *test) diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index bfacd2ed4..8e7bcd694 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -453,15 +453,32 @@ public: }; -class vhdl_assert_stmt : public vhdl_seq_stmt { -public: - vhdl_assert_stmt(const char *reason) - : reason_(reason) {} +enum vhdl_severity_t { + SEVERITY_NOTE, + SEVERITY_WARNING, + SEVERITY_ERROR, + SEVERITY_FAILURE +}; - void emit(std::ostream &of, int level) const; - void find_vars(vhdl_var_set_t& read, vhdl_var_set_t& write) {} +class vhdl_report_stmt : public vhdl_seq_stmt { +public: + vhdl_report_stmt(vhdl_expr *text, + vhdl_severity_t severity = SEVERITY_NOTE); + virtual ~vhdl_report_stmt() {} + + virtual void emit(ostream& of, int level) const; + void find_vars(vhdl_var_set_t& read, vhdl_var_set_t& write); private: - std::string reason_; + vhdl_severity_t severity_; + vhdl_expr *text_; +}; + + +class vhdl_assert_stmt : public vhdl_report_stmt { +public: + vhdl_assert_stmt(const char *reason); + + void emit(ostream &of, int level) const; };