Skip to content

Commit bfd61cc

Browse files
committed
Fix cdkersey#5. Now you can include cassert. You'd better have a damned good reason.
1 parent 1435486 commit bfd61cc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

assert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void assertion_t::tick(cdomain_handle_t cd) {
3232

3333
static vector<assertion_t *> assertions;
3434

35-
void chdl::assert(std::string text, node n) {
35+
void chdl::assert_node_true(std::string text, node n) {
3636
assertions.push_back(new assertion_t(text, n));
3737
}
3838

assert.h

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
// The assertion system allows certain error conditions to cause simulation to
22
// finish with an error message
3-
#ifndef __ASSERT_H
4-
#define __ASSERT_H
3+
#ifndef CHDL_ASSERT_H
4+
#define CHDL_ASSERT_H
55
#include <string>
66

77
#include "node.h"
88

99
namespace chdl {
10-
void assert(std::string text, node node);
10+
void assert_node_true(std::string text, node node);
1111
};
1212

1313
#define CHDL_STRINGIFY_INTERNAL(x) #x
1414
#define CHDL_STRINGIFY(x) CHDL_STRINGIFY_INTERNAL(x)
1515
#define CHDL_LINE_STR CHDL_STRINGIFY(__LINE__)
1616

17+
#ifndef CHDL_DISABLE_ASSERT
18+
#ifdef ASSERT
19+
// ASSERT has already been defined by another library. This is only a problem
20+
// if it was used in CHDL code.
21+
#error ASSERT already #defined. #undef it or define CHDL_DISABLE_ASSERT.
22+
#else
1723
#define ASSERT(x) do { \
18-
assert(std::string("Failed assertion in ") + \
19-
__FILE__ ": Line " CHDL_LINE_STR, x); \
24+
assert_node_true(std::string("Failed assertion in ") + \
25+
__FILE__ ": Line " CHDL_LINE_STR, x); \
2026
} while(0)
27+
#endif
28+
#endif
2129

2230
#endif

0 commit comments

Comments
 (0)