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/int/SConscript | 1 + src/systemc/dt/int/messages.cc | 53 ++++++++++++++++++++++++++++++++++++++ src/systemc/dt/int/sc_int_base.cc | 6 ++--- src/systemc/dt/int/sc_nbutils.cc | 30 +++++++++++---------- src/systemc/dt/int/sc_signed.cc | 9 ++++--- src/systemc/dt/int/sc_uint_base.cc | 6 ++--- src/systemc/dt/int/sc_unsigned.cc | 9 ++++--- 7 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 src/systemc/dt/int/messages.cc (limited to 'src/systemc/dt/int') diff --git a/src/systemc/dt/int/SConscript b/src/systemc/dt/int/SConscript index 93e01b243..3721c2f08 100644 --- a/src/systemc/dt/int/SConscript +++ b/src/systemc/dt/int/SConscript @@ -28,6 +28,7 @@ Import('*') if env['USE_SYSTEMC']: + Source('messages.cc') Source('sc_int_base.cc') Source('sc_int_mask.cc') Source('sc_length_param.cc') diff --git a/src/systemc/dt/int/messages.cc b/src/systemc/dt/int/messages.cc new file mode 100644 index 000000000..945f2cd0e --- /dev/null +++ b/src/systemc/dt/int/messages.cc @@ -0,0 +1,53 @@ +/* + * 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/int/messages.hh" +#include "systemc/utils/report.hh" + +namespace sc_core +{ + +const char SC_ID_INIT_FAILED_[] = "initialization failed"; +const char SC_ID_ASSIGNMENT_FAILED_[] = "assignment failed"; +const char SC_ID_OPERATION_FAILED_[] = "operation failed"; +const char SC_ID_CONVERSION_FAILED_[] = "conversion failed"; + +namespace +{ + +sc_gem5::DefaultReportMessages predefinedMessages{ + {400, SC_ID_INIT_FAILED_}, + {401, SC_ID_ASSIGNMENT_FAILED_}, + {402, SC_ID_OPERATION_FAILED_}, + {403, SC_ID_CONVERSION_FAILED_} +}; + +} // anonymous namespace + +} // namespace sc_core diff --git a/src/systemc/dt/int/sc_int_base.cc b/src/systemc/dt/int/sc_int_base.cc index 69b62d128..ec4e96b59 100644 --- a/src/systemc/dt/int/sc_int_base.cc +++ b/src/systemc/dt/int/sc_int_base.cc @@ -517,10 +517,10 @@ sc_int_base & sc_int_base::operator = (const char *a) { if (a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero"); } else if (*a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty"); } else try { int len = m_len; @@ -529,7 +529,7 @@ sc_int_base::operator = (const char *a) } catch(const sc_core::sc_report &) { std::stringstream msg; msg << "character string '" << a << "' is not valid"; - SC_REPORT_ERROR("conversion failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); } return *this; } diff --git a/src/systemc/dt/int/sc_nbutils.cc b/src/systemc/dt/int/sc_nbutils.cc index 5d2c50fc9..a78013d77 100644 --- a/src/systemc/dt/int/sc_nbutils.cc +++ b/src/systemc/dt/int/sc_nbutils.cc @@ -61,6 +61,8 @@ #include #include +#include "systemc/ext/dt/bit/messages.hh" +#include "systemc/ext/dt/int/messages.hh" #include "systemc/ext/dt/int/sc_nbutils.hh" #include "systemc/ext/utils/functions.hh" @@ -89,7 +91,7 @@ is_valid_base(sc_numrep base) std::stringstream msg; msg << "is_valid_base( sc_numrep base ) : base = " << base << " is not valid"; - 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()); } } @@ -233,7 +235,7 @@ get_base_and_sign(const char *v, small_type &b, small_type &s) static const char msg[] = "get_base_and_sign( const char* v, small_type&, small_type& ) : " "v = \"\" is not valid"; - SC_REPORT_ERROR("conversion failed", msg); + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg); } return v; } @@ -264,12 +266,12 @@ parse_binary_bits(const char *src_p, int dst_n, // MAKE SURE WE HAVE A STRING TO PARSE: if (src_p == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero"); return; } if (*src_p == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty"); return; } @@ -321,7 +323,7 @@ parse_binary_bits(const char *src_p, int dst_n, std::stringstream msg; msg << "character string '" << src_p << "' is not valid"; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return; } @@ -352,7 +354,7 @@ parse_binary_bits(const char *src_p, int dst_n, std::stringstream msg; msg << "character string '" << src_p << "' is not valid"; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return; } @@ -393,12 +395,12 @@ parse_hex_bits(const char *src_p, int dst_n, // MAKE SURE WE HAVE A STRING TO PARSE: if (src_p == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero"); return; } if (*src_p == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty"); return; } @@ -468,7 +470,7 @@ parse_hex_bits(const char *src_p, int dst_n, std::stringstream msg; msg << "character string '" << src_p << "' is not valid"; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return; } @@ -518,7 +520,7 @@ parse_hex_bits(const char *src_p, int dst_n, { std::stringstream msg; msg << "character string '" << src_p << "' is not valid"; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str() ); return; } @@ -561,7 +563,7 @@ vec_from_str(int unb, int und, sc_digit *u, const char *v, sc_numrep base) msg << "vec_from_str( int, int, sc_digit*, const char*, " << "sc_numrep base ) : base = " << base << " does not match the default base"; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return 0; } @@ -584,7 +586,7 @@ vec_from_str(int unb, int und, sc_digit *u, const char *v, sc_numrep base) msg << "vec_from_str( int, int, sc_digit*, const char*, " << "sc_numrep base ) : '" << *v << "' is not a valid " << "digit in base " << b; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return 0; } @@ -599,7 +601,7 @@ vec_from_str(int unb, int und, sc_digit *u, const char *v, sc_numrep base) msg << "vec_from_str( int, int, sc_digit*, const char*, " << "sc_numrep base ) : '" << *v << "' is not a valid " << "digit in base " << b; - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return 0; } @@ -1703,7 +1705,7 @@ vec_reverse(int unb, int und, sc_digit *ud, int l, int r) std::stringstream msg; msg << "vec_reverse( int, int, sc_digit*, int l, int r ) : " << "l = " << l << " < r = " << r << " is not valid", - SC_REPORT_ERROR("conversion failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); return; } diff --git a/src/systemc/dt/int/sc_signed.cc b/src/systemc/dt/int/sc_signed.cc index cbb688523..97dd8eb8f 100644 --- a/src/systemc/dt/int/sc_signed.cc +++ b/src/systemc/dt/int/sc_signed.cc @@ -82,6 +82,7 @@ #include "systemc/ext/dt/bit/sc_lv_base.hh" #include "systemc/ext/dt/fx/sc_fix.hh" #include "systemc/ext/dt/fx/scfx_other_defs.hh" +#include "systemc/ext/dt/int/messages.hh" #include "systemc/ext/dt/int/sc_int_base.hh" #include "systemc/ext/dt/int/sc_signed.hh" #include "systemc/ext/dt/int/sc_uint_base.hh" @@ -110,7 +111,7 @@ sc_signed::invalid_init(const char *type_name, int nb) const { std::stringstream msg; msg << "sc_signed("<< type_name << ") : nb = " << nb << " is not valid"; - SC_REPORT_ERROR("initialization failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_INIT_FAILED_, msg.str().c_str()); } // ---------------------------------------------------------------------------- @@ -440,10 +441,10 @@ const sc_signed & sc_signed::operator = (const char *a) { if (a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero"); } else if (*a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty"); } else try { int len = length(); @@ -452,7 +453,7 @@ sc_signed::operator = (const char *a) } catch(const sc_core::sc_report &) { std::stringstream msg; msg << "character string '" << a << "' is not valid"; - SC_REPORT_ERROR("conversion failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); } return *this; } diff --git a/src/systemc/dt/int/sc_uint_base.cc b/src/systemc/dt/int/sc_uint_base.cc index a6053813f..fc6107f12 100644 --- a/src/systemc/dt/int/sc_uint_base.cc +++ b/src/systemc/dt/int/sc_uint_base.cc @@ -503,10 +503,10 @@ sc_uint_base & sc_uint_base::operator = (const char *a) { if (a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero"); } else if (*a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty"); } else try { int len = m_len; @@ -515,7 +515,7 @@ sc_uint_base::operator = (const char *a) } catch(const sc_core::sc_report &) { std::stringstream msg; msg << "character string '" << a << "' is not valid"; - SC_REPORT_ERROR("conversion failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); } return *this; } diff --git a/src/systemc/dt/int/sc_unsigned.cc b/src/systemc/dt/int/sc_unsigned.cc index b358c5cd3..63e9f366b 100644 --- a/src/systemc/dt/int/sc_unsigned.cc +++ b/src/systemc/dt/int/sc_unsigned.cc @@ -84,6 +84,7 @@ #include "systemc/ext/dt/bit/sc_lv_base.hh" #include "systemc/ext/dt/fx/sc_ufix.hh" #include "systemc/ext/dt/fx/scfx_other_defs.hh" +#include "systemc/ext/dt/int/messages.hh" #include "systemc/ext/dt/int/sc_int_base.hh" #include "systemc/ext/dt/int/sc_signed.hh" #include "systemc/ext/dt/int/sc_uint_base.hh" @@ -118,7 +119,7 @@ sc_unsigned::invalid_init(const char *type_name, int nb) const { std::stringstream msg; msg << "sc_unsigned("<< type_name << ") : nb = " << nb << " is not valid"; - SC_REPORT_ERROR("initialization failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_INIT_FAILED_, msg.str().c_str()); } @@ -438,10 +439,10 @@ const sc_unsigned & sc_unsigned::operator = (const char *a) { if (a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is zero"); } else if (*a == 0) { - SC_REPORT_ERROR("conversion failed", + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, "character string is empty"); } else try { int len = length(); @@ -450,7 +451,7 @@ sc_unsigned::operator = (const char *a) } catch(const sc_core::sc_report &) { std::stringstream msg; msg << "character string '" << a << "' is not valid"; - SC_REPORT_ERROR("conversion failed", msg.str().c_str()); + SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str()); } return *this; } -- cgit v1.2.3