# HG changeset patch # User kent # Date 1264408065 -32400 # Node ID a14cd9f25ac47d75413118cde925b1676bc8b878 # Parent 607e6dc322e53f5fe6a5239c3a9c59df46a7615e# Parent 9e4f9e20b8f14b9e81310c694b49d44a6f1614d2 merge. diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/matrix/compute_power.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/matrix/compute_power.c Mon Jan 25 17:27:45 2010 +0900 @@ -0,0 +1,107 @@ +#include +#include "matrix.h" + +void compute(); +double ** create_identity_matrix(int size); +double ** multiply(double **a, double **b, int l, int m, int n); +void print_matrix(double **a, int row, int col); + +int +main(int argc, char **argv) +{ + compute(); + return 0; +} + +void +compute() +{ + double **A, **B, **C; + A = create_identity_matrix(4); + B = create_identity_matrix(4); + printf("A = \n"); + print_matrix(A, 4, 4); + printf("B = \n"); + print_matrix(B, 4, 4); + + C = multiply(A, B, 4,4,4); + printf("C = \n"); + print_matrix(C, 4, 4); + + + free(A); + free(B); + free(C); +} + +double ** +create_identity_matrix(int size) +{ + int i,j; + double **ret; + ret = create_matrix(sizeof(double), size, size); + + for (j=0; j +#include + +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +int +test(int a) +{ + return (int)pow(a, 2.0); +} + +int +callee(double a, double b, double c, int d) +{ + dprint("a=%d,b=%d,c=%d,d=%d\n", a,b,c,d); + return a+b+c+d; +} + +int +caller(int a, double b, double c, double d) +{ + int x; + double y,z,w; + //x = test(a); + //y = test(b); + //z = test(c); + //w = test(d); + x=a, y=b; + z=c, w=d; + + return callee(y,z,w,x); + //return callee(b,c,d, a); +} + +int +main (int argc, char **argv) +{ + int r; + r = caller(11,22,33,44); + //r = caller(11,22,33,44, 55,66,77,88); + printf("r = %d\n", r); +} + + + diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/parallel_check/c-int.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/parallel_check/c-int.c Mon Jan 25 17:27:45 2010 +0900 @@ -0,0 +1,71 @@ +#include +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +void +callee(int a, int b, int c, int d) +{ + int r; + dprint("a=%d,b=%d,c=%d,d=%d\n", a,b,c,d); + r = a+b+c+d; + printf("r = %d\n", r); + return; +} + +void +caller1(int a, int b, int c, int d) +{ + int x,y,z,w; + x=a, y=b; + z=c, w=d; + + callee(x,y,z,w); + return; +} + +void +caller2(int a, int b, int c, int d) +{ + int x,y,z,w; + x=a, y=b; + z=c, w=d; + + callee(y,z,w,x); + return; +} + +void +caller3(int a, int b, int c, int d) +{ + callee(b,c,d,a); + return; +} + +void +caller4(int a, int b, int c, int d) +{ + callee(a+b,b+c,c+d,d+a); + return; +} + +void +caller5(int a, int b, int c, int d) +{ + int x,y,z,w; + x = a+b; + y = b+c; + z = c+d; + w = d+a; + + callee(x,y,z,w); + return; +} + +int +main (int argc, char **argv) +{ + int r; + caller(11,22,33,44); + //r = caller(11,22,33,44, 55,66,77,88); +} + diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/parallel_check/c-struct.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/parallel_check/c-struct.c Mon Jan 25 17:27:45 2010 +0900 @@ -0,0 +1,51 @@ +#include +#include + +#define dprint(f, args...) \ + printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args) + +typedef struct { + int a; + double b; + char *c; +} STRUCT; + +int +test(int a) +{ + return (int)pow(a, 2.0); +} + + +int +callee(int a, STRUCT s, int b) + /* |-|----|-| */ +{ + dprint("a=%d,b=%d\n", a,b); + dprint("s.a=%d,s.b=%lf,s.c=%s\n", s.a, s.b, s.c); + return a+b+ s.a; +} + +int +caller(STRUCT s, int a, double b) + /* |----|-|--| */ +{ + STRUCT s0;// = {44, 55.5, "aiueo2"}; + //int a0 = 55; + //a0 = a; + s0 = s; + + return callee(10, s0, 20); +} + +int +main (int argc, char **argv) +{ + int r; + STRUCT s = { 33, 44.4, "aiueo" }; + + r = caller(s, 11, 22.2); + //r = caller(11,22,33,44, 55,66,77,88); + printf("r = %d\n", r); +} + diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/quicksort/Makefile --- a/CbC-examples/quicksort/Makefile Mon Jan 25 17:26:06 2010 +0900 +++ b/CbC-examples/quicksort/Makefile Mon Jan 25 17:27:45 2010 +0900 @@ -1,8 +1,8 @@ -CbCC=../../../build-gcc/INSTALL_DIR/bin/cbc-gcc +CbCC=../../../build_gcc/INSTALL_DIR/bin/gcc #CC=gcc -CC=../../../build-gcc/INSTALL_DIR/bin/cbc-gcc +CC=../../../build_gcc/INSTALL_DIR/bin/gcc HEADERMAKER=../../CbC-scripts/make_headers.py2 diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/quicksort/mc/Makefile --- a/CbC-examples/quicksort/mc/Makefile Mon Jan 25 17:26:06 2010 +0900 +++ b/CbC-examples/quicksort/mc/Makefile Mon Jan 25 17:27:45 2010 +0900 @@ -2,7 +2,7 @@ CbCC=../../../../device/mc #CC=gcc -CC=../../../../build-gcc/INSTALL_DIR/bin/cbc-gcc +CC=../../../../build_gcc/INSTALL_DIR/bin/gcc HEADERMAKER=../../../CbC-scripts/make_headers.py2 diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/return_check/test_return.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/return_check/test_return.c Mon Jan 25 17:27:45 2010 +0900 @@ -0,0 +1,89 @@ +#include + +#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); +} +#elif 1 +typedef char testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#elif 0 +typedef double testtype; +testtype good = 333.3; +testtype bad = 0.00; +void print_testtype(testtype t) +{ + 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]; +} 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]); +} +#else +typedef int testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#endif + +typedef void (*RET_FUNC)(testtype, void *); + +void g(RET_FUNC func) +{ + func(good, NULL); +} + +testtype f_cbc() +{ + //__label__ _cbc_exit0; + //int retval; + void *ret; + + ret = _CbC_return; + + 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; +} + +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)); +} + diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/return_check/typedeffed.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/return_check/typedeffed.c Mon Jan 25 17:27:45 2010 +0900 @@ -0,0 +1,89 @@ +#include + +#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); +} +#elif 1 +typedef char testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#elif 0 +typedef double testtype; +testtype good = 333.3; +testtype bad = 0.00; +void print_testtype(testtype t) +{ + 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]; +} 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]); +} +#else +typedef int testtype; +testtype good = 33; +testtype bad = 0; +void print_testtype(testtype t) +{ + printf("return value = %d, good=%d,bad=%d\n", t,good,bad); +} +#endif + +typedef void (*RET_FUNC)(testtype, void *); + +void g(RET_FUNC func) +{ + func(good, NULL); +} + +testtype f_cbc() +{ + //__label__ _cbc_exit0; + //int retval; + void *ret; + + ret = _CbC_return; + + 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; +} + +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)); +} + diff -r 607e6dc322e5 -r a14cd9f25ac4 CbC-examples/return_check/variable_return_type.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/return_check/variable_return_type.c Mon Jan 25 17:27:45 2010 +0900 @@ -0,0 +1,196 @@ +#include +#include + +#define dprint(f, args...) \ + fprintf(stdout, "in %s\t: "f, __FUNCTION__, ## args) + + +/* for integer. */ +int goodint = 33; +int badint = 0; +typedef void (*RETINT_FUNC)(int, void *); +void g_int(RETINT_FUNC func) +{ + func(goodint, NULL); +} +int f_int() +{ + void *ret; + + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_int(ret); + //goto g(ret); + + dprint("not good\n"); + return badint; +} + + +/* for double. */ +double gooddouble = 333.3; +double baddouble = 0.00; +typedef void (*RETDOUBLE_FUNC)(double, void *); +void g_double(RETDOUBLE_FUNC func) +{ + func(gooddouble, NULL); +} +double f_double() +{ + void *ret; + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_double(ret); + //goto g_double(ret); + + dprint("not good\n"); + return baddouble; +} + +/* for float. */ +float goodfloat = 33.3f; +float badfloat = 0.0f; +typedef void (*RETFLOAT_FUNC)(float, void *); +void g_float(RETFLOAT_FUNC func) +{ + func(goodfloat, NULL); +} +float f_float() +{ + void *ret; + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_float(ret); + //goto g_float(ret); + + dprint("not good\n"); + return badfloat; +} + +/* for char. */ +char goodchar = 33; +char badchar = 0; +typedef void (*RETCHAR_FUNC)(char, void *); +void g_char(RETCHAR_FUNC func) +{ + func(goodchar, NULL); +} +char f_char() +{ + void *ret; + + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_char(ret); + //goto g(ret); + + dprint("not good\n"); + return badchar; +} + + +/* for struct. */ +struct ifid { + int a; + float b; + int c[4]; + double d; +}; +struct ifid goodstruct = {33, 33.3, {4,4,4,4}, 333.333}; +struct ifid badstruct = {0, 00.0, {0,0,0,0}, 0.0}; +typedef void (*RETSTRUCT_FUNC)(struct ifid, void *); +void g_struct(RETSTRUCT_FUNC func) +{ + func(goodstruct, NULL); +} +struct ifid f_struct() +{ + void *ret; + + ret = _CbC_return; + + dprint("fp = %p\n", __builtin_frame_address(0)); + dprint("__return_func = %p\n", ret); + g_struct(ret); + //goto g(ret); + + dprint("not good\n"); + return badstruct; +} + +int main(int argc, char **argv) +{ + void *bptr; + int rint; + float rfloat; + double rdouble; + char rchar; + struct ifid rstruct; + + bptr = __builtin_frame_address(0); + + dprint("before int: fp = %p\n", __builtin_frame_address(0)); + rint = f_int(); + dprint("f_int = %d, good=%d,bad=%d\n", rint,goodint,badint); + + dprint("before float: fp = %p\n", __builtin_frame_address(0)); + rfloat = f_float(); + dprint("f_float = %3.3f, good=%3.3f,bad=%3.3f\n", rfloat,goodfloat,badfloat); + assert(bptr==__builtin_frame_address(0)); + + dprint("before double: fp = %p\n", __builtin_frame_address(0)); + rdouble = f_double(); + dprint("f_double = %3.3lf, good=%3.3lf,bad=%3.3lf\n", rdouble,gooddouble,baddouble); + assert(bptr==__builtin_frame_address(0)); + + dprint("before char: fp = %p\n", __builtin_frame_address(0)); + rchar = f_char(); + dprint("f_char = %d, good=%d,bad=%d\n", rchar,goodchar,badchar); + assert(bptr==__builtin_frame_address(0)); + + dprint("before struct: fp = %p\n", __builtin_frame_address(0)); + rstruct = f_struct(); + dprint( "return value = {\n" + " a = %d\n" + " b = %2.3f\n" + " c = { %d, %d, %d, %d }\n" + " d = %3.3f\n" + "}\n", rstruct.a, rstruct.b, + rstruct.c[0],rstruct.c[1],rstruct.c[2],rstruct.c[3], rstruct.d); + + + + dprint("end: fp = %p\n", __builtin_frame_address(0)); + + if (bptr!=__builtin_frame_address(0)) { + dprint("CbC_return failure!\n"); + return 1; + } + if ( rint!=goodint + || rchar!=goodchar + || (rfloat < goodfloat-0.01 || goodfloat+0.01 < rfloat) + || (rdouble < gooddouble-0.01 || gooddouble+0.01 < rdouble) + || rstruct.a!=goodstruct.a + || (rstruct.b < goodstruct.b-0.01 || goodstruct.b+0.01 < rstruct.b) + || (rstruct.d < goodstruct.d-0.01 || goodstruct.d+0.01 < rstruct.d) + || rstruct.c[0]!=goodstruct.c[0] + || rstruct.c[1]!=goodstruct.c[1] + || rstruct.c[2]!=goodstruct.c[2] + || rstruct.c[3]!=goodstruct.c[3] ) { + dprint("CbC_return failure!\n"); + return 1; + } + + + dprint("CbC_return successful!\n"); + return 0; +} +