From ce72eb4eb45ba3c454d75f555a41519f32f5b98a Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 16 Jun 2008 14:26:38 +0100 Subject: [PATCH] Fix Valgrind warnings --- tgt-vhdl/expr.cc | 2 +- tgt-vhdl/vhdl_syntax.cc | 11 ++++++----- tgt-vhdl/vhdl_syntax.hh | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tgt-vhdl/expr.cc b/tgt-vhdl/expr.cc index 8e302efc4..049b6d0e3 100644 --- a/tgt-vhdl/expr.cc +++ b/tgt-vhdl/expr.cc @@ -59,7 +59,7 @@ static vhdl_expr *translate_signal(ivl_expr_t e) */ static vhdl_expr *translate_number(ivl_expr_t e) { - return new vhdl_const_bits(ivl_expr_bits(e)); + return new vhdl_const_bits(ivl_expr_bits(e), ivl_expr_width(e)); } static vhdl_expr *translate_unary(ivl_expr_t e) diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index fd9ba1805..a912e70b3 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -187,7 +187,7 @@ vhdl_arch *vhdl_conc_stmt::get_parent() const } vhdl_process::vhdl_process(const char *name) - : name_(name) + : name_(name), initial_(false) { } @@ -547,11 +547,12 @@ void vhdl_nbassign_stmt::emit(std::ofstream &of, int level) const of << ";"; } -vhdl_const_bits::vhdl_const_bits(const char *value) - : vhdl_expr(vhdl_type::nsigned(strlen(value))), - value_(value) +vhdl_const_bits::vhdl_const_bits(const char *value, int width) + : vhdl_expr(vhdl_type::nsigned(width)) { - + // Can't rely on value being NULL-terminated + while (width--) + value_.push_back(*value++); } vhdl_expr *vhdl_const_bits::cast(const vhdl_type *to) diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index 5ceb45546..8e576cd42 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -113,7 +113,7 @@ private: class vhdl_const_bits : public vhdl_expr { public: - vhdl_const_bits(const char *value); + vhdl_const_bits(const char *value, int width); void emit(std::ofstream &of, int level) const; const std::string &get_value() const { return value_; } vhdl_expr *cast(const vhdl_type *to);