Mercurial > hg > CbC > old > device
changeset 195:c193120ee2a6
*** empty log message ***
author | kono |
---|---|
date | Sun, 04 Apr 2004 21:17:10 +0900 |
parents | 114e9d64b5cc |
children | 5f70abd9453d |
files | Changes Makefile hrs mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h mc-parse.c mc.h rsyncs |
diffstat | 12 files changed, 1572 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Jan 10 17:13:49 2004 +0900 +++ b/Changes Sun Apr 04 21:17:10 2004 +0900 @@ -3812,3 +3812,50 @@ ですかね。 +Wed Jan 14 10:21:49 CET 2004 + +function callを compiler の外に出せないかなぁ。 + code function_interface(args) { + ..... + push(args); (in asm) + push(next); + goto function... + } + code function_continuation(args) { + } +みたいな感じで... ま、遅くなるだろうけど... + +でも、そうすれば、コンパイラの移植は比較的簡単になる。 + +Thu Jan 15 11:52:03 CET 2004 + +stack は、 + system wide に一つ ( classical environment) + code に一つ ( fortran type ) + object に一つ (like message buffer in ABCL) +っていう選択もあるね。 + +Sun Jan 18 11:08:13 JST 2004 + +(なんか、遅すぎなんだよね... CPS 変換か...) + +shift/reset をCで実装するのは簡単だが... + reset{ + shfit(); + } +みたいな感じ? + +stack / data structure の保護の方法に、もっと何かがあるんじゃ +ないかな。 + +関数呼び出しなんだけど... + +apply みたいなのがあればいい? + goto apply(function_name,continuation(return_type),args....); +かな。で、この部分を、C/asm で書くというわけね。 +ま、おんなじようなものか。(何と?) この部分だけ interpreter 的に +なっちゃうな。varargs でもいいんだけど... + +コンパイラをCbCで書くと言う作業が残っているんだよな... + +う、やっぱり、long long は、遠い... できんの?
--- a/Makefile Sat Jan 10 17:13:49 2004 +0900 +++ b/Makefile Sun Apr 04 21:17:10 2004 +0900 @@ -19,6 +19,11 @@ mc: mc-$(ARCH) cp mc-$(ARCH) mc +TAGS: + tags mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h \ + mc-parse.c mc-tree.c mc.h conv/c.c conv/c.h \ + conv/conv.h conv/convdef.h conv/null.c + mc-powerpc : mc-code-powerpc.o $(COMPLIB) $(CONVERTER) $(CC) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hrs Sun Apr 04 21:17:10 2004 +0900 @@ -0,0 +1,2 @@ +#!/bin/sh +rsync -av --exclude CVS /Users/kono/src/device ..
--- a/mc-code-ia32.c Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-code-ia32.c Sun Apr 04 21:17:10 2004 +0900 @@ -149,11 +149,13 @@ static int edx_setup(); static void edx_cleanup(); static void local_table(void); +#if FLOAT_CODE static char * fload(int d); static int code_d1(double d); static int code_d2(double d); +static void code_save_fstacks(); +#endif static void code_save_stacks(); -static void code_save_fstacks(); void code_init(void) @@ -215,6 +217,8 @@ int use_int(int i) { return i;} int use_float(int i) { return i;} int use_double(int i) { return i;} +int use_longlong(int i) { return i; } + void gexpr_code_init(void){ @@ -275,6 +279,12 @@ return -1; } +int +get_lregister_var(NMTBL *n) +{ + return -1; +} + int register_full(void) { @@ -1082,11 +1092,13 @@ e3 = cadr(e2 = cadr(e1)); g_expr(e2); switch (car(e1)) { +#if FLOAT_CODE case FRINDIRECT: case DRINDIRECT: printf("\t%s (%s)\n",fload(car(e1)==DRINDIRECT),register_name(creg,0)); t=DOUBLE; return t; break; +#endif case CRINDIRECT: byte = 1; op="movsbl";t=CHAR; break; @@ -1581,8 +1593,10 @@ emit_data(int e, int t, NMTBL *n) { int l; +#if FLOAT_CODE double d; float f; +#endif char *name; name = n->nm; if(mode!=GDECL && mode!=STADECL) { @@ -1612,12 +1626,14 @@ printf("\t.long %d\n",cadr(e)); gpc += size_of_int; } +#if FLOAT_CODE } else if(t==DOUBLE) { d = dcadr(e); printf("\t.long\t0x%x,0x%x\n",code_d1(d),code_d2(d)); } else if(t==FLOAT) { f = dcadr(e); printf("\t.long\t0x%x\n",*(int *)&f); +#endif } else if(t!=CHAR) { gpc += size_of_int; if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { @@ -1710,6 +1726,8 @@ printf("\t.type\t%s,@object\n",name); } +#if FLOAT_CODE + /* floating point */ @@ -2002,6 +2020,8 @@ printf("# fpush:%d\n",freg_sp); } +#endif + void code_save_stacks() { @@ -2022,9 +2042,12 @@ creg=screg; } } +#if FLOAT_CODE code_save_fstacks(); +#endif } +#if FLOAT_CODE void code_save_fstacks() { @@ -2040,5 +2063,215 @@ } use = uses; } +#endif + + + +#if LONGLONG_CODE + + +/* 64bit int part */ + +void lrexpr(int e1, int e2,int l1, int op) +{ +} + +int lpop_register() +{ + return 0; +} + +int emit_lpop() +{ + return 0; +} + +void code_lregister(int e2,int reg) +{ + +} + +void code_cmp_lregister(int reg) +{ + +} + +void code_cmp_lrgvar(int e1,int e2) +{ + +} + +void code_cmp_lrlvar(int e1,int e2) +{ + +} + +void code_lassign(int e1,int e2) +{ + +} + +void code_lassign_gvar(int e1,int e2) +{ + +} + +void code_lassign_lvar(int e1,int e2) +{ + +} + +void code_lassign_lregister(int e2,int reg) +{ + +} + +void code_lconst(int e1,int e2) +{ + +} + +void code_lneg(int e1,int e2) +{ + +} + +void code_lrgvar(int e1,int e2) +{ + +} + +void code_lrlvar(int e1,int e2) +{ + +} + +void ltosop(int e1,int e2) +{ + +} + +void emit_lpop_free(int e1) +{ + +} + +void emit_lpush() +{ + +} + +void code_i2ll(int creg) +{ + +} + +void code_i2ull(int creg) +{ + +} + +void code_u2ll(int creg) +{ + +} + +void code_u2ull(int creg) +{ + +} + +void code_ll2i(int creg) +{ + +} + +void code_ll2u(int creg) +{ + +} + +void code_ull2i(int creg) +{ + +} + +void code_ull2u(int creg) +{ + +} + +#if FLOAT_CODE +void code_d2ll(int creg) +{ + +} + +void code_d2ull(int creg) +{ + +} + +void code_f2ll(int creg) +{ + +} + +void code_f2ull(int creg) +{ + +} + +void code_ll2d(int creg) +{ + +} + +void code_ll2f(int creg) +{ + +} + +void code_ull2d(int creg) +{ + +} + +void code_ull2f(int creg) +{ + +} + +void code_ull2ll(int creg) +{ + +} + +void code_ull2ull(int creg) +{ + +} + +#endif + + +void code_lpreinc(int e1,int e2,int reg) +{ + +} + +void code_lpostinc(int e1,int e2,int reg) +{ + +} + +void code_lassop(int op) +{ + +} + + +#endif /* end */ +
--- a/mc-code-mips.c Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-code-mips.c Sun Apr 04 21:17:10 2004 +0900 @@ -179,8 +179,14 @@ return i; } +int use_longlong(int i) { + return i; +} + +#if FLOAT_CODE static int code_d1(double d); static int code_d2(double d); +#endif static void code_save_stacks(); static void code_save_input_registers(); @@ -403,6 +409,7 @@ return reg; } } +#if FLOAT_CODE /* search dregister stack */ for(i=0;i<dreg_sp;i++) { if ((reg=dreg_stack[i])>=0) { @@ -413,6 +420,7 @@ return get_register(); /* 今度は必ずある */ } } +#endif for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { reg =REG_VAR_BASE-i; if (! regs[reg]) { /* 使われていないなら */ @@ -432,6 +440,8 @@ return reg_stack[--reg_sp]; } +#if FLOAT_CODE + static int get_dregister1() { int i; @@ -532,6 +542,16 @@ { /* レジスタから値を取り出す */ return dreg_stack[--dreg_sp]; } +#endif + +#if LONGLONG_CODE +int +get_lregister_var(NMTBL *n) +{ + return -1; +} +#endif + void emit_pop_free(int xreg) @@ -640,8 +660,10 @@ for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; regv[i+FREG_OFFSET]=0; } for(i=0;i<MAX_DREGISTER;i++) { regs[i+DREG_OFFSET]=0; regv[i+DREG_OFFSET]=0; } creg = get_register(); +#if FLOAT_CODE freg = get_dregister(0); dreg = DREG_DREGISTER; +#endif set_creg(CREG_REGISTER,0); set_freg(FREG_FREGISTER,0); set_dreg(DREG_DREGISTER,0); @@ -2072,8 +2094,10 @@ emit_data(int e, int t, NMTBL *n) { int l; +#if FLOAT_CODE double d; float f; +#endif char *name; name = n->nm; if(mode!=GDECL&&mode!=STADECL) { @@ -2103,12 +2127,14 @@ printf("\t.word %d\n",cadr(e)); gpc += size_of_int; } +#if FLOAT_CODE } else if(t==DOUBLE) { d = dcadr(e); printf("\t.word\t0x%x\n\t.word\t0x%x\n",code_d1(d),code_d2(d)); } else if(t==FLOAT) { f = dcadr(e); printf("\t.word\t0x%x\n",*(int *)&f); +#endif } else if(t!=CHAR) { gpc += size_of_int; if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { @@ -2212,6 +2238,8 @@ printf("\t.type\t%s,@object\n",name); } +#if FLOAT_CODE + char * fstore(int d) { @@ -2747,6 +2775,8 @@ } } +#endif + void code_save_stacks() { @@ -2758,6 +2788,7 @@ reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; } } +#if FLOAT_CODE for(i=0;i<dreg_sp;i++) { if ((reg=dreg_stack[i])>=0) { code_dassign_lvar( @@ -2772,6 +2803,7 @@ freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; } } +#endif } void @@ -2790,5 +2822,212 @@ fclose(asi); } + +#if LONGLONG_CODE + + +/* 64bit int part */ + +void lrexpr(int e1, int e2,int l1, int op) +{ +} + +int lpop_register() +{ + return 0; +} + +int emit_lpop() +{ + return 0; +} + +void code_lregister(int e2,int reg) +{ + +} + +void code_cmp_lregister(int reg) +{ + +} + +void code_cmp_lrgvar(int e1,int e2) +{ + +} + +void code_cmp_lrlvar(int e1,int e2) +{ + +} + +void code_lassign(int e1,int e2) +{ + +} + +void code_lassign_gvar(int e1,int e2) +{ + +} + +void code_lassign_lvar(int e1,int e2) +{ + +} + +void code_lassign_lregister(int e2,int reg) +{ + +} + +void code_lconst(int e1,int e2) +{ + +} + +void code_lneg(int e1,int e2) +{ + +} + +void code_lrgvar(int e1,int e2) +{ + +} + +void code_lrlvar(int e1,int e2) +{ + +} + +void ltosop(int e1,int e2) +{ + +} + +void emit_lpop_free(int e1) +{ + +} + +void emit_lpush() +{ + +} + +void code_i2ll(int creg) +{ + +} + +void code_i2ull(int creg) +{ + +} + +void code_u2ll(int creg) +{ + +} + +void code_u2ull(int creg) +{ + +} + +void code_ll2i(int creg) +{ + +} + +void code_ll2u(int creg) +{ + +} + +void code_ull2i(int creg) +{ + +} + +void code_ull2u(int creg) +{ + +} + +#if FLOAT_CODE +void code_d2ll(int creg) +{ + +} + +void code_d2ull(int creg) +{ + +} + +void code_f2ll(int creg) +{ + +} + +void code_f2ull(int creg) +{ + +} + +void code_ll2d(int creg) +{ + +} + +void code_ll2f(int creg) +{ + +} + +void code_ull2d(int creg) +{ + +} + +void code_ull2f(int creg) +{ + +} + +void code_ull2ll(int creg) +{ + +} + +void code_ull2ull(int creg) +{ + +} + +#endif + + +void code_lpreinc(int e1,int e2,int reg) +{ + +} + +void code_lpostinc(int e1,int e2,int reg) +{ + +} + +void code_lassop(int op) +{ + +} + + +#endif + /* end */
--- a/mc-code-powerpc.c Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-code-powerpc.c Sun Apr 04 21:17:10 2004 +0900 @@ -129,6 +129,12 @@ return i; } +int use_longlong(int i) { + return i; +} + + +#if FLOAT_CODE static NMTBL float_zero = {"_float_zero",STATIC,FLOAT,0}; static @@ -138,11 +144,14 @@ static char * fload(int d); static int code_d1(double d); static int code_d2(double d); +#endif + static void code_save_stacks(); static void code_save_input_registers(); static void clear_ptr_cache_reg(int r); static void set_creg(int,int); static void set_freg(int,int); +static void set_lreg(int,int); static int max_func_args; static int my_func_args; @@ -431,6 +440,7 @@ return reg_stack[--reg_sp]; } +#if FLOAT_CODE int get_dregister(int d) { /* 使われていないレジスタを調べる */ @@ -467,6 +477,15 @@ { /* レジスタから値を取り出す */ return freg_stack[--freg_sp]; } +#endif + +#if LONGLONG_CODE +int +get_lregister_var(NMTBL *n) +{ + return -1; +} +#endif void emit_pop_free(int xreg) @@ -555,10 +574,12 @@ int i; for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0; } for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; regv[i+FREG_OFFSET]=0; } - creg = get_register(); +#if FLOAT_CODE freg = get_dregister(1); + set_freg(FREG_FREGISTER,0); +#endif + ireg = creg = get_register(); set_creg(CREG_REGISTER,0); - set_freg(FREG_FREGISTER,0); return; } @@ -1245,6 +1266,8 @@ creg = ireg = reg; regs[creg]=1; } + if (ireg!=creg) error(-1); + ireg = reg; } void @@ -1258,6 +1281,13 @@ creg = freg = reg; regs[freg]=1; } + if (freg!=creg) error(-1); + freg = reg; +} + +void +set_lreg(int reg,int mode) +{ } void @@ -1545,12 +1575,14 @@ g_expr(e2); crn=register_name(creg); switch (car(e1)) { +#if FLOAT_CODE case FRINDIRECT: case DRINDIRECT: printf("\t%s %s,%d(%s)\n",fload(car(e1)==DRINDIRECT), fregister_name(freg),offset,crn); regv[creg]=0; regv[freg]=1; creg = freg; return DOUBLE; +#endif case CRINDIRECT: printf("\tlbz %s,%d(%s)\n",crn,offset,crn); printf("\textsb %s,%s\n",crn,crn); @@ -2056,6 +2088,8 @@ code_set_fixed_creg(int reg,int mode,int type) { if (type==FLOAT||type==DOUBLE) { set_freg(reg,mode); + } else if (type==LONGLONG) { + set_lreg(reg,mode); } else { set_creg(reg,mode); } @@ -2084,8 +2118,10 @@ emit_data(int e, int t, NMTBL *n) { int l; +#if FLOAT_CODE double d; float f; +#endif char *name; name = n->nm; if(mode!=GDECL && mode!=STADECL) { @@ -2115,12 +2151,16 @@ printf("\t.long %d\n",cadr(e)); gpc += size_of_int; } +#if LONGLONG_CODE +#endif +#if FLOAT_CODE } else if(t==DOUBLE) { d = dcadr(e); printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d)); } else if(t==FLOAT) { f = dcadr(e); printf("\t.long\t0x%x\n",*(int *)&f); +#endif } else if(t!=CHAR) { gpc += size_of_int; if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { @@ -2282,6 +2322,8 @@ */ } +#if FLOAT_CODE + /* floating point */ static int float_one_lib_used=0; @@ -2307,8 +2349,6 @@ 0 }; - - char * fstore(int d) { @@ -2823,6 +2863,214 @@ regv[freg]=1; } +#endif + +#if LONGLONG_CODE + + +/* 64bit int part */ + +void lrexpr(int e1, int e2,int l1, int op) +{ +} + +int lpop_register() +{ + return 0; +} + +int emit_lpop() +{ + return 0; +} + +void code_lregister(int e2,int reg) +{ + +} + +void code_cmp_lregister(int reg) +{ + +} + +void code_cmp_lrgvar(int e1,int e2) +{ + +} + +void code_cmp_lrlvar(int e1,int e2) +{ + +} + +void code_lassign(int e1,int e2) +{ + +} + +void code_lassign_gvar(int e1,int e2) +{ + +} + +void code_lassign_lvar(int e1,int e2) +{ + +} + +void code_lassign_lregister(int e2,int reg) +{ + +} + +void code_lconst(int e1,int e2) +{ + +} + +void code_lneg(int e1,int e2) +{ + +} + +void code_lrgvar(int e1,int e2) +{ + +} + +void code_lrlvar(int e1,int e2) +{ + +} + +void ltosop(int e1,int e2) +{ + +} + +void emit_lpop_free(int e1) +{ + +} + +void emit_lpush() +{ + +} + +void code_i2ll(int creg) +{ + +} + +void code_i2ull(int creg) +{ + +} + +void code_u2ll(int creg) +{ + +} + +void code_u2ull(int creg) +{ + +} + +void code_ll2i(int creg) +{ + +} + +void code_ll2u(int creg) +{ + +} + +void code_ull2i(int creg) +{ + +} + +void code_ull2u(int creg) +{ + +} + +#if FLOAT_CODE +void code_d2ll(int creg) +{ + +} + +void code_d2ull(int creg) +{ + +} + +void code_f2ll(int creg) +{ + +} + +void code_f2ull(int creg) +{ + +} + +void code_ll2d(int creg) +{ + +} + +void code_ll2f(int creg) +{ + +} + +void code_ull2d(int creg) +{ + +} + +void code_ull2f(int creg) +{ + +} + +void code_ull2ll(int creg) +{ + +} + +void code_ull2ull(int creg) +{ + +} + +#endif + + +void code_lpreinc(int e1,int e2,int reg) +{ + +} + +void code_lpostinc(int e1,int e2,int reg) +{ + +} + +void code_lassop(int op) +{ + +} + + +#endif + void code_save_stacks() { @@ -2834,6 +3082,7 @@ reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; } } +#if FLOAT_CODE for(i=0;i<freg_sp;i++) { if ((reg=freg_stack[i])>=0) { code_dassign_lvar( @@ -2841,6 +3090,7 @@ freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; } } +#endif } void @@ -2854,11 +3104,13 @@ void code_closing() { +#if FLOAT_CODE if (d2u_lib_used) emit_lib(d2u_lib); if (u2d_lib_used) emit_lib(u2d_lib); if (float_one_lib_used) emit_lib(float_one_lib); if (float_zero_lib_used) emit_lib(float_zero_lib); if (i2d_lib_used) emit_lib(i2d_lib); +#endif global_table(); /* printf("\t.ident \"Micro-C compiled\"\n"); */ }
--- a/mc-code.h Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-code.h Sun Apr 04 21:17:10 2004 +0900 @@ -32,8 +32,10 @@ extern int register_var(int r); extern int get_register_var(NMTBL *n); extern int get_dregister_var(NMTBL *n,int d); +extern int get_lregister_var(NMTBL *n); extern int get_input_register_var(int,NMTBL *,int); extern int get_input_dregister_var(int,NMTBL *,int,int); +extern int get_input_lregister_var(int,NMTBL *,int); extern void emit_push(); extern int emit_pop(int type); extern void gexpr_code_init(); @@ -85,7 +87,6 @@ extern void code_opening(char *filename); extern void code_closing(); extern void rexpr(int e1, int l1, char *s,int t); -extern void drexpr(int e1, int e2,int l1, int op); extern void jcond(int l, char cond); extern void jmp(int l); extern int code_get_fixed_creg(int reg,int type); @@ -99,8 +100,10 @@ extern void oprtc(int op,int v); +#if FLOAT_CODE /* floating point part */ +extern void drexpr(int e1, int e2,int l1, int op); extern int dpop_register(); extern int emit_dpop(int); extern void code_dregister(int e2,int reg,int d); @@ -134,6 +137,59 @@ extern void code_dpostinc(int e1,int e2,int d,int reg); extern void code_dassop(int op,int d); +#endif + +#if LONGLONG_CODE +/* 64bit int part */ + +extern void lrexpr(int e1, int e2,int l1, int op); +extern int lpop_register(); +extern int emit_lpop(); +extern void code_lregister(int e2,int reg); +extern void code_cmp_lregister(int); +extern void code_cmp_lrgvar(int,int); +extern void code_cmp_lrlvar(int,int); +extern void code_lassign(int,int); +extern void code_lassign_gvar(int,int); +extern void code_lassign_lvar(int,int); +extern void code_lassign_lregister(int e2,int reg); +extern void code_lconst(int,int); +extern void code_lneg(int,int); +extern void code_lrgvar(int,int); +extern void code_lrlvar(int,int); +extern void ltosop(int,int); +extern void emit_lpop_free(int); +extern void emit_lpush(); +extern void code_i2ll(int creg); +extern void code_i2ull(int creg); +extern void code_u2ll(int creg); +extern void code_u2ull(int creg); +extern void code_ll2i(int creg); +extern void code_ll2u(int creg); +extern void code_ull2i(int creg); +extern void code_ull2u(int creg); +#if FLOAT_CODE +extern void code_d2ll(int creg); +extern void code_d2ull(int creg); +extern void code_f2ll(int creg); +extern void code_f2ull(int creg); +extern void code_ll2d(int creg); +extern void code_ll2f(int creg); +extern void code_ull2d(int creg); +extern void code_ull2f(int creg); +extern void code_ull2ll(int creg); +extern void code_ull2ull(int creg); +#endif + + + + +extern void code_lpreinc(int e1,int e2,int reg); +extern void code_lpostinc(int e1,int e2,int reg); +extern void code_lassop(int op); + +#endif + extern void code_arg_register(NMTBL *fnptr); extern int get_register(void); @@ -145,5 +201,6 @@ extern int use_int(int); extern int use_float(int); extern int use_double(int); +extern int use_longlong(int); /* */
--- a/mc-codegen.c Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-codegen.c Sun Apr 04 21:17:10 2004 +0900 @@ -25,6 +25,22 @@ static int g_expr0(int e1); static int register_to_lvar(int e); +#if FLOAT_CODE + +/* floating point */ + +static void dassop(int e1); +static void dmachinop(int e1,int d); +static void dassign(int e1); + +#endif +#if LONGLONG_CODE +static void lassop(int e1); +static void lmachinop(int e1); +static void lassign(int e1); +#endif + + void codegen_init() { @@ -117,6 +133,7 @@ creg=use_int(creg); code_register(e2,creg); return INT; +#if FLOAT_CODE case DREGISTER: creg=use_double(creg); code_dregister(e2,creg,1); @@ -125,6 +142,7 @@ creg=use_float(creg); code_dregister(e2,creg,0); return FLOAT; +#endif case RLVAR: creg=use_int(creg); code_rlvar(e2,creg); @@ -145,6 +163,7 @@ creg=use_int(creg); code_crlvar(e2,creg,0,size_of_short); return UCHAR; +#if FLOAT_CODE case FRLVAR: creg=use_float(creg); code_drlvar(e2,0,creg); @@ -161,6 +180,7 @@ creg=use_double(creg); code_drgvar(e1,1,creg); return DOUBLE; +#endif case FNAME: creg=use_int(creg); code_fname((NMTBL *)(e2),creg); @@ -169,6 +189,7 @@ creg=use_int(creg); code_const(e2,creg); return INT; +#if FLOAT_CODE case DCONST: creg=use_double(creg); code_dconst(e1,creg,1); @@ -177,6 +198,7 @@ creg=use_float(creg); code_dconst(e1,creg,0); return FLOAT; +#endif case STRING: creg=use_int(creg); code_string(e1,creg); @@ -191,7 +213,9 @@ return g_expr0(e2); case RINDIRECT: case CRINDIRECT: case CURINDIRECT: case SRINDIRECT: case SURINDIRECT: +#if FLOAT_CODE case DRINDIRECT: case FRINDIRECT: +#endif return rindirect(e1); case ADDRESS: if (car(e2)==REGISTER||car(e2)==DREGISTER||car(e2)==FREGISTER) @@ -201,15 +225,18 @@ case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */ g_expr0(e2); code_neg(creg); return INT; +#if FLOAT_CODE case DMINUS: g_expr0(e2); code_dneg(creg,1); return DOUBLE; case FMINUS: g_expr0(e2); code_dneg(creg,0); return FLOAT; +#endif case CONV: g_expr0(e2); switch(caddr(e1)) { +#if FLOAT_CODE case I2D: code_i2d(creg); return DOUBLE; case D2I: code_d2i(creg); return INT; case U2D: code_u2d(creg); return DOUBLE; @@ -220,6 +247,30 @@ case D2U: code_d2u(creg); return UNSIGNED; case D2F: code_d2f(creg); return FLOAT; case F2D: code_f2d(creg); return DOUBLE; +#endif +#if LONGLONG_CODE + case I2LL: code_i2ll(creg); return LONGLONG; + case I2ULL: code_i2ull(creg); return ULONGLONG; + case U2LL: code_u2ll(creg); return LONGLONG; + case U2ULL: code_u2ull(creg); return ULONGLONG; + case LL2I: code_ll2i(creg); return INT; + case LL2U: code_ll2u(creg); return UNSIGNED; + case ULL2I: code_ull2i(creg); return INT; + case ULL2U: code_ull2u(creg); return UNSIGNED; +#if FLOAT_CODE + case D2LL: code_d2ll(creg); return LONGLONG; + case D2ULL: code_d2ull(creg); return ULONGLONG; + case F2LL: code_f2ll(creg); return LONGLONG; + case F2ULL: code_f2ull(creg); return ULONGLONG; + case LL2D: code_ll2d(creg); return DOUBLE; + case LL2F: code_ll2f(creg); return FLOAT; + case ULL2D: code_ull2d(creg); return DOUBLE; + case ULL2F: code_ull2f(creg); return FLOAT; + case ULL2LL: code_ull2ll(creg); return LONGLONG; + case ULL2ULL: code_ull2ull(creg); return ULONGLONG; +#endif +#endif + default: error(-1); return INT; } @@ -245,6 +296,7 @@ creg=use_int(creg); code_postinc(e1,e2,caddr(e1),0,cadddr(e1),creg); return INT; +#if FLOAT_CODE case DPREINC: /* ++d */ creg=use_double(creg); code_dpreinc(e1,e2,1,creg); @@ -261,6 +313,17 @@ creg=use_float(creg); code_dpostinc(e1,e2,0,creg); return FLOAT; +#endif +#if LONGLONG_CODE + case LPREINC: /* ++d */ + creg=use_longlong(creg); + code_lpreinc(e1,e2,creg); + return DOUBLE; + case LPOSTINC: /* d++ */ + creg=use_longlong(creg); + code_lpostinc(e1,e2,creg); + return DOUBLE; +#endif case MUL: case UMUL: case DIV: case UDIV: case MOD: case UMOD: @@ -269,6 +332,7 @@ creg=use_int(creg); machinop(e1); return INT; +#if FLOAT_CODE case DMUL: case DDIV: case DADD: case DSUB: case DCMP: case DCMPGE: @@ -281,10 +345,22 @@ creg=use_float(creg); dmachinop(e1,0); return FLOAT; - case COND: /* a?0:1 should consider non-brach instruction */ case DCOND: case FCOND: - d = (car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT); +#endif +#if LONGLONG_CODE + case LMUL: case LUMUL: + case LDIV: case LUDIV: + case LMOD: case LUMOD: + case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT: + case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP: + creg=use_longlong(creg); + lmachinop(e1); + return INT; +#endif + case COND: /* a?0:1 should consider non-brach instruction */ + d = (car(e1)==LCOND?LONGLONG: + car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT); e2=fwdlabel(); b_expr(cadr(e1),0,e2,0); g_expr0(caddr(e1)); @@ -301,15 +377,25 @@ case ASS: case CASS: case SASS: assign(e1); return INT; - case FASS: case DASS: case LASS: - dassign(e1); - return DOUBLE; case ASSOP: case CASSOP: case CUASSOP: assop(e1); return INT; +#if FLOAT_CODE + case FASS: case DASS: + dassign(e1); + return DOUBLE; case DASSOP: case FASSOP: dassop(e1); return DOUBLE; +#endif +#if LONGLONG_CODE + case LASS: + lassign(e1); + return LONGLONG; + case LASSOP: case LUASSOP: + lassop(e1); + return LONGLONG ; +#endif case RSTRUCT: g_expr0(e2); return RSTRUCT; @@ -344,22 +430,33 @@ int rop_dual(op) { - if (op==GT) return LT; - if (op==UGT) return ULT; - if (op==GE) return LE; - if (op==UGE) return ULE; - if (op==LT) return GT; - if (op==ULT) return UGT; - if (op==LE) return GE; - if (op==ULE) return UGE; - if (op==DOP+GT) return DOP+LT; - if (op==DOP+GE) return DOP+LE; - if (op==DOP+LT) return DOP+GT; - if (op==DOP+LE) return DOP+GE; - if (op==FOP+GT) return FOP+LT; - if (op==FOP+GE) return FOP+LE; - if (op==FOP+LT) return FOP+GT; - if (op==FOP+LE) return FOP+GE; + switch(op) { + case GT: return LT; + case UGT: return ULT; + case GE: return LE; + case UGE: return ULE; + case LT: return GT; + case ULT: return UGT; + case LE: return GE; + case ULE: return UGE; + case DOP+GT: return DOP+LT; + case DOP+GE: return DOP+LE; + case DOP+LT: return DOP+GT; + case DOP+LE: return DOP+GE; + case FOP+GT: return FOP+LT; + case FOP+GE: return FOP+LE; + case FOP+LT: return FOP+GT; + case FOP+LE: return FOP+GE; + + case LOP+GT: return LOP+LT; + case LOP+GE: return LOP+LE; + case LOP+LT: return LOP+GT; + case LOP+LE: return LOP+GE; + case LOP+UGT: return FOP+ULT; + case LOP+UGE: return FOP+ULE; + case LOP+ULT: return FOP+UGT; + case LOP+ULE: return FOP+UGE; + } return op; } @@ -416,7 +513,7 @@ case NEQ: rexpr(e1,l1,code_eq(!cond),INT); return; - +#if FLOAT_CODE case DOP+GT: case DOP+GE: case DOP+EQ: @@ -439,7 +536,21 @@ case DOP+LE: drexpr(caddr(e1),cadr(e1),l1,DOP+GE); return; - +#endif +#if LONGLONG_CODE + case LOP+GT: + case LOP+GE: + case LOP+EQ: + case LOP+NEQ: + lrexpr(cadr(e1),caddr(e1),l1,car(e1)); + return; + case LOP+LT: + lrexpr(caddr(e1),cadr(e1),l1,LOP+GT); + return; + case LOP+LE: + lrexpr(caddr(e1),cadr(e1),l1,LOP+GE); + return; +#endif case LAND: b_expr(e2,0,cond?(l2=fwdlabel()):l1,0); b_expr(caddr(e1),cond,l1,0); @@ -480,6 +591,7 @@ code_cmp_rlvar(e2); jcond(l1,cond); return; +#if FLOATC_DOE case DRLVAR: creg=use_double(creg); code_cmp_drlvar(e2,1); @@ -500,11 +612,6 @@ code_cmp_drgvar(e2,0); jcond(l1,cond); return; - case REGISTER: - creg=use_int(creg); - code_cmp_register(e2); - jcond(l1,cond); - return; case FREGISTER: creg=use_float(creg); code_cmp_dregister(e2,0); @@ -515,22 +622,55 @@ code_cmp_dregister(e2,1); jcond(l1,cond); return; - case CONST: - if(control&&((cond&&e2)||(!cond&&!e2))) jmp(l1); - return; case DCONST: case FCONST: if(control&&((dcadr(e2)!=0.0)^cond)) jmp(l1); return; +#endif +#if LONGLONG_DOE + case LRLVAR: + creg=use_longlong(creg); + code_cmp_lrlvar(e2,1); + jcond(l1,cond); + return; + case LRGVAR: + creg=use_longlong(creg); + code_cmp_lrgvar(e2,1); + jcond(l1,cond); + return; + case LREGISTER: + creg=use_longlong(creg); + code_cmp_lregister(e2,1); + jcond(l1,cond); + return; + case LCONST: + if(control&&((lcadr(e2)!=0)^cond)) jmp(l1); + return; +#endif + case REGISTER: + creg=use_int(creg); + code_cmp_register(e2); + jcond(l1,cond); + return; + case CONST: + if(control&&((cond&&e2)||(!cond&&!e2))) jmp(l1); + return; default: if(err) { error(-1); return; /* recursive g_expr/b_expr */ } t=g_expr(e1); - if(t==FLOAT) + if (0) ; +#if FLOAT_CODE + else if(t==FLOAT) code_cmp_dregister(creg,0); else if(t==DOUBLE) code_cmp_dregister(creg,1); +#endif +#if LONGLONG_CODE + else if(t==LONGLONG||t==ULONGLONG) + code_cmp_lregister(creg); +#endif else code_cmp_register(creg); jcond(l1,cond); @@ -576,11 +716,14 @@ } else if (tag==FREGISTER) { n->dsp = new_lvar(size_of_float); t = DOUBLE; + } else if (tag==LREGISTER) { + n->dsp = new_lvar(size_of_longlong); + t = LONGLONG; } else error(-1); n->sc = LVAR; lvar = list2(LVAR,n->dsp); g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),t,t)); - if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER) { + if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) { free_register(reg); return g_expr0(lvar); #endif @@ -644,6 +787,7 @@ *use=list3(t,*use,e1); g_expr_u(assign_expr0(e1,s,ty,ty)); *target = append4(*target,t,ty,e1); +#if FLOAT_CODE } else if (sz==size_of_double && (e1=get_dregister(1))!=-1) { e1=list3(DREGISTER,e1,0); *use=list3(t,*use,e1); @@ -654,6 +798,7 @@ *use=list3(t,*use,e1); g_expr_u(assign_expr0(e1,s,ty,ty)); *target = append4(*target,t,ty,e1); +#endif } else { g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty)); *target = append4(*target,t,ty,e1); @@ -757,9 +902,9 @@ { return ( e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||e1==DREGISTER || - e1==FREGISTER || + e1==FREGISTER || e1==LREGISTER || e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR || - e1==DRLVAR || e1==FRLVAR || + e1==DRLVAR || e1==FRLVAR || e1==LRLVAR || e1==CURLVAR || e1==SURLVAR || e1==CURGVAR || e1==SURGVAR ); } @@ -774,10 +919,12 @@ || (ce1==LVAR && (ce2==SRLVAR||ce2==SURLVAR||ce2==CURLVAR)) || (ce2==LVAR && (ce1==RLVAR||ce1==CRLVAR||ce1==FRLVAR||ce1==DRLVAR)) || (ce2==LVAR && (ce1==SRLVAR||ce1==SURLVAR||ce1==CURLVAR)) + || (ce2==LVAR && (ce1==LRLVAR)) || (ce1==GVAR && (ce2==RGVAR||ce2==CRGVAR||ce2==FRGVAR||ce2==DRGVAR)) || (ce1==GVAR && (ce2==SRGVAR||ce2==SURGVAR||ce2==CURGVAR)) || (ce2==GVAR && (ce1==RGVAR||ce1==CRGVAR||ce1==FRGVAR||ce1==DRGVAR)) || (ce2==GVAR && (ce1==SRGVAR||ce1==SURGVAR||ce1==CURGVAR)) + || (ce2==GVAR && (ce1==LRGVAR)) ); } @@ -786,8 +933,9 @@ { int ce1=car(e1); return ( - ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR || ce1==DRLVAR || - ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR || ce1==DRGVAR || + ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR || ce1==DRLVAR || ce1==LRLVAR || + ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR || ce1==DRGVAR || ce1==LRGVAR || + ce1==FRLVAR || ce1==FRGVAR || ce1==CURGVAR ||ce1==SURGVAR||ce1==SRGVAR || ce1==REGISTER|| ce1==DREGISTER || ce1==FREGISTER ); @@ -889,7 +1037,7 @@ parallel_assign(&target,&source,&processing,&use); while (use) { reg = car(caddr(use)); - if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER) + if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER||reg==LREGISTER) free_register(cadr(caddr(use))); else if (car(caddr(use))==LVAR) free_lvar(cadr(caddr(use))); @@ -943,6 +1091,7 @@ return; } +#if FLOAT_CODE void dmachinop(int e1,int d) { @@ -958,6 +1107,25 @@ emit_dpop_free(e2,d); return; } +#endif + +#if LONGLONG_CODE +void +lmachinop(int e1) +{ + int e2,e3,op; + + e2 = cadr(e1); + op = car(e1); + e3 = caddr(e1); + g_expr(e3); + emit_lpush(); + g_expr(e2); + ltosop(car(e1),(e2=emit_lpop())); + emit_lpop_free(e2); + return; +} +#endif void sassign(int e1) @@ -1077,6 +1245,8 @@ return; } +#if FLOAT_CODE + void dassign_opt(int e5,int e2,int e4,int d) { @@ -1163,6 +1333,91 @@ return; } +#endif + +#if LONGLONG_CODE + +void +lassign_opt(int e5,int e2,int e4) +{ + int reg; + /* e2=e4 */ + if (e5==LREGISTER) { + reg = cadr(e4); + switch(car(e2)) { + case GVAR: /* i=3 */ + code_lassign_gvar(e2,reg); + return; + case LVAR: + code_lassign_lvar(cadr(e2),reg); + return; + case LREGISTER: + if (reg!=cadr(e2)) + code_lassign_lregister(cadr(e2),reg); + return; + default: + error(-1); + } + } + /* e2 is register now */ + if (car(e2)!=LREGISTER) error(-1); + reg = cadr(e2); + switch(e5) { + case LRGVAR: code_lrgvar(e4,reg); return; + case LRLVAR: code_lrlvar(cadr(e4),reg); return; + case LCONST: code_lconst(e4,reg); return; + default: + error(-1); + } +} + +void +lassign(int e1) +{ + int e2,e3,e4,e5; + + /* e2=e4 */ + e2 = cadr(e1); + e3 = cadr(e2); + e4 = caddr(e1); e5=car(e4); + if (!use && ( + (e5==LREGISTER) || + (car(e2)==LREGISTER&&(e5==LRGVAR||e5==LRLVAR||e5==LCONST)) + )) { + creg = use_longlong(creg); + lassign_opt(e5,e2,e4); + return; + } + switch(car(e2)) { + case GVAR: + g_expr(e4); + creg = use_longlong(creg); + code_lassign_gvar(e2,creg); + return; + case LVAR: + g_expr(e4); + creg = use_longlong(creg); + code_lassign_lvar(cadr(e2),creg); + return; + case LREGISTER: + g_expr(e4); + if (creg!=cadr(e2)) { + creg = use_longlong(creg); + code_lassign_lregister(cadr(e2),creg); + } + return; + } + g_expr(e2); + emit_lpush(); + g_expr(e4); + e2 = emit_lpop(); + code_lassign(e2,creg); + emit_lpop_free(e2); + return; +} + +#endif + void assop(int e1) { @@ -1197,6 +1452,8 @@ return; } +#if FLOAT_CODE + void dassop(int e1) { @@ -1222,6 +1479,36 @@ return; } +#endif + +#if LONGLONG_CODE + +void +lassop(int e1) +{ + int e2,e3,op; + + /* e2 op= e3 */ + e2 = cadr(e1); + if (car(e2)==INDIRECT) e2=cadr(e2); + e3 = caddr(e1); + op = cadddr(e1); + + creg = use_longlong(creg); + g_expr(e3); + emit_lpush(); + g_expr(e2); + if (car(e2)==LREGISTER) { + /* code_register_lassop(cadr(e2),op); */ + error(-1); /* unsupported now */ + return; + } + code_lassop(op); + return; +} + +#endif + void cmpdimm(int e, int csreg) {
--- a/mc-codegen.h Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-codegen.h Sun Apr 04 21:17:10 2004 +0900 @@ -8,6 +8,7 @@ extern int get_register_var(NMTBL *); extern int get_dregister_var(NMTBL *,int); +extern int get_lregister_var(NMTBL *); extern void arg_register(NMTBL *fnptr); @@ -58,10 +59,5 @@ extern int contains(int e,int type); extern int contains_in_list(int e,int type); -/* floating point */ - -extern void dassop(int e1); -extern void dmachinop(int e1,int d); -extern void dassign(int e1); /* end */
--- a/mc-parse.c Sat Jan 10 17:13:49 2004 +0900 +++ b/mc-parse.c Sun Apr 04 21:17:10 2004 +0900 @@ -136,6 +136,8 @@ case 'd': debug = 1; break; + case 'D': + break; case 'C': if (av[ac2+1]) set_converter(av[ac2]+2); chk = 1; @@ -313,7 +315,9 @@ #ifdef bsd macro_define("bsd 1\n"); #endif - + for(i=0;av[i]&&av[i][0]=='-'&&av[i][1]=='D';i++) { + macro_define(av[i]+2); + } } static void @@ -1010,10 +1014,16 @@ if (stmode==REGISTER) { if(scalar(type)) { ndsp = get_register_var(n); +#if FLOAT_CODE } else if (type==FLOAT) { ndsp = get_dregister_var(n,0); } else if (type==DOUBLE) { ndsp = get_dregister_var(n,1); +#endif +#if LONGLONG_CODE + } else if (type==LONGLONG||type==ULONGLONG) { + ndsp = get_lregister_var(n); +#endif } else error(DCERR); nsc = car(ndsp); ndsp = cadr(ndsp); @@ -1093,7 +1103,7 @@ type=t; return offset; } - if (t==FLOAT||t==DOUBLE) { + if (t==FLOAT||t==DOUBLE||t==LONGLONG||t==ULONGLONG) { e=expr1(); mode = mode_save; offset = assign_data(e,t,n,offset); @@ -1984,33 +1994,94 @@ int double_value(int e2,int type) { +#if FLOAT_CODE if (car(e2)==CONST) return dlist2(DCONST,(double)cadr(e2)); if (car(e2)==FCONST) return dlist2(DCONST,dcadr(e2)); if(type==DOUBLE) return e2; if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2D); if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2D); if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2D); + if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2D); + if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2D); error(TYERR); return dlist2(DCONST,1.0); +#else + error(TYERR); return list2(CONST,0); +#endif } int float_value(int e2,int type) { +#if FLOAT_CODE if (car(e2)==CONST) return dlist2(FCONST,(double)cadr(e2)); if (car(e2)==DCONST) return dlist2(FCONST,dcadr(e2)); if(type==FLOAT) return e2; if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2F); if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2D); + if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2F); + if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2F); if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2D); error(TYERR); return dlist2(DCONST,1.0); +#else + error(TYERR); return list2(CONST,0); +#endif +} + +int +longlong_value(int e2,int type) +{ +#if LONGLONG_CODE + if (car(e2)==CONST) return llist2(LCONST,(long long)cadr(e2)); + if (car(e2)==LCONST) return e2; +#if FLOAT_CODE + if (car(e2)==DCONST) return llist2(LCONST,(long long)dcadr(e2)); + if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2LL); + if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2LL); +#endif + if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2LL); + if(type==LONGLONG) return e2; + if(type==ULONGLONG) return e2; + if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2LL); + error(TYERR); return llist2(LCONST,0LL); +#else + error(TYERR); return list2(CONST,0); +#endif +} + +int +ulonglong_value(int e2,int type) +{ +#if LONGLONG_CODE + if (car(e2)==CONST) return llist2(LCONST,(unsigned long long)cadr(e2)); + if (car(e2)==LCONST) return e2; +#if FLOAT_CODE + if (car(e2)==DCONST) return llist2(LCONST,(unsigned long long)dcadr(e2)); + if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2ULL); + if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2ULL); +#endif + if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2ULL); + if(type==LONGLONG) return e2; + if(type==ULONGLONG) return e2; + if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2ULL); + error(TYERR); return llist2(LCONST,0LL); +#else + error(TYERR); return list2(CONST,0); +#endif } int int_value(int e2,int type) { + if(scalar(type)) return e2; +#if FLOAT_CODE if (car(e2)==DCONST||car(e2)==FCONST) return list2(CONST,(int)dcadr(e2)); - if(scalar(type)||car(type)==ARRAY) return e2; if(type==FLOAT||type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2I); +#endif +#if LONGLONG_CODE + if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2I); + if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2I); +#endif + if(car(type)==ARRAY) return e2; error(TYERR); return list2(CONST,1); } @@ -2018,8 +2089,14 @@ unsigned_value(int e2,int type) { if(scalar(type)) return e2; +#if FLOAT_CODE if (car(e2)==DCONST||car(e2)==FCONST) return list2(CONST,(unsigned)dcadr(e2)); if(type==FLOAT||type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2U); +#endif +#if LONGLONG_CODE + if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2U); + if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2U); +#endif error(TYERR); return e2; } @@ -2052,12 +2129,22 @@ e2=(t==USHORT)?unsigned_value(e2,type):int_value(e2,type); if (!integral(type)) error(TYERR); type= t;return(list3(SASS,e1,e2)); +#if FLOAT_CODE } else if(t==DOUBLE) { e2=double_value(e2,type); type= t;return(list3(DASS,e1,e2)); } else if(t==FLOAT) { e2=float_value(e2,type); type= t;return(list3(FASS,e1,e2)); +#endif +#if LONGLONG_CODE + } else if(t==LONGLONG) { + e2=longlong_value(e2,type); + type= t;return(list3(LASS,e1,e2)); + } else if(t==ULONGLONG) { + e2=ulonglong_value(e2,type); + type= t;return(list3(LASS,e1,e2)); +#endif } else if(scalar(t)) { e2=(t==UNSIGNED)?unsigned_value(e2,type):int_value(e2,type); type=t; @@ -2125,17 +2212,29 @@ getsym(0); e2=rvalue(expr1()); - if(!(integral(type)||type==FLOAT||type==DOUBLE)) error(TYERR); + if(!(integral(type)||type==FLOAT||type==DOUBLE|| + type==LONGLONG||type==ULONGLONG + )) error(TYERR); +#if FLOAT_CODE if (t==FLOAT) { if (no_float) error(TYERR); e2=float_value(e2,type); type=t; return(list4(FASSOP,e1,e2,op+FOP)); - } - if (t==DOUBLE) { + } else if (t==DOUBLE) { if (no_float) error(TYERR); e2=double_value(e2,type); type=t; return(list4(DASSOP,e1,e2,op+DOP)); } +#endif +#if LONGLONG_CODE + if (t==LONGLONG) { + e2=longlong_value(e2,type); type=t; + return(list4(LASSOP,e1,e2,op+LOP)); + } else if (t==ULONGLONG) { + e2=ulonglong_value(e2,type); type=t; + return(list4(LASSOP,e1,e2,op+LOP+US)); + } +#endif if(!integral(type)) error(TYERR); if((t==UNSIGNED||type==UNSIGNED)&& (op==MUL||op==DIV||op==MOD||op==RSHIFT||op==LSHIFT)) @@ -2183,6 +2282,7 @@ if(car(e1)==CONST) { if(cadr(e1)) {type=t;return e2;} else return e3; } +#if FLOAT_CODE if(type==DOUBLE||t==DOUBLE) { e2=double_value(e2,t); e3=double_value(e3,type); @@ -2195,6 +2295,21 @@ t=type=FLOAT; return(list4(FCOND,e1,e2,e3)); } +#endif +#if LONGLONG_CODE + if(type==LONGLONG||t==LONGLONG) { + e2=longlong_value(e2,t); + e3=longlong_value(e3,type); + t=type=LONGLONG; + return(list4(LCOND,e1,e2,e3)); + } + if(type==ULONGLONG||t==ULONGLONG) { + e2=ulonglong_value(e2,t); + e3=ulonglong_value(e3,type); + t=type=ULONGLONG; + return(list4(LCOND,e1,e2,e3)); + } +#endif if(type==INT||(t!=INT&&type==UNSIGNED)) type=t; /* if (t!=type) error(TYERR); */ @@ -2328,7 +2443,9 @@ e1=binop(op,e1,e2,t,type); else if(t==INT&&type==INT) /* signed case */ e1=binop(op,e1,e2,t,type); - else /* LONGONG? */ + else if(t==LONGLONG&&type==LONGLONG) /* signed case */ + e1=binop(op,e1,e2,t,type); + else /* UNSIGNED, ULONGONG */ e1=binop(op+US,e1,e2,t,type); type= INT; } @@ -2409,13 +2526,21 @@ type= UNSIGNED; return(list4(UPREINC,e,dir,size_of_short)); } else if(type==INT) { type= INT; return(list4(PREINC,e,dir,size_of_int)); +#if LONGLONG_CODE + } else if(type==LONGLONG) { + type= LONGLONG; return(list4(LPREINC,e,dir,size_of_longlong)); + } else if(type==ULONGLONG) { + type= ULONGLONG; return(list4(LUPREINC,e,dir,size_of_longlong)); +#endif } if(integral(type)) return(list4(PREINC,e,dir,size_of_int)); +#if FLOAT_CODE if(type==FLOAT) return(list3(FPREINC,e,dir)); if(type==DOUBLE) return(list3(DPREINC,e,dir)); +#endif if(car(type)!=POINTER) error(TYERR); return(list4(UPREINC,e, @@ -2434,6 +2559,7 @@ break; case DREGISTER: /* should be error? */ case FREGISTER: + case LREGISTER: case REGISTER: case GVAR: case LVAR: @@ -2449,10 +2575,18 @@ conv->prefix_(sym); getsym(0); e=rvalue(expr13()); +#if FLOAT_CODE if(type==FLOAT||type==DOUBLE) { - return list2(DMINUS,e); + // return list2(DMINUS,e); return(car(e)==DCONST?dlist2(DCONST,-dcadr(e)):list2(DMINUS,e)); } +#endif +#if LONGLONG_CODE + if(type==LONGLONG||type==ULONGLONG) { + // return list2(LMINUS,e); + return(car(e)==LCONST?llist2(LCONST,-lcadr(e)):list2(LMINUS,e)); + } +#endif if(!integral(type)) error(TYERR); return(car(e)==CONST?list2(CONST,-cadr(e)):list2(MINUS,e)); @@ -2460,6 +2594,7 @@ conv->prefix_(sym); getsym(0); e=rvalue(expr13()); + // LONGLONG? if(!integral(type)) error(TYERR); return(car(e)==CONST?list2(CONST,~cadr(e)):list2(BNOT,e)); @@ -2467,9 +2602,16 @@ conv->prefix_(sym); getsym(0); e=rvalue(expr13()); +#if FLOAT_CODE if(type==FLOAT||type==DOUBLE) return(car(e)==DCONST?list2(CONST,!dcadr(e)): - list3((type==DOUBLE?DOP:FOP)+NEQ,list2(CONST,0),e)); + list3((type==DOUBLE?DOP:FOP)+NEQ,dlist2(DCONST,0.0),e)); +#endif +#if LONGLONG_CODE + if(type==LONGLONG||type==ULONGLONG) + return(car(e)==LCONST?list2(LCONST,!lcadr(e)): + list3(LOP+NEQ,llist2(LCONST,0LL),e)); +#endif if(!scalar(type)) error(TYERR); return(car(e)==CONST?list2(CONST,!cadr(e)):list2(LNOT,e)); @@ -2525,10 +2667,18 @@ } if(integral(type)) return(list4(POSTINC,e,dir,size_of_int)); +#if FLOAT_CODE if(type==FLOAT) return(list3(FPOSTINC,e,dir)); if(type==DOUBLE) return(list3(DPOSTINC,e,dir)); +#endif +#if LONGLONG_CODE + if(type==LONGLONG) + return(list3(LPOSTINC,e,dir)); + if(type==ULONGLONG) + return(list3(LUPOSTINC,e,dir)); +#endif if(car(type)!=POINTER) error(TYERR); return(list4(UPOSTINC,e, @@ -2631,12 +2781,22 @@ e1=list2(CONST,symval); getsym(0); break; +#if FLOAT_CODE case DCONST: conv-> const_(symval); type= DOUBLE; e1=dlist2(DCONST,dsymval); getsym(0); break; +#endif +#if LONGLONG_CODE + case LCONST: + conv-> const_(symval); + type= LONGLONG; + e1=llist2(LCONST,lsymval); + getsym(0); + break; +#endif case RETURN: conv-> return_f_(); if (!is_function(fnptr)) { @@ -2679,6 +2839,10 @@ e1=float_value(e1,type); } else if(t==DOUBLE) { e1=double_value(e1,type); + } else if(t==LONGLONG) { + e1=longlong_value(e1,type); + } else if(t==ULONGLONG) { + e1=ulonglong_value(e1,type); } type=t; return e1; @@ -2809,7 +2973,8 @@ lcheck(int e) { int t; - if(!(scalar(type)||type==DOUBLE||type==FLOAT)|| + if(!(scalar(type)||type==DOUBLE||type==FLOAT|| + type==LONGLONG||type==ULONGLONG)|| (car(e)!=GVAR&&car(e)!=LVAR&&car(e)!=INDIRECT&&car(e)!=REGISTER)) if ((t=car(type))<0 && t!=STRUCT && t!=UNION) error(LVERR); @@ -2885,6 +3050,7 @@ return e; } +#if FLOAT_CODE /* binary floating compuation */ #define DTYPE(dop) (dop==DOP?DOUBLE:FLOAT) @@ -2986,6 +3152,111 @@ return fdbinop(op, e1, e2, t1, t2,FOP); } +#endif + +#if LONGLONG_CODE + +static int +lbinop(int op, int e1, int e2, int t1, int t2) +{ + int e=0; + long long le1, le2; + long long le = 0; + + if (t1==LONGLONG||t2==LONGLONG) { + e1=longlong_value(e1,t1); + e2=longlong_value(e2,t2); + type = LONGLONG; + } else { + e1=ulonglong_value(e1,t1); + e2=ulonglong_value(e2,t2); + type = ULONGLONG; + } + if(car(e1)==LCONST&&car(e2)==LCONST) { + le1=lcadr(e1); + le2=lcadr(e2); + switch(op) { + case BOR: + le=le1|le2;break; + case EOR: + le=le1^le2;break; + case BAND: + le=le1&le2;break; + case ADD: + le=le1+le2;break; + case SUB: + le=le1-le2;break; + case MUL: + le=le1*le2;break; + case DIV: + if(!le2) error(EXERR);le=le1/le2;break; + case MOD: + if(!le2) error(EXERR);le=le1%le2;break; + case RSHIFT: + le=le1>>le2;break; + case LSHIFT: + le=le1<<le2;break; + default: + switch(op) { + case EQ: + e=(le1==le2);break; + case NEQ: + e=(le1!=le2);break; + case GT: + e=(le1>le2);break; + case GE: + e=(le1>=le2);break; + case LT: + e=(le1<le2);break; + case LE: + e=(le1<=le2);break; + case UGT: + e=((unsigned)le1>(unsigned)le2);break; + case UGE: + e=((unsigned)le1>=(unsigned)le2);break; + case ULT: + e=((unsigned)le1<(unsigned)le2);break; + case ULE: + e=((unsigned)le1<=(unsigned)le2);break; + default: + error(-1); return list2(CONST,0); + } + type = INT; + return list2(CONST,e); + } + return llist2(LCONST,le); + } + if(op==LT) { + type = INT; return(list3(GT+LOP,e2,e1)); + } else if(op==LE) { + type = INT; return(list3(GE+LOP,e2,e1)); + } else if(op==ULT) { + type = INT; return(list3(UGT+LOP,e2,e1)); + } else if(op==ULE) { + type = INT; return(list3(UGE+LOP,e2,e1)); + } else if(op==GT||op==GE||op==LT||op==LE|| + op==UGT||op==UGE||op==ULT||op==ULE|| + op==EQ||op==NEQ + ) + type = INT; return(list3(op+LOP,e1,e2)); + if(op==SUB&&car(e2)==LCONST) { op=ADD+LOP; lcadr(e2)=-lcadr(e2); } + if((op==ADD||op==MUL||op==BOR||op==EOR||op==BAND)&& + (car(e1)==LCONST||(car(e2)!=LCONST&& + (car(e1)==RGVAR||car(e1)==RLVAR)))) { + e=e1;e1=e2;e2=e;e=t1;t1=t2;t2=e; + } + if(op==ADD) { + return(list3(ADD+LOP,e1,e2)); + } + if(op==SUB) { + return(list3(SUB+LOP,e1,e2)); + } + if((op==MUL||op==DIV)&&car(e2)==LCONST&&lcadr(e2)==1) return e1; + if(op==BOR||op==EOR||op==BAND) return(list3(op+LOP,e1,e2)); + return(list3(type==ULONGLONG?op+US+LOP:op,e1,e2)); +} +#endif + /* binary integer compuation */ static int @@ -2993,10 +3264,18 @@ { int e=0; +#if FLOAT_CODE if(t1==DOUBLE||t2==DOUBLE) return dbinop(op,e1,e2,t1,t2); if(t1==FLOAT||t2==FLOAT) return fbinop(op,e1,e2,t1,t2); +#endif +#if LONGLONG_CODE + if(t1==LONGLONG||t2==LONGLONG) + return lbinop(op,e1,e2,t1,t2); + if(t1==ULONGLONG||t2==ULONGLONG) + return lbinop(op+US,e1,e2,t1,t2); +#endif if(car(e1)==CONST&&car(e2)==CONST) { e1=cadr(e1); e2=cadr(e2); @@ -3062,6 +3341,7 @@ e=((unsigned)e1<(unsigned)e2);break; case ULE: e=((unsigned)e1<=(unsigned)e2);break; + default: error(-1); return list2(CONST,0); } return list2(CONST,e); } @@ -3144,8 +3424,14 @@ if (t==DOTS) return e; if (t==UNSIGNED) e = unsigned_value(e,type); else if (integral(t)) e = int_value(e,type); +#if FLOAT_CODE else if (t==FLOAT) e = float_value(e,type); else if (t==DOUBLE) e = double_value(e,type); +#endif +#if LONGLONG_CODE + else if (t==LONGLONG) e = longlong_value(e,type); + else if (t==ULONGLONG) e = ulonglong_value(e,type); +#endif else if ((t1=car(t))==STRUCT||t1==UNION) { if(size(t)!=size(type)) error(TYERR); } @@ -3458,10 +3744,20 @@ if (!d && ch=='L') { getch(); if (ch=='L') { +#if LONGLONG_CODE getch(); /*LONGLONG*/ + *cheapp++ = 0; + lsymval = strtoll(scheapp,0,0); + cheapp=scheapp; + return sym=LCONST; +#else + symval = 0; + return sym=CONST; +#endif } return sym=CONST; } +#if FLOAT_CODE /* floating point case */ while(digit(ch)|| ch=='.'||ch=='e') { *cheapp++ = ch; @@ -3476,6 +3772,10 @@ dsymval = strtod(scheapp,0); cheapp=scheapp; return sym=DCONST; +#else + symval = 0; + return sym=CONST; +#endif } else if(ch=='\'') { getch(); symval=escape(); @@ -4108,6 +4408,8 @@ nptr->sc = MACRO; nptr->ty = -1; } + // equal is allowed for -Dhoge=aho option + if (ch=='=') chptr++; while((c=*chptr)==' '||c=='\t') chptr++; nptr->dsp = list2((int)cheapp,args); /* macro body */ scheapp = cheapp; @@ -4353,6 +4655,35 @@ /* node management (cdr coding ) */ +#if LONGLONG_CODE + +int +llist2(int e1, long long d1) +{ + int e; + + e=getfree((size_of_int+size_of_longlong)/size_of_int); + heap[e]=e1; + lcadr(e)=d1; + return e; +} + +int +llist3(int e1, int e2,long long d1) +{ + int e; + + e=getfree((size_of_int+size_of_longlong)/size_of_int); + heap[e]=e1; + heap[e+1]=e2; + lcaddr(e)=d1; + return e; +} + +#endif + +#if FLOAT_CODE + int dlist2(int e1, double d1) { @@ -4376,6 +4707,8 @@ return e; } +#endif + int list2(int e1, int e2) {
--- a/mc.h Sat Jan 10 17:13:49 2004 +0900 +++ b/mc.h Sun Apr 04 21:17:10 2004 +0900 @@ -7,8 +7,12 @@ #include "stdio.h" #else #include <stdio.h> +#include <stdlib.h> #endif +#define FLOAT_CODE 1 +#define LONGLONG_CODE 1 + #define SIZE_INT 4 /* reserved word start */ @@ -56,21 +60,22 @@ #define REGISTER (-40) #define FREGISTER (-41) #define DREGISTER (-42) -#define CODE (-43) -#define ENVIRONMENT (-44) -#define DEFINED (-45) -#define ENUM (-46) -#define KONST (-47) -#define FMACRO (-48) -#define LMACRO (-49) -#define SIGNED (-50) -#define DOTS (-51) +#define LREGISTER (-43) +#define CODE (-44) +#define ENVIRONMENT (-45) +#define DEFINED (-46) +#define ENUM (-47) +#define KONST (-48) +#define FMACRO (-49) +#define LMACRO (-50) +#define SIGNED (-51) +#define DOTS (-52) -#define FLOAT (-52) -#define DOUBLE (-53) -#define LONGLONG (-54) -#define ULONGLONG (-55) -#define VOLATILE (-56) +#define FLOAT (-53) +#define DOUBLE (-54) +#define LONGLONG (-55) +#define ULONGLONG (-56) +#define VOLATILE (-57) /* reserved word end */ @@ -254,8 +259,10 @@ #define LASS (LOP+CASS) #define LCMPGE (LOP+CMPGE) -#define LASSOP (LOP+CASSOP) +#define LASSOP (LOP+CASSOP) #define LUASSOP (LOP+CUASSOP) +#define LCMP (LOP+CMP) +#define LMINUS (LOP+MINUS) #define LMUL (LOP+MUL) #define LDIV (LOP+DIV) #define LUMUL (LOP+UMUL) @@ -263,6 +270,18 @@ #define LADD (LOP+ADD) #define LSUB (LOP+SUB) + +#define LMOD (LOP+MOD) +#define LUMOD (LOP+UMOD) +#define LLSHIFT (LOP+LSHIFT) +#define LULSHIFT (LOP+ULSHIFT) +#define LRSHIFT (LOP+RSHIFT) +#define LURSHIFT (LOP+URSHIFT) +#define LBAND (LOP+BAND) +#define LEOR (LOP+EOR) +#define LBOR (LOP+BOR) + + #define STASS 71 #define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS) @@ -378,7 +397,6 @@ EXTERN int symval,args,init_vars,heap[HEAPSIZE]; EXTERN int blabel,clabel,dlabel,cslabel,ilabel,control,ac,ac2,lsrc,chk,asmf; EXTERN int MAX_REGISTER_VAR; -EXTERN double dsymval; EXTERN unsigned hash; @@ -419,7 +437,14 @@ extern void error(int n); extern int size(int t); extern int scalar(int t); +#if FLOAT_CODE +EXTERN double dsymval; extern int dlist2(int e1, double e2); +#endif +#if LONGLONG_CODE +EXTERN long long lsymval; +extern int llist2(int e1, long long e2); +#endif extern int list2(int e1, int e2); extern int list3(int e1, int e2, int e3); extern int list4(int e1, int e2, int e3,int e4); @@ -439,8 +464,15 @@ #define cadddr(e) (heap[((int)(e))+3]) +#if FLOAT_CODE #define dcadr(e) (*(double*)&heap[((int)(e))+1]) #define dcaddr(e) (*(double*)&heap[((int)(e))+2]) +#endif + +#if LONGLONG_CODE +#define lcadr(e) (*(long long*)&heap[((int)(e))+1]) +#define lcaddr(e) (*(long long*)&heap[((int)(e))+2]) +#endif #include "conv/conv.h" /*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rsyncs Sun Apr 04 21:17:10 2004 +0900 @@ -0,0 +1,14 @@ +#!/bin/sh +rsync -e ssh -av --rsync-path /usr/bin/rsync \ + --exclude '*.o' --exclude '*.s' --exclude mc --exclude mc1 \ + --exclude mc-ia32 --exclude mc-powerpc --exclude CVS \ + --exclude '*.bak' --exclude '*.out' \ + kono@"$1":~/src/device /root +# touch Makefile *.c conv_* *.h */*.[hc] +# make clean +cp .gdbinit.ia32 .gdbinit +rm -f mc-ia32 +make depend +rm b*.s +touch *.[hc] conv/*.[hc] +make diff ARCH=ia32