changeset 31:79124facde7c

add some tests.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Dec 2009 12:50:31 +0900
parents c845c9fe357a
children 59194914942b
files CbC-examples/conv1/Makefile CbC-examples/conv1/conv1.c CbC-examples/conv1/conv1.h
diffstat 3 files changed, 292 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-examples/conv1/Makefile	Tue Dec 08 12:50:31 2009 +0900
@@ -0,0 +1,11 @@
+CbCC = ../../../build_cbc44/INSTALL_DIR/libexec/gcc/i686-pc-linux-gnu/4.4.1/cc1
+
+
+time:
+	for exe in *; do \
+	    if [ -x $$exe ]; then \
+	    	echo $$exe; \
+	    	time ./$$exe; \
+	    fi; \
+	done
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-examples/conv1/conv1.c	Tue Dec 08 12:50:31 2009 +0900
@@ -0,0 +1,227 @@
+#include <stdio.h>
+static int loop;
+
+#if 1 // def __micro_c__
+#define CC_ONLY 0
+#else
+#define CC_ONLY 1
+#endif
+
+typedef char *stack;
+#include "conv1.h"
+
+/* 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) */
+
+
+struct cont_interface { // General Return Continuation
+    __code (*ret)();
+};
+
+__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 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)(int,void*);
+    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);
+    exit(0);
+    //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 500000000
+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 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-examples/conv1/conv1.h	Tue Dec 08 12:50:31 2009 +0900
@@ -0,0 +1,54 @@
+/* defined in file conv1.c at offset 468 */
+__code f (int i,stack sp);
+
+/* defined in file conv1.c at offset 680 */
+__code f_g0 (int i,int k,stack sp);
+
+/* defined in file conv1.c at offset 897 */
+__code f_g1 (int j,stack sp);
+
+/* defined in file conv1.c at offset 1162 */
+__code g (int i,stack sp);
+
+/* defined in file conv1.c at offset 1355 */
+__code g_h1 (int j,stack sp);
+
+/* defined in file conv1.c at offset 1588 */
+__code h (int i,stack sp);
+
+/* defined in file conv1.c at offset 1838 */
+__code main_return (int i,stack sp);
+
+/* defined in file conv1.c at offset 2107 */
+__code f2 (int i,char *sp);
+
+/* defined in file conv1.c at offset 2189 */
+__code g2 (int i,int k,int j,char *sp);
+
+/* defined in file conv1.c at offset 2270 */
+__code h2_1 (int i,int k,int j,char *sp);
+
+/* defined in file conv1.c at offset 2346 */
+__code h2 (int i,int k,char *sp);
+
+/* defined in file conv1.c at offset 2410 */
+__code main_return2 (int i,stack sp);
+
+/* defined in file conv1.c at offset 2658 */
+__code f2_1 (int i,char *sp);
+
+/* defined in file conv1.c at offset 2742 */
+__code g2_1 (int k,int i,char *sp);
+
+/* defined in file conv1.c at offset 2844 */
+__code h2_1_1 (int i,int k,int j,char *sp);
+
+/* defined in file conv1.c at offset 2918 */
+__code h2_11 (int i,int k,char *sp);
+
+/* defined in file conv1.c at offset 2987 */
+__code f2_0_1 (int k,int j,char *sp);
+
+/* defined in file conv1.c at offset 3086 */
+__code main_return2_1 (int i,stack sp);
+