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