Skip to content

Commit bf57c72

Browse files
Non-boolean stable/rose/fell assertions supported, #39
1 parent 3926c0e commit bf57c72

13 files changed

+623
-164
lines changed

components/common/sctcommon/sct_assert.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ inline void sct_assert(bool expr, const char* msg) {}
8686
struct sct_property_mod
8787
{
8888
explicit sct_property_mod() {}
89-
template<class T1, class T2>
90-
explicit sct_property_mod(bool lexpr, bool rexpr, sc_event_finder& event,
89+
template<class T1, class T2, class RT>
90+
explicit sct_property_mod(bool lexpr, RT rexpr, sc_event_finder& event,
9191
const char* name, T1 lotime, T2 hitime,
9292
unsigned stable) {}
93-
template<class T1>
94-
explicit sct_property_mod(bool lexpr, bool rexpr, sc_event_finder& event,
93+
template<class T1, class RT>
94+
explicit sct_property_mod(bool lexpr, RT rexpr, sc_event_finder& event,
9595
const char* name, T1 time, unsigned stable) {}
96-
template<class T1, class T2>
97-
explicit sct_property_mod(bool lexpr, bool rexpr, sc_port_base& event,
96+
template<class T1, class T2, class RT>
97+
explicit sct_property_mod(bool lexpr, RT rexpr, sc_port_base& event,
9898
const char* name, T1 lotime, T2 hitime,
9999
unsigned stable) {}
100-
template<class T1>
101-
explicit sct_property_mod(bool lexpr, bool rexpr, sc_port_base& event,
100+
template<class T1, class RT>
101+
explicit sct_property_mod(bool lexpr, RT rexpr, sc_port_base& event,
102102
const char* name, T1 time, unsigned stable) {}
103103
};
104104

@@ -111,17 +111,17 @@ struct sct_property_mod
111111

112112
#define SCT_ASSERT4_STABLE(LE, TIMES, RE, EVENT)\
113113
sct_property_mod SCT_TWO(sctTmpVar,__LINE__){\
114-
static_cast<bool>(LE), static_cast<bool>(RE), EVENT,\
114+
static_cast<bool>(LE), RE, EVENT,\
115115
"sctAssertLine" SCT_ONE(__LINE__), SCT_ARGS(TIMES), 1};
116116

117117
#define SCT_ASSERT4_ROSE(LE, TIMES, RE, EVENT)\
118118
sct_property_mod SCT_TWO(sctTmpVar,__LINE__){\
119-
static_cast<bool>(LE), static_cast<bool>(RE), EVENT,\
119+
static_cast<bool>(LE), RE, EVENT,\
120120
"sctAssertLine" SCT_ONE(__LINE__), SCT_ARGS(TIMES), 2};
121121

122122
#define SCT_ASSERT4_FELL(LE, TIMES, RE, EVENT)\
123123
sct_property_mod SCT_TWO(sctTmpVar,__LINE__){\
124-
static_cast<bool>(LE), static_cast<bool>(RE), EVENT,\
124+
static_cast<bool>(LE), RE, EVENT,\
125125
"sctAssertLine" SCT_ONE(__LINE__), SCT_ARGS(TIMES), 3};
126126
#else
127127
// No parameter passed, LE/RE can use not-bound port/not-allocated pointers
@@ -140,7 +140,7 @@ struct sct_property_mod
140140

141141
#else
142142
#define SCT_ASSERT4(LE, TIMES, RE, EVENT)\
143-
sct_property* SCT_TWO(sctTmpVar,__LINE__) =\
143+
sct_property_base* SCT_TWO(sctTmpVar,__LINE__) =\
144144
sct_property_storage::getProperty(\
145145
[&]()->bool{return ( LE );},\
146146
[&]()->bool{return ( RE );},\
@@ -150,32 +150,32 @@ struct sct_property_mod
150150
);
151151

152152
#define SCT_ASSERT4_STABLE(LE, TIMES, RE, EVENT)\
153-
sct_property* SCT_TWO(sctTmpVar,__LINE__) =\
153+
sct_property_base* SCT_TWO(sctTmpVar,__LINE__) =\
154154
sct_property_storage::getPropertyStable(\
155155
[&]()->bool{return ( LE );},\
156-
[&]()->bool{return ( RE );},\
156+
[&]()->decltype(RE){return ( RE );},\
157157
&EVENT,\
158158
[&]()->sct_time{return (sct_time(SCT_ARGS(TIMES)));},\
159159
std::string(__FILE__)+":"+std::to_string(__LINE__),\
160160
stStable\
161161
);
162162

163163
#define SCT_ASSERT4_ROSE(LE, TIMES, RE, EVENT)\
164-
sct_property* SCT_TWO(sctTmpVar,__LINE__) =\
164+
sct_property_base* SCT_TWO(sctTmpVar,__LINE__) =\
165165
sct_property_storage::getPropertyStable(\
166166
[&]()->bool{return ( LE );},\
167-
[&]()->bool{return ( RE );},\
167+
[&]()->decltype(RE){return ( RE );},\
168168
&EVENT,\
169169
[&]()->sct_time{return (sct_time(SCT_ARGS(TIMES)));},\
170170
std::string(__FILE__)+":"+std::to_string(__LINE__),\
171171
stRose\
172172
);
173173

174174
#define SCT_ASSERT4_FELL(LE, TIMES, RE, EVENT)\
175-
sct_property* SCT_TWO(sctTmpVar,__LINE__) =\
175+
sct_property_base* SCT_TWO(sctTmpVar,__LINE__) =\
176176
sct_property_storage::getPropertyStable(\
177177
[&]()->bool{return ( LE );},\
178-
[&]()->bool{return ( RE );},\
178+
[&]()->decltype(RE){return ( RE );},\
179179
&EVENT,\
180180
[&]()->sct_time{return (sct_time(SCT_ARGS(TIMES)));},\
181181
std::string(__FILE__)+":"+std::to_string(__LINE__),\

components/common/sctcommon/sct_property.cpp

+2-69
Original file line numberDiff line numberDiff line change
@@ -42,73 +42,6 @@ std::string sct_property_utils::getFileName(const std::string& s)
4242
namespace sc_core {
4343

4444
// Static container of created @sct_property instances
45-
std::unordered_map<std::size_t, sct_property*> sct_property_storage::stor;
45+
std::unordered_map<std::size_t, sct_property_base*> sct_property_storage::stor;
4646

47-
// Put antecedent(left) and consequent (right) expressions every cycle
48-
void sct_property::check(bool lexpr, bool rexpr) {
49-
50-
assert (initalized && "sct_property is not initalized");
51-
52-
// Stored left expression or current one for single time zero
53-
bool lcond = pastSize ? leftPast[lindx] : lexpr;
54-
55-
if (lcond) {
56-
// Get current right expression for single time
57-
bool rcond = rexpr;
58-
59-
// Join all stored right expressions for time interval
60-
for (size_t i = 0; i < timeInt; i++) {
61-
rcond = rcond || rightPast[i];
62-
}
63-
64-
if (!rcond) {
65-
std::cout << std::endl << sc_time_stamp()
66-
<< ", Error : sct_property violation " << msg
67-
<< std::endl;
68-
assert (false);
69-
}
70-
}
71-
72-
// Store left and right expression values
73-
if (pastSize) {
74-
leftPast[lindx] = lexpr;
75-
lindx = (lindx+1) % pastSize;
76-
}
77-
if (timeInt) {
78-
rightPast[rindx] = rexpr;
79-
rindx = (rindx+1) % timeInt;
80-
}
81-
}
82-
83-
void sct_property::check(StableType stable, bool lexpr, bool rexpr) {
84-
85-
assert (initalized && "sct_property is not initalized");
86-
assert (stable == stStable || timeInt == 0);
87-
88-
bool lcond = pastSize ? leftPast[lindx] : lexpr;
89-
90-
if (lcond) {
91-
92-
bool rcond = stable == stStable ? rexpr == rightPast[0] :
93-
stable == stRose ? rexpr > rightPast[0] : rexpr < rightPast[0];
94-
for (size_t i = 0; i < timeInt; i++) {
95-
rcond = rcond && rexpr == rightPast[i+1];
96-
}
97-
if (!rcond) {
98-
std::cout << std::endl << sc_time_stamp()
99-
<< ", Error : sct_property " << stableStr
100-
<< " violation " << msg << std::endl;
101-
assert (false);
102-
}
103-
}
104-
105-
// Store left and right expression values
106-
if (pastSize) {
107-
leftPast[lindx] = lexpr;
108-
if (pastSize > 1) lindx = (lindx+1) % pastSize;
109-
}
110-
rightPast[rindx] = rexpr;
111-
if (timeInt) rindx = (rindx+1) % (timeInt+1);
112-
}
113-
114-
} // namespace sc_core
47+
}

0 commit comments

Comments
 (0)