1 ****** Example1: ******
2 Global Variable Declaration
4 /* Include the header files first
5 ** This declaration will be written into a header file
7 /* @file _spec_sequential_generated.h */
8 /* @brief automatically generated file */
9 #ifndef __SPEC_SEQUENTIAL_GENERATED_H
10 #define __SPEC_SEQUENTIAL_GENERATED_H
11 #include <specannotation.h>
12 #include <spec_private_hashtable.h>
15 /* Beginning of struct Sequential */
16 typedef struct Sequential {
17 spec_private_hashtable condition;
18 spec_private_hashtable id;
19 spec_private_hashtable interface;
20 spec_private_hashtable interface_call_sequence;
21 Tag global_call_sequence;
23 /* DefineVar unfolded here */
24 spec_private_hashtable Put__Old_Val;
26 /* Beginning of other user-defined variables */
29 /* End of other user-defined variables */
31 } Sequential; /* End of struct Sequential */
33 /* Instance of the struct */
34 Sequential __sequential;
36 /* Define function for sequential code initialization */
37 void __sequential_init() {
38 /* Init internal variables */
39 init(&__sequential.condition);
40 init(&__sequential.id);
41 init(&__sequential.interface);
42 init(&__sequential.interface_call_sequence);
43 init(&global_call_sequence);
45 init(&__sequential.Put__Old_Val);
46 /* Init user-defined variables */
47 lock_acquired = false;
50 /* Pass the happens-before initialization here */
51 /* PutIfAbsent (putIfAbsent_Succ) -> Get (true) */
52 anno_hb_init hbConditionInit0;
53 hbConditionInit0.interface_num_before = 1;
54 hbConditionInit0.hb_condition_num_before = 1;
55 hbConditionInit0.interface_num_after = 2;
56 hbConditionInit0.hb_condition_num_after = 0;
57 spec_annotation hb_init0;
58 hb_init0.type = HB_INIT;
59 hb_init0.annotation = &hbConditionInit0;
60 cdsannotate(SPEC_ANALYSIS, &hb_init0);
64 /* All other user-defined functions */
65 ALL_USER_DEFINED_FUNCTIONS
71 ****** Example2: ******
74 /* Include the header files first */
76 #include <cdsannotate.h>
77 #include <specannotation.h>
79 #include <spec_private_hashtable.h>
81 TypeReturn interfaceName(ARGType1 arg1, ARGType2 arg2)
83 thrd_t tid = thrd_current();
84 uint64_t call_sequence_num = current(&__sequential.global_call_sequence);
85 next(&__sequential.global_call_sequence);
86 put(&__sequential.interface_call_sequence, tid, call_sequence_num);
89 anno_interface_boundary interface_boundary;
90 interface_boundary.interface_num = 0; // Interface number
91 interface_boundary.call_sequence_num = call_sequence_num;
92 spec_annotation annotation_interface_begin;
93 annotation_interface_begin.type = INTERFACE_BEGIN;
94 annotation_interface_begin.annotation = &interface_boundary;
95 cdsannotate(SPEC_ANALYSIS, &annoation_interface_begin);
97 TypeReturn __RET__ = __wrapper_interfaceName(arg1, arg2);
98 int __COND__ = get(&__sequential.condition, tid);
99 uint64_t __ID__ = get(&__sequential.id, tid);
101 /* Post_check action, define macros for all DefineVars */
102 #define _Old_Val (get(&__sequential.put__Old_Val, tid))
104 bool post_check_passed = INTERFACE_POST_CHECK_CONDITION;
106 anno_post_check post_check;
107 post_check.check_passed = post_check_passed;
108 post_check.interface_num = interface_num;
109 post_check.call_sequence_num = call_sequence_num;
110 spec_annotation annotation_post_check;
111 annotation_post_check.type = POST_CHECK;
112 annotation_post_check.annotation = &post_check;
113 cdsannotate(SPEC_ANALYSIS, &annotation_post_check);
115 // Post Action (if any)
116 POST_ACTION_CODE // Unfolded in place
120 // HB conditions (if any)
122 anno_hb_condition hb_condition1;
123 hb_condition1.interface_num = 0; // Interface number
124 hb_condition1.hb_condition_num = 1; // HB condition number
125 hb_condition1.id = __ID__;
126 hb_condition1.call_sequence_num = call_sequence_num;
127 spec_annotation annotation_hb_condition;
128 annotation_hb_condition.type = HB_CONDITION;
129 annotation_hb_condition.annotation = &hb_condition;
130 cdsannotate(SPEC_ANALYSIS, &annotation_hb_condition);
135 spec_annotation annotation_interface_end;
136 annotation_interface_end.type = INTERFACE_END;
137 annotation_interface_end.annotation = &interface_boundary;
138 cdsannotate(SPEC_ANALYSIS, &annoation_interface_end);
142 ****** Example3: ******
143 Potential Commit Point
146 #include <cdstrace.h>
147 #include <cdsannotate.h>
148 #include <spec_private_hashtable.h>
149 #include <_sepc_sequential_genenrated.h>
151 thrd_t tid = thrd_current();
152 uint64_t __ATOMIC_RET__ = get_prev_value(tid);
153 if (POTENTIAL_CP_DEFINE_CONDITION) {
154 uint64_t call_sequence_num = get(&__sequential.interface_call_sequence, tid);
156 anno_potential_cp_define potential_cp_define;
157 potential_cp_define.interface_num = get(&__sequential.interface, tid);
158 potential_cp_define.label_num = 1; // Commit point label number
159 potential_cp_define.call_sequence_num = call_sequence_num;
160 spec_annotation annotation_potential_cp_define;
161 annotation_potential_cp_define.type = POTENTIAL_CP_DEFINE;
162 annotation_potential_cp_define.annotation = &potential_cp_define;
163 cdsannotate(SPEC_ANALYSIS, &annotation_potential_cp_define);
166 ****** Example4: ******
170 #include <cdstrace.h>
171 #include <cdsannotate.h>
172 #include <spec_private_hashtable.h>
173 #include <_spec_sequential_generated.h>
175 thrd_t __tid = thrd_current();
176 int interface_num = get(&__sequential.interface, tid);
177 /* For all the interface check at this commit point (if there is multiple
179 /* Need to compute the relationship between labels before hand */
180 switch (interface_num) {
182 // Commit point 3 <=> potentialCP 4
183 if (COMMIT_POINT3_CONDITION && potential_cp_satisfied(3, 4)) {
184 if (INTERFACE0_CHECK_CONDITION) {
187 /* For all DefineVar of INTERFACE0 (Type id = Expr) (Type must be a
189 /* Unfold all if there are multiple DefineVars */
191 put(&__sequential.put__Old_Val, tid, (uint64_t) res0);
194 /* Compute id; If not defined, assign the default ID */
195 int id = INTERFACE0_ID_EXPRESSION;
196 put(__sequential.id, tid, id);
198 /* Execute actions if there's any */
199 #define _Old_Val res0;
200 INTERFACE0_ACTION; // Unfolded right in place
204 anno_cp_define cp_define;
205 uint64_t call_sequence_num = get(&__sequential.interface_call_sequence, tid);
206 bool check_passed = false;
207 cp_define.check_passed = check_passed;
208 cp_define.interface_num = interface_num;
209 cp_define.label_num = 3;
210 cp_define.call_sequence_num = call_sequence_num;
211 spec_annotation annotation_cp_define;
212 annotation_cp_define.type = CP_DEFINE;
213 annotation_cp_define.annotation = &cp_define;
214 cdsannotate(SPEC_ANALYSIS, &annotation_cp_define);
218 // Commit point 5 <=> potentialCP 6
219 if (COMMIT_POINT5_CONDITION && potential_cp_satisfied(5, 6)) {
220 if (INTERFACE1_CHECK_CONDITION) {
224 // Same as the above case
232 ***** Example5: ******
233 Commit Point Define Check
237 #include <cdstrace.h>
238 #include <cdsannotate.h>
239 #include <spec_private_hashtable.h>
240 #include <_spec_sequential_generated.h>
243 thrd_t __tid = thrd_current();
244 int interface_num = get(&__sequential.interface, tid);
245 /* For all the interface check at this commit point (if there is multiple
247 /* Need to compute the relationship between labels before hand */
248 switch (interface_num) {
250 if (COMMIT_POINT3_CONDITION) {
251 if (INTERFACE0_CHECK_CONDITION) {
254 /* For all DefineVar of INTERFACE0 (Type id = Expr) (Type must be a
256 /* Unfold all if there are multiple DefineVars */
258 put(&__sequential.put__Old_Val, tid, (uint64_t) res0);
261 /* Compute id; If not defined, assign the default ID */
262 int id = INTERFACE0_ID_EXPRESSION;
263 put(__sequential.id, tid, id);
265 /* Execute actions if there's any */
266 #define _Old_Val res0;
267 INTERFACE0_ACTION; // Unfolded right in place
271 anno_cp_define cp_define;
272 uint64_t call_sequence_num = get(&__sequential.interface_call_sequence, tid);
273 bool check_passed = false;
274 cp_define.check_passed = check_passed;
275 cp_define.interface_num = interface_num;
276 cp_define.label_num = 3;
277 cp_define.call_sequence_num = call_sequence_num;
278 spec_annotation annotation_cp_define;
279 annotation_cp_define.type = CP_DEFINE;
280 annotation_cp_define.annotation = &cp_define;
281 cdsannotate(SPEC_ANALYSIS, &annotation_cp_define);
285 if (COMMIT_POINT5_CONDITION) {
286 if (INTERFACE1_CHECK_CONDITION) {
290 // Same as the above case