1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 void* ycf_debug_global_stack_start_ptr = NULL;
ycf_debug_get_stack_start()6 void* ycf_debug_get_stack_start(){
7     return ycf_debug_global_stack_start_ptr;
8 }
9 #define YCF_YIELD()
10 
fun2(char * to_stack_in_other_fun)11 int fun2(char* to_stack_in_other_fun){
12     char value = *to_stack_in_other_fun;
13     YCF_YIELD();
14     if (value == 42) {
15         return 1;
16     } else {
17         return 0;
18     }
19 }
20 
21 #include "tmp.ycf.h"
22 
fun(char x)23 static int fun(char x){
24   char array[1];
25   array[0] = 42;
26   char *to_stack = &array[0];
27   x = x + 1; /* x == 2*/
28   printf("ptr to: %d", (int)(*to_stack));
29   x = x + 1; /* x == 3*/
30   {
31       int hej = 0;
32       hej = fun2(to_stack);
33       YCF_YIELD();
34       to_stack = NULL;
35       return x + hej;
36   }
37 }
38 
allocator(size_t size,void * context)39 void* allocator(size_t size, void* context){
40   (void)context;
41   return malloc(size);
42 }
43 
freer(void * data,void * context)44 void freer(void* data, void* context){
45   (void)context;
46   free(data);
47 }
48 
main(int argc,const char * argv[])49 int main( int argc, const char* argv[] )
50 {
51 #ifdef YCF_YIELD_CODE_GENERATED
52   void* wb = NULL;
53   long nr_of_reductions = 1;
54 #endif
55   int ret = 0;
56   (void)fun;
57 #ifdef YCF_YIELD_CODE_GENERATED
58   do{
59     ycf_debug_global_stack_start_ptr = &wb;
60     ret = fun_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL,1);
61     ycf_debug_global_stack_start_ptr = NULL;
62     if(wb != NULL){
63       printf("TRAPPED\n");
64     }
65   }while(wb != NULL);
66   if(wb != NULL){
67     free(wb);
68   }
69 #else
70   fun(1);
71 #endif
72   printf("RETURNED %d\n", ret);
73   if(ret != 4){
74     return 1;
75   }else{
76     return 0;
77   }
78 }
79 
80