Mercurial > hg > CbC > CbC_gcc
annotate CbC-examples/quicksort/quicksort_test.cbc @ 35:3f5886e153cb
modify cbc_replace_args
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Dec 2009 20:49:36 +0900 |
parents | 2476ed92181e |
children |
rev | line source |
---|---|
22 | 1 #include<stdio.h> |
2 #include<stdlib.h> | |
3 #include<assert.h> | |
4 #include<unistd.h> | |
5 | |
6 #include"quicksort_test.h" | |
7 | |
25
2476ed92181e
modified machine description of i386 for support indirect sibcall attributed fastcall.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
23
diff
changeset
|
8 extern __code quicksort(int *,int,int, __code (*)(void*), void*); |
23 | 9 |
10 | |
22 | 11 void |
12 random_initialize(int *v, int size, int min, int max) | |
13 { | |
14 int i; | |
15 int diff = max-min+1; | |
16 | |
17 for (i=0; i<size; i++) { | |
18 v[i] = min+random()%diff; | |
19 } | |
20 return; | |
21 } | |
22 | |
23 static void | |
24 print_array(int *v, int size) | |
25 { | |
26 int i; | |
27 printf("["); | |
28 for (i=0; i<size; i++) { | |
29 printf("%s%4d", (i%10==0)? "\n ":" ", v[i]); | |
30 } | |
31 printf(" ]\n"); | |
32 } | |
33 | |
34 void | |
23 | 35 starter(int size) |
22 | 36 { |
37 int *target; | |
38 | |
39 target = (int*)malloc(sizeof(int)*size); | |
40 if (!target) { | |
41 perror("malloc"); | |
42 exit(1); | |
43 } | |
44 | |
45 random_initialize(target, size, 0, 90); | |
46 | |
23 | 47 //print_array(target, size); |
22 | 48 goto quicksort(target, 0, size-1, exit0, (void*)target); |
49 | |
50 printf("bad region\n"); | |
51 } | |
52 | |
25
2476ed92181e
modified machine description of i386 for support indirect sibcall attributed fastcall.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
23
diff
changeset
|
53 static int size=100; |
2476ed92181e
modified machine description of i386 for support indirect sibcall attributed fastcall.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
23
diff
changeset
|
54 |
22 | 55 int |
56 main(int argc, char **argv) | |
57 { | |
58 unsigned int seed=0; | |
59 int opt; | |
60 | |
23 | 61 while ((opt = getopt(argc, argv, "s:n:")) != -1) { |
22 | 62 switch (opt) { |
63 case 's': | |
64 seed = atoi(optarg); | |
65 break; | |
23 | 66 case 'n': |
67 size = atoi(optarg); | |
68 break; | |
22 | 69 default: |
70 fprintf(stderr, "Usage: %s [-t times] [-n sizeofarray] [-s seed]\n", argv[0]); | |
71 exit(1); | |
72 } | |
73 } | |
74 | |
75 srandom(seed); | |
23 | 76 starter(size); |
22 | 77 return 0; |
78 } | |
79 | |
80 static int | |
81 check_sort(int *v, int size) | |
82 { | |
83 int i; | |
84 for (i=0; i<size-1; i++) { | |
85 if (v[i] > v[i+1]) | |
86 return 0; | |
87 } | |
88 return 1; | |
89 } | |
90 | |
91 __code | |
92 exit0(void *arg) | |
93 { | |
94 int *v = arg; | |
95 int b; | |
25
2476ed92181e
modified machine description of i386 for support indirect sibcall attributed fastcall.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
23
diff
changeset
|
96 //print_array(arg, size); |
2476ed92181e
modified machine description of i386 for support indirect sibcall attributed fastcall.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
23
diff
changeset
|
97 b = check_sort(arg, size); |
22 | 98 if (b) { |
99 printf("sorting successful!\n"); | |
35 | 100 exit(EXIT_SUCCESS); |
22 | 101 } else { |
102 printf("sorting failure! \n"); | |
35 | 103 exit(EXIT_FAILURE); |
22 | 104 } |
105 } | |
106 |