Mercurial > hg > CbC > CbC_gcc
annotate CbC-examples/test_csp1.c @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | f9b1a53df341 |
children |
rev | line source |
---|---|
16 | 1 #include<stdio.h> |
2 #include<stdlib.h> | |
3 | |
4 //static __code (*csp)(int, int, int, int); | |
5 | |
27
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
6 __code cs_end (int a); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
7 __code cs0 (int a, int b, int c, int d); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
8 void* freturn (); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
9 __code cs_goto (int a, int b, int c, int d); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
10 int function (double a, float b, int c); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
11 int main (int argc, char **argv); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
12 |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
13 |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
14 __code cs_goto(int a, int b, int c, int d){ |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
15 __code (*csp)(int, int, int, int); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
16 csp = freturn(); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
17 printf("csp = %x.\n", csp); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
18 |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
19 //printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
20 //printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
21 //printf("cs_goto : a-4=%d, a-8=%d, a-12=%d, a-16=%d.\n", *(&a-4), *(&a-8), *(&a-12), *(&a-16)); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
22 //printf("cs_goto : cs0(a, b, c, d)\n"); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
23 #ifdef INDIRECT |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
24 goto csp(b+a, d+b, a+c, c+d); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
25 #else |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
26 goto cs0(b+a, d+b, a+c, c+d); |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
27 #endif |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
28 } |
f9b1a53df341
implemented indirect sibcall for ppc.
kent@teto.cr.ie.u-ryukyu.ac.jp
parents:
16
diff
changeset
|
29 |
16 | 30 __code cs_end(int a){ |
31 printf("cs_exit : a=%d.\n", a); | |
32 exit(a); | |
33 goto cs_end(a); | |
34 } | |
35 | |
36 __code cs0(int a, int b, int c, int d){ | |
37 //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); | |
38 printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); | |
39 goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); | |
40 } | |
41 | |
42 | |
43 void* freturn(){ | |
44 return cs0; | |
45 } | |
46 | |
47 int function(double a, float b, int c){ | |
48 | |
49 printf("function:\n"); | |
50 printf("a=%lf, b=%f, c=%d\n", a, b, c); | |
51 //goto cs_goto(10, 20, 30, 40); | |
52 goto cs_goto(10, 20, 30, 40); | |
53 } | |
54 | |
55 int main(int argc, char **argv){ | |
56 //csp = cs0; | |
57 function(10.01, 20.02, 30); | |
58 return 0; | |
59 } | |
60 |