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 
29 #include <stdio.h>
30 #include <stdlib.h>
31 
32 #define YCF_YIELD()
33 
34 
fun()35 int fun(){
36   int y = 0;
37   for(int x = 0; x < 10; x++){
38     y++;
39     for(int x = 0; x < 10; x++){
40       y++;
41     }
42   }
43   return y;
44 }
45 
allocator(size_t size,void * context)46 void* allocator(size_t size, void* context){
47   (void)context;
48   return malloc(size);
49 }
50 
freer(void * data,void * context)51 void freer(void* data, void* context){
52   (void)context;
53   free(data);
54 }
55 
main(int argc,const char * argv[])56 int main( int argc, const char* argv[] )
57 {
58 #ifdef YCF_YIELD_CODE_GENERATED
59   void* wb = NULL;
60 #endif
61   int ret = 0;
62   long nr_of_reductions = 1;
63 #ifdef YCF_YIELD_CODE_GENERATED
64   do{
65     nr_of_reductions = 1;
66     ret = fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL);
67     if(wb != NULL){
68       printf("TRAPPED\n");
69     }
70   }while(wb != NULL);
71   if(wb != NULL){
72     free(wb);
73   }
74 #else
75   ret = fun(1);
76 #endif
77   printf("RETURNED %d\n", ret);
78   if(ret != 110){
79     return 1;
80   }else{
81     return 0;
82   }
83 }
84