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 interface;
18 Tag global_call_sequence;
20 /* Beginning of other user-defined variables */
23 /* End of other user-defined variables */
25 } Sequential; /* End of struct Sequential */
27 /* Instance of the struct */
28 Sequential __sequential;
30 /* Define function for sequential code initialization */
31 void __sequential_init() {
32 /* Init internal variables */
33 init(&__sequential.interface);
34 init(&global_call_sequence);
35 /* Init user-defined variables */
36 lock_acquired = false;
39 /* Pass the happens-before initialization here */
40 /* PutIfAbsent (putIfAbsent_Succ) -> Get (true) */
41 anno_hb_init hbConditionInit0;
42 hbConditionInit0.interface_num_before = 1;
43 hbConditionInit0.hb_condition_num_before = 1;
44 hbConditionInit0.interface_num_after = 2;
45 hbConditionInit0.hb_condition_num_after = 0;
46 spec_annotation hb_init0;
47 hb_init0.type = HB_INIT;
48 hb_init0.annotation = &hbConditionInit0;
49 cdsannotate(SPEC_ANALYSIS, &hb_init0);
52 /* All other user-defined functions */
53 ALL_USER_DEFINED_FUNCTIONS
59 ****** Example2: ******
62 /* Include the header files first */
64 #include <cdsannotate.h>
65 #include <specannotation.h>
67 #include <spec_private_hashtable.h>
69 TypeReturn interfaceName(ARGType1 arg1, ARGType2 arg2)
71 thrd_t tid = thrd_current();
72 uint64_t call_sequence_num = current(&__sequential.global_call_sequence);
73 next(&__sequential.global_call_sequence);
74 put(&__sequential.interface_call_sequence, tid, call_sequence_num);
77 anno_interface_boundary interface_boundary;
78 interface_boundary.interface_num = 0; // Interface number
79 interface_boundary.call_sequence_num = call_sequence_num;
80 spec_annotation annotation_interface_begin;
81 annotation_interface_begin.type = INTERFACE_BEGIN;
82 annotation_interface_begin.annotation = &interface_boundary;
83 cdsannotate(SPEC_ANALYSIS, &annoation_interface_begin);
86 TypeReturn __RET__ = __wrapper_interfaceName(arg1, arg2);
87 int __COND__ = get(&__sequential.condition, tid);
88 uint64_t __ID__ = get(&__sequential.id, tid);
90 /* Post_check action, define macros for all DefineVars */
91 #define _Old_Val (get(&__sequential.put__Old_Val, tid))
93 bool post_check_passed = INTERFACE_POST_CHECK_CONDITION;
95 anno_post_check post_check;
96 post_check.check_passed = post_check_passed;
97 post_check.interface_num = interface_num;
98 post_check.call_sequence_num = call_sequence_num;
99 spec_annotation annotation_post_check;
100 annotation_post_check.type = POST_CHECK;
101 annotation_post_check.annotation = &post_check;
102 cdsannotate(SPEC_ANALYSIS, &annotation_post_check);
104 // Post Action (if any)
105 POST_ACTION_CODE // Unfolded in place
109 // HB conditions (if any)
111 anno_hb_condition hb_condition1;
112 hb_condition1.interface_num = 0; // Interface number
113 hb_condition1.hb_condition_num = 1; // HB condition number
114 hb_condition1.id = __ID__;
115 hb_condition1.call_sequence_num = call_sequence_num;
116 spec_annotation annotation_hb_condition;
117 annotation_hb_condition.type = HB_CONDITION;
118 annotation_hb_condition.annotation = &hb_condition;
119 cdsannotate(SPEC_ANALYSIS, &annotation_hb_condition);
124 spec_annotation annotation_interface_end;
125 annotation_interface_end.type = INTERFACE_END;
126 annotation_interface_end.annotation = &interface_boundary;
127 cdsannotate(SPEC_ANALYSIS, &annoation_interface_end);
131 ****** Example3: ******
132 Potential Commit Point
135 #include <cdstrace.h>
136 #include <cdsannotate.h>
137 #include <spec_private_hashtable.h>
138 #include <_sepc_sequential_genenrated.h>
140 thrd_t tid = thrd_current();
141 uint64_t __ATOMIC_RET__ = get_prev_value(tid);
142 if (POTENTIAL_CP_DEFINE_CONDITION) {
143 uint64_t call_sequence_num = get(&__sequential.interface_call_sequence, tid);
145 anno_potential_cp_define potential_cp_define;
146 potential_cp_define.interface_num = get(&__sequential.interface, tid);
147 potential_cp_define.label_num = 1; // Commit point label number
148 potential_cp_define.call_sequence_num = call_sequence_num;
149 spec_annotation annotation_potential_cp_define;
150 annotation_potential_cp_define.type = POTENTIAL_CP_DEFINE;
151 annotation_potential_cp_define.annotation = &potential_cp_define;
152 cdsannotate(SPEC_ANALYSIS, &annotation_potential_cp_define);
155 ****** Example4: ******
159 #include <cdstrace.h>
160 #include <cdsannotate.h>
161 #include <spec_private_hashtable.h>
162 #include <_spec_sequential_generated.h>
164 thrd_t __tid = thrd_current();
165 int interface_num = get(&__sequential.interface, tid);
166 /* For all the interface check at this commit point (if there is multiple
168 /* Need to compute the relationship between labels before hand */
169 switch (interface_num) {
171 // Commit point 3 <=> potentialCP 4
172 if (COMMIT_POINT3_CONDITION && potential_cp_satisfied(3, 4)) {
173 if (INTERFACE0_CHECK_CONDITION) {
176 /* For all DefineVar of INTERFACE0 (Type id = Expr) (Type must be a
178 /* Unfold all if there are multiple DefineVars */
180 put(&__sequential.put__Old_Val, tid, (uint64_t) res0);
183 /* Compute id; If not defined, assign the default ID */
184 int id = INTERFACE0_ID_EXPRESSION;
185 put(__sequential.id, tid, id);
187 /* Execute actions if there's any */
188 #define _Old_Val res0;
189 INTERFACE0_ACTION; // Unfolded right in place
193 anno_cp_define cp_define;
194 uint64_t call_sequence_num = get(&__sequential.interface_call_sequence, tid);
195 bool check_passed = false;
196 cp_define.check_passed = check_passed;
197 cp_define.interface_num = interface_num;
198 cp_define.label_num = 3;
199 cp_define.call_sequence_num = call_sequence_num;
200 spec_annotation annotation_cp_define;
201 annotation_cp_define.type = CP_DEFINE;
202 annotation_cp_define.annotation = &cp_define;
203 cdsannotate(SPEC_ANALYSIS, &annotation_cp_define);
207 // Commit point 5 <=> potentialCP 6
208 if (COMMIT_POINT5_CONDITION && potential_cp_satisfied(5, 6)) {
209 if (INTERFACE1_CHECK_CONDITION) {
213 // Same as the above case
221 ***** Example5: ******
222 Commit Point Define Check
226 #include <cdstrace.h>
227 #include <cdsannotate.h>
228 #include <spec_private_hashtable.h>
229 #include <_spec_sequential_generated.h>
232 thrd_t __tid = thrd_current();
233 int interface_num = get(&__sequential.interface, tid);
234 /* For all the interface check at this commit point (if there is multiple
236 /* Need to compute the relationship between labels before hand */
237 switch (interface_num) {
239 if (COMMIT_POINT3_CONDITION) {
240 if (INTERFACE0_CHECK_CONDITION) {
243 /* For all DefineVar of INTERFACE0 (Type id = Expr) (Type must be a
245 /* Unfold all if there are multiple DefineVars */
247 put(&__sequential.put__Old_Val, tid, (uint64_t) res0);
250 /* Compute id; If not defined, assign the default ID */
251 int id = INTERFACE0_ID_EXPRESSION;
252 put(__sequential.id, tid, id);
254 /* Execute actions if there's any */
255 #define _Old_Val res0;
256 INTERFACE0_ACTION; // Unfolded right in place
260 anno_cp_define cp_define;
261 uint64_t call_sequence_num = get(&__sequential.interface_call_sequence, tid);
262 bool check_passed = false;
263 cp_define.check_passed = check_passed;
264 cp_define.interface_num = interface_num;
265 cp_define.label_num = 3;
266 cp_define.call_sequence_num = call_sequence_num;
267 spec_annotation annotation_cp_define;
268 annotation_cp_define.type = CP_DEFINE;
269 annotation_cp_define.annotation = &cp_define;
270 cdsannotate(SPEC_ANALYSIS, &annotation_cp_define);
274 if (COMMIT_POINT5_CONDITION) {
275 if (INTERFACE1_CHECK_CONDITION) {
279 // Same as the above case