• R/O
  • SSH

GCC: Commit

Continuation based C on GCC


Commit MetaInfo

Revisão0e48f0ff4a49505ee43e06a0ef3cef264962fc32 (tree)
Hora2008-04-13 07:47:45
Autorshinji_kono
Commitershinji_kono

Mensagem de Log

*** empty log message ***

Mudança Sumário

Diff

diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-implemantation.ja
--- a/CbC-implemantation.ja Tue Mar 18 20:10:50 2008 +0900
+++ b/CbC-implemantation.ja Sun Apr 13 07:47:45 2008 +0900
@@ -7,14 +7,18 @@
77 $ mkdir build-test
88 $ cd build-test
99 $ CFLAGS=-O0 ../GCC/configure --disable-nls --disable-bootstrap \
10- > --enable-languages=c --prefix=$PWD/INSTALL-DIR \
11- > --enable-checking=tree,rtl,assert
10+ --enable-languages=c --prefix=$PWD/INSTALL-DIR \
11+ --enable-checking=tree,rtl,assert
1212 $ make
1313 $ make install
1414 installまでしないと環境によってはinclude<stdio.h>に問題が出る場合がある
1515 実際に使用する場合はconfigureには何もオプションはつけないでいい
1616 CFLAGSには "-O0 -gdwarf-2 -g3"をつけると gdbでのmacro表示できる
1717
18+ $ CFLAGS="-O0 -gdwarf-2 -g3" ../GCC/configure --disable-nls --disable-bootstrap \
19+ --enable-languages=c --prefix=$PWD/INSTALL-DIR \
20+ --enable-checking=tree,rtl,assert
21+
1822
1923 CVS管理
2024 GCC new release のインポート
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-implemantation.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-implemantation.txt Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,84 @@
1+
2+Notes on Continuation based C implementation on GCC
3+
4+Sun Apr 13 07:30:44 JST 2008
5+
6+How to BUILD
7+
8+Like normal gcc compilation, it is better to configure it in different directory.
9+
10+ $ cd ../
11+ $ mkdir build-test
12+ $ cd build-test
13+ $ CFLAGS=-O0 ../GCC/configure --disable-nls --disable-bootstrap \
14+ --enable-languages=c --prefix=$PWD/INSTALL-DIR \
15+ --enable-checking=tree,rtl,assert
16+ $ make
17+ $ make install
18+
19+We recommend install because stdio.h may make some troubles. All
20+CbC dependent parts are marked as #ifndef NoCbC, so no special
21+flag is necessary for configure. All flags are debugging purpose.
22+
23+We recommend CFLAGS "-O0 -gdwarf-2 -g3" to show a macro in gdb.
24+
25+ $ CFLAGS="-O0 -gdwarf-2 -g3" ../GCC/configure --disable-nls --disable-bootstrap \
26+ --enable-languages=c --prefix=$PWD/INSTALL-DIR \
27+ --enable-checking=tree,rtl,assert
28+
29+
30+CVS management
31+
32+ Import GCC new release
33+ $ wget gcc-core-4.x.y.tar.gz
34+ $ tar xzvf gcc-core-4.x.y.tar.gz
35+ $ cd gcc-core-4.x.y.tar.gz
36+ $ cvs import -ko -m "comment" CbC_project/GCC FSF_GCC REL_4_x_y
37+
38+
39+ How to Merge local fix
40+
41+ In an empty directory,
42+ $ cvs checkout -jREL_4_._. -j REL_4_x_y CbC_project/GCC
43+
44+ or already existing CVS checkout-ed directory
45+ $ cvs update -jREL_4_._. -j REL_4_x_y
46+
47+ 4_._. is previous version
48+ conflict have to be fix by hands
49+
50+ after successful check
51+ $ cvs commit
52+
53+ this should complete merging new release
54+
55+
56+How to debug the compiler
57+ use gdb on cc1 not on gcc command,
58+
59+ $ ls
60+ GCC/ build-test/ test/
61+ $ cd test
62+ $ gdb ../build-test/gcc/cc1
63+
64+ to show tree
65+ (gdb) p browse_tree (exp) <== exp is a tree type
66+
67+ to show rtx
68+ (gdb) p debug_rtx (exp) <== exp is a rtx type
69+
70+ to use browse_tree and debug_rtx, in configure
71+ option --enable-checking tree, rtx is necessary in
72+ configure.
73+
74+
75+ to show macro
76+ use CFLAGS='-O0 -gdwarf-2 -g3' in configure in clean directory
77+ (gdb) macro expand MACRO(a)
78+ (gdb) info macro MACRO
79+ (gdb) help macro
80+
81+
82+
83+
84+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/arg.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/arg.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,100 @@
1+#include "stdio.h"
2+
3+struct arg {
4+ int a0;int a1;int a2;int a3;int a4;
5+};
6+
7+extern void exit(int);
8+
9+void *exit_env;
10+__code (*exit___code)();
11+
12+__code carg1(int arg0,int arg1,int arg2,int arg3,int arg4,__code(*exit1)(),void *env)
13+{
14+ printf("#0011:arg1: %d %d %d %d %d : %x %x\n",arg0,arg1,arg2,arg3,arg4,exit1==exit___code,env==exit_env);
15+ goto carg2(arg1,arg2,arg3,arg4,arg0,exit1,env);
16+}
17+
18+__code carg2(int arg0,int arg1,int arg2,int arg3,int arg4,__code(*exit1)(),void *env)
19+{
20+ struct arg args0;
21+ printf("#0018:arg1: %d %d %d %d %d : %x %x\n",arg0,arg1,arg2,arg3,arg4,exit1==exit___code,env==exit_env );
22+ args0.a0 = arg0;
23+ args0.a1 = arg1;
24+ args0.a2 = arg2;
25+ args0.a3 = arg3;
26+ args0.a4 = arg4;
27+ goto cargs(args0,exit1,env);
28+}
29+
30+__code cargs(struct arg args0,__code exit1(),void *env)
31+{
32+ printf("#0029:args: %d %d %d %d %d : %x %x\n",
33+ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,
34+ exit1==exit___code,env==exit_env);
35+ // goto exit1(321),env;
36+ goto (*exit1)(0),env;
37+}
38+
39+
40+__code carg3(struct arg args0,struct arg args1,int i, int j,int k,int l)
41+{
42+ printf("#0039:args3: %d %d %d %d %d : %x %x %x %x\n",
43+ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
44+ printf("#0041:args3: args0 %d %d %d %d %d : args1 %d %d %d %d %d : %x %x %x %x\n",
45+ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,
46+ args1.a0,args1.a1,args1.a2,args1.a3,args1.a4,
47+ i,j,k,l);
48+ if (args0.a0==args1.a0) exit(0);
49+ goto carg4(args0,args1,j,k,l,i);
50+}
51+
52+__code carg4(struct arg args0,struct arg args1,int i, int j,int k,int l)
53+{
54+ printf("#0051:args4: %d %d %d %d %d : %x %x %x %x\n",
55+ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
56+ goto carg5(args1,args0,j,k,l,i);
57+}
58+
59+__code carg5(struct arg args0,struct arg args1,int i, int j,int k,int l)
60+{
61+ printf("#0058:args5: %d %d %d %d %d : %x %x %x %x\n",
62+ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
63+ goto carg6(i,j,k,l,args0);
64+}
65+
66+__code carg6(int i, int j,int k,int l,struct arg args0)
67+{
68+ printf("#0065:args6: %d %d %d %d %d : %x %x %x %x\n",
69+ args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,i,j,k,l);
70+ goto carg3(args0,args0,i,j,k,l);
71+}
72+
73+int main1(int n)
74+{
75+ goto carg1(0,1,2,3,4,exit___code=__return,exit_env=__environment);
76+ return n;
77+}
78+
79+struct arg a00;
80+struct arg a01;
81+
82+int main( int ac, char *av[])
83+{
84+ int n;
85+ n = main1(123);
86+ printf("#0083:321=%d\n",n);
87+
88+ a00.a0 = 11;
89+ a00.a1 = 22;
90+ a00.a2 = 33;
91+ a00.a3 = 44;
92+ a00.a4 = 55;
93+ a01.a0 = 66;
94+ a01.a1 = 77;
95+ a01.a2 = 88;
96+ a01.a3 = 99;
97+ a01.a4 = 10;
98+ goto carg3(a00,a01,1,2,3,4);
99+}
100+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/basic-code.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/basic-code.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,88 @@
1+int printf(const char *format, ...);
2+
3+__code
4+f50(
5+float a0,float a1,float a2,float a3,float a4,float a5,float a6,float a7,float a8,float a9,float a10,float a11,float a12,float a13,float a14,float a15,float a16,float a17,float a18,float a19,float a20,float a21,float a22,float a23,float a24,float a25,float a26,float a27,float a28,float a29,float a30,float a31,float a32,float a33,float a34,float a35,float a36,float a37,float a38,float a39,float a40,float a41,float a42,float a43,float a44,float a45,float a46,float a47,float a48,float a49
6+);
7+
8+
9+__code
10+d50(
11+double a0,double a1,double a2,double a3,double a4,double a5,double a6,double a7,double a8,double a9,double a10,double a11,double a12,double a13,double a14,double a15,double a16,double a17,double a18,double a19,double a20,double a21,double a22,double a23,double a24,double a25,double a26,double a27,double a28,double a29,double a30,double a31,double a32,double a33,double a34,double a35,double a36,double a37,double a38,double a39,double a40,double a41,double a42,double a43,double a44,double a45,double a46,double a47,double a48,double a49
12+);
13+
14+__code
15+i50(
16+int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12,int a13,int a14,int a15,int a16,int a17,int a18,int a19,int a20,int a21,int a22,int a23,int a24,int a25,int a26,int a27,int a28,int a29,int a30,int a31,int a32,int a33,int a34,int a35,int a36,int a37,int a38,int a39,int a40,int a41,int a42,int a43,int a44,int a45,int a46,int a47,int a48,int a49
17+)
18+{
19+ printf("#0018:i50: %d\n",
20+a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20+a21+a22+a23+a24+a25+a26+a27+a28+a29+a30+a31+a32+a33+a34+a35+a36+a37+a38+a39+a40+a41+a42+a43+a44+a45+a46+a47+a48+a49
21+ );
22+ printf("#0021:%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47,a48,a49);
23+
24+ goto f50(
25+0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,37.0,38.0,39.0,40.0,41.0,42.0,43.0,44.0,45.0,46.0,47.0,48.0,49.0
26+);
27+}
28+
29+__code
30+f50(
31+float a0,float a1,float a2,float a3,float a4,float a5,float a6,float a7,float a8,float a9,float a10,float a11,float a12,float a13,float a14,float a15,float a16,float a17,float a18,float a19,float a20,float a21,float a22,float a23,float a24,float a25,float a26,float a27,float a28,float a29,float a30,float a31,float a32,float a33,float a34,float a35,float a36,float a37,float a38,float a39,float a40,float a41,float a42,float a43,float a44,float a45,float a46,float a47,float a48,float a49
32+)
33+{
34+ printf("#0036:f50: %g\n",
35+a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20+a21+a22+a23+a24+a25+a26+a27+a28+a29+a30+a31+a32+a33+a34+a35+a36+a37+a38+a39+a40+a41+a42+a43+a44+a45+a46+a47+a48+a49
36+ );
37+ printf("#0039:%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g \n",
38+a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47,a48,a49);
39+
40+ goto d50(
41+0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,37.0,38.0,39.0,40.0,41.0,42.0,43.0,44.0,45.0,46.0,47.0,48.0,49.0
42+);
43+}
44+
45+__code
46+d50(
47+double a0,double a1,double a2,double a3,double a4,double a5,double a6,double a7,double a8,double a9,double a10,double a11,double a12,double a13,double a14,double a15,double a16,double a17,double a18,double a19,double a20,double a21,double a22,double a23,double a24,double a25,double a26,double a27,double a28,double a29,double a30,double a31,double a32,double a33,double a34,double a35,double a36,double a37,double a38,double a39,double a40,double a41,double a42,double a43,double a44,double a45,double a46,double a47,double a48,double a49
48+)
49+{
50+ printf("#0054:d50: %g\n",
51+a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20+a21+a22+a23+a24+a25+a26+a27+a28+a29+a30+a31+a32+a33+a34+a35+a36+a37+a38+a39+a40+a41+a42+a43+a44+a45+a46+a47+a48+a49
52+ );
53+ printf("#0057:%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g \n",
54+a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47,a48,a49);
55+
56+ goto exit0();
57+}
58+
59+__code (*ret)(int);
60+void *env;
61+
62+__code
63+exit0()
64+{
65+ goto (*ret)(0),env;
66+}
67+
68+
69+int
70+main0()
71+{
72+
73+ret = __return;
74+env = __environment;
75+goto
76+i50(
77+0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49
78+);
79+
80+}
81+
82+
83+
84+int
85+main() {
86+ printf("#0092:%d\n",main0());
87+ return 0;
88+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/conv.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/conv.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,86 @@
1+#include "stdio.h"
2+
3+f0(int i) {
4+ int k,j;
5+ k = 3+i;
6+ j = g0(i+3);
7+ return k+4+j;
8+}
9+
10+g0(int i) {
11+ return i+4;
12+}
13+
14+typedef char *stack;
15+
16+struct cont_interface { // General Return Continuation
17+ __code (*ret)();
18+};
19+
20+__code f(int i,stack sp) {
21+ int k,j;
22+ k = 3+i;
23+ goto f_g0(i,k,sp);
24+}
25+
26+struct f_g0_interface { // Specialized Return Continuation
27+ __code (*ret)();
28+ int i_,k_,j_;
29+};
30+
31+__code f_g1(int j,stack sp);
32+
33+__code f_g0(int i,int k,stack sp) { // Caller
34+ struct f_g0_interface *c =
35+ (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
36+
37+ c->ret = f_g1;
38+ c->k_ = k;
39+ c->i_ = i;
40+
41+ goto g(i+3,sp);
42+}
43+
44+__code f_g1(int j,stack sp) { // Continuation
45+ struct f_g0_interface *c = (struct f_g0_interface *)sp;
46+ int k = c->k_;
47+ sp += sizeof(struct f_g0_interface);
48+ goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp);
49+}
50+
51+__code g(int i,stack sp) {
52+ goto (( (struct cont_interface *)sp)->ret)(i+4,sp);
53+}
54+
55+struct main_continuation { // General Return Continuation
56+ __code (*ret)();
57+ __code (*main_ret)();
58+ void *env;
59+};
60+
61+__code main_return(int i,stack sp) {
62+ printf("#0061:%d\n",i);
63+ goto (( (struct main_continuation *)sp)->main_ret)(0),
64+ ((struct main_continuation *)sp)->env;
65+}
66+
67+#define STACK_SIZE 2048
68+char main_stack[STACK_SIZE];
69+#define stack_last (&main_stack[STACK_SIZE])
70+
71+main()
72+{
73+ struct main_continuation *cont;
74+ stack sp = stack_last;
75+
76+ printf("#0075:%d\n",f0(233));
77+
78+ sp -= sizeof(*cont);
79+ cont = (struct main_continuation *)sp;
80+ cont->ret = main_return;
81+ cont->main_ret = __return;
82+ cont->env = __environment;
83+ goto f(233,sp);
84+}
85+
86+/* end */
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/conv1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/conv1.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,225 @@
1+#include "stdio.h"
2+
3+static int loop;
4+
5+#if 1 // def __micro_c__
6+#define CC_ONLY 0
7+#else
8+#define CC_ONLY 1
9+#endif
10+
11+/* classical function call case (0) */
12+
13+f0(int i) {
14+ int k,j;
15+ k = 3+i;
16+ j = g0(i+3);
17+ return k+4+j;
18+}
19+
20+g0(int i) {
21+ return h0(i+4)+i;
22+}
23+
24+h0(int i) {
25+ return i+4;
26+}
27+
28+#if !CC_ONLY
29+
30+/* straight conversion case (1) */
31+
32+typedef char *stack;
33+
34+struct cont_interface { // General Return Continuation
35+ __code (*ret)();
36+};
37+
38+__code f(int i,stack sp) {
39+ int k,j;
40+ k = 3+i;
41+ goto f_g0(i,k,sp);
42+}
43+
44+struct f_g0_interface { // Specialized Return Continuation
45+ __code (*ret)();
46+ int i_,k_,j_;
47+};
48+
49+__code f_g1(int j,stack sp);
50+
51+__code f_g0(int i,int k,stack sp) { // Caller
52+ struct f_g0_interface *c =
53+ (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
54+
55+ c->ret = f_g1;
56+ c->k_ = k;
57+ c->i_ = i;
58+
59+ goto g(i+3,sp);
60+}
61+
62+__code f_g1(int j,stack sp) { // Continuation
63+ struct f_g0_interface *c = (struct f_g0_interface *)sp;
64+ int k = c->k_;
65+ sp+=sizeof(struct f_g0_interface);
66+ c = (struct f_g0_interface *)sp;
67+ goto (c->ret)(k+4+j,sp);
68+}
69+
70+__code g_h1(int j,stack sp);
71+
72+__code g(int i,stack sp) { // Caller
73+ struct f_g0_interface *c =
74+ (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface));
75+
76+ c->ret = g_h1;
77+ c->i_ = i;
78+
79+ goto h(i+3,sp);
80+}
81+
82+__code g_h1(int j,stack sp) { // Continuation
83+ struct f_g0_interface *c = (struct f_g0_interface *)sp;
84+ int i = c->i_;
85+ sp+=sizeof(struct f_g0_interface);
86+ c = (struct f_g0_interface *)sp;
87+ goto (c->ret)(j+i,sp);
88+}
89+
90+__code h(int i,stack sp) {
91+ struct f_g0_interface *c = (struct f_g0_interface *)sp;
92+ goto (c->ret)(i+4,sp);
93+}
94+
95+struct main_continuation { // General Return Continuation
96+ __code (*ret)();
97+ __code (*main_ret)();
98+ void *env;
99+};
100+
101+__code main_return(int i,stack sp) {
102+ if (loop-->0)
103+ goto f(233,sp);
104+ printf("#0103:%d\n",i);
105+ goto (( (struct main_continuation *)sp)->main_ret)(0),
106+ ((struct main_continuation *)sp)->env;
107+}
108+
109+/* little optimzation without stack continuation (2) */
110+
111+__code f2(int i,char *sp) {
112+ int k,j;
113+ k = 3+i;
114+ goto g2(i,k,i+3,sp);
115+}
116+
117+__code g2(int i,int k,int j,char *sp) {
118+ j = j+4;
119+ goto h2(i,k+4+j,sp);
120+}
121+
122+__code h2_1(int i,int k,int j,char *sp) {
123+ goto main_return2(i+j,sp);
124+}
125+
126+__code h2(int i,int k,char *sp) {
127+ goto h2_1(i,k,i+4,sp);
128+}
129+
130+__code main_return2(int i,stack sp) {
131+ if (loop-->0)
132+ goto f2(233,sp);
133+ printf("#0132:%d\n",i);
134+ goto (( (struct main_continuation *)sp)->main_ret)(0),
135+ ((struct main_continuation *)sp)->env;
136+}
137+
138+/* little optimizaed case (3) */
139+
140+__code f2_1(int i,char *sp) {
141+ int k,j;
142+ k = 3+i;
143+ goto g2_1(k,i+3,sp);
144+}
145+
146+__code g2_1(int k,int i,char *sp) {
147+ goto h2_11(k,i+4,sp);
148+}
149+
150+__code f2_0_1(int k,int j,char *sp);
151+__code h2_1_1(int i,int k,int j,char *sp) {
152+ goto f2_0_1(k,i+j,sp);
153+}
154+
155+__code h2_11(int i,int k,char *sp) {
156+ goto h2_1_1(i,k,i+4,sp);
157+}
158+
159+__code f2_0_1(int k,int j,char *sp) {
160+ goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp);
161+}
162+
163+__code main_return2_1(int i,stack sp) {
164+ if (loop-->0)
165+ goto f2_1(233,sp);
166+ printf("#0165:%d\n",i);
167+ goto (( (struct main_continuation *)sp)->main_ret)(0),
168+ ((struct main_continuation *)sp)->env;
169+}
170+
171+#define STACK_SIZE 2048
172+char main_stack[STACK_SIZE];
173+#define stack_last (main_stack+STACK_SIZE)
174+
175+#endif
176+
177+#define LOOP_COUNT 10000000
178+
179+main(int ac,char *av[])
180+{
181+#if !CC_ONLY
182+ struct main_continuation *cont;
183+ stack sp = stack_last;
184+#endif
185+ int sw;
186+ int j;
187+ if (ac==2) sw = atoi(av[1]);
188+ else sw=3;
189+
190+ if (sw==0) {
191+ for(loop=0;loop<LOOP_COUNT;loop++) {
192+ j = f0(233);
193+ }
194+ printf("#0193:%d\n",j);
195+#if !CC_ONLY
196+ } else if (sw==1) {
197+ loop = LOOP_COUNT;
198+ sp -= sizeof(*cont);
199+ cont = (struct main_continuation *)sp;
200+ cont->ret = main_return;
201+ cont->main_ret = __return;
202+ cont->env = __environment;
203+ goto f(233,sp);
204+ } else if (sw==2) {
205+ loop = LOOP_COUNT;
206+ sp -= sizeof(*cont);
207+ cont = (struct main_continuation *)sp;
208+ cont->ret = main_return2;
209+ cont->main_ret = __return;
210+ cont->env = __environment;
211+ goto f2(233,sp);
212+ } else if (sw==3) {
213+ loop = LOOP_COUNT;
214+ sp -= sizeof(*cont);
215+ cont = (struct main_continuation *)sp;
216+ cont->ret = main_return2_1;
217+ cont->main_ret = __return;
218+ cont->env = __environment;
219+ goto f2_1(233,sp);
220+#endif
221+ }
222+return 0;
223+}
224+
225+/* end */
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/fact-a.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/fact-a.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,33 @@
1+#include "stdio.h"
2+
3+__code factorial(int n,int result,int orig,__code(*print)(),__code(*exit1)(), void *exit1env)
4+{
5+ if (n<0) {
6+ printf("#0005:err %d!\n",n);
7+ goto (*exit1)(0),exit1env;
8+ }
9+ if (n==0)
10+ goto (*print)(n,result,orig,print,exit1,exit1env);
11+ else {
12+ result *= n;
13+ n--;
14+ goto factorial(n,result,orig,print,exit1,exit1env);
15+ }
16+}
17+
18+__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(),void*exit1env);
19+
20+int main( int ac, char *av[])
21+{
22+ int n;
23+ // n = atoi(av[1]);
24+ n = 10;
25+ goto factorial(n,1,n,print,__return,__environment);
26+}
27+
28+__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(),void*exit1env)
29+{
30+ printf("#0029:%d! = %d\n",orig, result);
31+ goto (*exit1)(0),exit1env;
32+}
33+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/fact.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/fact.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,41 @@
1+#include "stdio.h"
2+__code print();
3+int
4+main(ac,av)
5+int ac;
6+char *av[];
7+{
8+ int n;
9+ // n = atoi(av[1]);
10+ n = 10;
11+ goto factorial(n,1,n,print,__return,__environment);
12+}
13+
14+__code print(n,result,orig,print,exit1,exit1env)
15+int n,result,orig;
16+__code (*print)(),(*exit1)();
17+void *exit1env;
18+{
19+ printf("#0018:%d! = %d\n",n, result);
20+ goto (*exit1)(0),exit1env;
21+}
22+
23+__code factorial(n,result,orig,print,exit1,exit1env)
24+int n,result,orig;
25+__code (*print)();
26+__code (*exit1)();
27+void *exit1env;
28+{
29+ if (n<0) {
30+ printf("#0029:err %d!\n",n);
31+ goto (*exit1)(0),exit1env;
32+ }
33+ if (n==0)
34+ goto (*print)(n,result,orig,print,exit1,exit1env);
35+ /* goto print(n,result,orig,print,exit1,exit1env); */
36+ else {
37+ result *= n;
38+ n--;
39+ goto factorial(n,result,orig,print,exit1,exit1env);
40+ }
41+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/func_conv_err.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/func_conv_err.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,41 @@
1+
2+__code hoge()
3+{
4+ goto hoge(); // ok
5+}
6+
7+int
8+f()
9+{
10+ return 1;
11+}
12+
13+__code hoga(int i)
14+{
15+ f(); // ok
16+ h(); // ok h() is a function
17+ if (i)
18+ goto f(); // bad
19+ else if(i-1)
20+ goto g(i); // ok g() is a __code segement
21+} // need goto bad
22+
23+int
24+g(int i) { // g is already used as __code bad
25+ k();
26+ if (i)
27+ goto h(); // bad
28+ // should complain.... no return value
29+}
30+
31+__code k() { // bad k is already used as function
32+ goto hoge(); // ok
33+}
34+
35+int
36+main()
37+{
38+ hoge(); // bad
39+ return 0;
40+}
41+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/goto.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/goto.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,93 @@
1+extern int printf(const char *,...);
2+
3+__code (*conv)(int,__code (*)());
4+__code a2(int i,__code conv());
5+__code a3(int i,__code conv());
6+__code a4(int i,__code conv());
7+__code a5(int i,__code conv());
8+__code a6();
9+__code a7();
10+__code a8();
11+__code a9();
12+
13+char* print_conv(__code conv());
14+
15+__code (*exit0)(int);
16+void *env;
17+
18+__code
19+a2(int i,__code conv())
20+{
21+ printf("#0020:a2 %d %s\n",i,print_conv(conv));
22+ goto conv(i+1,a4);
23+}
24+
25+__code
26+a3(int i,__code (*conv)())
27+{
28+ printf("#0027:a3 %d %s\n",i,print_conv(conv));
29+ goto conv(i+1,a5);
30+}
31+
32+__code
33+a4(int i,__code conv())
34+{
35+ printf("#0034:a4 %d %s\n",i,print_conv(conv));
36+ goto (*conv)(i+1,a6);
37+}
38+
39+__code
40+a5(int i,__code (*conv)())
41+{
42+ printf("#0041:a5 %d %s\n",i,print_conv(conv));
43+ goto (*conv)(i+1,i+2,i+3,a7);
44+}
45+
46+__code
47+a6(int i,int j,int k,__code conv())
48+{
49+ printf("#0048:a6 %d %s\n",i,print_conv(conv));
50+ goto conv(i+1,j,k,a8);
51+}
52+
53+__code
54+a7(int i,int j,int k,__code (*conv)())
55+{
56+ printf("#0055:a7 %d %s\n",i,print_conv(conv));
57+ goto conv(i+1,j,k,a9);
58+}
59+
60+__code
61+a8(int i,int j,int k,__code conv())
62+{
63+ printf("#0062:a8 %d %s\n",i,print_conv(conv));
64+ goto (*conv)(i+1,j,k,exit0);
65+}
66+
67+__code
68+a9(int i,int j,int k,__code (*conv)())
69+{
70+ printf("#0069:a9 %d %s\n",i,print_conv(conv));
71+ goto (*conv)(0),env;
72+}
73+
74+main(int ac,char *av[]) {
75+ exit0 = __return;
76+ env = __environment;
77+ conv = a2;
78+ goto conv(1,a3);
79+}
80+
81+char*
82+print_conv(__code conv())
83+{
84+ if(conv==a2) return "a2";
85+ if(conv==a3) return "a3";
86+ if(conv==a4) return "a4";
87+ if(conv==a5) return "a5";
88+ if(conv==a6) return "a6";
89+ if(conv==a7) return "a7";
90+ if(conv==a8) return "a8";
91+ if(conv==a9) return "a9";
92+ else return "xx";
93+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/hoge.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/hoge.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,60 @@
1+#include <stdio.h>
2+// #include "hoge.h"
3+// #include "task.h"
4+
5+struct task;
6+
7+typedef
8+struct pkt {
9+ int val;
10+ __code (*next)(struct pkt *,struct task *);
11+} Pkt, *PktPtr;
12+
13+
14+typedef
15+struct task {
16+ int val;
17+ __code (*next)(struct pkt *,struct task *);
18+} Task, *TaskPtr;
19+
20+int count = 5;
21+
22+void *env;
23+__code (*exit0)(int);
24+
25+__code scheduler(PktPtr pkt, TaskPtr task)
26+{
27+ if (count-->0)
28+ goto pkt->next(pkt,task);
29+ goto exit0(0),env;
30+}
31+
32+__code modulo(PktPtr pkt, TaskPtr current_task);
33+
34+__code increment(PktPtr pkt, TaskPtr current_task)
35+{
36+ pkt->val++;
37+ printf("inc: %d\n", pkt->val);
38+ pkt->next = modulo;
39+ goto scheduler(pkt, current_task);
40+}
41+
42+__code modulo(PktPtr pkt, TaskPtr current_task)
43+{
44+ pkt->val %= 10;
45+ pkt->val = pkt->val % 10;
46+ printf("mod: %d\n", pkt->val);
47+ pkt->next = increment;
48+ goto scheduler(pkt, current_task);
49+}
50+
51+static Pkt pkt;
52+static Task task;
53+
54+int
55+main()
56+{
57+ exit0 = __return;
58+ env = __environment;
59+ goto increment(&pkt,&task);
60+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/longcode.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/longcode.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,60 @@
1+
2+typedef struct teki {
3+ float x;
4+ float y;
5+ float sx;
6+ float sy;
7+ int charno;
8+ char tama;
9+ char f;
10+ int p;
11+ int move;
12+ int sc;
13+ int dt1;
14+ int dt2;
15+} teki;
16+
17+
18+
19+typedef struct player {
20+ int x;
21+ int y;
22+ int ch;
23+ int point;
24+ char bf;
25+ int muteki;
26+ int zanki;
27+ int ccount;
28+} player;
29+
30+struct move_interface {
31+ int y;
32+ int ch;
33+ int point;
34+ char bf;
35+ int muteki;
36+ int zanki;
37+ int ccount;
38+};
39+
40+__code
41+put_enemy_bung(
42+ __code(*junction)(int,teki *,player,struct move_interface),
43+ int tekino,
44+ teki *enemy,
45+ player jiki,
46+ struct move_interface interface);
47+
48+__code
49+move13_1(int tekino,teki *enemy,player jiki,struct move_interface interface);
50+
51+__code
52+move13(int tekino,teki *enemy,player jiki,struct move_interface interface)
53+{
54+ if (enemy[tekino].f == 0 ) {
55+
56+ goto put_enemy_bung(move13_1,tekino,enemy,jiki,interface);
57+ }
58+ goto move13_1(tekino,enemy,jiki,interface);
59+}
60+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/ps2code.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/ps2code.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,68 @@
1+#ifndef INLINE
2+#define INLINE
3+#endif
4+
5+int printf(const char *,...);
6+void bzero(void *b, unsigned int len);
7+
8+
9+
10+typedef float ps2_vu0_fmatrix[4][4] __attribute__((aligned (16)));
11+typedef ps2_vu0_fmatrix FMATRIX;
12+
13+typedef float ps2_vu0_fmatrix1[4][4];
14+typedef ps2_vu0_fmatrix1 FMATRIX1;
15+
16+
17+void ps2_vu0_unit_matrix(ps2_vu0_fmatrix m)
18+{
19+ printf("%g\n",m[1][1]);
20+ m[1][1] = -0.5;
21+}
22+
23+
24+#define mod16(a) (((int)(&a))%16)
25+
26+__code
27+align16(int i, FMATRIX a, FMATRIX b) {
28+ FMATRIX m;
29+ FMATRIX n;
30+ int k = i;
31+ FMATRIX o;
32+ ps2_vu0_unit_matrix(a);
33+ if (i==0) goto align16_1(2,a,b);
34+ printf("offset %d\n",((char*)a) - ((char*)(&m)));
35+ printf("%d %d %d\n",mod16(m),mod16(n),mod16(o));
36+ goto align16(i-1,m,n);
37+}
38+
39+__code (*exit0)(int);
40+void *env;
41+
42+__code
43+align16_1(int i, FMATRIX1 a, FMATRIX1 b) {
44+ FMATRIX1 m;
45+ FMATRIX1 n;
46+ int k = i;
47+ FMATRIX1 o;
48+ ps2_vu0_unit_matrix(a);
49+ if (i==0) goto exit0(0),env;
50+ printf("offset %d\n",((char*)a) - ((char*)(&m)));
51+ printf("%d %d %d\n",mod16(m),mod16(n),mod16(o));
52+ goto align16_1(i-1,m,n);
53+}
54+
55+
56+int
57+main(int ac, char *av[])
58+{
59+ FMATRIX m;
60+
61+ m[1][1] = 0.5;
62+ exit0 = return;
63+ env = environment;
64+ goto align16(2,m,m);
65+}
66+
67+
68+/* end */
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/ret_check.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/ret_check.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,96 @@
1+extern int printf(char *,...);
2+
3+#ifdef __micro_c__
4+
5+____code(*f_incl_ret)(int);
6+void *f_incl_env;
7+
8+__code
9+f_incl2(int a0)
10+{ // 正しいのはコッチ
11+ printf("#0010:%d\n",a0);
12+ goto f_incl_ret(a0),f_incl_env;
13+}
14+
15+__code
16+f_incl2_test(float a0)
17+{ // ret先のinterface型が異なる
18+ printf("#0017:%g\n",a0);
19+ goto f_incl_ret(a0),f_incl_env;
20+}
21+
22+__code
23+f_incl1(int a0,__code(*ret)(int))
24+{
25+ printf("#0024:%d\n",a0);
26+ goto ret(a0*a0);
27+}
28+
29+int
30+f_incl0(int a0)
31+{
32+ f_incl_ret=return;
33+ f_incl_env=environment;
34+ printf("#0033:%d\n",a0);
35+ goto f_incl1(a0,f_incl2);
36+}
37+
38+int
39+f_incl0_test(int a0)
40+{
41+ f_incl_ret=return;
42+ f_incl_env=environment;
43+ printf("#0033:%d\n",a0);
44+ goto f_incl1(a0,f_incl2_test);
45+}
46+
47+#else
48+
49+int
50+f_incl0(int a0)
51+{
52+ printf("#0042:%d\n",a0);
53+ return a0;
54+}
55+
56+int
57+f_incl0_test(int a0)
58+{
59+ printf("#0042:%d\n",a0);
60+ return a0;
61+}
62+
63+#endif
64+
65+int
66+g_incl2(int a0)
67+{
68+ printf("#0051:%d\n",a0);
69+ return a0;
70+}
71+
72+int
73+g_incl2_test(float a0)
74+{
75+ printf("#0058:%g\n",a0);
76+ return (int) a0;
77+}
78+
79+int
80+g_incl1(int a0,int (*ret)(int))
81+{
82+ return ret(a0);
83+}
84+
85+int
86+main()
87+{
88+ int f0=f_incl0(10);
89+ printf("#0066:%d\n",f0);
90+ printf("#0066:%d\n",f_incl0_test(11));
91+ printf("#0067:%d\n",g_incl1(12,g_incl2));
92+ printf("#0068:%d\n",g_incl1(13,g_incl2_test));
93+ return 0;
94+}
95+
96+/* end */
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/test1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/test1.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,120 @@
1+/*
2+ test for CbC converted __code from C
3+ */
4+
5+#include <stdio.h>
6+
7+extern void *malloc(int);
8+
9+typedef void *stack;
10+
11+void *stack0; /* size of void* == 1 */
12+
13+struct cont_save { /* General Return Continuation */
14+ __code (*ret)();
15+};
16+
17+/*
18+ __code g(int,void *);
19+ __code f_g0(int ,int ,void *);
20+ __code f_g1(int,void *);
21+*/
22+
23+struct f_g0_save { /* Specialized Return Continuation */
24+ __code (*ret)();
25+ int ii,kk,jj;
26+};
27+
28+__code g(int i,void *sp) {
29+ goto (* ((struct cont_save *)sp)->ret)(i+4,sp);
30+}
31+
32+__code f_g1(int j,void *sp) { /* Continuation */
33+ int k;
34+ struct f_g0_save *c;
35+
36+ c = sp;
37+ k = c->kk;
38+ sp += sizeof(struct f_g0_save);
39+ goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp);
40+}
41+
42+__code f(int i,void *sp) {
43+ int k,j;
44+ struct f_g0_save *c;
45+printf("#0042:f 0 sp: %x\n",sp-stack0);
46+
47+ k = 3+i;
48+
49+printf("#0046:f 1 sp: %x\n",sp-stack0);
50+ sp -= sizeof(struct f_g0_save);
51+printf("#0048:f 2 sp: %x\n",sp-stack0);
52+ c = sp;
53+ c->kk = k;
54+ c->ii = i;
55+ c->jj = j;
56+ c->ret = f_g1;
57+ goto g(i,sp);
58+}
59+
60+
61+
62+struct f0_save { /* Specialized Return Continuation */
63+ __code (*ret)();
64+ __code (*exit1)();
65+ void *exit1env;
66+ int jj;
67+};
68+
69+__code f1(int i,void *sp) ;
70+__code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp)
71+{
72+ struct f0_save *c;
73+ printf("#0070:f0 1 sp: %x\n",sp-stack0);
74+ sp -= sizeof(struct f0_save);
75+ printf("#0072:f0 2 sp: %x\n",sp-stack0);
76+ c = sp;
77+ c->jj = j;
78+ c->exit1 = exit2;
79+ c->exit1env = exit2env;
80+ c->ret = f1;
81+ printf("#0078:f0 3 sp: %x\n",sp-stack0);
82+ goto f(i,sp);
83+}
84+
85+__code f1(int i,void *sp) {
86+ int j;
87+ int *exit2env;
88+ __code (*exit2)();
89+ struct f0_save *c;
90+
91+ c = sp;
92+ j = c->jj;
93+ exit2 = c->exit1;
94+ exit2env = c->exit1env;
95+
96+ sp += sizeof(struct f0_save);
97+ goto print(i,j,exit2,exit2env);
98+}
99+
100+int main( int ac, char *av[])
101+{
102+ int i,j;
103+ int *sp;
104+
105+ // i = atoi(av[1]);
106+ i = 1;
107+ stack0 = ((char *)malloc(1024)+1024);
108+ sp = stack0;
109+ j = i;
110+
111+ printf("#0108:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0));
112+ goto f0(i,j,__return,__environment,sp);
113+}
114+
115+__code print(int i,int j,__code (*exit1)(),void*exit1env)
116+{
117+ printf("#0114:%d %d\n",i,j);
118+ goto (*exit1)(0),exit1env;
119+}
120+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/test2.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/test2.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,42 @@
1+#include <stdio.h>
2+int sender_bit;
3+
4+__code (*ret)(int);
5+void *env;
6+
7+struct packet {
8+ int bit;
9+ char *msg;
10+ __code (*next)();
11+};
12+
13+__code print_struct(struct packet pkt)
14+{
15+ printf("bit: %d\n", pkt.bit);
16+ printf("message: %s\n", pkt.msg);
17+ goto ret(0), env;
18+}
19+
20+__code initSender(int init_bit, struct packet pkt)
21+{
22+ sender_bit = init_bit;
23+ pkt.next = print_struct;
24+ printf("initSender bit: %d\n", pkt.bit);
25+ printf("initSender message: %s\n", pkt.msg);
26+ printf("sender_bit: %d\n", sender_bit);
27+ goto print_struct(pkt);
28+}
29+
30+int main(void)
31+{
32+ struct packet pkt;
33+ pkt.bit = 1;
34+ pkt.msg = "hogehoge";
35+ pkt.next = initSender;
36+ ret = __return;
37+ env = __environment;
38+ printf("main bit: %d\n", pkt.bit);
39+ printf("main message: %s\n", pkt.msg);
40+ goto initSender(0, pkt);
41+}
42+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/throw.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/throw.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,116 @@
1+
2+extern int printf(const char *,...);
3+extern void *malloc(int);
4+
5+__code (*ret)();
6+void *env;
7+
8+#define ENVSIZE (1<<14)
9+
10+typedef
11+struct interface1 {
12+ int a;
13+ int b;
14+ char c[100];
15+ int last;
16+} interface1;
17+
18+__code
19+throw2(interface1 arg,int i,int j)
20+{
21+ goto ret(3),env;
22+}
23+
24+__code
25+throw1(interface1 arg,int i,int j)
26+{
27+ printf("%d %d %d %d %d\n",arg.last,arg.a,arg.c[99],i,j);
28+ arg.last=96;
29+ goto throw2(arg,i,74);
30+}
31+
32+__code
33+throw(interface1 arg,int i,int j)
34+{
35+ char *space = (char *)malloc(ENVSIZE)+ENVSIZE;
36+ printf("%d %d %d %d %d\n",arg.last,arg.a,arg.c[99],i,j);
37+ arg.last=97;
38+ goto throw1(arg,i,75),space;
39+}
40+
41+void
42+setup(interface1 *arg)
43+{
44+ register int i;
45+ for(i=0;i<100;i++) arg->c[i]=i;
46+}
47+
48+int
49+main0()
50+{
51+ interface1 arg;
52+
53+ arg.a = 3;
54+ arg.b = 55;
55+ setup(&arg);
56+ arg.c[99] = 66;
57+ arg.last = 96;
58+
59+ printf("main0\n");
60+ ret = __return;
61+ env = __environment;
62+
63+ goto throw(arg,-7,76);
64+}
65+
66+int
67+main1()
68+{
69+ int dummy;
70+ int dummy1;
71+ interface1 arg;
72+ char *space = (char *)malloc(ENVSIZE)+ENVSIZE;
73+
74+ arg.a = 3;
75+ arg.b = 55;
76+ setup(&arg);
77+ arg.c[99] = 66;
78+ arg.last=98;
79+
80+ printf("main1\n");
81+ ret = __return;
82+ env = __environment;
83+
84+ goto throw1(arg,-6,77),space;
85+}
86+
87+int
88+main2()
89+{
90+ int dummy;
91+ interface1 arg;
92+ char *space = (char *)malloc(ENVSIZE)+ENVSIZE;
93+
94+ arg.a = 3;
95+ arg.b = 55;
96+ setup(&arg);
97+ arg.c[99] = 66;
98+ arg.last=99;
99+
100+ printf("main2\n");
101+ ret = __return;
102+ env = __environment;
103+
104+ goto throw1(arg,-5,78);
105+}
106+
107+int
108+main()
109+{
110+ main0();
111+ main1();
112+ main2();
113+ return 0;
114+}
115+
116+/* end */
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/tmp1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/tmp1.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,91 @@
1+/* easy test */
2+
3+extern int printf(const char *,...);
4+
5+__code (*ret)();
6+void *env;
7+__code exit1(int ac);
8+
9+main0(ac,av)
10+int ac;
11+char *av[];
12+{
13+ ret = __return;
14+ env = __environment;
15+ printf("#0012:main0 %d start.\n",ac);
16+ if (ac>=1)
17+ goto code0(ac,av,__return);
18+ goto code1(ac,av,exit1);
19+ // not reached. (warning?)
20+ printf("#0017:main0 %d end.\n",ac);
21+}
22+
23+__code exit1(int ac)
24+{
25+ // exit(0);
26+ goto code3(0,1,2,3,4,5);
27+}
28+
29+__code code3(a,b,c,d,e,f)
30+char a,b;
31+int c,d,e,f;
32+{
33+ printf("#0030:code3: %d %d %d %d %d %d\n",a,b,c,d,e,f);
34+ if(a<10)
35+ goto code3(a+1,b,c,d,e,f);
36+ else
37+ goto code4(a+3,b+3,c+3,d+3,e+3,f+3);
38+}
39+
40+__code code4(a,b,c,d,e,f)
41+char a,b;
42+int c,d,e,f;
43+{
44+ int i=1,j=2;
45+ printf("#0042:code4: %d %d %d %d %d %d\n",a,b,c,d,e,f);
46+ if(a<20) // cyclic binary dependency
47+ goto code3(a+b,b+c,c+d,d+e,e+f,f+a);
48+ else if(a<30)
49+ goto code3(a,b,c,d,e,f);
50+ else if(a<40) // cyclic dependency
51+ goto code3(b,c,a,e,f,d);
52+ else if(a<50)
53+ goto code4(a+i,b+j,c+i,d+3,e+3,f+3);
54+ else goto ret(0),env;
55+}
56+
57+__code code0(ac,av,ret)
58+int ac;
59+char *av[];
60+__code (*ret)(int);
61+{
62+ goto code1(ac,av,ret);
63+}
64+
65+__code code1(ac,av,exit)
66+int ac;
67+__code (*exit)(int);
68+char *av[];
69+{
70+ __code (*f)(int);
71+ printf("#0067:code1: %d\n",ac);
72+ f = exit;
73+ if (ac>3)
74+ goto code1(ac,av,f);
75+ else if (ac>2)
76+ goto code1(av,ac,f);
77+ else
78+ goto (*f)(ac),env;
79+}
80+
81+int
82+main(int ac,char *av[])
83+{
84+ main0(1,av);
85+ printf("#0081:main continue.\n");
86+ main0(0,av);
87+ printf("#0083:main end.\n");
88+return 0;
89+}
90+
91+/* end */
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/tmp2.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/tmp2.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,41 @@
1+#include "stdio.h"
2+
3+int
4+main(ac,av)
5+int ac;
6+char *av[];
7+{
8+ int i;
9+ i=main0(ac,av);
10+ fprintf(stdout,"1: %s %d\n",av[0],i);
11+ return 0;
12+}
13+
14+int
15+main0(ac,av)
16+int ac;
17+char *av[];
18+{
19+ fprintf(stdout,"2: %s\n",av[0]);
20+ goto code0(av,__return,__environment);
21+}
22+
23+__code code0(av,ret,retenv)
24+char *av[];
25+__code (*ret)();
26+void *retenv;
27+{
28+ char *p;
29+ p = av[0];
30+ fprintf(stdout,"3: %s\n",p);
31+ goto code1(av,ret,retenv);
32+}
33+
34+__code code1(av,ret,retenv)
35+char *av[];
36+__code (*ret)();
37+void *retenv;
38+{
39+ fprintf(stdout,"4: %s\n",av[0]);
40+ goto (*ret)(1234),retenv;
41+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/tmp4.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/tmp4.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,58 @@
1+#include "stdio.h"
2+
3+int
4+main(ac,av)
5+int ac;
6+char *av[];
7+{
8+ int i;
9+ i=main0(ac,av);
10+ fprintf(stdout,"1: %s %d\n",av[0]+2,i);
11+ return 0;
12+}
13+
14+int
15+main0(ac,av)
16+int ac;
17+char *av[];
18+{
19+ int i,j,k;
20+ i=123;
21+ j=456;
22+ k=789;
23+ fprintf(stdout,"2: %s\n",av[0]+2);
24+ goto code0(i,j,k,av,__return,__environment);
25+}
26+
27+__code code0(i,j,k,av,ret,retenv)
28+int i,j,k;
29+char *av[];
30+__code (*ret)();
31+void *retenv;
32+{
33+ char *p;
34+ p = av[0]+2;
35+ fprintf(stdout,"3: i=%d j=%d k=%d av[0]=%s p=%s\n",i,j,k,av[0]+2,p);
36+ goto code1(i,j,k,av,ret,retenv);
37+}
38+
39+__code code1(i,j,k,av,ret,retenv)
40+int i,j,k;
41+char *av[];
42+__code (*ret)();
43+void *retenv;
44+{
45+ fprintf(stdout,"4: %s\n",av[0]+2);
46+ goto code2(i,j,k,av,ret,retenv);
47+}
48+
49+__code code2(i,j,k,av,ret,retenv)
50+int i,j,k;
51+char *av[];
52+__code (*ret)();
53+void *retenv;
54+{
55+ fprintf(stdout,"5: %s\n",av[0]+2);
56+ fprintf(stdout,"5: i=%d j=%d k=%d\n",i,j,k);
57+ goto (*ret)(1234),retenv;
58+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/tmp6.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/tmp6.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,77 @@
1+#include "stdio.h"
2+
3+char *a[] = {"test1","2"};
4+
5+int
6+main(ac,av)
7+int ac;
8+char *av[];
9+{
10+ int i;
11+
12+ if(ac!=2) {
13+ fprintf(stdout,"#0012:a used.\n");
14+ // return(0);
15+ i=main0(2,a,__return,__environment);
16+ return 0;
17+ }
18+ i=main0(ac,av,__return,__environment);
19+ fprintf(stdout,"#0018:1: %s %d\n",av[0],i);
20+ return 0;
21+}
22+
23+int
24+main0(ac,av,ret,retenv)
25+int ac;
26+char *av[];
27+__code (*ret)();
28+void *retenv;
29+{
30+ int i,j,k;
31+ i=123;
32+ j=456;
33+ k = atoi(av[1]);
34+ fprintf(stdout,"#0033:2: av=%x av[0]=%x %s\n",av==a,av[0]==a[0],av[0]);
35+ goto code0(i,j,k,av,ret,retenv,__return,__environment);
36+}
37+
38+__code code0(i,j,k,av,ret,retenv,ret1,ret1env)
39+int i,j,k;
40+char *av[];
41+__code (*ret)();
42+void *retenv;
43+__code (*ret1)();
44+void *ret1env;
45+{
46+ char *p;
47+ p = av[0];
48+ fprintf(stdout,"#0047:code0\n",av[0]);
49+ goto code1(i,j,k,av,ret,retenv,ret1,ret1env);
50+}
51+
52+__code code1(i,j,k,av,ret,retenv,ret1,ret1env)
53+int i,j,k;
54+char *av[];
55+__code (*ret)();
56+void *retenv;
57+__code (*ret1)();
58+void *ret1env;
59+{
60+ fprintf(stdout,"#0059:4: %s\n",av[0]);
61+ goto code2(i,j,k,av,ret,retenv,ret1,ret1env);
62+}
63+
64+__code code2(i,j,k,av,ret,retenv,ret1,ret1env)
65+int i,j,k;
66+char *av[];
67+__code (*ret)();
68+void *retenv;
69+__code (*ret1)();
70+void *ret1env;
71+{
72+ fprintf(stdout,"#0071:5: %s\n",av[0]);
73+ fprintf(stdout,"#0072:5: i=%d j=%d k=%d av=%x\n",i,j,k,av==a);
74+ if (k>3)
75+ goto (*ret1)(1234),ret1env;
76+ goto (*ret)(1234),retenv;
77+}
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/tmpa.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/tmpa.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,46 @@
1+#include <stdio.h>
2+
3+struct enemy{
4+ int charno; // image number
5+ float x; // x location
6+ float y; // y location
7+ int ap; // armor point
8+};
9+void
10+print_param(struct enemy *e)
11+{
12+ printf("#0011:charno:%d x,y:%f,%f hp:%d\n",
13+ e->charno,e->x,e->y,e->ap);
14+}
15+
16+typedef struct{
17+ char dest;
18+ int VF01[4];
19+ __code (*ret)();
20+ void *env;
21+} interface;
22+
23+__code a0(interface a) {
24+ printf("#0023:%d\n",a.dest);
25+ goto a.ret(0),a.env;
26+}
27+
28+
29+int main(int argc,char *argv[])
30+{
31+ struct enemy e;
32+#if 0
33+ interface args = {15,{0,0,0,0},return,environment};
34+#else
35+ interface args = {15,{0,0,0,0},0,0};
36+ args.ret = __return;
37+ args.env = __environment;
38+#endif
39+
40+ e.charno=5; e.x=50.0; e.y=30.0; e.ap=100;
41+ print_param(&e);
42+
43+ printf("#0042:%d %d\n",args.VF01[2],args.VF01[1]);
44+ goto a0(args);
45+}
46+
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 CbC-test/too-long-argument.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-test/too-long-argument.c Sun Apr 13 07:47:45 2008 +0900
@@ -0,0 +1,101 @@
1+#include <stdio.h>
2+
3+#undef WRONGNUMBER
4+
5+typedef __code
6+(*CCC)( int f1,int f2,int f3,int f4,int f5,int f6,int f7,int f8,int f9,int fa,int fb,int fc,int fd,int fe,int ff,
7+ __code(*ret)(int),
8+ void *env);
9+
10+__code
11+tcode2( int f1,int f2,int f3,int f4,int f5,int f6,int f7,int f8,int f9,int fa,int fb,int fc,int fd,int fe,int ff,
12+ __code(*ret)(int),
13+ void *env)
14+{
15+fprintf(stdout,"tcode2: f1=%d,f2=%d,f3=%d,f4=%d,f5=%d,f6=%d,f7=%d,f8=%d,f9=%d,fa=%d,fb=%d,fc=%d,fd=%d,fe=%d,ff=%d\n",
16+f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff);
17+ goto ret(0),env;
18+}
19+
20+__code
21+tcode1(f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff,ret,env)
22+ int f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff;
23+ __code(*ret)(int);
24+ void *env;
25+{
26+fprintf(stdout,"tcode1: f1=%d,f2=%d,f3=%d,f4=%d,f5=%d,f6=%d,f7=%d,f8=%d,f9=%d,fa=%d,fb=%d,fc=%d,fd=%d,fe=%d,ff=%d\n",
27+f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff);
28+ goto ret(0),env;
29+}
30+
31+__code
32+tcode4(int x,int y,CCC junction,__code(*ret)(int),void *env)
33+{
34+#ifdef WRONGNUMBER
35+ goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,ret,env);
36+#else
37+ goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env);
38+#endif
39+}
40+
41+__code
42+tcode0(int x,int y,__code(*junction)(int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,__code(*)(int),void *),__code(*ret)(int),void *env)
43+{
44+#ifdef WRONGNUMBER
45+ goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,ret,env);
46+#else
47+ goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env);
48+#endif
49+}
50+
51+int
52+main0()
53+{
54+#ifdef WRONGNUMBER
55+ goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
56+ __return,__environment);
57+#else
58+ goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
59+ __return,__environment);
60+#endif
61+}
62+
63+int
64+main1()
65+{
66+#ifdef WRONGNUMBER
67+ goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13,
68+ __return,__environment);
69+#else
70+ goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
71+ __return,__environment);
72+#endif
73+}
74+
75+int
76+main2()
77+{
78+ goto tcode0(0,1,tcode1,__return,__environment);
79+}
80+
81+int
82+main4()
83+{
84+ goto tcode4(0,1,tcode2,__return,__environment);
85+}
86+
87+int
88+main()
89+{
90+ printf("#0089:main4\n");
91+ main4();
92+ printf("#0091:main2\n");
93+ main2();
94+ printf("#0093:main0\n");
95+ main0();
96+ printf("#0095:main1\n");
97+ main1();
98+return 0;
99+}
100+
101+//
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/c-common.h
--- a/gcc/c-common.h Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/c-common.h Sun Apr 13 07:47:45 2008 +0900
@@ -101,7 +101,7 @@
101101
102102 #ifndef noCbC
103103 /* Continuation based C */
104- RID_CbC_CODE, RID_CbC_ENV,
104+ RID_CbC_CODE, RID_CbC_ENV, RID_CbC_RET,
105105 #endif
106106
107107 RID_MAX,
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/c-decl.c
--- a/gcc/c-decl.c Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/c-decl.c Sun Apr 13 07:47:45 2008 +0900
@@ -62,6 +62,7 @@
6262 #include "pointer-set.h"
6363 #ifndef noCbC
6464 #include "cbc-tree.h"
65+tree cbc_return;
6566 #endif
6667
6768 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
@@ -2333,8 +2334,13 @@
23332334 /* Generate an implicit declaration for identifier FUNCTIONID as a
23342335 function of type int (). */
23352336
2337+#ifndef noCbC
2338+tree
2339+implicitly_declare (tree functionid, int fun)
2340+#else
23362341 tree
23372342 implicitly_declare (tree functionid)
2343+#endif
23382344 {
23392345 struct c_binding *b;
23402346 tree decl = 0;
@@ -2409,7 +2415,12 @@
24092415 }
24102416
24112417 /* Not seen before. */
2418+#ifndef noCbC
2419+ decl = build_decl (FUNCTION_DECL, functionid,
2420+ fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type);
2421+#else
24122422 decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2423+#endif
24132424 DECL_EXTERNAL (decl) = 1;
24142425 TREE_PUBLIC (decl) = 1;
24152426 C_DECL_IMPLICIT (decl) = 1;
@@ -5976,10 +5987,10 @@
59765987 static void cbc_set_codesegment(tree fndecl){
59775988 tree args;
59785989 tree *nextp;
5979- tree itype;
5980- tree icst;
5981- tree padding_array;
5982- tree list;
5990+// tree itype;
5991+// tree icst;
5992+// tree padding_array;
5993+// tree list;
59835994 int padding_size = CbC_STACK_SIZE;
59845995
59855996 //CbC_IS_CODE_SEGMENT(TREE_TYPE(fndecl)) = 1;
@@ -6083,6 +6094,7 @@
60836094 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL);
60846095
60856096 #ifndef noCbC
6097+ cbc_return = 0;
60866098 if ( declspecs->typespec_word == cts_CbC_code )
60876099 {
60886100 cbc_set_codesegment(decl1);
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/c-parser.c
--- a/gcc/c-parser.c Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/c-parser.c Sun Apr 13 07:47:45 2008 +0900
@@ -125,6 +125,7 @@
125125 #ifndef noCbC
126126 /* CbC project */
127127 { "__environment", RID_CbC_ENV, 0 },
128+ { "__return", RID_CbC_RET, 0 },
128129 #endif
129130 { "__extension__", RID_EXTENSION, 0 },
130131 { "__func__", RID_C99_FUNCTION_NAME, 0 },
@@ -1436,11 +1437,13 @@
14361437 DECL_SOURCE_LOCATION (current_function_decl)
14371438 = c_parser_peek_token (parser)->location;
14381439 store_parm_decls ();
1440+ push_scope();
14391441 fnbody = c_parser_compound_statement (parser);
14401442 if (nested)
14411443 {
14421444 tree decl = current_function_decl;
14431445 add_stmt (fnbody);
1446+ pop_scope();
14441447 finish_function ();
14451448 pop_function_context ();
14461449 add_stmt (build_stmt (DECL_EXPR, decl));
@@ -1448,6 +1451,16 @@
14481451 else
14491452 {
14501453 add_stmt (fnbody);
1454+#ifndef noCbC
1455+ if (cbc_return) {
1456+ tree tlab = define_label(input_location,cbc_return);
1457+ tree stmt= build_stmt (LABEL_EXPR, tlab);
1458+ add_stmt(stmt);
1459+ // c_finish_return(build_int_cst(NULL_TREE,0));
1460+ cbc_return =0;
1461+ }
1462+#endif
1463+ pop_scope();
14511464 finish_function ();
14521465 }
14531466 break;
@@ -3748,39 +3761,6 @@
37483761 if (c_parser_next_token_is (parser, CPP_NAME))
37493762 {
37503763 #endif
3751- /*
3752- tree id = c_parser_peek_token (parser)->value;
3753- c_parser_consume_token (parser);
3754- if ( !c_parser_next_token_is (parser, CPP_OPEN_PAREN) )
3755- {
3756- stmt = c_finish_goto_label (id);
3757- }
3758- else //CbC goto statement
3759- {
3760- struct c_expr expr;
3761- tree exprlist;
3762- // from c_parser_postfix_expression
3763- expr.value = build_external_ref (id, 1, loc);
3764- expr.original_code = ERROR_MARK;
3765-
3766- c_parser_consume_token (parser);
3767- // from c_parser_postfix_expression_after_primary
3768- if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
3769- exprlist = NULL_TREE;
3770- else
3771- exprlist = c_parser_expr_list (parser, true);
3772- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
3773- "expected %<)%>");
3774- expr.value = build_function_call (expr.value, exprlist);
3775- CbC_IS_CbC_GOTO (expr.value) = 1;
3776- CALL_EXPR_TAILCALL (expr.value) = 1;
3777- //expr.value->common.lang_flag_5 = 1;
3778- expr.original_code = ERROR_MARK;
3779- expr = default_function_array_conversion (expr);
3780- stmt = c_finish_return (expr.value);
3781- CbC_HAVE_CbC_GOTO (current_function_decl) = 1;
3782- }
3783- */
37843764 stmt = c_finish_goto_label (c_parser_peek_token (parser)->value);
37853765 c_parser_consume_token (parser);
37863766 }
@@ -3793,17 +3773,37 @@
37933773 #ifndef noCbC
37943774 {
37953775 struct c_expr expr;
3796- expr = c_parser_postfix_expression (parser);
3776+ struct c_expr env;
3777+ if (c_parser_next_token_is (parser, CPP_NAME))
3778+ {
3779+ tree id = c_parser_peek_token (parser)->value;
3780+ location_t loc = c_parser_peek_token (parser)->location;
3781+ build_external_ref (id,RID_CbC_CODE , loc);
3782+ }
3783+ expr = c_parser_expr_no_commas (parser, NULL);
37973784 if (TREE_CODE(expr.value) == CALL_EXPR )
37983785 {
3799-
3786+ TREE_TYPE(expr.value) = void_type_node;
3787+ if (c_parser_next_token_is (parser, CPP_COMMA))
3788+ {
3789+ c_parser_consume_token (parser);
3790+ env = c_parser_expr_no_commas (parser, NULL);
3791+ env = default_function_array_conversion (env);
3792+/*
3793+ expr.value->attributes = cainon(
3794+ build_tree_list(env_keyword,env),
3795+ expr.value->attributes);
3796+ */
3797+ }
38003798 CbC_IS_CbC_GOTO (expr.value) = 1;
38013799 CALL_EXPR_TAILCALL (expr.value) = 1;
3802- stmt = c_finish_return (expr.value);
3800+ // stmt = c_finish_return (expr.value);
3801+ add_stmt(expr.value);
38033802 CbC_HAVE_CbC_GOTO (current_function_decl) = 1;
3803+ stmt = c_finish_return (0);
38043804 }
38053805 else
3806- c_parser_error (parser, "expected identifier or %<*%>");
3806+ c_parser_error (parser, "expected code segment jump or %<*%>");
38073807 }
38083808 #else
38093809 c_parser_error (parser, "expected identifier or %<*%>");
@@ -5478,6 +5478,21 @@
54785478 expr.original_code = ERROR_MARK;
54795479 }
54805480 break;
5481+#ifndef noCbC
5482+ case RID_CbC_ENV:
5483+ expr.value = build_int_cst (NULL_TREE, 0);
5484+ c_parser_consume_token (parser);
5485+ break;
5486+ case RID_CbC_RET:
5487+ if (cbc_return==0) {
5488+ cbc_return = c_parser_peek_token (parser)->value;
5489+ }
5490+ tree label = lookup_label(cbc_return);
5491+ TREE_USED(label) = 1;
5492+ expr.value = build1(ADDR_EXPR, ptr_type_node, label);
5493+ c_parser_consume_token (parser);
5494+ break;
5495+#endif
54815496 default:
54825497 c_parser_error (parser, "expected expression");
54835498 expr.value = error_mark_node;
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/c-tree.h
--- a/gcc/c-tree.h Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/c-tree.h Sun Apr 13 07:47:45 2008 +0900
@@ -468,7 +468,11 @@
468468 extern tree grokfield (struct c_declarator *, struct c_declspecs *, tree);
469469 extern tree groktypename (struct c_type_name *);
470470 extern tree grokparm (const struct c_parm *);
471+#ifndef noCbC
472+extern tree implicitly_declare (tree,int);
473+#else
471474 extern tree implicitly_declare (tree);
475+#endif
472476 extern void keep_next_level (void);
473477 extern void pending_xref_error (void);
474478 extern void c_push_function_context (struct function *);
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/c-typeck.c
--- a/gcc/c-typeck.c Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/c-typeck.c Sun Apr 13 07:47:45 2008 +0900
@@ -2089,7 +2089,11 @@
20892089 ref = decl;
20902090 else if (fun)
20912091 /* Implicit function declaration. */
2092+#ifndef noCbC
2093+ ref = implicitly_declare (id, fun);
2094+#else
20922095 ref = implicitly_declare (id);
2096+#endif
20932097 else if (decl == error_mark_node)
20942098 /* Don't complain about something that's already been
20952099 complained about. */
@@ -7027,18 +7031,6 @@
70277031 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
70287032 bool no_warning = false;
70297033
7030-#ifndef noCbC
7031- if ( retval
7032- && TREE_CODE(retval)==CALL_EXPR
7033- && CbC_IS_CbC_GOTO(retval)
7034- //&& !CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl))
7035- && !(current_function_decl&&CbC_IS_CODE_SEGMENT(TREE_TYPE(current_function_decl)))
7036- //&& !(current_function_decl&&CbC_IS_CODE_SEGMENT(current_function_decl))
7037- ){
7038- valtype = 0;
7039- }
7040-#endif
7041-
70427034 if (TREE_THIS_VOLATILE (current_function_decl))
70437035 warning (0, "function declared %<noreturn%> has a %<return%> statement");
70447036
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/calls.c
--- a/gcc/calls.c Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/calls.c Sun Apr 13 07:47:45 2008 +0900
@@ -2265,7 +2265,7 @@
22652265 )
22662266 {
22672267
2268- fprintf(stderr, "\n\tgoto code segment.\n");
2268+ // fprintf(stderr, "\n\tgoto code segment.\n");
22692269 args_size.constant = CbC_ARGS_SIZE;
22702270 return expand_cbc_goto(exp, target, fndecl, funtype,
22712271 addr, ignore, flags, num_actuals, args, &args_size,
@@ -2279,7 +2279,7 @@
22792279 {
22802280 /* calling code segment from function */
22812281 /* delete it later. */
2282- fprintf(stderr, "\n\tcall code segment.\n");
2282+ fprintf(stderr, "\n\terror call code segment.\n");
22832283 //args_size.constant = CbC_ARGS_SIZE;
22842284 }
22852285 #endif
diff -r ec4cbc2ac877 -r 0e48f0ff4a49 gcc/cbc-tree.h
--- a/gcc/cbc-tree.h Tue Mar 18 20:10:50 2008 +0900
+++ b/gcc/cbc-tree.h Sun Apr 13 07:47:45 2008 +0900
@@ -6,8 +6,9 @@
66 /* Set if the CALL_EXPR NODE is goto statement on CbC language. */
77 #define CbC_IS_CbC_GOTO(NODE) (CALL_EXPR_CHECK(NODE)->common.lang_flag_5)
88
9-
109 // old difinition
1110 //#define CbC_IS_CODE_SEGMENT(EXP) DECL_LANG_FLAG_7 (FUNCTION_DECL_CHECK (EXP))
1211 //#define CbC_IS_CODE_SEGMENT(NODE) (TYPE_CHECK (NODE)->type.lang_flag_5)
1312 //#define CbC_IS_CbC_GOTO(NODE) TREE_LANG_FLAG_5 (CALL_EXPR_CHECK(NODE))
13+
14+extern tree cbc_return;
Show on old repository browser