From c9f83ec94ba1d7de0cfc46a9a23af2f9e04450e8 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 8 Oct 2018 19:01:38 -0700 Subject: systemc: Switch to using predefined messages for datatypes. Create and use predefined messages for datatypes which match the ones Accellera uses. Change-Id: I92dd52f62462b864264217bb81f3ff1dcec020bf Reviewed-on: https://gem5-review.googlesource.com/c/13331 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/dt/bit/SConscript | 1 + src/systemc/dt/bit/messages.cc | 76 ++++++++++++++++++++++++++++++++++++++++ src/systemc/dt/bit/sc_bit.cc | 5 +-- src/systemc/dt/bit/sc_bv_base.cc | 13 +++---- src/systemc/dt/bit/sc_logic.cc | 16 ++++----- src/systemc/dt/bit/sc_lv_base.cc | 3 +- 6 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 src/systemc/dt/bit/messages.cc (limited to 'src/systemc/dt/bit') diff --git a/src/systemc/dt/bit/SConscript b/src/systemc/dt/bit/SConscript index ed6eb35a0..e44a9d81f 100644 --- a/src/systemc/dt/bit/SConscript +++ b/src/systemc/dt/bit/SConscript @@ -28,6 +28,7 @@ Import('*') if env['USE_SYSTEMC']: + Source('messages.cc') Source('sc_bit.cc') Source('sc_bv_base.cc') Source('sc_logic.cc') diff --git a/src/systemc/dt/bit/messages.cc b/src/systemc/dt/bit/messages.cc new file mode 100644 index 000000000..8609b806b --- /dev/null +++ b/src/systemc/dt/bit/messages.cc @@ -0,0 +1,76 @@ +/* + * Copyright 2018 Google, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Gabe Black + */ + +#include "systemc/ext/dt/bit/messages.hh" +#include "systemc/utils/report.hh" + +namespace sc_core +{ + +const char SC_ID_LENGTH_MISMATCH_[] = + "length mismatch in bit/logic vector assignment"; +const char SC_ID_INCOMPATIBLE_TYPES_[] = "incompatible types"; +const char SC_ID_CANNOT_CONVERT_[] = "cannot perform conversion"; +const char SC_ID_INCOMPATIBLE_VECTORS_[] = "incompatible vectors"; +const char SC_ID_VALUE_NOT_VALID_[] = "value is not valid"; +const char SC_ID_ZERO_LENGTH_[] = "zero length"; +const char SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_[] = + "vector contains 4-value logic"; +const char SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_[] = + "sc_bv cannot contain values X and Z"; +const char SC_ID_VECTOR_TOO_LONG_[] = "vector is too long: truncated"; +const char SC_ID_VECTOR_TOO_SHORT_[] = "vector is too short: 0-padded"; +const char SC_ID_WRONG_VALUE_[] = "wrong value"; +const char SC_ID_LOGIC_Z_TO_BOOL_[] = + "sc_logic value 'Z' cannot be converted to bool"; +const char SC_ID_LOGIC_X_TO_BOOL_[] = + "sc_logic value 'X' cannot be converted to bool"; + +namespace +{ + +sc_gem5::DefaultReportMessages predefinedMessages{ + {200, SC_ID_LENGTH_MISMATCH_}, + {201, SC_ID_INCOMPATIBLE_TYPES_}, + {202, SC_ID_CANNOT_CONVERT_}, + {203, SC_ID_INCOMPATIBLE_VECTORS_}, + {204, SC_ID_VALUE_NOT_VALID_}, + {205, SC_ID_ZERO_LENGTH_}, + {206, SC_ID_VECTOR_CONTAINS_LOGIC_VALUE_}, + {207, SC_ID_SC_BV_CANNOT_CONTAIN_X_AND_Z_}, + {208, SC_ID_VECTOR_TOO_LONG_}, + {209, SC_ID_VECTOR_TOO_SHORT_}, + {210, SC_ID_WRONG_VALUE_}, + {211, SC_ID_LOGIC_Z_TO_BOOL_}, + {212, SC_ID_LOGIC_X_TO_BOOL_} +}; + +} // anonymous namespace + +} // namespace sc_core diff --git a/src/systemc/dt/bit/sc_bit.cc b/src/systemc/dt/bit/sc_bit.cc index e2e157905..e386b190d 100644 --- a/src/systemc/dt/bit/sc_bit.cc +++ b/src/systemc/dt/bit/sc_bit.cc @@ -58,6 +58,7 @@ #include +#include "systemc/ext/dt/bit/messages.hh" #include "systemc/ext/dt/bit/sc_bit.hh" #include "systemc/ext/dt/bit/sc_logic.hh" #include "systemc/ext/utils/messages.hh" @@ -79,7 +80,7 @@ sc_bit::invalid_value(char c) { std::stringstream msg; msg << "sc_bit( '" << c << "' )"; - SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str()); sc_core::sc_abort(); // can't recover from here } @@ -88,7 +89,7 @@ sc_bit::invalid_value(int i) { std::stringstream msg; msg << "sc_bit( " << i << " )"; - SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str()); sc_core::sc_abort(); // can't recover from here } diff --git a/src/systemc/dt/bit/sc_bv_base.cc b/src/systemc/dt/bit/sc_bv_base.cc index 84265af8d..41675d48e 100644 --- a/src/systemc/dt/bit/sc_bv_base.cc +++ b/src/systemc/dt/bit/sc_bv_base.cc @@ -55,6 +55,7 @@ #include #include +#include "systemc/ext/dt/bit/messages.hh" #include "systemc/ext/dt/bit/sc_bv_base.hh" #include "systemc/ext/dt/fx/sc_fix.hh" #include "systemc/ext/dt/fx/sc_ufix.hh" @@ -74,7 +75,7 @@ sc_bv_base::init(int length_, bool init_value) { // check the length if (length_ <= 0) { - SC_REPORT_ERROR("zero length", 0); + SC_REPORT_ERROR(sc_core::SC_ID_ZERO_LENGTH_, 0); sc_core::sc_abort(); // can't recover from here } // allocate memory for the data and control words @@ -101,7 +102,7 @@ sc_bv_base::assign_from_string(const std::string &s) for (; i < min_len; ++i) { char c = s[s_len - i - 1]; if (c != '0' && c != '1') { - SC_REPORT_ERROR("cannot perform conversion", + SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, "string can contain only '0' and '1' characters"); // may continue, if suppressed c = '0'; @@ -161,12 +162,12 @@ convert_to_bin(const char *s) // because this is seen as a hexadecimal encoding prefix! if (s == 0) { - SC_REPORT_ERROR("cannot perform conversion", - "character string is zero"); + SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, + "character string is zero"); return std::string(); } if (*s == 0) { - SC_REPORT_ERROR("cannot perform conversion", + SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, "character string is empty"); return std::string(); } @@ -203,7 +204,7 @@ convert_to_bin(const char *s) } catch (const sc_core::sc_report &) { std::stringstream msg; msg << "character string '" << s << "' is not valid"; - SC_REPORT_ERROR("cannot perform conversion", + SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, msg.str().c_str()); return std::string(); } diff --git a/src/systemc/dt/bit/sc_logic.cc b/src/systemc/dt/bit/sc_logic.cc index 4943d3df1..876fd3570 100644 --- a/src/systemc/dt/bit/sc_logic.cc +++ b/src/systemc/dt/bit/sc_logic.cc @@ -48,6 +48,7 @@ #include +#include "systemc/ext/dt/bit/messages.hh" #include "systemc/ext/dt/bit/sc_logic.hh" #include "systemc/ext/utils/sc_report_handler.hh" @@ -72,7 +73,7 @@ sc_logic::invalid_value(char c) { std::stringstream msg; msg << "sc_logic('" << c << "')"; - SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str()); } void @@ -80,20 +81,17 @@ sc_logic::invalid_value(int i) { std::stringstream msg; msg << "sc_logic(" << i << ")"; - SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str()); } void sc_logic::invalid_01() const { - if ((int)m_val == Log_Z) { - SC_REPORT_WARNING( - "(W211) sc_logic value 'Z' cannot be converted to bool", 0); - } else { - SC_REPORT_WARNING( - "(W212) sc_logic value 'X' cannot be converted to bool", 0); - } + if ((int)m_val == Log_Z) + SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_Z_TO_BOOL_, 0); + else + SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_X_TO_BOOL_, 0); } diff --git a/src/systemc/dt/bit/sc_lv_base.cc b/src/systemc/dt/bit/sc_lv_base.cc index de2d655db..ae5d52a8a 100644 --- a/src/systemc/dt/bit/sc_lv_base.cc +++ b/src/systemc/dt/bit/sc_lv_base.cc @@ -50,6 +50,7 @@ #include +#include "systemc/ext/dt/bit/messages.hh" #include "systemc/ext/dt/bit/sc_lv_base.hh" #include "systemc/ext/utils/messages.hh" @@ -90,7 +91,7 @@ sc_lv_base::init(int length_, const sc_logic& init_value) { // check the length if (length_ <= 0) { - SC_REPORT_ERROR("zero length", 0); + SC_REPORT_ERROR(sc_core::SC_ID_ZERO_LENGTH_, 0); sc_core::sc_abort(); // can't recover from here } // allocate memory for the data and control words -- cgit v1.2.3