summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-01 17:49:20 -0700
committerGabe Black <gabeblack@google.com>2018-10-03 00:47:35 +0000
commitf8217428d59e191013a6c8037fb945aaf7550db6 (patch)
treec81c63aaf4337d1b95bf8208ec03ce897dc24788
parent902d2a598dcdc93ffe1778ad1d42f651b8a1b9ee (diff)
downloadgem5-f8217428d59e191013a6c8037fb945aaf7550db6.tar.xz
systemc: Add some error checks to sc_set_default_time_unit.
Change-Id: I1d21c56d3b39044d91c96c98d242a571c099707c Reviewed-on: https://gem5-review.googlesource.com/c/12463 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/systemc/core/sc_time.cc29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/systemc/core/sc_time.cc b/src/systemc/core/sc_time.cc
index e0e8cf107..74345d041 100644
--- a/src/systemc/core/sc_time.cc
+++ b/src/systemc/core/sc_time.cc
@@ -371,7 +371,7 @@ const sc_time SC_ZERO_TIME;
void
sc_set_time_resolution(double d, sc_time_unit tu)
{
- if (d < 0.0) {
+ if (d <= 0.0) {
SC_REPORT_ERROR("(E514) set time resolution failed",
"value not positive");
}
@@ -426,7 +426,34 @@ sc_max_time()
void
sc_set_default_time_unit(double d, sc_time_unit tu)
{
+ if (d < 0.0) {
+ SC_REPORT_ERROR("(E515) set default time unit failed",
+ "value not positive");
+ }
+ double dummy;
+ if (modf(log10(d), &dummy) != 0.0) {
+ SC_REPORT_ERROR("(E515) set default time unit failed",
+ "value not a power of ten");
+ }
+ if (sc_is_running()) {
+ SC_REPORT_ERROR("(E515) set default time unit failed",
+ "simulation running");
+ }
+ static bool specified = false;
+ if (specified) {
+ SC_REPORT_ERROR("(E515) set default time unit failed",
+ "already specified");
+ }
+ // This won't detect the timescale being fixed outside of systemc, but
+ // it's at least some protection.
+ if (timeFixed) {
+ SC_REPORT_ERROR("(E515) set default time unit failed",
+ "sc_time object(s) constructed");
+ }
+
+ // Normalize d to seconds.
defaultUnit = d * TimeUnitScale[tu];
+ specified = true;
}
sc_time