CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
abstract_event.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: abstract events
4
5Author: Vincent Nimal
6
7Date: 2012
8
9\*******************************************************************/
10
13
14#ifndef CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H
15#define CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H
16
18#include <util/graph.h>
19
20#include "wmm.h"
21
22class abstract_eventt:public graph_nodet<empty_edget>
23{
24protected:
26 memory_modelt model, bool lwsync_met) const;
27
28public:
29 /* for now, both fence functions and asm fences accepted */
31
33 unsigned thread;
35 unsigned id;
38 bool local;
39
40 // for ASMfence
41 bool WRfence;
42 bool WWfence;
43 bool RRfence;
44 bool RWfence;
45 bool WWcumul;
46 bool RWcumul;
47 bool RRcumul;
48
63
66 unsigned _th,
68 unsigned _id,
71 bool _local)
72 : operation(_op),
73 thread(_th),
75 id(_id),
79 {
80 }
81
84 unsigned _th,
86 unsigned _id,
89 bool _local,
90 bool WRf,
91 bool WWf,
92 bool RRf,
93 bool RWf,
94 bool WWc,
95 bool RWc,
96 bool RRc)
97 : operation(_op),
98 thread(_th),
100 id(_id),
103 local(_local),
104 WRfence(RWf),
105 WWfence(WWf),
106 RRfence(RRf),
107 RWfence(WRf),
108 WWcumul(WWc),
109 RWcumul(RWc),
110 RRcumul(RRc)
111 {
112 }
113
114 /* post declaration (through graph) -- doesn't copy */
115 void operator()(const abstract_eventt &other)
116 {
117 operation=other.operation;
118 thread=other.thread;
119 variable=other.variable;
120 id=other.id;
122 function_id = other.function_id;
123 local=other.local;
124 }
125
126 bool operator==(const abstract_eventt &other) const
127 {
128 return (id == other.id);
129 }
130
131 bool operator<(const abstract_eventt &other) const
132 {
133 return (id < other.id);
134 }
135
142
143 /* checks the safety of the pair locally (i.e., w/o taking fences
144 or dependencies into account -- use is_unsafe on the whole
145 critical cycle for this) */
146 bool unsafe_pair(const abstract_eventt &next, memory_modelt model) const
147 {
148 return unsafe_pair_lwfence_param(next, model, false);
149 }
150
152 const abstract_eventt &next,
153 memory_modelt model) const
154 {
155 return unsafe_pair_lwfence_param(next, model, true);
156 }
157
158 bool unsafe_pair_asm(
159 const abstract_eventt &next,
160 memory_modelt model,
161 unsigned char met) const;
162
163 std::string get_operation() const
164 {
165 switch(operation)
166 {
167 case operationt::Write: return "W";
168 case operationt::Read: return "R";
169 case operationt::Fence: return "F";
170 case operationt::Lwfence: return "f";
171 case operationt::ASMfence: return "asm:";
172 }
174 return "?";
175 }
176
178 const abstract_eventt &second) const
179 {
180 return
181 (WRfence &&
183 second.operation==operationt::Read) ||
184 ((WWfence || WWcumul) &&
186 second.operation==operationt::Write) ||
187 ((RWfence || RWcumul) &&
189 second.operation==operationt::Write) ||
190 ((RRfence || RRcumul) &&
193 }
194
195 bool is_direct() const { return WWfence || WRfence || RRfence || RWfence; }
196 bool is_cumul() const { return WWcumul || RWcumul || RRcumul; }
197
198 unsigned char fence_value() const
199 {
200 return uc(WRfence) + 2u * uc(WWfence) + 4u * uc(RRfence) +
201 8u * uc(RWfence) + 16u * uc(WWcumul) + 32u * uc(RWcumul) +
202 64u * uc(RRcumul);
203 }
204
205private:
206 static unsigned char uc(bool truth_value)
207 {
208 return truth_value ? 1u : 0u;
209 }
210};
211
212inline std::ostream &operator<<(
213 std::ostream &s,
214 const abstract_eventt &e)
215{
216 return s << e.get_operation() << e.variable;
217}
218
219#endif // CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H
std::ostream & operator<<(std::ostream &s, const abstract_eventt &e)
bool is_cumul() const
bool unsafe_pair(const abstract_eventt &next, memory_modelt model) const
bool is_corresponding_fence(const abstract_eventt &first, const abstract_eventt &second) const
std::string get_operation() const
void operator()(const abstract_eventt &other)
static unsigned char uc(bool truth_value)
bool is_fence() const
bool unsafe_pair_lwfence(const abstract_eventt &next, memory_modelt model) const
source_locationt source_location
bool unsafe_pair_asm(const abstract_eventt &next, memory_modelt model, unsigned char met) const
bool unsafe_pair_lwfence_param(const abstract_eventt &next, memory_modelt model, bool lwsync_met) const
bool is_direct() const
abstract_eventt(operationt _op, unsigned _th, irep_idt _var, unsigned _id, source_locationt _loc, irep_idt _function_id, bool _local, bool WRf, bool WWf, bool RRf, bool RWf, bool WWc, bool RWc, bool RRc)
bool operator<(const abstract_eventt &other) const
operationt operation
abstract_eventt(operationt _op, unsigned _th, irep_idt _var, unsigned _id, source_locationt _loc, irep_idt _function_id, bool _local)
unsigned char fence_value() const
bool operator==(const abstract_eventt &other) const
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
This class represents a node in a directed graph.
Definition graph.h:35
A Template Class for Graphs.
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
memory models
memory_modelt
Definition wmm.h:18