Mercurial > hg > CbC > old > device
changeset 197:b5f49f32c2ee
*** empty log message ***
author | kono |
---|---|
date | Thu, 08 Apr 2004 18:35:19 +0900 |
parents | 5f70abd9453d |
children | ef6f0c2d932f |
files | mc-codegen.c mc-parse.c test/code-gen.c |
diffstat | 3 files changed, 519 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-codegen.c Wed Apr 07 21:14:19 2004 +0900 +++ b/mc-codegen.c Thu Apr 08 18:35:19 2004 +0900 @@ -224,10 +224,10 @@ case SURINDIRECT: return code_srindirect(e2,caddr(e1),1); #if FLOAT_CODE + case FRINDIRECT: + return code_drindirect(e2,caddr(e1),0); case DRINDIRECT: return code_drindirect(e2,caddr(e1),1); - case FRINDIRECT: - return code_drindirect(e2,caddr(e1),0); #endif #if LONGLONG_CODE case LRINDIRECT:
--- a/mc-parse.c Wed Apr 07 21:14:19 2004 +0900 +++ b/mc-parse.c Thu Apr 08 18:35:19 2004 +0900 @@ -2915,8 +2915,8 @@ case UNSIGNED: break; case VOID: break; case CHAR: op=COP; type=INT; break; - case UCHAR: op=COP+US; type=INT; break; - case SHORT: op=SOP; type=UNSIGNED; break; + case UCHAR: op=COP+US; type=UNSIGNED; break; + case SHORT: op=SOP; type=SIGNED; break; case USHORT: op=SOP+US; type=UNSIGNED; break; case LONGLONG: op=LOP; break; case ULONGLONG: op=LOP+US; break;
--- a/test/code-gen.c Wed Apr 07 21:14:19 2004 +0900 +++ b/test/code-gen.c Thu Apr 08 18:35:19 2004 +0900 @@ -5,46 +5,550 @@ #define LONGLONG_CODE 1 // code_lvar(int e2,int creg) + +void +code_lvar() +{ + char c1,c2; + unsigned char uc1,uc2; + int i1,i2; + short s1,s2; + unsinged short us1,us2; +#if FLOAT_CODE + float f0,f1; + double d0,d1; +#endif +#if LONGLONG_CODE + long long l0,l1; + unsigned long long ul0,ul1; +#endif + + i1 = 1; i2 = -2; + s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; + printf("code_lvar %d %d %d %d %u %u\n",i1,i2,s1,s2,us1,us2); + c1 = -1; c2 = -3; uc1 = 65535; uc2 = 65535; + printf("code_lvar %d %d %u %u\n",c1,c2,uc1,uc2); +#if FLOAT_CODE + f0 = 0.0; f1 = 0.2; + d0 = 10; d1 = 10e10; + printf("code_lvar float %f %f %g %g\n",i1,i2,f0,f1,d0,d1); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + printf("code_lvar long long %ll %ll %ull %ull\n",i1,i2,f0,f1,d0,d1); +#endif +} + // code_label(int labelno) +void +code_label() +{ + goto hoge; +hage: + goto hage; +hoge: + printf("code_label done\n"); +} + // code_gvar(int e1,int creg) // code_rgvar(int e1,int creg) // code_crgvar(int e1,int creg,int sign,int sz) + +char c1,c2; +unsigned char uc1,uc2; +static char s_c1,s_c2; +static unsigned char s_uc1,s_uc2; +int i1,i2; +short s1,s2; +unsinged short us1,us2; +static int s_i1,s_i2; +static short s_s1,s_s2; +static unsinged short s_us1,s_us2; +#if FLOAT_CODE +float f0,f1; +double d0,d1; +static float s_f0,s_f1; +static double s_d0,s_d1; +#endif +#if LONGLONG_CODE +long long l0,l1; +unsigned long long ul0,ul1; +static long long s_l0,s_l1; +static unsigned long long s_ul0,s_ul1; +#endif + +void +code_gvar() +{ + i1 = 1; i2 = -2; + s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; + printf("code_gvar %d %d %u %u %u %u\n",i1,i2,s1,s2,us1,us2); + c1 = -1; c2 = -3; uc1 = 65535; uc2 = 65535; + printf("code_gvar %d %d %u %u\n",c1,c2,uc1,uc2); +#if FLOAT_CODE + f0 = 0.0; f1 = 0.2; + d0 = 10; d1 = 10e10; + printf("code_gvar float %f %f %g %g\n",i1,i2,f0,f1,d0,d1); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + printf("code_gvar long long %ll %ll %ull %ull\n",i1,i2,f0,f1,d0,d1); +#endif + s_i1 = 1; s_i2 = 2; + s_s1 = -1; s_s2 = -3; s_us1 = 65535; s_us2 = 65535; + printf("code_gvar %d %d %u %u %u %u\n",s_i1,s_i2,s1,s_s2,s_us1,s_us2); + s_c1 = -1; s_c2 = -3; s_uc1 = 65535; s_uc2 = 65535; + printf("code_gvar %d %d %u %u\n",s_c1,s_c2,s_uc1,s_uc2); +#if FLOAT_CODE + s_f0 = 0.0; s_f1 = 0.2; + s_d0 = 10; s_d1 = 10e10; + printf("code_gvar float %f %f %g %g\n",s_i1,s_i2,s_f0,s_f1,s_d0,s_d1); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + printf("code_gvar long long %ll %ll %ull %ull\n",s_i1,s_i2,s_f0,s_f1,s_d0,s_d1); +#endif +} + // code_register(int e2,int creg) -// code_rlvar(int e2,int reg) -// code_crlvar(int e2,int reg,int sign,int sz) + +code_register() +{ + register char c1,c2; + register unsigned char uc1,uc2; + register int i1,i2; + register short s1,s2; + register unsinged short us1,us2; +#if FLOAT_CODE + register float f0,f1; + register double d0,d1; +#endif +#if LONGLONG_CODE + register long long l0,l1; + register unsigned long long ul0,ul1; +#endif + + i1 = 1; i2 = -2; + s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; + printf("code_lvar %d %d %u %u %u %u\n",i1,i2,s1,s2,us1,us2); + c1 = -1; c2 = -3; uc1 = 65535; uc2 = 65535; + printf("code_gvar %d %d %u %u\n",c1,c2,uc1,uc2); +#if FLOAT_CODE + f0 = 0.0; f1 = 0.2; + d0 = 10; d1 = 10e10; + printf("code_lvar float %f %f %g %g\n",i1,i2,f0,f1,d0,d1); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + printf("code_lvar long long %ll %ll %ull %ull\n",i1,i2,f0,f1,d0,d1); +#endif +} + // code_fname(NMTBL *n,int creg) -// code_const(int e2,int creg) + +code_fname() +{ + int i,j; + i = (int)code_fname; + j = (int)code_register; + printf("code_fname %d\n",i==j); +} + + // code_neg(int creg) +void +code_neg() +{ + int i,j; + i = 123123123;j = -32423; + printf("code_neg %d %d\n",-i,-j); +} + // code_not(int creg) +void +code_not() +{ + int i,j; + i = 123123123;j = 0; + printf("code_neg %d %d\n",~i,~j); +} + // code_lnot(int creg) +void +code_lnot() +{ + int i,j; + i = 123123123;j = 0; + printf("code_neg %d %d\n",!i,!j); +} + // code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) +void +code_preinc() +{ + int i,j; + i = 123123123;j = 0; + printf("code_preinc %d %d\n",++i,--j); +} + // code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) +void +code_postinc() +{ + int i,j; + i = 123123123;j = 0; + printf("code_preinc %d %d\n",i++,j--); +} + // code_return(int creg) -// code_bool(int e1) + +int +code_return_int() +{ + return 1; +} + +float +code_return_float() +{ + return 1.0; +} + +double +code_return_double() +{ + return 1.0; +} + +long long +code_return_longlong() +{ + return 10LL; +} + +struct aa { char a[100]; } a0; +struct aa +code_return_struct() +{ + a0.a[55]=3; + return a0; +} + // code_gt(int cond) + +void code_gt() +{ + if (i1>i2) + printf("code_gt 1\n"); + else + printf("code_gt 0\n"); +} + // code_ugt(int cond) +void code_ugt() +{ + if (ui1>ui2) + printf("code_ugt 1\n"); + else + printf("code_ugt 0\n"); +} + // code_ge(int cond) +void code_ge() +{ + if (i1>=i2) + printf("code_ge 1\n"); + else + printf("code_ge 0\n"); +} + // code_uge(int cond) +void code_uge() +{ + if (ui1>=ui2) + printf("code_uge 1\n"); + else + printf("code_uge 0\n"); +} + // code_eq(int cond) -// code_cmp_crgvar(int e1,int sz) -// code_cmp_crlvar(int e2,int sz) -// code_cmp_rgvar(int e1) -// code_cmp_rlvar(int e2) -// code_cmp_register(int e2) -// ascii(char *s) +void code_eq() +{ + if (ui1==ui2) + printf("code_eq 1\n"); + else + printf("code_eq 0\n"); + if (i1!=i2) + printf("code_neq 1\n"); + else + printf("code_neq 0\n"); +} + +// code_bool(int e1) + +void +code_bool() +{ + printf("code_bool %d %d %d %d %d %d\n", + i1>i2,ui1>ui2,i1>=i2,ui1>=ui2,ui1==ui2,i1!=i2); +#if FLOAT_CODE + printf("code_bool float %d %d %d %d\n", + f0>f1,f0>=f1,f0==f1,f0!=f1); + printf("code_bool double %d %d %d %d\n", + d0>d1,d0>=d1,d0==d1,d0!=d1); +#endif +#if LONGLONG_CODE + printf("code_bool long long %d %d %d %d %d %d\n", + l1>l0,ul1>ul0,l1>=l0,ul1>=ul0,ul1==ul0,l1!=l0); +#endif +} + +void +code_cmp() +{ + char c1,c2; + unsigned char uc1,uc2; + int i1,i2; + short s1,s2; + unsinged short us1,us2; +#if FLOAT_CODE + float f0,f1; + double d0,d1; +#endif +#if LONGLONG_CODE + long long l0,l1; + unsigned long long ul0,ul1; +#endif + i1 = 1; i2 = -2; + s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; + c1 = -1; c2 = -3; uc1 = 65535; uc2 = 65535; + i1 && printf("code_bool local 1\n"); + s1 && printf("code_bool local 2\n"); + us1 && printf("code_bool local 3\n"); + c1 && printf("code_bool local 4\n"); + uc1 && printf("code_bool local 5\n"); +#if FLOAT_CODE + f0 = 0.0; f1 = 0.2; + d0 = 10; d1 = 10e10; + f0 && printf("code_bool local 6\n"); + d0 && printf("code_bool local 7\n"); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + l0 && printf("code_bool local 8\n"); + ul0 && printf("code_bool local 9\n"); +#endif + +} +void +code_cmp_global() +{ + i1 = 1; i2 = -2; + s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; + c1 = -1; c2 = -3; uc1 = 65535; uc2 = 65535; + i1 && printf("code_bool global 1\n"); + s1 && printf("code_bool global 2\n"); + us1 && printf("code_bool global 3\n"); + c1 && printf("code_bool global 4\n"); + uc1 && printf("code_bool global 5\n"); +#if FLOAT_CODE + f0 = 0.0; f1 = 0.2; + d0 = 10; d1 = 10e10; + f0 && printf("code_bool global 6\n"); + d0 && printf("code_bool global 7\n"); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + l0 && printf("code_bool global 8\n"); + ul0 && printf("code_bool global 9\n"); +#endif +} + +void +code_cmp_register() +{ + register char c1,c2; + register unsigned char uc1,uc2; + register int i1,i2; + register short s1,s2; + register unsinged short us1,us2; +#if FLOAT_CODE + register float f0,f1; + register double d0,d1; +#endif +#if LONGLONG_CODE + register long long l0,l1; + register unsigned long long ul0,ul1; +#endif + i1 = 1; i2 = -2; + s1 = -1; s2 = -3; us1 = 65535; us2 = 65535; + c1 = -1; c2 = -3; uc1 = 65535; uc2 = 65535; + i1 && printf("code_bool register 1\n"); + s1 && printf("code_bool register 2\n"); + us1 && printf("code_bool register 3\n"); + c1 && printf("code_bool register 4\n"); + uc1 && printf("code_bool register 5\n"); +#if FLOAT_CODE + f0 = 0.0; f1 = 0.2; + d0 = 10; d1 = 10e10; + f0 && printf("code_bool register 6\n"); + d0 && printf("code_bool register 7\n"); +#endif +#if LOGNLONG_CODE + l0 = 123123123LL; + l1 = 123123123LL; + ul0 = 123123123LL; + ul1 = 123123123LL; + l0 && printf("code_bool register 8\n"); + ul0 && printf("code_bool register 9\n"); +#endif + +} + + // code_string(int e1,int creg) + +void +code_string(int e1,int creg) +{ + printf("code_string test\n"); +} + // struct_push(int e4,int t,int arg) -// function(int e1) + +struct aa +struct_push0(int i,struct aa a) +{ + a.a[55]++; + if (i==0) { + return struct_push(1,a0); + } + return a0; +} + +void +struct_push() +{ + a0.a[55]=3; + a0 = struct_push0(0,a0); + printf("struct_push %d\n",a0.a[55]); +} + // code_jmp(char *s) // code_indirect_jmp(int e2) + // code_rindirect(int e1, int offset, int us); +void +code_rindirect() +{ + int i1,i2; + unsigned int ui1,ui2; + int *pi1,*pi2; + unsigned int *pui1,*pui2; + + i1 = -555; i2= 555; + ui1 = 632423423; ui2= 32394234; + pi1 = &i1; + pi2 = &i2; + pui1 = &ui1; + pui2 = &ui2; + printf("code_rindirect %d %d %u %u\n",*pi1,*pi2,*pui1,*pui2); +} + // code_crindirect(int e1, int offset, int us); +void +code_crindirect() +{ + char i1,i2; + unsigned char ui1,ui2; + char *pi1,*pi2; + unsigned char *pui1,*pui2; + + i1 = -55; i2= 55; + ui1 = 200; ui2= 128; + pi1 = &i1; + pi2 = &i2; + pui1 = &ui1; + pui2 = &ui2; + printf("code_cindirect %d %d %u %u\n",*pi1,*pi2,*pui1,*pui2); +} + // code_srindirect(int e1, int offset, int us); +void +code_srindirect() +{ + short i1,i2; + unsigned short ui1,ui2; + short *pi1,*pi2; + unsigned short *pui1,*pui2; + + i1 = -55; i2= 55; + ui1 = 200; ui2= 128; + pi1 = &i1; + pi2 = &i2; + pui1 = &ui1; + pui2 = &ui2; + printf("code_sindirect %d %d %u %u\n",*pi1,*pi2,*pui1,*pui2); +} + #if FLOAT_CODE // code_drindirect(int e1, int offset, int d); +void +code_drindirect() +{ + float i1,i2; + double ui1,ui2; + float *pi1,*pi2; + double *pui1,*pui2; + + i1 = -55; i2= 55; + ui1 = 200; ui2= 128; + pi1 = &i1; + pi2 = &i2; + pui1 = &ui1; + pui2 = &ui2; + printf("code_dindirect %g %g %g %g\n",*pi1,*pi2,*pui1,*pui2); +} + #endif + #if LONGLONG_CODE // code_lrindirect(int e1, int offset, int us); +void +code_lrindirect() +{ + long long i1,i2; + unsigned long long ui1,ui2; + long long *pi1,*pi2; + unsigned long long *pui1,*pui2; + + i1 = -55; i2= 55; + ui1 = 200; ui2= 128; + pi1 = &i1; + pi2 = &i2; + pui1 = &ui1; + pui2 = &ui2; + printf("code_lrindirect %lld %lld %llu %llu\n",*pi1,*pi2,*pui1,*pui2); +} + #endif