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 
sub_fun(char * x)34 void sub_fun(char* x){
35   *x = *x + 1; /* x == 3*/
36   *x = *x + 1; /* x == 4*/
37 }
38 
sub_fun2(int x,int y)39 int sub_fun2(int x, int y){
40   return x+y;
41 }
42 
fun(char x)43 int fun(char x){
44   int y;
45   (void)y;
46   x = x + 1; /* x == 2*/
47   sub_fun(((&x)));
48   sub_fun2(10, 20);
49   y = sub_fun2(10, 20);
50   YCF_YIELD();
51   x = x + 1; /* x == 5*/
52   return x;
53 }
54 
allocator(size_t size,void * context)55 void* allocator(size_t size, void* context){
56   (void)context;
57   return malloc(size);
58 }
59 
freer(void * data,void * context)60 void freer(void* data, void* context){
61   (void)context;
62   free(data);
63 }
64 
main(int argc,const char * argv[])65 int main( int argc, const char* argv[] )
66 {
67 #ifdef YCF_YIELD_CODE_GENERATED
68   void* wb = NULL;
69 #endif
70   int ret = 0;
71   long nr_of_reductions = 1;
72 #ifdef YCF_YIELD_CODE_GENERATED
73   do{
74     ret = fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL,1);
75     if(wb != NULL){
76       printf("TRAPPED\n");
77     }
78   }while(wb != NULL);
79   if(wb != NULL){
80     free(wb);
81   }
82 #else
83   fun(1);
84 #endif
85   printf("RETURNED %d\n", ret);
86   if(ret != 5){
87     return 1;
88   }else{
89     return 0;
90   }
91 }
92 
93