1 /*
2 * %CopyrightBegin%
3 *
4 * Copyright Ericsson AB and Kjell Winblad 2019. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * %CopyrightEnd%
19 */
20
21 /*
22 * Description:
23 *
24 * Author: Kjell Winblad
25 *
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #define YCF_YIELD()
32
33
fun(char x)34 int fun(char x){
35 long y = x + 1; /* y == 2*/
36 YCF_YIELD();
37 {
38 int x = 10;
39 YCF_YIELD();
40 y = y + x; /* y == 12*/
41 YCF_YIELD();
42 {
43 long x = 30;
44 YCF_YIELD();
45 y = y + x; /* y == 42*/
46 YCF_YIELD();
47 }
48 YCF_YIELD();
49 y = y + x; /* y == 52*/
50 }
51 YCF_YIELD();
52 y = y + x; /* y == 53*/
53 YCF_YIELD();
54 return y;
55 }
56
allocator(size_t size,void * context)57 void* allocator(size_t size, void* context){
58 (void)context;
59 return malloc(size);
60 }
61
freer(void * data,void * context)62 void freer(void* data, void* context){
63 (void)context;
64 free(data);
65 }
66
main(int argc,const char * argv[])67 int main( int argc, const char* argv[] )
68 {
69 #ifdef YCF_YIELD_CODE_GENERATED
70 void* wb = NULL;
71 #endif
72 int ret = 0;
73 long nr_of_reductions = 1;
74 #ifdef YCF_YIELD_CODE_GENERATED
75 do{
76 ret = fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL,1);
77 if(wb != NULL){
78 printf("TRAPPED\n");
79 }
80 }while(wb != NULL);
81 if(wb != NULL){
82 free(wb);
83 }
84 #else
85 fun(1);
86 #endif
87 printf("RETURNED %d\n", ret);
88 if(ret != 53){
89 return 1;
90 }else{
91 return 0;
92 }
93 }
94