Mercurial > hg > CbC > CbC_examples
changeset 2:35d6eabeadb0
modify Makefile. we can use makefile to compile outside CbC examples. (some examples are not compilable...)
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Oct 2014 02:06:29 +0900 |
parents | ba74047a4d78 |
children | 18eda8cb71e9 |
files | Makefile conv1.c conv1/conv1.c conv1_llvm.c conv1_llvm_no_w.c conv1_llvm_noinline.c fact-a.c loto6.c normal2.c stack1.c test01.c test02.c test03.c test04.c test05.c test1.c test2.c test_array.c test_call.c test_cs.c test_csp1.c test_env.c test_func2code.c test_nest.c test_para.c test_para2.c test_para3.c test_para4.c test_return.c test_struct.c test_tailcall1.c test_tree.c tmp1.c tmp2.c tmp4.c tmpa.c too-long-argument.c |
diffstat | 37 files changed, 669 insertions(+), 1678 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Wed Oct 22 00:38:01 2014 +0900 +++ b/Makefile Wed Oct 22 02:06:29 2014 +0900 @@ -1,5 +1,5 @@ CC=/Users/e105711/prog/seminar/CbC/llvmInst/Debug+Asserts/bin/clang -TARGET=arg bug conv normal +TARGET=bug conv fact-a loto6 normal normal2 test01 test02 test04 test05 test2 test_array test_call test_cs test_para test_para2 test_para4 test_return test_struct test_tailcall1 test_tree tmp1 tmp2 tmp4 test_csp1 test_func2code tmpa too-long-argument CFLAGS=-O2 -D"CLANG" .SUFFIXES: .c .o
--- a/conv1.c Wed Oct 22 00:38:01 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ -#include "stdio.h" - -static int loop; - -#if 1 // def __micro_c__ -#define CC_ONLY 0 -#else -#define CC_ONLY 1 -#endif - -/* classical function call case (0) */ - -f0(int i) { - int k,j; - k = 3+i; - j = g0(i+3); - return k+4+j; -} - -g0(int i) { - return h0(i+4)+i; -} - -h0(int i) { - return i+4; -} - -#if !CC_ONLY - -/* straight conversion case (1) */ - -typedef char *stack; - -struct cont_interface { // General Return Continuation - __code (*ret)(int, void *); -}; - -__code f(int i,stack sp) { - int k,j; - k = 3+i; - goto f_g0(i,k,sp); -} - -struct f_g0_interface { // Specialized Return Continuation - __code (*ret)(int, void *); - int i_,k_,j_; -}; - -__code f_g1(int j,stack sp); - -__code f_g0(int i,int k,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = f_g1; - c->k_ = k; - c->i_ = i; - - goto g(i+3,sp); -} - -__code f_g1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int k = c->k_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(k+4+j,sp); -} - -__code g_h1(int j,stack sp); - -__code g(int i,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = g_h1; - c->i_ = i; - - goto h(i+3,sp); -} - -__code g_h1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int i = c->i_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(j+i,sp); -} - -__code h(int i,stack sp) { - struct f_g0_interface *c = (struct f_g0_interface *)sp; - goto (c->ret)(i+4,sp); -} - -struct main_continuation { // General Return Continuation - __code (*ret)(); - __code (*main_ret)(); - void *env; -}; - -__code main_return(int i,stack sp) { - if (loop-->0) - goto f(233,sp); - printf("#0103:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -/* little optimzation without stack continuation (2) */ - -__code f2(int i,char *sp) { - int k,j; - k = 3+i; - goto g2(i,k,i+3,sp); -} - -__code g2(int i,int k,int j,char *sp) { - j = j+4; - goto h2(i,k+4+j,sp); -} - -__code h2_1(int i,int k,int j,char *sp) { - goto main_return2(i+j,sp); -} - -__code h2(int i,int k,char *sp) { - goto h2_1(i,k,i+4,sp); -} - -__code main_return2(int i,stack sp) { - if (loop-->0) - goto f2(233,sp); - printf("#0132:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -/* little optimizaed case (3) */ - -__code f2_1(int i,char *sp) { - int k,j; - k = 3+i; - goto g2_1(k,i+3,sp); -} - -__code g2_1(int k,int i,char *sp) { - goto h2_11(k,i+4,sp); -} - -__code f2_0_1(int k,int j,char *sp); -__code h2_1_1(int i,int k,int j,char *sp) { - goto f2_0_1(k,i+j,sp); -} - -__code h2_11(int i,int k,char *sp) { - goto h2_1_1(i,k,i+4,sp); -} - -__code f2_0_1(int k,int j,char *sp) { - goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); -} - -__code main_return2_1(int i,stack sp) { - if (loop-->0) - goto f2_1(233,sp); - printf("#0165:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -#define STACK_SIZE 2048 -char main_stack[STACK_SIZE]; -#define stack_last (main_stack+STACK_SIZE) - -#endif - -#define LOOP_COUNT 10000000 - -main(int ac,char *av[]) -{ -#if !CC_ONLY - struct main_continuation *cont; - stack sp = stack_last; -#endif - int sw; - int j; - if (ac==2) sw = atoi(av[1]); - else sw=3; - - if (sw==0) { - for(loop=0;loop<LOOP_COUNT;loop++) { - j = f0(233); - } - printf("#0193:%d\n",j); -#if !CC_ONLY - } else if (sw==1) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f(233,sp); - } else if (sw==2) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2(233,sp); - } else if (sw==3) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2_1; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2_1(233,sp); -#endif - } -return 0; -} - -/* end */
--- a/conv1/conv1.c Wed Oct 22 00:38:01 2014 +0900 +++ b/conv1/conv1.c Wed Oct 22 02:06:29 2014 +0900 @@ -109,7 +109,7 @@ goto f(233,sp); printf("#0103:%d\n",i); goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); + ((struct main_continuation *)sp)->env); } /* little optimzation without stack continuation (2) */ @@ -138,7 +138,7 @@ goto f2(233,sp); printf("#0132:%d\n",i); goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); + ((struct main_continuation *)sp)->env); } /* little optimizaed case (3) */
--- a/conv1_llvm.c Wed Oct 22 00:38:01 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,239 +0,0 @@ -#include "stdio.h" - -static int loop; - -#if 1 // def __micro_c__ -#define CC_ONLY 0 -#else -#define CC_ONLY 1 -#endif - -#ifdef CLANG -#define _CbC_return __return -#define _CbC_environment __environment -#endif - - -/* classical function call case (0) */ - -f0(int i) { - int k,j; - k = 3+i; - j = g0(i+3); - return k+4+j; -} - -g0(int i) { - return h0(i+4)+i; -} - -h0(int i) { - return i+4; -} - -#if !CC_ONLY - -/* straight conversion case (1) */ - -typedef char *stack; - -__code f_g0(int i,int k,stack sp); -__code g(int i,stack sp); -__code h(int i,stack sp); -__code g2(int i,int k,int j,char *sp); -__code g2_1(int k,int i,char *sp); -__code h2_11(int i,int k,char *sp); -__code h2(int i,int k,char *sp); -__code main_return2(int i,stack sp); - -struct cont_interface { // General Return Continuation - __code (*ret)(int, void *); -}; - -__code f(int i,stack sp) { - int k,j; - k = 3+i; - goto f_g0(i,k,sp); -} - -struct f_g0_interface { // Specialized Return Continuation - __code (*ret)(int, void *); - int i_,k_,j_; -}; - -__code f_g1(int j,stack sp); - -__code f_g0(int i,int k,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = f_g1; - c->k_ = k; - c->i_ = i; - - goto g(i+3,sp); -} - -__code f_g1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int k = c->k_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(k+4+j,sp); -} - -__code g_h1(int j,stack sp); - -__code g(int i,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = g_h1; - c->i_ = i; - - goto h(i+3,sp); -} - -__code g_h1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int i = c->i_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(j+i,sp); -} - -__code h(int i,stack sp) { - struct f_g0_interface *c = (struct f_g0_interface *)sp; - goto (c->ret)(i+4,sp); -} - -struct main_continuation { // General Return Continuation - __code (*ret)(); - __code (*main_ret)(); - void *env; -}; - -__code main_return(int i,stack sp) { - if (loop-->0) - goto f(233,sp); - printf("#0103:%d\n",i); - goto ( ( (struct main_continuation *)sp)->main_ret)(0,((struct main_continuation *)sp) ->env ); -} - -/* little optimzation without stack continuation (2) */ - -__code f2(int i,char *sp) { - int k,j; - k = 3+i; - goto g2(i,k,i+3,sp); -} - -__code g2(int i,int k,int j,char *sp) { - j = j+4; - goto h2(i,k+4+j,sp); -} - -__code h2_1(int i,int k,int j,char *sp) { - goto main_return2(i+j,sp); -} - -__code h2(int i,int k,char *sp) { - goto h2_1(i,k,i+4,sp); -} - -__code main_return2(int i,stack sp) { - if (loop-->0) - goto f2(233,sp); - printf("#0132:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -/* little optimizaed case (3) */ - -__code f2_1(int i,char *sp) { - int k,j; - k = 3+i; - goto g2_1(k,i+3,sp); -} - -__code g2_1(int k,int i,char *sp) { - goto h2_11(k,i+4,sp); -} - -__code f2_0_1(int k,int j,char *sp); -__code h2_1_1(int i,int k,int j,char *sp) { - goto f2_0_1(k,i+j,sp); -} - -__code h2_11(int i,int k,char *sp) { - goto h2_1_1(i,k,i+4,sp); -} - -__code f2_0_1(int k,int j,char *sp) { - goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); -} - -__code main_return2_1(int i,stack sp) { - if (loop-->0) - goto f2_1(233,sp); - printf("#0165:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -#define STACK_SIZE 2048 -char main_stack[STACK_SIZE]; -#define stack_last (main_stack+STACK_SIZE) - -#endif - -#define LOOP_COUNT 10000000 - -main(int ac,char *av[]) -{ -#if !CC_ONLY - struct main_continuation *cont; - stack sp = stack_last; -#endif - int sw; - int j; - if (ac==2) sw = atoi(av[1]); - else sw=3; - - if (sw==0) { - for(loop=0;loop<LOOP_COUNT;loop++) { - j = f0(233); - } - printf("#0193:%d\n",j); -#if !CC_ONLY - } else if (sw==1) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f(233,sp); - } else if (sw==2) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2(233,sp); - } else if (sw==3) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2_1; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2_1(233,sp); -#endif - } -return 0; -} - -/* end */
--- a/conv1_llvm_no_w.c Wed Oct 22 00:38:01 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,243 +0,0 @@ -#include "stdio.h" -#include "stdlib.h" - -static int loop; - -#if 1 // def __micro_c__ -#define CC_ONLY 0 -#else -#define CC_ONLY 1 -#endif - -#ifdef CLANG -#define _CbC_return __return -#define _CbC_environment __environment -#endif - - -/* classical function call case (0) */ -int g0(int i); -int h0(int i); - -int f0(int i) { - int k,j; - k = 3+i; - j = g0(i+3); - return k+4+j; -} - -int g0(int i) { - return h0(i+4)+i; -} - -int h0(int i) { - return i+4; -} - -#if !CC_ONLY - -/* straight conversion case (1) */ - -typedef char *stack; - -__code f_g0(int i,int k,stack sp); -__code g(int i,stack sp); -__code h(int i,stack sp); -__code g2(int i,int k,int j,char *sp); -__code g2_1(int k,int i,char *sp); -__code h2_11(int i,int k,char *sp); -__code h2(int i,int k,char *sp); -__code main_return2(int i,stack sp); - -struct cont_interface { // General Return Continuation - __code (*ret)(int, stack); -}; - -__code f(int i,stack sp) { - int k,j; - k = 3+i; - goto f_g0(i,k,sp); -} - -struct f_g0_interface { // Specialized Return Continuation - __code (*ret)(int, stack); - int i_,k_,j_; -}; - -__code f_g1(int j,stack sp); - -__code f_g0(int i,int k,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = f_g1; - c->k_ = k; - c->i_ = i; - - goto g(i+3,sp); -} - -__code f_g1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int k = c->k_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(k+4+j,sp); -} - -__code g_h1(int j,stack sp); - -__code g(int i,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = g_h1; - c->i_ = i; - - goto h(i+3,sp); -} - -__code g_h1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int i = c->i_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(j+i,sp); -} - -__code h(int i,stack sp) { - struct f_g0_interface *c = (struct f_g0_interface *)sp; - goto (c->ret)(i+4,sp); -} - -struct main_continuation { // General Return Continuation - __code (*ret)(); - __code (*main_ret)(); - void *env; -}; - -__code main_return(int i,stack sp) { - if (loop-->0) - goto f(233,sp); - printf("#0103:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -/* little optimzation without stack continuation (2) */ - -__code f2(int i,char *sp) { - int k,j; - k = 3+i; - goto g2(i,k,i+3,sp); -} - -__code g2(int i,int k,int j,char *sp) { - j = j+4; - goto h2(i,k+4+j,sp); -} - -__code h2_1(int i,int k,int j,char *sp) { - goto main_return2(i+j,sp); -} - -__code h2(int i,int k,char *sp) { - goto h2_1(i,k,i+4,sp); -} - -__code main_return2(int i,stack sp) { - if (loop-->0) - goto f2(233,sp); - printf("#0132:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -/* little optimizaed case (3) */ - -__code f2_1(int i,char *sp) { - int k,j; - k = 3+i; - goto g2_1(k,i+3,sp); -} - -__code g2_1(int k,int i,char *sp) { - goto h2_11(k,i+4,sp); -} - -__code f2_0_1(int k,int j,char *sp); -__code h2_1_1(int i,int k,int j,char *sp) { - goto f2_0_1(k,i+j,sp); -} - -__code h2_11(int i,int k,char *sp) { - goto h2_1_1(i,k,i+4,sp); -} - -__code f2_0_1(int k,int j,char *sp) { - goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); -} - -__code main_return2_1(int i,stack sp) { - if (loop-->0) - goto f2_1(233,sp); - printf("#0165:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -#define STACK_SIZE 2048 -char main_stack[STACK_SIZE]; -#define stack_last (main_stack+STACK_SIZE) - -#endif - -#define LOOP_COUNT 10000000 - -int main(int ac,char *av[]) -{ -#if !CC_ONLY - struct main_continuation *cont; - stack sp = stack_last; -#endif - int sw; - int j; - if (ac==2) sw = atoi(av[1]); - else sw=3; - - if (sw==0) { - for(loop=0;loop<LOOP_COUNT;loop++) { - j = f0(233); - } - printf("#0193:%d\n",j); -#if !CC_ONLY - } else if (sw==1) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f(233,sp); - } else if (sw==2) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2(233,sp); - } else if (sw==3) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2_1; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2_1(233,sp); -#endif - } -return 0; -} - -/* end */
--- a/conv1_llvm_noinline.c Wed Oct 22 00:38:01 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,239 +0,0 @@ -#include "stdio.h" - -static int loop; - -#if 1 // def __micro_c__ -#define CC_ONLY 0 -#else -#define CC_ONLY 1 -#endif - -#ifdef CLANG -#define _CbC_return __return -#define _CbC_environment __environment -#endif - - -/* classical function call case (0) */ - -__attribute__((noinline)) f0(int i) { - int k,j; - k = 3+i; - j = g0(i+3); - return k+4+j; -} - -__attribute__((noinline)) g0(int i) { - return h0(i+4)+i; -} - -__attribute__((noinline)) h0(int i) { - return i+4; -} - -#if !CC_ONLY - -/* straight conversion case (1) */ - -typedef char *stack; - -__attribute__((noinline)) __code f_g0(int i,int k,stack sp); -__attribute__((noinline)) __code g(int i,stack sp); -__attribute__((noinline)) __code h(int i,stack sp); -__attribute__((noinline)) __code g2(int i,int k,int j,char *sp); -__attribute__((noinline)) __code g2_1(int k,int i,char *sp); -__attribute__((noinline)) __code h2_11(int i,int k,char *sp); -__attribute__((noinline)) __code h2(int i,int k,char *sp); -__attribute__((noinline)) __code main_return2(int i,stack sp); - -struct cont_interface { // General Return Continuation - __code (*ret)(int, void *); -}; - -__attribute__((noinline)) __code f(int i,stack sp) { - int k,j; - k = 3+i; - goto f_g0(i,k,sp); -} - -struct f_g0_interface { // Specialized Return Continuation - __code (*ret)(int, void *); - int i_,k_,j_; -}; - -__attribute__((noinline)) __code f_g1(int j,stack sp); - -__attribute__((noinline)) __code f_g0(int i,int k,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = f_g1; - c->k_ = k; - c->i_ = i; - - goto g(i+3,sp); -} - -__attribute__((noinline)) __code f_g1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int k = c->k_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(k+4+j,sp); -} - -__attribute__((noinline)) __code g_h1(int j,stack sp); - -__attribute__((noinline)) __code g(int i,stack sp) { // Caller - struct f_g0_interface *c = - (struct f_g0_interface *)(sp -= sizeof(struct f_g0_interface)); - - c->ret = g_h1; - c->i_ = i; - - goto h(i+3,sp); -} - -__attribute__((noinline)) __code g_h1(int j,stack sp) { // Continuation - struct f_g0_interface *c = (struct f_g0_interface *)sp; - int i = c->i_; - sp+=sizeof(struct f_g0_interface); - c = (struct f_g0_interface *)sp; - goto (c->ret)(j+i,sp); -} - -__attribute__((noinline)) __code h(int i,stack sp) { - struct f_g0_interface *c = (struct f_g0_interface *)sp; - goto (c->ret)(i+4,sp); -} - -struct main_continuation { // General Return Continuation - __code (*ret)(); - __code (*main_ret)(); - void *env; -}; - -__attribute__((noinline)) __code main_return(int i,stack sp) { - if (loop-->0) - goto f(233,sp); - printf("#0103:%d\n",i); - goto ( ( (struct main_continuation *)sp)->main_ret)(0,((struct main_continuation *)sp) ->env ); -} - -/* little optimzation without stack continuation (2) */ - -__attribute__((noinline)) __code f2(int i,char *sp) { - int k,j; - k = 3+i; - goto g2(i,k,i+3,sp); -} - -__attribute__((noinline)) __code g2(int i,int k,int j,char *sp) { - j = j+4; - goto h2(i,k+4+j,sp); -} - -__attribute__((noinline)) __code h2_1(int i,int k,int j,char *sp) { - goto main_return2(i+j,sp); -} - -__attribute__((noinline)) __code h2(int i,int k,char *sp) { - goto h2_1(i,k,i+4,sp); -} - -__attribute__((noinline)) __code main_return2(int i,stack sp) { - if (loop-->0) - goto f2(233,sp); - printf("#0132:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -/* little optimizaed case (3) */ - -__attribute__((noinline)) __code f2_1(int i,char *sp) { - int k,j; - k = 3+i; - goto g2_1(k,i+3,sp); -} - -__attribute__((noinline)) __code g2_1(int k,int i,char *sp) { - goto h2_11(k,i+4,sp); -} - -__attribute__((noinline)) __code f2_0_1(int k,int j,char *sp); -__attribute__((noinline)) __code h2_1_1(int i,int k,int j,char *sp) { - goto f2_0_1(k,i+j,sp); -} - -__attribute__((noinline)) __code h2_11(int i,int k,char *sp) { - goto h2_1_1(i,k,i+4,sp); -} - -__attribute__((noinline)) __code f2_0_1(int k,int j,char *sp) { - goto (( (struct cont_interface *)sp)->ret)(k+4+j,sp); -} - -__attribute__((noinline)) __code main_return2_1(int i,stack sp) { - if (loop-->0) - goto f2_1(233,sp); - printf("#0165:%d\n",i); - goto (( (struct main_continuation *)sp)->main_ret)(0, - ((struct main_continuation *)sp)->env); -} - -#define STACK_SIZE 2048 -char main_stack[STACK_SIZE]; -#define stack_last (main_stack+STACK_SIZE) - -#endif - -#define LOOP_COUNT 10000000 - -main(int ac,char *av[]) -{ -#if !CC_ONLY - struct main_continuation *cont; - stack sp = stack_last; -#endif - int sw; - int j; - if (ac==2) sw = atoi(av[1]); - else sw=3; - - if (sw==0) { - for(loop=0;loop<LOOP_COUNT;loop++) { - j = f0(233); - } - printf("#0193:%d\n",j); -#if !CC_ONLY - } else if (sw==1) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f(233,sp); - } else if (sw==2) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2(233,sp); - } else if (sw==3) { - loop = LOOP_COUNT; - sp -= sizeof(*cont); - cont = (struct main_continuation *)sp; - cont->ret = main_return2_1; - cont->main_ret = _CbC_return; - cont->env = _CbC_environment; - goto f2_1(233,sp); -#endif - } -return 0; -} - -/* end */
--- a/fact-a.c Wed Oct 22 00:38:01 2014 +0900 +++ b/fact-a.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,36 +1,39 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif #include "stdio.h" -__code factorial(int n,int result,int orig,__code(*print)(),__code(*exit1)(), void *exit1env) +__code factorial(int n,int result,int orig,__code(*print)(),__code(*exit1)(), void *exit1env); +__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(),void*exit1env); + +__code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) { if (n<0) { - printf("#0008:err %d!\n",n); - goto (*exit1)(0,exit1env); + printf("#0008:err %d!\n",n); + goto (*exit1)(0,exit1env); } if (n==0) - goto (*print)(n,result,orig,print,exit1,exit1env); + goto (*print)(n,result,orig,print,exit1,exit1env); else { - result *= n; - n--; - goto factorial(n,result,orig,print,exit1,exit1env); + result *= n; + n--; + goto factorial(n,result,orig,print,exit1,exit1env); } } -__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(),void*exit1env); int main( int ac, char *av[]) { - int n; - // n = atoi(av[1]); - n = 10; - goto factorial(n,1,n,print,__return,__environment); + int n; + n = 10; + goto factorial(n,1,n,print,__return,__environment); } -__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(),void*exit1env) +__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) { - printf("#0032:%d! = %d\n",orig, result); - goto (*exit1)(0,exit1env); + printf("#0032:%d! = %d\n",orig, result); + goto (*exit1)(0,exit1env); }
--- a/loto6.c Wed Oct 22 00:38:01 2014 +0900 +++ b/loto6.c Wed Oct 22 02:06:29 2014 +0900 @@ -8,73 +8,80 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> -(*ret)(int, void*); +#ifdef CLANG // for clang/LLVM +#define _CbC_return __return +#define _CbC_environment __environment +#endif + +__code (*ret)(int, void*); void *env; __code print(int *numbers) { - printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]); - free(numbers); - goto ret(0, env); + printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]); + free(numbers); + goto ret(0, env); } - __code +__code take(int *array, int size, int length) { - int *taked = (int*)malloc(sizeof(int)*length); + int *taked = (int*)malloc(sizeof(int)*length); - memcpy(taked, array, sizeof(int)*length); - free(array); + memcpy(taked, array, sizeof(int)*length); + free(array); - goto print(taked); + goto print(taked); } __code shuffle(int *array, int size, int idx) { - int j = random() % size; - int tmp = array[idx]; - array[idx] = array[j]; - array[j] = tmp; + int j = random() % size; + int tmp = array[idx]; + array[idx] = array[j]; + array[j] = tmp; - if (++idx < size) { - goto shuffle(array, size, idx); - } else { - goto take(array, size, 6); - } + if (++idx < size) { + goto shuffle(array, size, idx); + } else { + goto take(array, size, 6); + } } __code range_loop(int *array, int idx, int from, int to, int step, int size) { - array[idx] = from; + array[idx] = from; - if (from+step > to) { - goto shuffle(array, size, 0); - } else { - goto range_loop(array, idx+1, from+step, to, step, size); - } + if (from+step > to) { + goto shuffle(array, size, 0); + } else { + goto range_loop(array, idx+1, from+step, to, step, size); + } } __code range(int from, int to, int step) { - int size = (to-from+1)/step; - int *array = (int*)malloc(sizeof(int)*size); + int size = (to-from+1)/step; + int *array = (int*)malloc(sizeof(int)*size); - goto range_loop(array, 0, from, to, step, size); + goto range_loop(array, 0, from, to, step, size); } int main() { - srand(time(NULL)); - ret = _CbC_return; - env = _CbC_environment; + srand(time(NULL)); + ret = _CbC_return; + env = _CbC_environment; - goto range(1, 43, 1); + goto range(1, 43, 1); }
--- a/normal2.c Wed Oct 22 00:38:01 2014 +0900 +++ b/normal2.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,63 +1,63 @@ -//#include<stdio.h> -//#include<stdlib.h> +#include<stdio.h> +#include<stdlib.h> struct abc { - int a; - double b; - char c; - double *d; + int a; + double b; + char c; + double *d; }; struct def { - int d; - struct abc e; - struct abc *f; + int d; + struct abc e; + struct abc *f; }; void print_abc(struct abc a){ - printf("\tstruct abc:\n"); - printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d); + printf("\tstruct abc:\n"); + printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d); } void print_def(struct def b){ - printf("\tstruct def:\n"); - printf("\ta=%d, b=%p\n", b.d, b.f); - print_abc(b.e); + printf("\tstruct def:\n"); + printf("\ta=%d, b=%p\n", b.d, b.f); + print_abc(b.e); } void cs_exit(int a){ - printf("cs_exit : a=%d.\n", a); - exit(a); + printf("cs_exit : a=%d.\n", a); + exit(a); } void cs0(struct abc a, struct def b, int c){ - printf("cs0 :\n"); - print_abc(a); - print_def(b); - return cs_exit( c*a.a+b.e.c ); + printf("cs0 :\n"); + print_abc(a); + print_def(b); + return cs_exit( c*a.a+b.e.c ); } void cs_goto(int c, struct abc a, struct def b){ - printf("cs_return :\n"); - print_abc(a); - print_def(b); - return cs0(a, b, c); + printf("cs_return :\n"); + print_abc(a); + print_def(b); + return cs0(a, b, c); } int main(int argc, char **argv){ - struct abc A; - struct def B; - //int a=10, b=20, c=30, d=40, e=50, f=60, g=70; - A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0; - B.d = 30, B.f = &A; - B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0; + struct abc A; + struct def B; + //int a=10, b=20, c=30, d=40, e=50, f=60, g=70; + A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0; + B.d = 30, B.f = &A; + B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0; - printf("main :\n"); - print_abc(A); - print_def(B); - //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); - cs_goto(100, A, B); - return 0; + printf("main :\n"); + print_abc(A); + print_def(B); + //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); + cs_goto(100, A, B); + return 0; }
--- a/stack1.c Wed Oct 22 00:38:01 2014 +0900 +++ b/stack1.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,8 +1,8 @@ /* - test for CbC converted __code from C - */ + test for CbC converted __code from C +*/ -//#include <stdio.h> +#include <stdio.h> #define NULL 0 extern void *malloc(int); @@ -12,115 +12,115 @@ void *stack0; /* size of void* == 1 */ struct cont_save { /* General Return Continuation */ - __code (*ret)(); + __code (*ret)(); }; - __code g(int,void *); - __code f_g0(int ,int ,void *); - __code f_g1(int,void *); - __code print(int i,int j,__code (*exit1)(),void*exit1env); +__code g(int,void *); +__code f_g0(int ,int ,void *); +__code f_g1(int,void *); +__code print(int i,int j,__code (*exit1)(),void*exit1env); struct f_g0_save { /* Specialized Return Continuation */ - __code (*ret)(); - int ii,kk,jj; + __code (*ret)(); + int ii,kk,jj; }; __code g(int i,void *sp) { - goto (* ((struct cont_save *)sp)->ret)(i+4,sp); + goto (* ((struct cont_save *)sp)->ret)(i+4,sp); } __code __attribute__ ((fastcall)) f_g1(int j,void *sp) { /* Continuation */ - int k; - struct f_g0_save *c; + int k; + struct f_g0_save *c; - c = sp; - k = c->kk; - sp += sizeof(struct f_g0_save); - goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp); + c = sp; + k = c->kk; + sp += sizeof(struct f_g0_save); + goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp); } __code f(int i,void *sp) { - int k,j; - struct f_g0_save *c; -printf("#0042:f 0 sp: %x\n",sp-stack0); + int k,j; + struct f_g0_save *c; + printf("#0042:f 0 sp: %x\n",sp-stack0); - k = 3+i; + k = 3+i; -printf("#0046:f 1 sp: %x\n",sp-stack0); - sp -= sizeof(struct f_g0_save); -printf("#0048:f 2 sp: %x\n",sp-stack0); - c = sp; - c->kk = k; - c->ii = i; - c->jj = j; - c->ret = f_g1; - goto g(i,sp); + printf("#0046:f 1 sp: %x\n",sp-stack0); + sp -= sizeof(struct f_g0_save); + printf("#0048:f 2 sp: %x\n",sp-stack0); + c = sp; + c->kk = k; + c->ii = i; + c->jj = j; + c->ret = f_g1; + goto g(i,sp); } struct f0_save { /* Specialized Return Continuation */ - __code (*ret)(); - __code (*exit1)(); - void *exit1env; - int jj; + __code (*ret)(); + __code (*exit1)(); + void *exit1env; + int jj; }; __code f1(int i,void *sp) ; __code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp) { - struct f0_save *c; - printf("#0070:f0 1 sp: %x\n",sp-stack0); - sp -= sizeof(struct f0_save); - printf("#0072:f0 2 sp: %x\n",sp-stack0); - c = sp; - c->jj = j; - c->exit1 = exit2; - c->exit1env = exit2env; - c->ret = f1; - printf("#0078:f0 3 sp: %x\n",sp-stack0); - goto f(i,sp); + struct f0_save *c; + printf("#0070:f0 1 sp: %x\n",sp-stack0); + sp -= sizeof(struct f0_save); + printf("#0072:f0 2 sp: %x\n",sp-stack0); + c = sp; + c->jj = j; + c->exit1 = exit2; + c->exit1env = exit2env; + c->ret = f1; + printf("#0078:f0 3 sp: %x\n",sp-stack0); + goto f(i,sp); } __code f1(int i,void *sp) { - int j; - int *exit2env; - __code (*exit2)(); - struct f0_save *c; + int j; + int *exit2env; + __code (*exit2)(); + struct f0_save *c; - c = sp; - j = c->jj; - exit2 = c->exit1; - exit2env = c->exit1env; + c = sp; + j = c->jj; + exit2 = c->exit1; + exit2env = c->exit1env; - sp += sizeof(struct f0_save); - goto print(i,j,exit2,exit2env); + sp += sizeof(struct f0_save); + goto print(i,j,exit2,exit2env); } int main(int ac, char*av[]){ - main0(ac,av); + main0(ac,av); } int main0( int ac, char *av[]) { - int i,j; - int *sp; + int i,j; + int *sp; - // i = atoi(av[1]); - i = 1; - stack0 = ((char *)malloc(1024)+1024); - sp = stack0; - j = i; + // i = atoi(av[1]); + i = 1; + stack0 = ((char *)malloc(1024)+1024); + sp = stack0; + j = i; - printf("#0108:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0)); - //goto f0(i,j,_CbC_return,_CbC_environment,sp); - goto f0(i,j,NULL,NULL,sp); + printf("#0108:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0)); + //goto f0(i,j,_CbC_return,_CbC_environment,sp); + goto f0(i,j,NULL,NULL,sp); } __code print(int i,int j,__code (*exit1)(),void*exit1env) { - printf("#0114:%d %d\n",i,j); - //goto (*exit1)(0),exit1env; - exit(0); + printf("#0114:%d %d\n",i,j); + //goto (*exit1)(0),exit1env; + exit(0); }
--- a/test01.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test01.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,34 +1,34 @@ #include<stdio.h> +int test_goto2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j); + int test_code(void){ - printf("\t\ttest_code: return 10\n"); - return 10; + printf("\t\ttest_code: return 10\n"); + return 10; } int test_goto(int a){ - printf("\ttest_goto: a = %d\n", a); - //return test_code(); - return test_code(); + printf("\ttest_goto: a = %d\n", a); + return test_code(); } int main(int argc, char **argv){ - int ret; - printf("test code\n"); - ret = test_goto(20); - printf("main: ret = %d\n", ret); + int ret; + printf("test code\n"); + ret = test_goto(20); + printf("main: ret = %d\n", ret); - return test_goto2(10,20,30,40,50,60,70,80,90,100); - return 0; + return test_goto2(10,20,30,40,50,60,70,80,90,100); + return 0; } -int test_code2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k){ - printf("\t\ttest_code: return 10\n"); - printf("a=%d,b=%d,c=%d,d=%d,e=%d,f=%d,g=%d,h=%d,i=%d,j=%d,k=%d\n",a,b,c,d,e,f,g,h,i,j,k ); - return a+b+c+d+e+f+g+h+i+j+k; +int test_code2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j){ + printf("\t\ttest_code: return 10\n"); + printf("a=%d,b=%d,c=%d,d=%d,e=%d,f=%d,g=%d,h=%d,i=%d,j=%d\n",a,b,c,d,e,f,g,h,i,j); + return a+b+c+d+e+f+g+h+i+j; } -int test_goto2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k){ - printf("\ttest_goto: a = %d\n", a); - //return test_code(); - return test_code2(a,b,c,d,e,f,g,h,i,j,k); +int test_goto2(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j){ + printf("\ttest_goto: a = %d\n", a); + return test_code2(a,b,c,d,e,f,g,h,i,j); }
--- a/test02.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test02.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,22 +1,21 @@ #include<stdio.h> __code test_code(void){ - printf("\t\ttest_code: return 10\n"); - return; + printf("\t\ttest_code: return 10\n"); + return; } __code test_goto(int a){ - printf("\ttest_goto: a = %d\n", a); - //return test_code(); - goto test_code(); + printf("\ttest_goto: a = %d\n", a); + goto test_code(); } int main(int argc, char **argv){ - int ret=0; - printf("test code\n"); - test_goto(20); - printf("main: ret = %d\n", ret); - - return 0; + int ret=0; + printf("test code\n"); + test_goto(20); + printf("main: ret = %d\n", ret); + + return 0; }
--- a/test03.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test03.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,4 +1,3 @@ - extern void test02() ; extern void test03() ;
--- a/test04.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test04.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,33 +1,33 @@ - +#include<stdio.h> int test01(int a, double b, int *c){ - return a+b- *c; + return a+b- *c; } int test(int *a, double b){ - int c; - c = *a*b + 10; - printf("a = %x, *a = %d, b = %d\n", a, *a, b); - *a = test01( *a+b, 0.02, &c); - return *a+b; + int c; + c = *a*b + 10; + printf("a = %p, *a = %d, b = %f\n", a, *a, b); + *a = test01( *a+b, 0.02, &c); + return *a+b; } int test02(int a, int b){ - int i,sum=0; - i = a; - while ( i <= b ) { - sum += i; - i++; - } - return sum - a*b; + int i,sum=0; + i = a; + while ( i <= b ) { + sum += i; + i++; + } + return sum - a*b; } int main(int argc, char **argv){ - int a=10; + int a=10; - printf("= %d\n", test02(0, 10)); - test( &a, 10.1); - return 0; + printf("= %d\n", test02(0, 10)); + test( &a, 10.1); + return 0; }
--- a/test05.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test05.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,4 +1,5 @@ -//#include<stdio.h> +#include<stdio.h> +#include<stdlib.h> #define dprint(f, args...) \ printf("in %s: "f, __FUNCTION__, ## args)
--- a/test1.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test1.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,5 +1,7 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif /* test for CbC converted __code from C
--- a/test2.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test2.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,5 +1,7 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif #include <stdio.h> int sender_bit;
--- a/test_array.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_array.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,17 +1,17 @@ -//#include<stdio.h> +#include<stdio.h> void print_array(int *, int); int main(int argc, char **argv){ - int array[10] = {10, 2, 3, 0, 7, 5}; - array[1] += array[2]+array[4]; - print_array(array, 10); - return 0; + int array[10] = {10, 2, 3, 0, 7, 5}; + array[1] += array[2]+array[4]; + print_array(array, 10); + return 0; } void print_array(int *a, int size){ - while( size-->0 ){ - printf(" %7d", *a++); - } - printf("\n"); + while( size-->0 ){ + printf(" %7d", *a++); + } + printf("\n"); }
--- a/test_call.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_call.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,12 +1,12 @@ - +#include<stdio.h> int test(int a){ - printf("a = %d\n", a); - return 10*a; + printf("a = %d\n", a); + return 10*a; } int main(){ - test(10); - return 0; + test(10); + return 0; }
--- a/test_cs.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_cs.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,5 +1,5 @@ -//#include<stdio.h> -//#include<stdlib.h> +#include<stdio.h> +#include<stdlib.h> __code cs_exit(int , double , char ); __code cs1(int, int, int, int); @@ -7,37 +7,35 @@ void test_goto(void); int main(int argc, char **argv){ - printf("main start\n"); - //goto cs2(2.22, 3.33, 4, 5.55); - test_goto(); - return 0; + printf("main start\n"); + test_goto(); + return 0; } void test_goto(){ - goto cs1(10, 20, 30, 40); + goto cs1(10, 20, 30, 40); } __code cs1(int a, int b, int c, int d){ - printf("%4d, %4d, %4d, %4d\n", a, b, c, d); - a += 40, b += 40, c += 40, d += 40; - goto cs2((double)a, (double)b, c, (double)d); + printf("%4d, %4d, %4d, %4d\n", a, b, c, d); + a += 40, b += 40, c += 40, d += 40; + goto cs2((double)a, (double)b, c, (double)d); } __code cs2(double a, double b, int c, double d){ - printf("%4d, %4d, %4d, %4d\n", (int)a, (int)b, (int)c, (int)d); - a += 40, b += 40, c += 40, d += 40; - goto cs_exit((int)a, b, (char)c); + printf("%4d, %4d, %4d, %4d\n", (int)a, (int)b, (int)c, (int)d); + a += 40, b += 40, c += 40, d += 40; + goto cs_exit((int)a, b, (char)c); } __code cs_exit(int a, double b, char c){ - printf("%4d, %4d, %4d\n", (int)a, (int)b, (int)c); - printf("cs_exit was called!\n"); - exit(0); + printf("%4d, %4d, %4d\n", (int)a, (int)b, (int)c); + printf("cs_exit was called!\n"); + exit(0); } - void caller(int a, double b){ - cs2(b,20.0,a, 40.4); - cs1(10,20,30, 40); + cs2(b,20.0,a, 40.4); + cs1(10,20,30, 40); }
--- a/test_csp1.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_csp1.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,60 +1,52 @@ #include<stdio.h> #include<stdlib.h> -//static __code (*csp)(int, int, int, int); __code cs_end (int a); __code cs0 (int a, int b, int c, int d); void* freturn (); __code cs_goto (int a, int b, int c, int d); -int function (double a, float b, int c); +void function (double a, float b, int c); int main (int argc, char **argv); __code cs_goto(int a, int b, int c, int d){ - __code (*csp)(int, int, int, int); - csp = freturn(); - printf("csp = %x.\n", csp); + __code (*csp)(int, int, int, int); + csp = freturn(); + printf("csp = %p.\n", csp); - //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); - //printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); - //printf("cs_goto : a-4=%d, a-8=%d, a-12=%d, a-16=%d.\n", *(&a-4), *(&a-8), *(&a-12), *(&a-16)); - //printf("cs_goto : cs0(a, b, c, d)\n"); #ifdef INDIRECT - goto csp(b+a, d+b, a+c, c+d); + goto csp(b+a, d+b, a+c, c+d); #else - goto cs0(b+a, d+b, a+c, c+d); + goto cs0(b+a, d+b, a+c, c+d); #endif } __code cs_end(int a){ - printf("cs_exit : a=%d.\n", a); - exit(a); - goto cs_end(a); + printf("cs_exit : a=%d.\n", a); + exit(a); + goto cs_end(a); } __code cs0(int a, int b, int c, int d){ - //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); - printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); - goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); + printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); } void* freturn(){ - return cs0; + return cs0; } -int function(double a, float b, int c){ +void function(double a, float b, int c){ - printf("function:\n"); - printf("a=%lf, b=%f, c=%d\n", a, b, c); - //goto cs_goto(10, 20, 30, 40); - goto cs_goto(10, 20, 30, 40); + printf("function:\n"); + printf("a=%lf, b=%f, c=%d\n", a, b, c); + goto cs_goto(10, 20, 30, 40); } int main(int argc, char **argv){ - //csp = cs0; - function(10.01, 20.02, 30); - return 0; + function(10.01, 20.02, 30); + return 0; }
--- a/test_env.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_env.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,67 +1,53 @@ - typedef void (*RET_FUNC)(int, void *); int main(int argc, char **argv) { - int r; - r = f(); - printf("%d\n", r); + int r; + r = f(); + printf("%d\n", r); } -//void z(RET_FUNC ret, void *fp) __code z(RET_FUNC ret, void *fp) { - printf("z: fp=0x%x\n", __builtin_frame_address(0)); - ret(5, fp); + printf("z: fp=0x%x\n", __builtin_frame_address(0)); + ret(5, fp); } __code i(RET_FUNC ret, void *fp) { - printf("i: fp=0x%x\n", __builtin_frame_address(0)); - goto z(ret, fp); + printf("i: fp=0x%x\n", __builtin_frame_address(0)); + goto z(ret, fp); } __code h(RET_FUNC ret, void *fp) { - printf("h: fp=0x%x\n", __builtin_frame_address(0)); - goto i(ret, fp); + printf("h: fp=0x%x\n", __builtin_frame_address(0)); + goto i(ret, fp); } __code g(RET_FUNC ret, void *fp) { - printf("g: fp=0x%x\n", __builtin_frame_address(0)); - goto h(ret, fp); + printf("g: fp=0x%x\n", __builtin_frame_address(0)); + goto h(ret, fp); } int f() { - __label__ exit0; - int retval; - //void (*ret)(int retval_, void *fp); - - /* - ret = ({ - void __return_func(int retval_, void *fp){ - retval = retval_; - goto exit0; - } - __return_func; - }); - */ - printf("f0: fp = 0x%x\n", __builtin_frame_address(0)); - void __return_func(int retval_, void *fp){ - retval = retval_; - goto exit0; - } - //ret = __return_func; - - printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); - - //g(__return_func, __builtin_frame_address(0)); - goto g(__return_func, __builtin_frame_address(0)); - - printf("bad\n"); - -exit0: - printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); - return retval; + __label__ exit0; + int retval; + + printf("f0: fp = 0x%x\n", __builtin_frame_address(0)); + void __return_func(int retval_, void *fp){ + retval = retval_; + goto exit0; + } + + printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); + + goto g(__return_func, __builtin_frame_address(0)); + + printf("bad\n"); + + exit0: + printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); + return retval; }
--- a/test_func2code.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_func2code.c Wed Oct 22 02:06:29 2014 +0900 @@ -3,41 +3,41 @@ #define DEBUG 1 #ifdef DEBUG - #define log(f, args...) \ - fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) +#define log(f, args...) \ + fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) #else - #define log(f, args...) ; +#define log(f, args...) ; #endif __code exitter(int a) { - exit(0); + exit(0); } __code cs0(int x, int y) { - log("x = %d, y = %d.\n", x, y); - log("will exit with code %d.\n", x*y); - goto exitter(x*y); + log("x = %d, y = %d.\n", x, y); + log("will exit with code %d.\n", x*y); + goto exitter(x*y); } void continuation(int a) { - log("go code segment cs0\n"); - goto cs0(a, a*20); - log("Error: continuation reachs bad region.\n"); + log("go code segment cs0\n"); + goto cs0(a, a*20); + log("Error: continuation reachs bad region.\n"); } int main(int argc, char **argv) { - int a; - if (argc>2) { - a = atoi(argv[1]); - } - - continuation(20); + int a; + if (argc>2) { + a = atoi(argv[1]); + } + + continuation(20); }
--- a/test_nest.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_nest.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,50 +1,47 @@ - int printf(char *, ...); typedef void (*RET_FUNC)(int, void *); void g(RET_FUNC func) { - func(33, 0); + func(33, 0); } int f() { - void *ret; - ret = ({ - __label__ exit0; - int retval; - void __return_func(int retval_, void *fp){ - retval = retval_; - goto exit0; - } - if (0) { - exit0: - printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); - return retval; - } - __return_func; + void *ret; + ret = ({ + __label__ exit0; + int retval; + void __return_func(int retval_, void *fp){ + retval = retval_; + goto exit0; + } + if (0) { + exit0: + printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); + return retval; + } + __return_func; }); - //g(__return_func, __builtin_frame_address(0)); - printf("f0: fp = 0x%x\n", __builtin_frame_address(0)); - printf("__return_func = %x\n", ret); - g(ret); + //g(__return_func, __builtin_frame_address(0)); + printf("f0: fp = 0x%x\n", __builtin_frame_address(0)); + printf("__return_func = %x\n", ret); + g(ret); - printf("not good\n"); - return 0; + printf("not good\n"); + return 0; -//exit0: - //printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); - //return retval; + //exit0: + //printf("f2: fp = 0x%x\n", __builtin_frame_address(0)); + //return retval; } int main(int argc, char **argv) { - int t; - printf("main before: fp = 0x%x\n", __builtin_frame_address(0)); - t = f(); - printf("f = %d\n", t); - printf("main after: fp = 0x%x\n", __builtin_frame_address(0)); + int t; + printf("main before: fp = 0x%x\n", __builtin_frame_address(0)); + t = f(); + printf("f = %d\n", t); + printf("main after: fp = 0x%x\n", __builtin_frame_address(0)); } - -
--- a/test_para.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_para.c Wed Oct 22 02:06:29 2014 +0900 @@ -2,25 +2,23 @@ #include<stdlib.h> __code cs_exit(int a){ - printf("cs_exit was called: a=%d.\n", a); - exit(a); + printf("cs_exit was called: a=%d.\n", a); + exit(a); } __code cs0(int a, double b, int c, int d){ - printf("cs0 was called: a=%d, b=%lf, c=%d, d=%d.\n", a, b, c, d); - goto cs_exit( (int)(20*a + 4.4*b + 2022/c + 28*d) ); + printf("cs0 was called: a=%d, b=%lf, c=%d, d=%d.\n", a, b, c, d); + goto cs_exit( (int)(20*a + 4.4*b + 2022/c + 28*d) ); +} + +__code cs_goto(){ + goto cs0(11, 22.2, 33, 44); +} + +int main(int argc, char **argv){ + printf("it is in main.\n"); + goto cs_goto(); + return 0; } -__code cs_goto(){ - goto cs0(11, 22.2, 33, 44); -} - -int main(int argc, char **argv){ - - printf("it is in main.\n"); - goto cs_goto(); - return 0; -} - -
--- a/test_para2.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_para2.c Wed Oct 22 02:06:29 2014 +0900 @@ -2,39 +2,30 @@ #include<stdlib.h> __code cs_end(int a){ - printf("cs_exit : a=%d.\n", a); - exit(a); + printf("cs_exit : a=%d.\n", a); + exit(a); } __code cs0(int a, int b, int c, int d); __code cs_goto(int a, int b, int c, int d){ - //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); - printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); - //printf("cs_goto : a-4=%d, a-8=%d, a-12=%d, a-16=%d.\n", *(&a-4), *(&a-8), *(&a-12), *(&a-16)); - //printf("cs_goto : cs0(a, b, c, d)\n"); - goto cs0(b, c, d, a); + printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + goto cs0(b, c, d, a); } __code cs0(int a, int b, int c, int d){ - //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); - printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); - goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); + printf("cs_cs0 : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d); + goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) ); } -int function(double a, float b, int c){ - - //printf("function:\n"); - //printf("a=%lf, b=%f, c=%d\n", a, b, c); - //goto cs_goto(10, 20, 30, 40); - goto cs_goto(10, 20, 30, 40); +void function(double a, float b, int c){ + goto cs_goto(10, 20, 30, 40); } int main(int argc, char **argv){ - - function(10.01, 20.02, 30); - return 0; + function(10.01, 20.02, 30); + return 0; }
--- a/test_para3.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_para3.c Wed Oct 22 02:06:29 2014 +0900 @@ -2,82 +2,73 @@ #include<stdlib.h> struct abc { - int a; - double b; - char c; - double *d; + int a; + double b; + char c; + double *d; }; struct def { - int d; - struct abc e; - struct abc *f; + int d; + struct abc e; + struct abc *f; }; void print_abc(struct abc a){ - printf("\tstruct abc:\n"); - printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d); + printf("\tstruct abc:\n"); + printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d); } void print_def(struct def b){ - printf("\tstruct def:\n"); - printf("\td=%d, f=%p\n", b.d, b.f); - print_abc(b.e); + printf("\tstruct def:\n"); + printf("\td=%d, f=%p\n", b.d, b.f); + print_abc(b.e); } __code cs_exit(int a){ - printf("cs_exit : a=%d.\n", a); - exit(a); + printf("cs_exit : a=%d.\n", a); + exit(a); } __code cs0(struct abc a, struct def b, int c){ - printf("cs0 :\n"); - printf("c=%d\n", c); - print_abc(a); - print_def(b); - goto cs_exit( c*a.a+b.e.c ); + printf("cs0 :\n"); + printf("c=%d\n", c); + print_abc(a); + print_def(b); + goto cs_exit( c*a.a+b.e.c ); } __code cs_goto(int c, struct abc a, struct def b){ - printf("cs_goto :\n"); - printf("c=%d\n", c); - print_abc(a); - print_def(b); - goto cs0(a, b, c); + printf("cs_goto :\n"); + printf("c=%d\n", c); + print_abc(a); + print_def(b); + goto cs0(a, b, c); } int function(){ - struct abc A; - struct def B; - A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad; - B.d = 30, B.f = 0xbf; - B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed; + struct abc A; + struct def B; + A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad; + B.d = 30, B.f = 0xbf; + B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed; - printf("function :\n"); - print_abc(A); - print_def(B); - //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); - goto cs_goto(100, A, B); - return 0; + printf("function :\n"); + print_abc(A); + print_def(B); + goto cs_goto(100, A, B); + return 0; } int main(int argc, char **argv){ - struct abc A; - struct def B; - //int a=10, b=20, c=30, d=40, e=50, f=60, g=70; - A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad; - B.d = 30, B.f = 0xbf; - B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed; + struct abc A; + struct def B; + A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad; + B.d = 30, B.f = 0xbf; + B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed; - /* - printf("main :\n"); - print_abc(A); - print_def(B); - //printf("20*%d + 30*%d + 40*%d + 50*%d =\n", a, b, c, d); - goto cs_goto(100, A, B); - */ - function(); - return 0; + function(); + return 0; }
--- a/test_para4.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_para4.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,74 +1,63 @@ -//#include<stdio.h> -//#include<stdlib.h> +#include<stdio.h> +#include<stdlib.h> #define DPRINT 1 #define NOINLINE __attribute__((noinline)) extern __code cs_goto(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, - int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); extern __code cs0(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, - int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); __code (*csp)(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, - int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2); __code NOINLINE cs_exit(int a){ - int b = 20 * a + 3; - printf("cs_exit : a=%d. b=%d\n", a, b); - exit(a); + int b = 20 * a + 3; + printf("cs_exit : a=%d. b=%d\n", a, b); + exit(a); } __code NOINLINE cs0(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, - int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2){ + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2){ #if DPRINT - //printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g); - printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a, b, c, d, e, f, g, h, i, j); - printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); + printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("cs0 : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); #endif - goto cs_exit( (int)(10*a + 10*b + 10*i2 + 10*j2) ); + goto cs_exit( (int)(10*a + 10*b + 10*i2 + 10*j2) ); } __code NOINLINE cs_goto(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, - int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2){ + int a2, int b2, int c2, int d2, int e2, int f2, int g2, int h2, int i2, int j2){ #if DPRINT - printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a, b, c, d, e, f, g, h, i, j); - printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); + printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); #endif - goto cs0(b, c, d, e, f, g, h, i, j, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, a); + goto cs0(b, c, d, e, f, g, h, i, j, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, a); } -int function(double l, float m, int n){ - int a=10, b=20, c=30, d=40, e=50, f=60, g=70, h=80, i=90, j=100; - int a2=110, b2=120, c2=130, d2=140, e2=150, f2=160, g2=170, h2=180, i2=190, j2=200; +void function(double l, float m, int n){ + int a=10, b=20, c=30, d=40, e=50, f=60, g=70, h=80, i=90, j=100; + int a2=110, b2=120, c2=130, d2=140, e2=150, f2=160, g2=170, h2=180, i2=190, j2=200; #if DPRINT - printf("function: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a, b, c, d, e, f, g, h, i, j); - printf("function: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); - //printf("l=%lf, m=%f, n=%d\n", l, m, n); + printf("function: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, b, c, d, e, f, g, h, i, j); + printf("function: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); #endif - //goto cs_goto(10, 20, 30, 40); - goto cs_goto(a, b, c, d, e, f, g, h, i, j, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); + goto cs_goto(a, b, c, d, e, f, g, h, i, j, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); } int main(int argc, char **argv){ - //printf("main :\n"); - /* - printf("main : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a, b, c, d, e, f, g, h, i, j); - printf("main : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", - a2, b2, c2, d2, e2, f2, g2, h2, i2, j2); - */ - //csp = cs0; - function(10.01, 20.02, 30); - return 0; + function(10.01, 20.02, 30); + return 0; }
--- a/test_return.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_return.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,12 +1,18 @@ #include<stdio.h> +#ifdef CLANG +#define _CbC_return __return +#define _CbC_environment __environment +#endif + + #if 0 typedef float testtype; testtype good = 33.3f; testtype bad = 0.0f; void print_testtype(testtype t) { - printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad); + printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad); } #elif 1 typedef char testtype; @@ -14,7 +20,7 @@ testtype bad = 0; void print_testtype(testtype t) { - printf("return value = %d, good=%d,bad=%d\n", t,good,bad); + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); } #elif 0 typedef double testtype; @@ -22,25 +28,25 @@ testtype bad = 0.00; void print_testtype(testtype t) { - printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad); + printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad); } #elif 0 typedef struct { - int a; - float b; - int c[4]; + int a; + float b; + int c[4]; } testtype; testtype good = {33, 33.3, {4,4,4,4}}; testtype bad = {0, 00.0, {0,0,0,0}}; void print_testtype(testtype t) { - printf( "return value = {\n" - " a = %d\n" - " b = %2.3f\n" - " c = { %d, %d, %d, %d }" - "}\n", t.a, t.b, - t.c[0],t.c[1],t.c[2],t.c[3]); + printf( "return value = {\n" + " a = %d\n" + " b = %2.3f\n" + " c = { %d, %d, %d, %d }" + "}\n", t.a, t.b, + t.c[0],t.c[1],t.c[2],t.c[3]); } #else typedef int testtype; @@ -48,7 +54,7 @@ testtype bad = 0; void print_testtype(testtype t) { - printf("return value = %d, good=%d,bad=%d\n", t,good,bad); + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); } #endif @@ -56,34 +62,29 @@ void g(RET_FUNC func) { - func(good, NULL); + func(good, NULL); } testtype f_cbc() { - //__label__ _cbc_exit0; - //int retval; - void *ret; + void *ret; - ret = _CbC_return; + ret = _CbC_return; - printf("f0: fp = %p\n", __builtin_frame_address(0)); - printf("__return_func = %p\n", ret); - g(ret); + printf("f0: fp = %p\n", __builtin_frame_address(0)); + printf("__return_func = %p\n", ret); + g(ret); - printf("not good\n"); - return bad; -//_cbc_exit0: - //printf("f1: fp = 0x%x\n", __builtin_frame_address(0)); - //return retval; + printf("not good\n"); + return bad; } int main(int argc, char **argv) { - testtype t; - printf("main before: fp = %p\n", __builtin_frame_address(0)); - t = f_cbc(); - print_testtype(t); - printf("main after: fp = %p\n", __builtin_frame_address(0)); + testtype t; + printf("main before: fp = %p\n", __builtin_frame_address(0)); + t = f_cbc(); + print_testtype(t); + printf("main after: fp = %p\n", __builtin_frame_address(0)); }
--- a/test_struct.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_struct.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,31 +1,33 @@ - +#include<stdio.h> struct aaa{ - int a; // 4 - char b; // 1 - int c; // 4 - double d; // 8 - char e[10]; //10 + int a; // 4 + char b; // 1 + int c; // 4 + double d; // 8 + char e[10]; //10 }; //27 --> 32 +void tset01(struct aaa B, int size); + int main(int argc, char **argv){ - struct aaa A; - A.a = 10; - A.b = 'A'; - A.c = 20; - A.d = 1.11; - A.e[0] = 'A', A.e[1] = 'Z'; - - printf("sizeof aaa = %d\n", sizeof(struct aaa)); - tset01( A, 10); - return 0; + struct aaa A; + A.a = 10; + A.b = 'A'; + A.c = 20; + A.d = 1.11; + A.e[0] = 'A', A.e[1] = 'Z'; + + printf("sizeof aaa = %lu\n", sizeof(struct aaa)); + tset01(A, 10); + return 0; } -void tset01( struct aaa B, int size){ - printf("B.a = %d\n", B.a); - printf("B.b = %d\n", B.b); - printf("B.c = %d\n", B.c); - printf("B.d = %lf\n", B.d); - B.e[9] = '\0'; - printf("B.e = %s\n", B.e); - printf("size = %d\n", size); +void tset01(struct aaa B, int size){ + printf("B.a = %d\n", B.a); + printf("B.b = %d\n", B.b); + printf("B.c = %d\n", B.c); + printf("B.d = %lf\n", B.d); + B.e[9] = '\0'; + printf("B.e = %s\n", B.e); + printf("size = %d\n", size); }
--- a/test_tailcall1.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_tailcall1.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,28 +1,25 @@ #include<stdio.h> - void B(int a, int b, int c){ - printf("B: a=%d, b=%d, c=%d\n", a, b, c); - return ; + printf("B: a=%d, b=%d, c=%d\n", a, b, c); + return ; } void* freturn(){ - return B; + return B; } void A(int a, int b, int c, int d){ - void (*fp)(int, int, int); - fp = freturn(); - - printf("A: a=%d, b=%d, c=%d, d=%d\n", a, b, c, d); - return fp(a, b, c+d); - //return B(a, b, c+d); + void (*fp)(int, int, int); + fp = freturn(); + + printf("A: a=%d, b=%d, c=%d, d=%d\n", a, b, c, d); + return fp(a, b, c+d); } int main(int argc, char **argv){ - printf("main: \n"); - //fp = B; - A(10, 20, 30, 40); - return 0; + printf("main: \n"); + A(10, 20, 30, 40); + return 0; }
--- a/test_tree.c Wed Oct 22 00:38:01 2014 +0900 +++ b/test_tree.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,54 +1,55 @@ -//#include<stdio.h> +#include<stdio.h> +#include<stdlib.h> double test(char, char, int, double); __code cs(int , double , char ); void testvoid(double a); int testint(double a); +__code test_goto1(int a, int b, double c); __code cs(int a, double b, char c){ - printf("__code cs was called.\n"); - printf("a = %d, b = %lf, c = %d\n", a, b, c); - exit(0); + printf("__code cs was called.\n"); + printf("a = %d, b = %lf, c = %d\n", a, b, c); + exit(0); } __code cs1(int a, double b, char c, int d){ - printf("__code cs1 was called.\n"); - printf("a = %d, b = %lf, c = %d, d = %d\n", a, b, c, d); - exit(0); + printf("__code cs1 was called.\n"); + printf("a = %d, b = %lf, c = %d, d = %d\n", a, b, c, d); + exit(0); } int main(int argc, char **argv){ - double t; - //goto cs(2, 10.2, 2); + double t; - t = test('a', 'b', 10, 2.5); - printf("t = %lf\n", t); - testvoid(2.22); - testint(2.22); + t = test('a', 'b', 10, 2.5); + printf("t = %lf\n", t); + testvoid(2.22); + testint(2.22); - printf("test_goto\n"); - goto test_goto1(10, 20, 30.3); - return 0; + printf("test_goto\n"); + goto test_goto1(10, 20, 30.3); + return 0; } void test0(){ - exit(0); + exit(0); } void testvoid(double a){ - return ; + return ; } int testint(double a){ - int b; - b = (a*100-a) +2; - return 1; + int b; + b = (a*100-a) +2; + return 1; } double test(char c, char l, int a, double d){ - return (double)a*d+c+l; + return (double)a*d+c+l; } void test_goto(int a, int b, double c){ - goto cs(2, 10.2, 3); + goto cs(2, 10.2, 3); } __code test_goto1(int a, int b, double c){ - goto cs1(2, 10.2, 3, 4); + goto cs1(2, 10.2, 3, 4); }
--- a/tmp1.c Wed Oct 22 00:38:01 2014 +0900 +++ b/tmp1.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,94 +1,86 @@ /* easy test */ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return - +#endif extern int printf(const char *,...); -__code (*ret)(); +__code (*ret)(int, void*); void *env; -__code exit1(int ac,void *); +__code exit1(int ac,void *vp); +__code code0(int ac,char *av[],__code (*ret)(int, void*)); +__code code1(int ac,char *av[],__code (*exit)(int,void*)); +__code code3(char a,char b,int c,int d,int e,int f); +__code code4(char a,char b,int c,int d,int e,int f); -main0(ac,av) -int ac; -char *av[]; +int main0(int ac,char *av[]) { - ret = __return; - env = __environment; - printf("#0017:main0 %d start.\n",ac); - if (ac>=1) - goto code0(ac,av,__return); - goto code1(ac,av,exit1); - // not reached. (warning?) - printf("#0022:main0 %d end.\n",ac); + ret = __return; + env = __environment; + printf("#0017:main0 %d start.\n",ac); + if (ac>=1) + goto code0(ac,av,__return); + goto code1(ac,av,exit1); + // not reached. (warning?) + printf("#0022:main0 %d end.\n",ac); } -__code exit1(int ac) +__code exit1(int ac,void *vp) { - // exit(0); - goto code3(0,1,2,3,4,5); -} - -__code code3(a,b,c,d,e,f) -char a,b; -int c,d,e,f; -{ - printf("#0035:code3: %d %d %d %d %d %d\n",a,b,c,d,e,f); - if(a<10) - goto code3(a+1,b,c,d,e,f); - else - goto code4(a+3,b+3,c+3,d+3,e+3,f+3); + goto code3(0,1,2,3,4,5); } -__code code4(a,b,c,d,e,f) -char a,b; -int c,d,e,f; +__code code3(char a,char b,int c,int d,int e,int f) { - int i=1,j=2; - printf("#0047:code4: %d %d %d %d %d %d\n",a,b,c,d,e,f); - if(a<20) // cyclic binary dependency - goto code3(a+b,b+c,c+d,d+e,e+f,f+a); - else if(a<30) - goto code3(a,b,c,d,e,f); - else if(a<40) // cyclic dependency - goto code3(b,c,a,e,f,d); - else if(a<50) - goto code4(a+i,b+j,c+i,d+3,e+3,f+3); - else goto ret(0,env); + printf("#0035:code3: %d %d %d %d %d %d\n",a,b,c,d,e,f); + if(a<10) + goto code3(a+1,b,c,d,e,f); + else + goto code4(a+3,b+3,c+3,d+3,e+3,f+3); } -__code code0(ac,av,ret) -int ac; -char *av[]; -__code (*ret)(int); +__code code4(char a,char b,int c,int d,int e,int f) { - goto code1(ac,av,ret); + int i=1,j=2; + printf("#0047:code4: %d %d %d %d %d %d\n",a,b,c,d,e,f); + if(a<20) // cyclic binary dependency + goto code3(a+b,b+c,c+d,d+e,e+f,f+a); + else if(a<30) + goto code3(a,b,c,d,e,f); + else if(a<40) // cyclic dependency + goto code3(b,c,a,e,f,d); + else if(a<50) + goto code4(a+i,b+j,c+i,d+3,e+3,f+3); + else goto ret(0,env); } -__code code1(ac,av,exit) -int ac; -__code (*exit)(int,void*); -char *av[]; +__code code0(int ac,char *av[],__code (*ret)(int, void*)) +{ + goto code1(ac,av,ret); +} + +__code code1(int ac,char *av[], __code (*exit)(int,void*)) { - __code (*f)(int,void *); - printf("#0073:code1: %d\n",ac); - f = exit; - if (ac>3) - goto code1(ac,av,f); - else if (ac>2) - goto code1(av,ac,f); - else - goto (*f)(ac,env); + __code (*f)(int,void *); + printf("#0073:code1: %d\n",ac); + f = exit; + if (ac>3) + goto code1(ac,av,f); + else if (ac>2) + goto code1((int)av,(char**)ac,f); + else + goto (*f)(ac,env); } int main(int ac,char *av[]) { - main0(1,av); - printf("#0087:main continue.\n"); - main0(0,av); - printf("#0089:main end.\n"); -return 0; + main0(1,av); + printf("#0087:main continue.\n"); + main0(0,av); + printf("#0089:main end.\n"); + return 0; } /* end */
--- a/tmp2.c Wed Oct 22 00:38:01 2014 +0900 +++ b/tmp2.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,12 +1,16 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif #include "stdio.h" +int main0(int ac,char *av[]); +__code code0(char *av[],__code (*ret)(),void *retenv); +__code code1(char *av[],__code (*ret)(),void *retenv); + int -main(ac,av) -int ac; -char *av[]; +main(int ac,char *av[]) { int i; i=main0(ac,av); @@ -15,18 +19,13 @@ } int -main0(ac,av) -int ac; -char *av[]; +main0(int ac,char *av[]) { fprintf(stdout,"#0021:2: %s\n",av[0]); goto code0(av,__return,__environment); } -__code code0(av,ret,retenv) -char *av[]; -__code (*ret)(); -void *retenv; +__code code0(char *av[],__code (*ret)(int,void*),void *retenv) { char *p; p = av[0]; @@ -34,10 +33,7 @@ goto code1(av,ret,retenv); } -__code code1(av,ret,retenv) -char *av[]; -__code (*ret)(); -void *retenv; +__code code1(char *av[],__code (*ret)(int, void*),void *retenv) { fprintf(stdout,"#0041:4: %s\n",av[0]); goto (*ret)(1234,retenv);
--- a/tmp4.c Wed Oct 22 00:38:01 2014 +0900 +++ b/tmp4.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,12 +1,17 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif #include "stdio.h" +int main0(int ac,char *av[]); +__code code0(int i,int j,int k,char *av[],__code (*ret)(int,void*),void*retenv); +__code code1(int i,int j,int k,char *av[],__code(*ret)(int,void*),void*retenv); +__code code2(int i,int j,int k,char *av[],__code (*ret)(int, void*),void *retenv); + int -main(ac,av) -int ac; -char *av[]; +main(int ac,char *av[]) { int i; i=main0(ac,av); @@ -15,9 +20,7 @@ } int -main0(ac,av) -int ac; -char *av[]; +main0(int ac,char *av[]) { int i,j,k; i=123; @@ -27,11 +30,7 @@ goto code0(i,j,k,av,__return,__environment); } -__code code0(i,j,k,av,ret,retenv) -int i,j,k; -char *av[]; -__code (*ret)(); -void *retenv; +__code code0(int i,int j,int k,char *av[],__code (*ret)(int,void*),void*retenv) { char *p; p = av[0]+2; @@ -39,21 +38,13 @@ goto code1(i,j,k,av,ret,retenv); } -__code code1(i,j,k,av,ret,retenv) -int i,j,k; -char *av[]; -__code (*ret)(); -void *retenv; +__code code1(int i,int j,int k,char *av[],__code(*ret)(int,void*),void*retenv) { fprintf(stdout,"#0047:4: %s\n",av[0]+2); goto code2(i,j,k,av,ret,retenv); } -__code code2(i,j,k,av,ret,retenv) -int i,j,k; -char *av[]; -__code (*ret)(); -void *retenv; +__code code2(int i,int j,int k,char *av[],__code (*ret)(int,void*),void *retenv) { fprintf(stdout,"#0057:5: %s\n",av[0]+2); fprintf(stdout,"#0058:5: i=%d j=%d k=%d\n",i,j,k);
--- a/tmpa.c Wed Oct 22 00:38:01 2014 +0900 +++ b/tmpa.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,49 +1,51 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif #include <stdio.h> struct enemy{ - int charno; // image number - float x; // x location - float y; // y location - int ap; // armor point + int charno; // image number + float x; // x location + float y; // y location + int ap; // armor point }; void print_param(struct enemy *e) { - printf("#0014:charno:%d x,y:%f,%f hp:%d\n", - e->charno,e->x,e->y,e->ap); + printf("#0014:charno:%d x,y:%f,%f hp:%d\n", + e->charno,e->x,e->y,e->ap); } typedef struct{ - char dest; - int VF01[4]; - __code (*ret)(); - void *env; + char dest; + int VF01[4]; + __code (*ret)(int,void*); + void *env; } interface; __code a0(interface a) { - printf("#0026:%d\n",a.dest); - goto a.ret(0,a.env); + printf("#0026:%d\n",a.dest); + goto a.ret(0,a.env); } int main(int argc,char *argv[]) { - struct enemy e; + struct enemy e; #if 0 - interface args = {15,{0,0,0,0},return,environment}; + interface args = {15,{0,0,0,0},return,environment}; #else - interface args = {15,{0,0,0,0},0,0}; - args.ret = __return; - args.env = __environment; + interface args = {15,{0,0,0,0},0,0}; + args.ret = __return; + args.env = __environment; #endif - e.charno=5; e.x=50.0; e.y=30.0; e.ap=100; - print_param(&e); + e.charno=5; e.x=50.0; e.y=30.0; e.ap=100; + print_param(&e); - printf("#0045:%d %d\n",args.VF01[2],args.VF01[1]); - goto a0(args); + printf("#0045:%d %d\n",args.VF01[2],args.VF01[1]); + goto a0(args); }
--- a/too-long-argument.c Wed Oct 22 00:38:01 2014 +0900 +++ b/too-long-argument.c Wed Oct 22 02:06:29 2014 +0900 @@ -1,5 +1,7 @@ +#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return +#endif #include <stdio.h> @@ -7,37 +9,37 @@ typedef __code (*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, - __code(*ret)(int,void *), - void *env); + __code(*ret)(int,void *), + void *env); __code 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, - __code(*ret)(int,void *), - void *env) + __code(*ret)(int,void *), + void *env) { -fprintf(stdout,"#0017: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", -f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff); - goto ret(0,env); + fprintf(stdout,"#0017: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", + f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff); + goto ret(0,env); } __code tcode1(f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff,ret,env) - int f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff; - __code(*ret)(int,void *); - void *env; + int f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff; + __code(*ret)(int,void *); + void *env; { -fprintf(stdout,"#0028: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", -f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff); - goto ret(0,env); + fprintf(stdout,"#0028: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", + f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe,ff); + goto ret(0,env); } __code tcode4(int x,int y,CCC junction,__code(*ret)(int,void *),void *env) { #ifdef WRONGNUMBER - goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,ret,env); + goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,ret,env); #else - goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env); + goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env); #endif } @@ -45,9 +47,9 @@ 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 *),void *),__code(*ret)(int,void *),void *env) { #ifdef WRONGNUMBER - goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,ret,env); + goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,ret,env); #else - goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env); + goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env); #endif } @@ -55,11 +57,11 @@ main0() { #ifdef WRONGNUMBER - goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, - __return,__environment); + goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, + __return,__environment); #else - goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, - __return,__environment); + goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, + __return,__environment); #endif } @@ -67,38 +69,36 @@ main1() { #ifdef WRONGNUMBER - goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13, - __return,__environment); + goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13, + __return,__environment); #else - goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, - __return,__environment); + goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, + __return,__environment); #endif } int main2() { - goto tcode0(0,1,tcode1,__return,__environment); + goto tcode0(0,1,tcode1,__return,__environment); } int main4() { - goto tcode4(0,1,tcode2,__return,__environment); + goto tcode4(0,1,tcode2,__return,__environment); } int main() { - printf("#0092:main4\n"); - main4(); - printf("#0094:main2\n"); - main2(); - printf("#0096:main0\n"); - main0(); - printf("#0098:main1\n"); - main1(); -return 0; + printf("#0092:main4\n"); + main4(); + printf("#0094:main2\n"); + main2(); + printf("#0096:main0\n"); + main0(); + printf("#0098:main1\n"); + main1(); + return 0; } - -//