From 30fdadc5252f1d9746ac76177af9959bacd4ef58 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 23 Jul 2008 13:40:42 +0100 Subject: [PATCH] Support delays in logic devices --- tgt-vhdl/scope.cc | 21 +++++++++++++++++++-- tgt-vhdl/vhdl_syntax.cc | 6 ++++++ tgt-vhdl/vhdl_syntax.hh | 5 +++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tgt-vhdl/scope.cc b/tgt-vhdl/scope.cc index ac1202fff..69808076b 100644 --- a/tgt-vhdl/scope.cc +++ b/tgt-vhdl/scope.cc @@ -242,9 +242,26 @@ static void declare_logic(vhdl_arch *arch, ivl_scope_t scope) dynamic_cast(nexus_to_expr(arch->get_scope(), output)); if (NULL == lhs) continue; // Not suitable for continuous assignment - + vhdl_expr *rhs = translate_logic(arch->get_scope(), log); - arch->add_stmt(new vhdl_cassign_stmt(lhs, rhs)); + vhdl_cassign_stmt *ass = new vhdl_cassign_stmt(lhs, rhs); + + ivl_expr_t delay = ivl_logic_delay(log, 1); + vhdl_expr *after; + if (delay && (after = translate_expr(delay))) { + // Need to make 'after' a time value + // we can do this by multiplying by 1ns + vhdl_type integer(VHDL_TYPE_INTEGER); + after = after->cast(&integer); + + vhdl_expr *ns1 = new vhdl_const_time(1, TIME_UNIT_NS); + after = new vhdl_binop_expr(after, VHDL_BINOP_MULT, ns1, + vhdl_type::time()); + + ass->set_after(after); + } + + arch->add_stmt(ass); } } } diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index a14f11e6d..2f5e9f56f 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -611,6 +611,12 @@ void vhdl_cassign_stmt::emit(std::ostream &of, int level) const of << "else "; } rhs_->emit(of, level); + + if (after_) { + of << " after "; + after_->emit(of, level); + } + of << ";"; } diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index c6a2c727f..f7acf9762 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -227,14 +227,15 @@ typedef std::list conc_stmt_list_t; class vhdl_cassign_stmt : public vhdl_conc_stmt { public: vhdl_cassign_stmt(vhdl_var_ref *lhs, vhdl_expr *rhs) - : lhs_(lhs), rhs_(rhs) {} + : lhs_(lhs), rhs_(rhs), after_(NULL) {} ~vhdl_cassign_stmt(); void emit(std::ostream &of, int level) const; void add_condition(vhdl_expr *value, vhdl_expr *cond); + void set_after(vhdl_expr *a) { after_ = a; } private: vhdl_var_ref *lhs_; - vhdl_expr *rhs_; + vhdl_expr *rhs_, *after_; struct when_part_t { vhdl_expr *value, *cond;