aboutsummaryrefslogtreecommitdiffstats
path: root/backends/cxxrtl/cxxrtl.h
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2020-12-02 23:36:22 +0000
committerGitHub <noreply@github.com>2020-12-02 23:36:22 +0000
commit3e13cfe53dd62f71820b227d4c04cc47bbb95001 (patch)
treef51b573a0aae2accf93e77c5709b7422974b7de8 /backends/cxxrtl/cxxrtl.h
parent3cb109f54bb35ad1c29474c2742c8767535174e1 (diff)
parentaa0a15a42cf7513697b3d93457a69ecf2d8b9e05 (diff)
downloadyosys-3e13cfe53dd62f71820b227d4c04cc47bbb95001.tar.gz
yosys-3e13cfe53dd62f71820b227d4c04cc47bbb95001.tar.bz2
yosys-3e13cfe53dd62f71820b227d4c04cc47bbb95001.zip
Merge pull request #2468 from whitequark/cxxrtl-assert
cxxrtl: use CXXRTL_ASSERT for RTL contract violations instead of assert
Diffstat (limited to 'backends/cxxrtl/cxxrtl.h')
-rw-r--r--backends/cxxrtl/cxxrtl.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h
index 4528a7d8f..eb7d7eaeb 100644
--- a/backends/cxxrtl/cxxrtl.h
+++ b/backends/cxxrtl/cxxrtl.h
@@ -53,6 +53,20 @@
#define CXXRTL_ALWAYS_INLINE inline
#endif
+// CXXRTL uses assert() to check for C++ contract violations (which may result in e.g. undefined behavior
+// of the simulation code itself), and CXXRTL_ASSERT to check for RTL contract violations (which may at
+// most result in undefined simulation results).
+//
+// Though by default, CXXRTL_ASSERT() expands to assert(), it may be overridden e.g. when integrating
+// the simulation into another process that should survive violating RTL contracts.
+#ifndef CXXRTL_ASSERT
+#ifndef CXXRTL_NDEBUG
+#define CXXRTL_ASSERT(x) assert(x)
+#else
+#define CXXRTL_ASSERT(x)
+#endif
+#endif
+
namespace cxxrtl {
// All arbitrary-width values in CXXRTL are backed by arrays of unsigned integers called chunks. The chunk size