systemc: Add an error check to sc_time.
authorGabe Black <gabeblack@google.com>
Sat, 22 Sep 2018 13:12:16 +0000 (06:12 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 16 Oct 2018 00:28:06 +0000 (00:28 +0000)
Change-Id: Ie525a1624a6496a51277fb984cbfeec21eb79749
Reviewed-on: https://gem5-review.googlesource.com/c/12966
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/systemc/core/sc_time.cc
src/systemc/tests/systemc/kernel/sc_time/test16/expected_returncode [new file with mode: 0644]

index 999fba2f9ed5523b6a160145df234792f4646bb5..0b8ad620b6ea0c6bf46f593f585e858bc2ce108f 100644 (file)
@@ -494,6 +494,14 @@ sc_set_default_time_unit(double d, sc_time_unit tu)
     // Normalize d to seconds.
     defaultUnit = d * TimeUnitScale[tu];
     specified = true;
+
+    double resolution = SimClock::Float::Hz;
+    if (resolution == 0.0)
+        resolution = TimeUnitScale[SC_PS];
+    if (defaultUnit < resolution) {
+        SC_REPORT_ERROR("(E515) set default time unit failed",
+                "value smaller than time resolution");
+    }
 }
 
 sc_time
diff --git a/src/systemc/tests/systemc/kernel/sc_time/test16/expected_returncode b/src/systemc/tests/systemc/kernel/sc_time/test16/expected_returncode
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1