forked from cdkersey/chdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
assert.cpp
46 lines (36 loc) · 997 Bytes
/
assert.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// The assertion system allows certain error conditions to cause simulation to
// finish with an error message
#include <iostream>
#include <cstdlib>
#include "reset.h"
#include "sim.h"
#include "nodeimpl.h"
#include "assert.h"
#include "tickable.h"
#include "tap.h"
using namespace std;
using namespace chdl;
struct assertion_t : public tickable {
assertion_t(string &s, const node &n): message(s), x(n) { gtap(n); }
void tick(cdomain_handle_t cd);
void tock(cdomain_handle_t) {}
node x;
string message;
};
void assertion_t::tick(cdomain_handle_t cd) {
if (!nodes[x]->eval(cd)) {
cerr << "Cycle " << sim_time() << ": " << message << endl;
abort();
}
}
static vector<assertion_t *> assertions;
void chdl::assert_node_true(std::string text, node n) {
assertions.push_back(new assertion_t(text, n));
}
void reset_assertions() {
while (!assertions.empty()) {
delete *assertions.rbegin();
assertions.pop_back();
}
}
CHDL_REGISTER_RESET(reset_assertions);