From d6f116254705f098679d82e058d028bd6b75f7e5 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 12 Jun 2008 10:50:46 +0100 Subject: [PATCH] Generate correct VHDL signal values --- tgt-vhdl/vhdl_helper.hh | 17 +++++++++++++++++ tgt-vhdl/vhdl_syntax.cc | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tgt-vhdl/vhdl_helper.hh b/tgt-vhdl/vhdl_helper.hh index 656a35409..c1f9499ab 100644 --- a/tgt-vhdl/vhdl_helper.hh +++ b/tgt-vhdl/vhdl_helper.hh @@ -23,6 +23,7 @@ #include #include +#include template void emit_children(std::ofstream &of, @@ -54,4 +55,20 @@ void delete_children(std::list &children) children.clear(); } +static inline char vl_to_vhdl_bit(char bit) +{ + switch (bit) { + case '0': + case 'Z': + case '1': + return bit; + case 'z': + return 'Z'; + case 'x': + case 'X': + return 'U'; + } + assert(false); +} + #endif diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 9387f5eef..2145c5874 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -522,14 +522,14 @@ void vhdl_const_bits::emit(std::ofstream &of, int level) const // The bits appear to be in reverse order std::string::const_reverse_iterator it; for (it = value_.rbegin(); it != value_.rend(); ++it) - of << *it; + of << vl_to_vhdl_bit(*it); of << "\")"; } void vhdl_const_bit::emit(std::ofstream &of, int level) const { - of << "'" << bit_ << "'"; + of << "'" << vl_to_vhdl_bit(bit_) << "'"; } void vhdl_const_int::emit(std::ofstream &of, int level) const