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 int A(int depth);
35 int B(int depth);
36
A(int depth)37 int A(int depth){
38 int b;
39 YCF_YIELD();
40 depth++;
41 printf("A ");
42 YCF_YIELD();
43 if(depth == 100){
44 return 1;
45 } else {
46 b = B(depth);
47 }
48 YCF_YIELD();
49 return b + 1;
50 }
51
B(int depth)52 int B(int depth){
53 int a;
54 YCF_YIELD();
55 depth++;
56 printf("B ");
57 YCF_YIELD();
58 if(depth == 100){
59 YCF_YIELD();
60 return 1;
61 } else {
62 a = A(depth);
63 }
64 YCF_YIELD();
65 return a + 1;
66 }
67
allocator(size_t size,void * context)68 void* allocator(size_t size, void* context){
69 (void)context;
70 return malloc(size);
71 }
72
freer(void * data,void * context)73 void freer(void* data, void* context){
74 (void)context;
75 free(data);
76 }
77
main(int argc,const char * argv[])78 int main( int argc, const char* argv[] )
79 {
80 #ifdef YCF_YIELD_CODE_GENERATED
81 void* wb = NULL;
82 #endif
83 int ret = 0;
84 long nr_of_reductions = 1;
85 #ifdef YCF_YIELD_CODE_GENERATED
86 do{
87 ret = A_ycf_gen_yielding(&nr_of_reductions,&wb,NULL,allocator,freer,NULL,0,NULL,0);
88 if(wb != NULL){
89 printf("TRAPPED\n");
90 }
91 }while(wb != NULL);
92 if(wb != NULL){
93 free(wb);
94 }
95 #else
96 ret = A(0);
97 #endif
98 printf("RETURNED %d\n", ret);
99 if(ret != A(0)){
100 return 1;
101 }else{
102 return 0;
103 }
104 }
105