From: Brian Norris Date: Sat, 3 Nov 2012 22:52:16 +0000 (-0700) Subject: model-assert: add MODEL_ASSERT() for user programs X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d596a0e422232c82e01fe266ca2099d0eff5de0f;p=cdsspec-compiler.git model-assert: add MODEL_ASSERT() for user programs --- diff --git a/common.cc b/common.cc index b274989..20102b0 100644 --- a/common.cc +++ b/common.cc @@ -2,6 +2,8 @@ #include #include +#include + #include "common.h" #include "model.h" #include "stacktrace.h" @@ -40,3 +42,12 @@ void assert_hook(void) { printf("Add breakpoint to line %u in file %s.\n",__LINE__,__FILE__); } + +void model_assert(bool expr, const char *file, int line) +{ + if (!expr) { + printf(" [BUG] Program has hit assertion in file %s at line %d\n", + file, line); + model->set_assert(); + } +} diff --git a/include/model-assert.h b/include/model-assert.h new file mode 100644 index 0000000..a091e15 --- /dev/null +++ b/include/model-assert.h @@ -0,0 +1,15 @@ +#ifndef __MODEL_ASSERT_H__ +#define __MODEL_ASSERT_H__ + +#if __cplusplus +extern "C" { +#endif + +void model_assert(bool expr, const char *file, int line); +#define MODEL_ASSERT(expr) model_assert((expr), __FILE__, __LINE__) + +#if __cplusplus +} +#endif + +#endif /* __MODEL_ASSERT_H__ */