Mercurial > hg > CbC > old > device
diff mc-code-powerpc.c @ 880:5313ed059cee
no tabs in source
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Apr 2014 10:43:01 +0900 |
parents | a97cd8b97434 |
children | 8bdd5061cb8f |
line wrap: on
line diff
--- a/mc-code-powerpc.c Thu Apr 03 10:34:02 2014 +0900 +++ b/mc-code-powerpc.c Thu Apr 03 10:43:01 2014 +0900 @@ -90,18 +90,18 @@ if (__ap->float_first==__ap->float_last) \\\n\ __ap->float_first = __ap->stack_top;\\\n\ } else { \\\n\ - if (__builtin_types_compatible_p(type,long long)) { \\\n\ + if (__builtin_types_compatible_p(type,long long)) { \\\n\ if (__ap->arg==__ap->top+4) __ap->arg += 4; \\\n\ - __arg = __ap->arg; \\\n\ - __ap->arg += 8; \\\n\ + __arg = __ap->arg; \\\n\ + __ap->arg += 8; \\\n\ if (__ap->arg==__ap->top+16+16) \\\n\ - __ap->arg = __ap->stack_top; \\\n\ - } else { \\\n\ - __arg = __ap->arg; \\\n\ - __ap->arg = __ap->arg+sizeof(type); \\\n\ - if (__ap->arg==__ap->long_last) \\\n\ - __ap->arg = __ap->stack_top; \\\n\ - } \\\n\ + __ap->arg = __ap->stack_top; \\\n\ + } else { \\\n\ + __arg = __ap->arg; \\\n\ + __ap->arg = __ap->arg+sizeof(type); \\\n\ + if (__ap->arg==__ap->long_last) \\\n\ + __ap->arg = __ap->stack_top; \\\n\ + } \\\n\ } \\\n\ *((type *)(__arg)); \\\n\ }) \\\n\ @@ -379,10 +379,10 @@ int use_int0() { int i = creg; if (!i||!ireg||!is_int_reg(i)) { - if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } - if (!ireg) ireg = get_register(); - // else if (ireg!=i) free_register(i); - i = ireg; + if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } + if (!ireg) ireg = get_register(); + // else if (ireg!=i) free_register(i); + i = ireg; } if (!regs[i]) regs[i]=USING_REG; creg = i; @@ -396,10 +396,10 @@ int use_longlong0() { int i = creg; if (!is_longlong_reg(i)) { - if (ireg) { if (regs[ireg]!=REG_VAR) free_register(ireg); ireg=0; } - if (!lreg||!regs[lreg]) lreg = get_lregister(); - // else if (lreg!=i) free_register(i); - i = lreg; + if (ireg) { if (regs[ireg]!=REG_VAR) free_register(ireg); ireg=0; } + if (!lreg||!regs[lreg]) lreg = get_lregister(); + // else if (lreg!=i) free_register(i); + i = lreg; } if (!regv_l(i)) regv_l(i) = get_register(); if (!regv_h(i)) regv_h(i) = get_register(); @@ -418,10 +418,10 @@ int use_float0() { int i = creg; if (!is_float_reg(i)) { - if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } - if (!freg) freg = get_dregister(0); - else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); - i = freg; + if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } + if (!freg) freg = get_dregister(0); + else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); + i = freg; } if (!regs[i]) regs[i]=USING_REG; creg = i; @@ -431,10 +431,10 @@ int use_double0() { int i = creg; if (!is_float_reg(i)) { - if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } - if (!freg) freg = get_dregister(1); - else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); - i = freg; + if (lreg) { if (regs[lreg]!=REG_VAR) free_register(lreg); lreg = 0; } + if (!freg) freg = get_dregister(1); + else if (freg!=i) if (regs[i]!=REG_VAR) free_register(i); + i = freg; } if (!regs[i]) regs[i]=USING_REG; creg = i; @@ -565,17 +565,17 @@ int l; #endif int lvar_offsetv = - round16(-disp+max_func_args*SIZE_OF_INT)+func_disp_offset; + round16(-disp+max_func_args*SIZE_OF_INT)+func_disp_offset; int r1_offsetv = round16(lvar_offsetv-reg_save); printf(".set %s%d,%d\n",lpfx,lvar_offset_label,r1_offsetv-lvar_offsetv); if (r1_offsetv-lvar_offsetv > 65000) error(-1); - // too large function arguments? + // too large function arguments? printf(".set %s%d,%d\n",lpfx,r1_offset_label,r1_offsetv); if (max_func_arg_label) { - printf(".set %s%d,%d\n",lpfx,max_func_arg_label, - round16(max_func_args*SIZE_OF_INT)+24); - max_func_arg_label = 0; + printf(".set %s%d,%d\n",lpfx,max_func_arg_label, + round16(max_func_args*SIZE_OF_INT)+24); + max_func_arg_label = 0; } #if 0 @@ -608,18 +608,18 @@ { char *rn; if (!large_offset_reg) { - if (is_code(fnptr)) { - if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("lo16(%d)(r1)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); - } else - printf("lo16(%d)(r30)\n",CODE_LVAR(l)); - } else if (l<0) { /* local variable */ - printf("lo16(%d)(r30)\n",FUNC_LVAR(l)); - } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("lo16(%d)(r1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); - } else { /* callee's arguments */ - printf("lo16(%d+%s%d)(r30)\n",CALLEE_ARG(l),lpfx,lvar_offset_label); - } + if (is_code(fnptr)) { + if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ + printf("lo16(%d)(r1)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + } else + printf("lo16(%d)(r30)\n",CODE_LVAR(l)); + } else if (l<0) { /* local variable */ + printf("lo16(%d)(r30)\n",FUNC_LVAR(l)); + } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ + printf("lo16(%d)(r1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); + } else { /* callee's arguments */ + printf("lo16(%d+%s%d)(r30)\n",CALLEE_ARG(l),lpfx,lvar_offset_label); + } } else { rn = register_name(large_offset_reg); if (is_code(fnptr)) { @@ -657,7 +657,7 @@ if (LARGE_OFFSET(CODE_CALLER_ARG(l-ARG_LVAR_OFFSET))) { rn=register_name(large_offset_reg=get_register()); printf("\taddis %s,r1,ha16(%d)\n",rn, - CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); } } else { if (LARGE_OFFSET(CODE_LVAR(l))) { @@ -679,7 +679,7 @@ if (LARGE_OFFSET(CALLEE_ARG(l))) { rn=register_name(large_offset_reg=get_register()); printf("\taddis %s,r30,ha16(%d+%s%d)\n", - rn,CALLEE_ARG(l),lpfx,lvar_offset_label); + rn,CALLEE_ARG(l),lpfx,lvar_offset_label); } } } @@ -691,18 +691,18 @@ { char *rn; if (!large_offset_reg) { - if (is_code(fnptr)) { - if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("%d@l(1)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); - } else - printf("%d@l(%d)\n",CODE_LVAR(l),REG_fp); - } else if (l<0) { /* local variable */ - printf("%d@l(%d)\n",FUNC_LVAR(l),REG_fp); - } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("%d@l(1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); - } else { /* callee's arguments */ + if (is_code(fnptr)) { + if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ + printf("%d@l(1)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + } else + printf("%d@l(%d)\n",CODE_LVAR(l),REG_fp); + } else if (l<0) { /* local variable */ + printf("%d@l(%d)\n",FUNC_LVAR(l),REG_fp); + } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ + printf("%d@l(1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); + } else { /* callee's arguments */ printf("%d+%s%d@l(%d)\n",CALLEE_ARG(l),lpfx,lvar_offset_label,REG_fp) ; - } + } } else { rn = register_name(large_offset_reg); if (is_code(fnptr)) { @@ -740,7 +740,7 @@ if (LARGE_OFFSET(CODE_CALLER_ARG(l-ARG_LVAR_OFFSET))) { rn=register_name(large_offset_reg=get_register()); printf("\taddis %s,1,%d@ha\n",rn, - CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); } } else { if (LARGE_OFFSET(CODE_LVAR(l))) { @@ -847,7 +847,7 @@ mode = LDECL; stmode = 0; n = def(lsearch("__my_va_list",0),0); - n->dsp = 0; // first argument + n->dsp = 0; // first argument } if (in) return; @@ -855,7 +855,7 @@ /* process in reverse order */ n = ncadddr(args); type = n->ty; - int sz = size(type); + int sz = size(type); offset = code_arg_alignment(offset,n,type,sz,is_code0); if (scalar(type)) { if ((reg = get_input_register_var(reg_var,n,is_code0))) { @@ -863,7 +863,7 @@ n->dsp = cadr(reg); regs[n->dsp]= INPUT_REG; reg_var++; - arg_offset_v += (caddr(args)=SIZE_OF_INT); + arg_offset_v += (caddr(args)=SIZE_OF_INT); } } else if (type==FLOAT) { if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { @@ -871,7 +871,7 @@ n->dsp = cadr(reg); regs[n->dsp]= INPUT_REG; freg_var++; - arg_offset_v += (caddr(args)=size(type)); + arg_offset_v += (caddr(args)=size(type)); } } else if (type==DOUBLE) { if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { @@ -879,7 +879,7 @@ n->dsp = cadr(reg); regs[n->dsp]= INPUT_REG; freg_var++; - arg_offset_v += (caddr(args)=size(type)); + arg_offset_v += (caddr(args)=size(type)); } } else if (type==LONGLONG||type==ULONGLONG) { if ((reg = get_input_lregister_var(reg_var,n,is_code0))) { @@ -889,22 +889,22 @@ regs[regv_l(i)]= INPUT_REG; regs[regv_h(i)]= INPUT_REG; reg_var+=2; - arg_offset_v += (caddr(args)=size(type)); + arg_offset_v += (caddr(args)=size(type)); } } args = cadr(args); } if (is_function(fnptr)) { #ifndef __APPLE__ - if (dots) { - arg_offset_v = - MAX_INPUT_REGISTER_VAR*SIZE_OF_INT + - MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE; - } - printf(".set %s%d, %d\n",lpfx, arg_offset_label, - arg_offset_v+ arg_offset); -#endif - code_save_input_registers(dots); + if (dots) { + arg_offset_v = + MAX_INPUT_REGISTER_VAR*SIZE_OF_INT + + MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE; + } + printf(".set %s%d, %d\n",lpfx, arg_offset_label, + arg_offset_v+ arg_offset); +#endif + code_save_input_registers(dots); } } @@ -914,43 +914,43 @@ { /* 使われていないレジスタを調べる */ int i,j,reg; for(i=MAX_TMP_REG;i>MIN_TMP_REG;i--) { - if (regs[i]) continue; /* 使われている */ - regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ - return i; /* その場所を表す番号を返す */ + if (regs[i]) continue; /* 使われている */ + regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + return i; /* その場所を表す番号を返す */ } /* PTR_CACHE をつぶす */ if ((i=last_ptr_cache())) { - clear_ptr_cache_reg(i); - regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ - return i; /* その場所を表す番号を返す */ + clear_ptr_cache_reg(i); + regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + return i; /* その場所を表す番号を返す */ } /* search register stack */ for(i=0;i<reg_sp;i++) { - if ((reg=reg_stack[i])>=0) { + if ((reg=reg_stack[i])>=0) { code_assign_lvar( (j=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= j-REG_LVAR_OFFSET; - return reg; - } + return reg; + } } #if LONGLONG_CODE /* search register stack */ for(i=0;i<lreg_sp;i++) { - if ((reg=lreg_stack[i])>=0) { + if ((reg=lreg_stack[i])>=0) { code_lassign_lvar( (j=new_lvar(SIZE_OF_LONGLONG)),reg); lreg_stack[i]= j-REG_LVAR_OFFSET; - free_register(reg); - return get_register(); - } + free_register(reg); + return get_register(); + } } #endif for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { reg =REG_VAR_BASE-i; if (! regs[reg]) { /* 使われていないなら */ regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ - if (i>max_reg_var) max_reg_var=i; - return reg; /* その場所を表す番号を返す */ + if (i>max_reg_var) max_reg_var=i; + return reg; /* その場所を表す番号を返す */ } } /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */ @@ -979,25 +979,25 @@ { /* 使われていないレジスタを調べる */ int i,reg; for(i=MAX_TMP_FREG+FREG_OFFSET;i>MIN_TMP_FREG+FREG_OFFSET;i--) { - if (regs[i]) continue; /* 使われている */ - regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ - return i; /* その場所を表す番号を返す */ + if (regs[i]) continue; /* 使われている */ + regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ + return i; /* その場所を表す番号を返す */ } /* search register stack */ for(i=0;i<freg_sp;i++) { - if ((reg=freg_stack[i])>=0) { + if ((reg=freg_stack[i])>=0) { code_dassign_lvar( (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; - return reg; - } + return reg; + } } for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { reg =FREG_VAR_BASE-i+FREG_OFFSET; if (! regs[reg]) { /* 使われていないなら */ regs[reg]=USING_REG; /* そのレジスタを使うことを宣言し */ - if (i>max_freg_var) max_freg_var=i; - return reg; /* その場所を表す番号を返す */ + if (i>max_freg_var) max_freg_var=i; + return reg; /* その場所を表す番号を返す */ } } /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */ @@ -1027,9 +1027,9 @@ { int i; for(i=LREG_OFFSET+1;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { - if (regs[i]==0) { - return i; - } + if (regs[i]==0) { + return i; + } } return -1; } @@ -1040,9 +1040,9 @@ int i; #if 1 for(i=LREG_OFFSET;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { - if (regv_l(i)==n && regv_h(i)==m) { - return i; - } + if (regv_l(i)==n && regv_h(i)==m) { + return i; + } } #endif return get_lregister0(); @@ -1057,15 +1057,15 @@ // lost some input register variables. #if 1 for(i=LREG_OFFSET+1;i<REAL_MAX_LREGISTER+LREG_OFFSET;i++) { - if (regs[i]) { - if(!regv_l(i) && !regv_h(i)) { - regs[i]=0; - // printf("## cleanup lreg 0 %d\n",i); - } else if(!regs[regv_l(i)] && !regs[regv_h(i)]) { - free_register(i); - // printf("## cleanup lreg 1 %d\n",i); - } - } + if (regs[i]) { + if(!regv_l(i) && !regv_h(i)) { + regs[i]=0; + // printf("## cleanup lreg 0 %d\n",i); + } else if(!regs[regv_l(i)] && !regs[regv_h(i)]) { + free_register(i); + // printf("## cleanup lreg 1 %d\n",i); + } + } } #endif } @@ -1081,9 +1081,9 @@ regv_h(i) = h; l = get_register(); if (l==-1) { - if (regs[h]!=REG_VAR) free_register(h); - if (regs[i]!=REG_VAR) free_register(i); - return -1; + if (regs[h]!=REG_VAR) free_register(h); + if (regs[i]!=REG_VAR) free_register(i); + return -1; } regv_l(i) = l; if (!regs[i]) regs[i]=USING_REG; @@ -1099,30 +1099,30 @@ ll = get_lregister0(); if (ll==-1) goto not_found; if (regs[ll]==0) { - for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { - if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ - /* そのレジスタを使うことを宣言し */ - regs[REG_VAR_BASE-i]=USING_REG; - if (i>max_reg_var) max_reg_var=i; - for(j=0;j<REG_VAR_BASE-REG_VAR_MIN;j++) { - if (! regs[REG_VAR_BASE-j]) { - /* 使われていないなら */ - /* そのレジスタを使うことを宣言し */ - regs[REG_VAR_BASE-j]=REG_VAR; - if (j>max_reg_var) max_reg_var=j; - /* その場所を表す番号を返す */ - regs[ll]=REG_VAR; - regv_l(ll) = REG_VAR_BASE-j; - regv_h(ll) = REG_VAR_BASE-i; - return list3n(LREGISTER,ll,n); - } - } - /* ひとつしかなかった */ - regs[REG_VAR_BASE-i]=0; - max_reg_var=max_reg_var_save; - goto not_found; - } - } + for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { + if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ + /* そのレジスタを使うことを宣言し */ + regs[REG_VAR_BASE-i]=USING_REG; + if (i>max_reg_var) max_reg_var=i; + for(j=0;j<REG_VAR_BASE-REG_VAR_MIN;j++) { + if (! regs[REG_VAR_BASE-j]) { + /* 使われていないなら */ + /* そのレジスタを使うことを宣言し */ + regs[REG_VAR_BASE-j]=REG_VAR; + if (j>max_reg_var) max_reg_var=j; + /* その場所を表す番号を返す */ + regs[ll]=REG_VAR; + regv_l(ll) = REG_VAR_BASE-j; + regv_h(ll) = REG_VAR_BASE-i; + return list3n(LREGISTER,ll,n); + } + } + /* ひとつしかなかった */ + regs[REG_VAR_BASE-i]=0; + max_reg_var=max_reg_var_save; + goto not_found; + } + } } not_found: return list3n(LVAR,new_lvar(SIZE_OF_LONGLONG),0); @@ -1132,7 +1132,7 @@ emit_pop_free(int xreg) { if (xreg>=0 && xreg!=creg && regs[xreg]!=REG_VAR) - free_register(xreg); + free_register(xreg); } void @@ -1140,8 +1140,8 @@ free_register(int i) { /* いらなくなったレジスタを開放 */ // printf("## free_register %d\n",i); if (is_longlong_reg(i)) { - regs[regv_l(i)]=0; - regs[regv_h(i)]=0; + regs[regv_l(i)]=0; + regs[regv_h(i)]=0; } regs[i]=0; } @@ -1156,11 +1156,11 @@ get_input_dregister_var(int i,NMTBL *n,int is_code,int d) { if (is_code) { - if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0; - i = FREG_VAR_BASE-i+FREG_OFFSET; + if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0; + i = FREG_VAR_BASE-i+FREG_OFFSET; } else { - if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; - i = i+MIN_TMP_FREG+FREG_OFFSET; + if (i<0||i>=MAX_INPUT_DREGISTER_VAR) return 0; + i = i+MIN_TMP_FREG+FREG_OFFSET; } return list3n(DREGISTER,i,n); } @@ -1170,23 +1170,23 @@ { int ll; if (i!=-1) { - if (is_code) { - if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; - i = REG_VAR_BASE-i; - } else { - if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; + if (is_code) { + if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; + i = REG_VAR_BASE-i; + } else { + if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; #ifndef __APPLE__ if (i%2==1) i++; #endif - i = i+MIN_TMP_REG; - } - ll = get_lregister1(i,i+1); + i = i+MIN_TMP_REG; + } + ll = get_lregister1(i,i+1); #if ENDIAN_L==0 - regv_l(ll)=i; - regv_h(ll)=i+1; + regv_l(ll)=i; + regv_h(ll)=i+1; #else - regv_h(ll)=i; - regv_l(ll)=i+1; + regv_h(ll)=i; + regv_l(ll)=i+1; #endif } else { error(-1); ll=LREG_OFFSET+2; } return list3n(LREGISTER,ll,n); @@ -1196,11 +1196,11 @@ get_input_register_var(int i,NMTBL *n,int is_code) { if (is_code) { - if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; - i = REG_VAR_BASE-i; + if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; + i = REG_VAR_BASE-i; } else { - if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; - i = i+MIN_TMP_REG; + if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0; + i = i+MIN_TMP_REG; } return list3n(REGISTER,i,n); } @@ -1211,11 +1211,11 @@ get_input_register_var_1(int i,NMTBL *n,int is_code) { if (is_code) { - if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; - i = REG_VAR_BASE-i; + if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; + i = REG_VAR_BASE-i; } else { - if (i<0||i>=MAX_INPUT_REGISTER_VAR+1) return 0; - i = i+MIN_TMP_REG; + if (i<0||i>=MAX_INPUT_REGISTER_VAR+1) return 0; + i = i+MIN_TMP_REG; } return list3n(REGISTER,i,n); } @@ -1241,9 +1241,9 @@ { int i; for(i=0;i<MAX_REGISTER;i++) { - if (! regs[i]) { - return 0; - } + if (! regs[i]) { + return 0; + } } return 1; } @@ -1256,9 +1256,9 @@ // printf("## free_all register\n"); #if LONGLONG_CODE for(i=0;i<REAL_MAX_LREGISTER;i++) { - regs[i+LREG_OFFSET]=0; - regv_l(i+LREG_OFFSET) = 0; - regv_h(i+LREG_OFFSET) = 0; + regs[i+LREG_OFFSET]=0; + regv_l(i+LREG_OFFSET) = 0; + regv_h(i+LREG_OFFSET) = 0; } lreg = 0; // set_lreg(LREG_LREGISTER,0); @@ -1279,41 +1279,41 @@ { switch(car(s)) { case REGISTER: - switch(car(t)) { - case DREGISTER: case FREGISTER: break; - case REGISTER: - if(cadr(s)==cadr(t)) return 1; - break; - case LREGISTER: - if(cadr(s)==regv_l(cadr(t))) return 1; - if(cadr(s)==regv_h(cadr(t))) return 1; - break; - } - break; + switch(car(t)) { + case DREGISTER: case FREGISTER: break; + case REGISTER: + if(cadr(s)==cadr(t)) return 1; + break; + case LREGISTER: + if(cadr(s)==regv_l(cadr(t))) return 1; + if(cadr(s)==regv_h(cadr(t))) return 1; + break; + } + break; case DREGISTER: case FREGISTER: - switch(car(t)) { - case REGISTER: case LREGISTER: break; - case DREGISTER: case FREGISTER: - if(cadr(s)==cadr(t)) return 1; - break; - } - break; + switch(car(t)) { + case REGISTER: case LREGISTER: break; + case DREGISTER: case FREGISTER: + if(cadr(s)==cadr(t)) return 1; + break; + } + break; case LREGISTER: - switch(car(t)) { - case DREGISTER: case FREGISTER: break; - case REGISTER: - if(cadr(t)==regv_l(cadr(s))) return 1; - if(cadr(t)==regv_h(cadr(s))) return 1; - break; - case LREGISTER: - if(regv_l(cadr(t))==regv_l(cadr(s))) return 1; - if(regv_l(cadr(t))==regv_h(cadr(s))) return 1; - if(regv_h(cadr(t))==regv_l(cadr(s))) return 1; - if(regv_h(cadr(t))==regv_h(cadr(s))) return 1; - break; - } - break; + switch(car(t)) { + case DREGISTER: case FREGISTER: break; + case REGISTER: + if(cadr(t)==regv_l(cadr(s))) return 1; + if(cadr(t)==regv_h(cadr(s))) return 1; + break; + case LREGISTER: + if(regv_l(cadr(t))==regv_l(cadr(s))) return 1; + if(regv_l(cadr(t))==regv_h(cadr(s))) return 1; + if(regv_h(cadr(t))==regv_l(cadr(s))) return 1; + if(regv_h(cadr(t))==regv_h(cadr(s))) return 1; + break; + } + break; } return 0; } @@ -1332,60 +1332,60 @@ if (ireg) printf(" creg=%s",register_name(ireg)); if (freg) printf(" freg=%s",fregister_name(freg)); if (lreg) printf(" lreg=%s,%s",lregister_name_high(lreg), - lregister_name_low(lreg)); + lregister_name_low(lreg)); #if 1 for(j=0,i=0;i<MAX_REGISTER;i++) if (regs[i]) j++; if (j>USAGE_MAX) { - printf("\n## regs(%d):",j); - for(i=0;i<MAX_REGISTER;i++) { printf("%d",regs[i]); } + printf("\n## regs(%d):",j); + for(i=0;i<MAX_REGISTER;i++) { printf("%d",regs[i]); } } if (reg_sp>0) { - printf(" stack "); - for(i=reg_sp;i>0;i--) { - if(reg_stack[i-1]>=0) { - printf(" %s",register_name(reg_stack[i-1])); + printf(" stack "); + for(i=reg_sp;i>0;i--) { + if(reg_stack[i-1]>=0) { + printf(" %s",register_name(reg_stack[i-1])); } else - printf(",%d",reg_stack[i-1]); - } + printf(",%d",reg_stack[i-1]); + } } for(j=0,i=0;i<MAX_FREGISTER;i++) if (regs[i+FREG_OFFSET]) j++; if (j>USAGE_MAX) { - printf("\n## freg(%d):",j); - for(i=0;i<MAX_FREGISTER;i++) { printf("%d",regs[i+FREG_OFFSET]); } + printf("\n## freg(%d):",j); + for(i=0;i<MAX_FREGISTER;i++) { printf("%d",regs[i+FREG_OFFSET]); } } if (freg_sp>0) { - printf(" fstack "); - for(i=freg_sp;i>0;i--) { - if(freg_stack[i-1]>=0) { - printf(" %s",fregister_name(freg_stack[i-1])); + printf(" fstack "); + for(i=freg_sp;i>0;i--) { + if(freg_stack[i-1]>=0) { + printf(" %s",fregister_name(freg_stack[i-1])); } else - printf(",%d",freg_stack[i-1]); - } + printf(",%d",freg_stack[i-1]); + } } for(j=0,i=0;i<REAL_MAX_LREGISTER;i++) if (regs[i+LREG_OFFSET]) j++; // lreg_count = j; if (j>USAGE_MAX) { - printf("\n## lreg(%d):",j); - for(i=0;i<REAL_MAX_LREGISTER;i++) { printf("%d",regs[i+LREG_OFFSET]); } + printf("\n## lreg(%d):",j); + for(i=0;i<REAL_MAX_LREGISTER;i++) { printf("%d",regs[i+LREG_OFFSET]); } #if 0 - for(i=0;i<REAL_MAX_LREGISTER;i++) { - if (regs[i+LREG_OFFSET] && regv_l(i+LREG_OFFSET)) - printf(" %s-%s", lregister_name_high(i+LREG_OFFSET),lregister_name_low(i+LREG_OFFSET)); - else if (regv_l(i+LREG_OFFSET)) - printf(" *%s-%s", lregister_name_high(i+LREG_OFFSET),lregister_name_low(i+LREG_OFFSET)); - } + for(i=0;i<REAL_MAX_LREGISTER;i++) { + if (regs[i+LREG_OFFSET] && regv_l(i+LREG_OFFSET)) + printf(" %s-%s", lregister_name_high(i+LREG_OFFSET),lregister_name_low(i+LREG_OFFSET)); + else if (regv_l(i+LREG_OFFSET)) + printf(" *%s-%s", lregister_name_high(i+LREG_OFFSET),lregister_name_low(i+LREG_OFFSET)); + } #endif } if (lreg_sp>0) { - printf(" lstack "); - for(i=lreg_sp;i>0;i--) { - if(lreg_stack[i-1]>=0) { - printf(" %s",lregister_name_high(lreg_stack[i-1])); - printf(",%s",lregister_name_low(lreg_stack[i-1])); + printf(" lstack "); + for(i=lreg_sp;i>0;i--) { + if(lreg_stack[i-1]>=0) { + printf(" %s",lregister_name_high(lreg_stack[i-1])); + printf(",%s",lregister_name_low(lreg_stack[i-1])); } else - printf(",%d",lreg_stack[i-1]); - } + printf(",%d",lreg_stack[i-1]); + } } #endif printf("\n"); @@ -1396,16 +1396,16 @@ gexpr_init(void) { while(reg_sp > 0) { - error(-1); - free_register(reg_stack[--reg_sp]); + error(-1); + free_register(reg_stack[--reg_sp]); } while(freg_sp > 0) { - error(-1); - free_register(freg_stack[--freg_sp]); + error(-1); + free_register(freg_stack[--freg_sp]); } while(lreg_sp > 0) { - error(-1); - free_register(lreg_stack[--lreg_sp]); + error(-1); + free_register(lreg_stack[--lreg_sp]); } use_int0(); text_mode(0); @@ -1432,13 +1432,13 @@ { int i; for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { - if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ - /* そのレジスタを使うことを宣言し */ - regs[REG_VAR_BASE-i]=REG_VAR; - if (i>max_reg_var) max_reg_var=i; - /* その場所を表す番号を返す */ - return list3n(REGISTER,REG_VAR_BASE-i,n); - } + if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ + /* そのレジスタを使うことを宣言し */ + regs[REG_VAR_BASE-i]=REG_VAR; + if (i>max_reg_var) max_reg_var=i; + /* その場所を表す番号を返す */ + return list3n(REGISTER,REG_VAR_BASE-i,n); + } } return list3n(LVAR,new_lvar(SIZE_OF_INT),0); } @@ -1450,10 +1450,10 @@ for(i=0;i<FREG_VAR_BASE-FREG_VAR_MIN;i++) { if (! regs[FREG_VAR_BASE-i+FREG_OFFSET]) { /* 使われていないなら */ regs[FREG_VAR_BASE-i+FREG_OFFSET]=REG_VAR; /*そのレジスタを使うことを宣言し*/ - if (i>max_freg_var) max_freg_var=i; - /* その場所を表す番号を返す */ - return list3n(DREGISTER, - FREG_VAR_BASE-i+FREG_OFFSET,n); + if (i>max_freg_var) max_freg_var=i; + /* その場所を表す番号を返す */ + return list3n(DREGISTER, + FREG_VAR_BASE-i+FREG_OFFSET,n); } } return list3n(LVAR,new_lvar(SIZE_OF_DOUBLE),0); @@ -1479,10 +1479,10 @@ int xreg,reg; xreg=pop_register(); if (xreg<= -REG_LVAR_OFFSET) { - reg = get_register(); + reg = get_register(); code_rlvar(REG_LVAR_OFFSET+xreg,reg); - free_lvar(REG_LVAR_OFFSET+xreg); - xreg = reg; + free_lvar(REG_LVAR_OFFSET+xreg); + xreg = reg; } return xreg; } @@ -1497,21 +1497,21 @@ char *rrn = register_name(r); #ifdef __APPLE__ if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { - printf("\taddis %s,r31,ha16(_%s-L_%d)\n", - rrn,nptr->nm,code_base); - printf("\tla %s,lo16(_%s-L_%d)(%s)\n", - rrn,nptr->nm,code_base,rrn); + printf("\taddis %s,r31,ha16(_%s-L_%d)\n", + rrn,nptr->nm,code_base); + printf("\tla %s,lo16(_%s-L_%d)(%s)\n", + rrn,nptr->nm,code_base,rrn); } else { - printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n", - rrn,nptr->nm,code_base); - printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n", - rrn,nptr->nm,code_base,rrn); + printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n", + rrn,nptr->nm,code_base); + printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n", + rrn,nptr->nm,code_base,rrn); } #else printf("\tlis %s,%s@ha\n", - rrn,nptr->nm); + rrn,nptr->nm); printf("\tla %s,%s@l(%s)\n", - rrn,nptr->nm,rrn); + rrn,nptr->nm,rrn); #endif } @@ -1523,15 +1523,15 @@ { char *crn = register_name(reg); if (sign) { - if (sz==1) - printf("\textsb %s,%s\n",crn,crn); - else if (sz==SIZE_OF_SHORT) - printf("\textsh %s,%s\n",crn,crn); + if (sz==1) + printf("\textsb %s,%s\n",crn,crn); + else if (sz==SIZE_OF_SHORT) + printf("\textsh %s,%s\n",crn,crn); } else { - if (sz==1) - printf("\trlwinm %s,%s,0,0xff\n",crn,crn); - else if (sz==SIZE_OF_SHORT) - printf("\trlwinm %s,%s,0,0xffff\n",crn,crn); + if (sz==1) + printf("\trlwinm %s,%s,0,0xff\n",crn,crn); + else if (sz==SIZE_OF_SHORT) + printf("\trlwinm %s,%s,0,0xffff\n",crn,crn); } } @@ -1549,18 +1549,18 @@ char *crn = register_name(reg); char *rrn = register_name(r); if (offset==0) { - if(r!=reg) - printf("\tmr %s,%s\n",crn,rrn); + if(r!=reg) + printf("\tmr %s,%s\n",crn,rrn); } else if (LARGE_OFFSET(offset)) { #ifdef __APPLE__ - printf("\tla %s,lo16(%d)(%s)\n",crn,offset,rrn); - printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); + printf("\tla %s,lo16(%d)(%s)\n",crn,offset,rrn); + printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); #else - printf("\tla %s,%d@l(%s)\n",crn,offset,rrn); - printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); + printf("\tla %s,%d@l(%s)\n",crn,offset,rrn); + printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); #endif } else - printf("\taddi %s,%s,%d\n",crn,rrn,offset); + printf("\taddi %s,%s,%d\n",crn,rrn,offset); } static void @@ -1570,14 +1570,14 @@ char *rrn = register_name(r); if (LARGE_OFFSET(offset)) { #ifdef __APPLE__ - printf("\taddis %s,%s,ha16(%d)\n",crn,rrn,offset); - printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,crn); + printf("\taddis %s,%s,ha16(%d)\n",crn,rrn,offset); + printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,crn); #else - printf("\taddis %s,%s,%d@ha\n",crn,rrn,offset); - printf("\t%s %s,%d@l(%s)\n",ld,crn,offset,crn); + printf("\taddis %s,%s,%d@ha\n",crn,rrn,offset); + printf("\t%s %s,%d@l(%s)\n",ld,crn,offset,crn); #endif } else - printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn); + printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn); } static void @@ -1587,17 +1587,17 @@ int reg; char *lrn; if (offset<-32768||32767<offset) { - lrn = register_name(reg = get_register()); + lrn = register_name(reg = get_register()); #ifdef __APPLE__ - printf("\taddis %s,%s,ha16(%d)\n",lrn,rrn,offset); - printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,lrn); + printf("\taddis %s,%s,ha16(%d)\n",lrn,rrn,offset); + printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,lrn); #else - printf("\taddis %s,%s,%d@ha\n",lrn,rrn,offset); - printf("\t%s %s,%d@l(%s)\n",ld,crn,offset,lrn); -#endif - free_register(reg); + printf("\taddis %s,%s,%d@ha\n",lrn,rrn,offset); + printf("\t%s %s,%d@l(%s)\n",ld,crn,offset,lrn); +#endif + free_register(reg); } else - printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn); + printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn); } void @@ -1626,7 +1626,7 @@ code_register(int e2,int reg) { use_int(reg); if (reg!=e2) - printf("\tmr %s,%s\n",register_name(reg),register_name(e2)); + printf("\tmr %s,%s\n",register_name(reg),register_name(e2)); } extern void @@ -1680,7 +1680,7 @@ use_int(reg); r = get_ptr_cache(n); if(r!=reg) - printf("\tmr %s,%s\n",register_name(reg),register_name(r)); + printf("\tmr %s,%s\n",register_name(reg),register_name(r)); return; } @@ -1707,21 +1707,21 @@ // printf("## 0x%08x\n",e2); #ifdef __APPLE__ if (-32768<e2&&e2<32768) - printf("\tli %s,%d\n",crn,e2); + printf("\tli %s,%d\n",crn,e2); else if ((e2&0xffff)==0) - printf("\tlis %s,ha16(%d)\n",crn,e2); + printf("\tlis %s,ha16(%d)\n",crn,e2); else { - printf("\tlis %s,ha16(%d)\n",crn,e2); - printf("\taddi %s,%s,lo16(%d)\n",crn,crn,e2); + printf("\tlis %s,ha16(%d)\n",crn,e2); + printf("\taddi %s,%s,lo16(%d)\n",crn,crn,e2); } #else if (-32768<e2&&e2<32768) - printf("\tli %s,%d\n",crn,e2); + printf("\tli %s,%d\n",crn,e2); else if ((e2&0xffff)==0) - printf("\tlis %s,%d@ha\n",crn,e2); + printf("\tlis %s,%d@ha\n",crn,e2); else { - printf("\tlis %s,%d@ha\n",crn,e2); - printf("\taddi %s,%s,%d@l\n",crn,crn,e2); + printf("\tlis %s,%d@ha\n",crn,e2); + printf("\taddi %s,%s,%d@l\n",crn,crn,e2); } #endif } @@ -1737,7 +1737,7 @@ code_not(int creg) { use_int(creg); printf("\tnor %s,%s,%s\n", - register_name(creg), register_name(creg),register_name(creg)); + register_name(creg), register_name(creg),register_name(creg)); } @@ -1757,22 +1757,22 @@ code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { char *xrn,*drn; if (car(e2)==REGISTER) { - use_int(reg); - printf("\taddi %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)), dir); - if (use && cadr(e2)!=reg) - printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); - return; + use_int(reg); + printf("\taddi %s,%s,%d\n", + register_name(cadr(e2)),register_name(cadr(e2)), dir); + if (use && cadr(e2)!=reg) + printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); + return; } g_expr(e2); if (!is_int_reg(creg)) error(-1); xrn = register_name(creg); if (reg==USE_CREG) { - reg=get_register(); if (!reg) error(-1); - drn = register_name(reg); - set_ireg(reg,0); + reg=get_register(); if (!reg) error(-1); + drn = register_name(reg); + set_ireg(reg,0); } else { - drn = register_name(reg); + drn = register_name(reg); } printf("\t%s %s,0(%s)\n",cload(sz),drn,xrn); if (use) cext(sign,sz,reg); @@ -1786,12 +1786,12 @@ char *xrn,*crn,*nrn; int nreg; if (car(e2)==REGISTER) { - use_int(reg); - if (use) - printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); - printf("\taddi %s,%s,%d\n", - register_name(cadr(e2)),register_name(cadr(e2)),dir); - return; + use_int(reg); + if (use) + printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); + printf("\taddi %s,%s,%d\n", + register_name(cadr(e2)),register_name(cadr(e2)),dir); + return; } g_expr(e2); if (!is_int_reg(creg)) error(-1); @@ -1799,11 +1799,11 @@ nreg=get_register(); if (!nreg) error(-1); nrn = register_name(nreg); if (reg==USE_CREG) { - reg=get_register(); if (!reg) error(-1); - xrn = register_name(reg); - set_ireg(reg,0); + reg=get_register(); if (!reg) error(-1); + xrn = register_name(reg); + set_ireg(reg,0); } else { - xrn = register_name(reg); + xrn = register_name(reg); } printf("\t%s %s,0(%s)\n",cload(sz),xrn,crn); if (use) cext(sign,sz,reg); @@ -1866,15 +1866,15 @@ b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ if (use) { - use_int(reg); - xrn = register_name(reg); - printf("\tli %s,0\n",xrn); - jmp(e3=fwdlabel()); - fwddef(e2); - printf("\tli %s,1\n",xrn); - fwddef(e3); + use_int(reg); + xrn = register_name(reg); + printf("\tli %s,0\n",xrn); + jmp(e3=fwdlabel()); + fwddef(e2); + printf("\tli %s,1\n",xrn); + fwddef(e3); } else { - fwddef(e2); + fwddef(e2); } } @@ -1895,7 +1895,7 @@ { // gcc use cmpflag 4 and 7, and gcc4 believes flag 4 is preserved. do { - cmpflag = (cmpflag+1)%8; + cmpflag = (cmpflag+1)%8; } while (cmpflag!=4 && cmpflag!=7); } @@ -1975,9 +1975,9 @@ lb = emit_string_label(); ascii(n->nm); if (output_mode==TEXT_EMIT_MODE) { - printf(".text\n"); + printf(".text\n"); } else { - text_mode(0); + text_mode(0); } code_label_value(lb,creg); set_attr(n,LABEL,lb); @@ -2004,9 +2004,9 @@ ascii(scaddr(i)); } if (output_mode==TEXT_EMIT_MODE) { - printf(".text\n"); + printf(".text\n"); } else { - text_mode(0); + text_mode(0); } code_label_value(l,reg); } @@ -2024,82 +2024,82 @@ int l; int dreg = get_register(); if (!dreg) error(-1); - drn = register_name(dreg); + drn = register_name(dreg); use_int(from); use_int(to); - frn = register_name(from); - trn = register_name(to); + frn = register_name(from); + trn = register_name(to); /* length <0 means upward direction copy */ switch (length) { - case 0: break; + case 0: break; case 1: case -1: - printf("\tlbz %s,%d(%s)\n",drn,offset,frn); - printf("\tstb %s,%d(%s)\n",drn,offset,trn); - break; + printf("\tlbz %s,%d(%s)\n",drn,offset,frn); + printf("\tstb %s,%d(%s)\n",drn,offset,trn); + break; case 2: case -2: - printf("\tlhz %s,%d(%s)\n",drn,offset,frn); - printf("\tsth %s,%d(%s)\n",drn,offset,trn); - break; + printf("\tlhz %s,%d(%s)\n",drn,offset,frn); + printf("\tsth %s,%d(%s)\n",drn,offset,trn); + break; case 4: case -4: - printf("\tlwz %s,%d(%s)\n",drn,offset,frn); - printf("\tstw %s,%d(%s)\n",drn,offset,trn); - break; + printf("\tlwz %s,%d(%s)\n",drn,offset,frn); + printf("\tstw %s,%d(%s)\n",drn,offset,trn); + break; default: - if (length <0) { - if (length >= -MAX_COPY_LEN) { - free_register(dreg); dreg = 0; - for(;length<=-4;length+=4,offset-=4) - emit_copy(from,to,-4,offset-4,0,det); - for(;length<=-2;length+=2,offset-=2) - emit_copy(from,to,-2,offset-2,0,det); - if(length<0) - emit_copy(from,to,length,offset-1,0,det); - break; - } - } else if (length <=MAX_COPY_LEN) { - free_register(dreg); dreg = 0; - for(;length>=4;length-=4,offset+=4) - emit_copy(from,to,4,offset,0,det); - for(;length>=2;length-=2,offset+=2) - emit_copy(from,to,2,offset,0,det); - if(length>0) - emit_copy(from,to,length,offset,0,det); - break; - } - clear_ptr_cache(); - code_save_stacks(); + if (length <0) { + if (length >= -MAX_COPY_LEN) { + free_register(dreg); dreg = 0; + for(;length<=-4;length+=4,offset-=4) + emit_copy(from,to,-4,offset-4,0,det); + for(;length<=-2;length+=2,offset-=2) + emit_copy(from,to,-2,offset-2,0,det); + if(length<0) + emit_copy(from,to,length,offset-1,0,det); + break; + } + } else if (length <=MAX_COPY_LEN) { + free_register(dreg); dreg = 0; + for(;length>=4;length-=4,offset+=4) + emit_copy(from,to,4,offset,0,det); + for(;length>=2;length-=2,offset+=2) + emit_copy(from,to,2,offset,0,det); + if(length>0) + emit_copy(from,to,length,offset,0,det); + break; + } + clear_ptr_cache(); + code_save_stacks(); l = list3(3,0,to); l = list3(4,l,from); parallel_rassign(l); #ifdef __APPLE__ - printf("\tli r5,%d\n",length>0?length:-length); - /* offset should be ignored */ + printf("\tli r5,%d\n",length>0?length:-length); + /* offset should be ignored */ /* overrap must be allowed */ - printf("\tbl L_%s$stub\n",memmove); + printf("\tbl L_%s$stub\n",memmove); #else - printf("\tli 5,%d\n",length>0?length:-length); - /* offset should be ignored */ + printf("\tli 5,%d\n",length>0?length:-length); + /* offset should be ignored */ /* overrap must be allowed */ - printf("\tbl %s\n",memmove); -#endif - extern_define(memmove,0,FUNCTION,1); - set_ireg(RET_REGISTER,0); - //if (creg!=to) { - // free_register(to); to = creg; - //} - break; + printf("\tbl %s\n",memmove); +#endif + extern_define(memmove,0,FUNCTION,1); + set_ireg(RET_REGISTER,0); + //if (creg!=to) { + // free_register(to); to = creg; + //} + break; } if (value) { /* creg must point top of the destination data */ /* this code is necessary for the value of assignment or function call */ /* otherwise we don't need this */ - if(creg!=to) { - free_register(to); - // set_ireg(to,1); - } + if(creg!=to) { + free_register(to); + // set_ireg(to,1); + } } if (dreg) free_register(dreg); } @@ -2113,26 +2113,26 @@ if (!is_int_reg(creg)) error(-1); length=size(t); if(length%SIZE_OF_INT) { - length += SIZE_OF_INT - (length%SIZE_OF_INT); + length += SIZE_OF_INT - (length%SIZE_OF_INT); } dreg = get_register(); if (!dreg) error(-1); drn = register_name(dreg); crn = register_name(creg); if (length<MAX_COPY_LEN) { - sreg = get_register(); if (!sreg) error(-1); - srn = register_name(sreg); - code_lvar(cadr(arg),dreg); - for(count=0;count<length;count+=SIZE_OF_INT) { - printf("\tlwz %s,%d(%s)\n",srn,count,crn); - printf("\tstw %s,%d(%s)\n",srn,count,drn); - } - free_register(sreg); - free_register(dreg); - return length/SIZE_OF_INT; + sreg = get_register(); if (!sreg) error(-1); + srn = register_name(sreg); + code_lvar(cadr(arg),dreg); + for(count=0;count<length;count+=SIZE_OF_INT) { + printf("\tlwz %s,%d(%s)\n",srn,count,crn); + printf("\tstw %s,%d(%s)\n",srn,count,drn); + } + free_register(sreg); + free_register(dreg); + return length/SIZE_OF_INT; } else { - code_lvar(cadr(arg),dreg); - /* downward direction copy */ - emit_copy(creg,dreg,length,0,0,1); + code_lvar(cadr(arg),dreg); + /* downward direction copy */ + emit_copy(creg,dreg,length,0,0,1); } free_register(dreg); return length/SIZE_OF_INT; @@ -2143,20 +2143,20 @@ { if (!is_int_reg(reg)) error(-1); if (reg!=creg) { - clear_ptr_cache_reg(reg); - if (ireg && reg!=ireg ) { - clear_ptr_cache_reg(ireg); - if (regs[ireg]!=REG_VAR) free_register(ireg); - if (mode) { - printf("\tmr %s,%s\n",register_name(reg),register_name(ireg)); - } - } - if (regs[creg]!=REG_VAR) { - clear_ptr_cache_reg(creg); - free_register(creg); - } - if (creg==lreg) lreg = 0; - regs[reg]=USING_REG; + clear_ptr_cache_reg(reg); + if (ireg && reg!=ireg ) { + clear_ptr_cache_reg(ireg); + if (regs[ireg]!=REG_VAR) free_register(ireg); + if (mode) { + printf("\tmr %s,%s\n",register_name(reg),register_name(ireg)); + } + } + if (regs[creg]!=REG_VAR) { + clear_ptr_cache_reg(creg); + free_register(creg); + } + if (creg==lreg) lreg = 0; + regs[reg]=USING_REG; } creg = ireg = reg; } @@ -2166,14 +2166,14 @@ { if (!is_float_reg(reg)) error(-1); if (reg!=creg) { - if (freg && reg!=freg) { - free_register(freg); - if (mode) { - printf("\tfmr %s,%s\n",fregister_name(reg),fregister_name(freg)); - } - } - // if (creg!=ireg) free_register(creg); - regs[reg]=USING_REG; + if (freg && reg!=freg) { + free_register(freg); + if (mode) { + printf("\tfmr %s,%s\n",fregister_name(reg),fregister_name(freg)); + } + } + // if (creg!=ireg) free_register(creg); + regs[reg]=USING_REG; } creg = freg = reg; } @@ -2182,30 +2182,30 @@ set_lreg(int reg,int mode) { if (reg==RET_LREGISTER) { - regv_l(reg) = RET_LREGISTER_L; - regv_h(reg) = RET_LREGISTER_H; + regv_l(reg) = RET_LREGISTER_L; + regv_h(reg) = RET_LREGISTER_H; } if (!is_longlong_reg(reg)) error(-1); if (reg!=creg) { - if (lreg) { - if (reg!=lreg) { - if (mode) { - printf("\tmr %s,%s\n", - lregister_name_low(reg),lregister_name_low(lreg)); - printf("\tmr %s,%s\n", - lregister_name_high(reg),lregister_name_high(lreg)); - } - free_register(lreg); - } - if (lreg==creg) creg=0; - } - if (creg) free_register(creg); - regs[reg]=USING_REG; - clear_ptr_cache_reg(regv_l(reg)); - regs[regv_l(reg)]=USING_REG; - clear_ptr_cache_reg(regv_h(reg)); - regs[regv_h(reg)]=USING_REG; - creg = lreg = reg; + if (lreg) { + if (reg!=lreg) { + if (mode) { + printf("\tmr %s,%s\n", + lregister_name_low(reg),lregister_name_low(lreg)); + printf("\tmr %s,%s\n", + lregister_name_high(reg),lregister_name_high(lreg)); + } + free_register(lreg); + } + if (lreg==creg) creg=0; + } + if (creg) free_register(creg); + regs[reg]=USING_REG; + clear_ptr_cache_reg(regv_l(reg)); + regs[regv_l(reg)]=USING_REG; + clear_ptr_cache_reg(regv_h(reg)); + regs[regv_h(reg)]=USING_REG; + creg = lreg = reg; } } @@ -2215,10 +2215,10 @@ // save_stack,clear_ptr_cache is assumed if (!is_longlong_reg(reg)) { error(-1); return; } if (mode) { - if (regv_l(reg)!=3) - printf("\tmr %s,%s\n", register_name(3),lregister_name_high(reg)); - if (regv_l(reg)!=4) - printf("\tmr %s,%s\n", register_name(4),lregister_name_low(reg)); + if (regv_l(reg)!=3) + printf("\tmr %s,%s\n", register_name(3),lregister_name_high(reg)); + if (regv_l(reg)!=4) + printf("\tmr %s,%s\n", register_name(4),lregister_name_low(reg)); } } @@ -2228,10 +2228,10 @@ // save_stack,clear_ptr_cache is assumed if (!is_longlong_reg(reg)) { error(-1); return; } if (mode) { - if (regv_l(reg)!=5) - printf("\tmr %s,%s\n", register_name(5),lregister_name_high(reg)); - if (regv_l(reg)!=6) - printf("\tmr %s,%s\n", register_name(6),lregister_name_low(reg)); + if (regv_l(reg)!=5) + printf("\tmr %s,%s\n", register_name(5),lregister_name_high(reg)); + if (regv_l(reg)!=6) + printf("\tmr %s,%s\n", register_name(6),lregister_name_low(reg)); } } @@ -2240,14 +2240,14 @@ { // printf("## use reg %d\n",arg); if (arg<0||arg> REAL_MAX_REGISTER+REAL_MAX_FREGISTER+ REAL_MAX_LREGISTER) - error(-1); + error(-1); clear_ptr_cache_reg(arg); regs[arg]=USING_REG; if (is_longlong_reg(arg)) { - clear_ptr_cache_reg(regv_l(arg)); - regs[regv_l(arg)]=USING_REG; - clear_ptr_cache_reg(regv_h(arg)); - regs[regv_h(arg)]=USING_REG; + clear_ptr_cache_reg(regv_l(arg)); + regs[regv_l(arg)]=USING_REG; + clear_ptr_cache_reg(regv_h(arg)); + regs[regv_h(arg)]=USING_REG; } } @@ -2281,65 +2281,65 @@ for(args = fnptr->dsp;args;args = cadr(args)) { - n = ncadddr(args); - tag = n->sc; - reg = n->dsp; - if (!n||n==&null_nptr) error(REG_ERR); - if (tag==REGISTER) { - n->dsp = offset; - offset+=SIZE_OF_INT; - t = INT; - reg += reg_offset; /* for duplicated floating point argument */ - reg_var++; - } else if (tag==DREGISTER) { - n->dsp = offset; - t = n->ty; + n = ncadddr(args); + tag = n->sc; + reg = n->dsp; + if (!n||n==&null_nptr) error(REG_ERR); + if (tag==REGISTER) { + n->dsp = offset; + offset+=SIZE_OF_INT; + t = INT; + reg += reg_offset; /* for duplicated floating point argument */ + reg_var++; + } else if (tag==DREGISTER) { + n->dsp = offset; + t = n->ty; #ifdef __APPLE__ - if(t==FLOAT) { offset+=SIZE_OF_FLOAT; reg_offset+=1; } - else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; reg_offset+=2; } - else error(-1); - reg_var += 2; + if(t==FLOAT) { offset+=SIZE_OF_FLOAT; reg_offset+=1; } + else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; reg_offset+=2; } + else error(-1); + reg_var += 2; #else - if(t==FLOAT) { offset+=SIZE_OF_FLOAT; } - else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; } - else error(-1); -#endif - } else if (tag==LREGISTER) { - n->dsp = offset; - t = n->ty; - offset+=SIZE_OF_LONGLONG; - reg_offset+=2; - reg_var += 2; - } else { - // n->dsp = offset; this is no allowed becase of arg reorder - offset += size(n->ty); - continue; - } - n->sc = LVAR; - g_expr_u(assign_expr0( - list3n(LVAR,n->dsp,0),list3n(tag,reg,n),n->ty,t)); - if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) { - free_register(reg); - } + if(t==FLOAT) { offset+=SIZE_OF_FLOAT; } + else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; } + else error(-1); +#endif + } else if (tag==LREGISTER) { + n->dsp = offset; + t = n->ty; + offset+=SIZE_OF_LONGLONG; + reg_offset+=2; + reg_var += 2; + } else { + // n->dsp = offset; this is no allowed becase of arg reorder + offset += size(n->ty); + continue; + } + n->sc = LVAR; + g_expr_u(assign_expr0( + list3n(LVAR,n->dsp,0),list3n(tag,reg,n),n->ty,t)); + if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) { + free_register(reg); + } } if (dots) { - while ((reg = get_input_register_var(reg_var,0,0))) { - g_expr_u(assign_expr0( - list3n(LVAR,offset,0),reg,INT,INT)); - offset+=SIZE_OF_INT; - reg_var++; - } + while ((reg = get_input_register_var(reg_var,0,0))) { + g_expr_u(assign_expr0( + list3n(LVAR,offset,0),reg,INT,INT)); + offset+=SIZE_OF_INT; + reg_var++; + } #ifndef __APPLE__ - int skip = fwdlabel(); - int freg_var = 0; - printf("\tbne 1,%s%d\n",lpfx,skip); - while ((reg = get_input_dregister_var(freg_var,0,0,1))) { - g_expr_u(assign_expr0( - list3n(LVAR,offset,0),reg,DOUBLE,DOUBLE)); - offset+=SIZE_OF_DOUBLE; - freg_var++; - } - fwddef(skip); + int skip = fwdlabel(); + int freg_var = 0; + printf("\tbne 1,%s%d\n",lpfx,skip); + while ((reg = get_input_dregister_var(freg_var,0,0,1))) { + g_expr_u(assign_expr0( + list3n(LVAR,offset,0),reg,DOUBLE,DOUBLE)); + offset+=SIZE_OF_DOUBLE; + freg_var++; + } + fwddef(skip); #endif } my_func_args = offset; @@ -2349,10 +2349,10 @@ not_simple_p(int e3) { switch (e3) { - case FUNCTION: case CONV: case LCALL: case STASS: - case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT: - case LDIV: case LUDIV: case LMOD: case LUMOD: case LASSOP: case ALLOCA: - case INLINE: + case FUNCTION: case CONV: case LCALL: case STASS: + case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT: + case LDIV: case LUDIV: case LMOD: case LUMOD: case LASSOP: case ALLOCA: + case INLINE: return 1; } return 0; @@ -2369,45 +2369,45 @@ /* use input register as current register なんで、こんなに複雑なんだ? - むしろ、INPUT_REG みたいな mark をいれたら? + むしろ、INPUT_REG みたいな mark をいれたら? */ static void use_input_reg(int reg,int mode) { if (is_int_reg(reg)) { - if (ireg&® == ireg) { - if (creg==ireg) creg = 0; - ireg = 0; - } - if (lreg) { - // free_regsiter(lreg) でいいんじゃないの? - if (regv_l(lreg)==reg) { - regs[lreg]=0; - if (regv_h(lreg)>reg&®s[regv_h(lreg)]==USING_REG) { - free_register(regv_h(lreg)); - } - if (creg==lreg) creg = ireg; - free_register(lreg); - lreg = 0; - } else if (regv_h(lreg)==reg) { - regs[lreg]=0; - if (regv_h(lreg)>reg&®s[regv_l(lreg)]==USING_REG) { - free_register(regv_l(lreg)); - } - if (creg==lreg) creg = ireg; - free_register(lreg); - lreg = 0; - } - } + if (ireg&® == ireg) { + if (creg==ireg) creg = 0; + ireg = 0; + } + if (lreg) { + // free_regsiter(lreg) でいいんじゃないの? + if (regv_l(lreg)==reg) { + regs[lreg]=0; + if (regv_h(lreg)>reg&®s[regv_h(lreg)]==USING_REG) { + free_register(regv_h(lreg)); + } + if (creg==lreg) creg = ireg; + free_register(lreg); + lreg = 0; + } else if (regv_h(lreg)==reg) { + regs[lreg]=0; + if (regv_h(lreg)>reg&®s[regv_l(lreg)]==USING_REG) { + free_register(regv_l(lreg)); + } + if (creg==lreg) creg = ireg; + free_register(lreg); + lreg = 0; + } + } } else if (is_longlong_reg(reg)) { - use_input_reg(regv_h(reg),mode); - use_input_reg(regv_l(reg),mode); + use_input_reg(regv_h(reg),mode); + use_input_reg(regv_l(reg),mode); } else if (is_float_reg(reg)) { - if (freg&® == freg) { - if (creg==freg) creg = ireg; - freg = 0; - } + if (freg&® == freg) { + if (creg==freg) creg = ireg; + freg = 0; + } } if (mode) use_reg(reg); } @@ -2418,8 +2418,8 @@ int e4 = car(e3); reg_arg_list = list2(arg,reg_arg_list); if (car(arg)==REGISTER||car(arg)==DREGISTER|| - car(arg)==FREGISTER||car(arg)==LREGISTER) - use_input_reg(cadr(arg),1); + car(arg)==FREGISTER||car(arg)==LREGISTER) + use_input_reg(cadr(arg),1); g_expr_u(assign_expr0(arg,e4,t,t)); car(e3) = arg; return reg_arg_list; @@ -2432,30 +2432,30 @@ int nargs=0,reg_arg=0,freg_arg=0; int t=type_value(caddr(e3)); if (t>=0&&(car(t)==BIT_FIELD)) { - t = type_value(cadr(t)); + t = type_value(cadr(t)); } if(scalar(t)) { - nargs ++ ; reg_arg++; + nargs ++ ; reg_arg++; } else if (t==LONGLONG||t==ULONGLONG) { - nargs ++ ; reg_arg++; - nargs ++ ; reg_arg++; + nargs ++ ; reg_arg++; + nargs ++ ; reg_arg++; } else if (t==FLOAT) { - if (*preg_arg<MAX_INPUT_REGISTER_VAR) { - reg_arg += 1; - } - freg_arg++; - nargs += size(t)/SIZE_OF_INT; + if (*preg_arg<MAX_INPUT_REGISTER_VAR) { + reg_arg += 1; + } + freg_arg++; + nargs += size(t)/SIZE_OF_INT; } else if (t==DOUBLE) { - if (*preg_arg<MAX_INPUT_REGISTER_VAR) { - reg_arg += 2; - } - nargs += size(t)/SIZE_OF_INT; - freg_arg++; + if (*preg_arg<MAX_INPUT_REGISTER_VAR) { + reg_arg += 2; + } + nargs += size(t)/SIZE_OF_INT; + freg_arg++; } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { - nargs += round4(size(t))/SIZE_OF_INT; + nargs += round4(size(t))/SIZE_OF_INT; } else { - error(TYERR); - nargs ++ ; + error(TYERR); + nargs ++ ; } *pnargs += nargs; *preg_arg += reg_arg; @@ -2467,27 +2467,27 @@ int nargs=0,reg_arg=0,freg_arg=0; int t=type_value(caddr(e3)); if (t>=0&&(car(t)==BIT_FIELD)) { - t = type_value(cadr(t)); + t = type_value(cadr(t)); } if(scalar(t)) { - reg_arg++; - if (*preg_arg>=MAX_INPUT_REGISTER_VAR) nargs ++ ; + reg_arg++; + if (*preg_arg>=MAX_INPUT_REGISTER_VAR) nargs ++ ; } else if (t==LONGLONG||t==ULONGLONG) { if (*preg_arg%2==1) reg_arg++; // alignment if (*pnargs%2==1) nargs++; // alignment - reg_arg++; reg_arg++; - if (*preg_arg+1>=MAX_INPUT_REGISTER_VAR) nargs += 2; + reg_arg++; reg_arg++; + if (*preg_arg+1>=MAX_INPUT_REGISTER_VAR) nargs += 2; } else if (t==FLOAT) { - freg_arg++; - if (*pfreg_arg>=MAX_INPUT_DREGISTER_VAR) nargs += size(t)/SIZE_OF_INT; + freg_arg++; + if (*pfreg_arg>=MAX_INPUT_DREGISTER_VAR) nargs += size(t)/SIZE_OF_INT; } else if (t==DOUBLE) { - freg_arg++; - if (*pfreg_arg>=MAX_INPUT_DREGISTER_VAR) nargs += round4(size(t))/SIZE_OF_INT; + freg_arg++; + if (*pfreg_arg>=MAX_INPUT_DREGISTER_VAR) nargs += round4(size(t))/SIZE_OF_INT; } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { - nargs += round4(size(t))/SIZE_OF_INT; + nargs += round4(size(t))/SIZE_OF_INT; } else { - error(TYERR); - nargs ++ ; + error(TYERR); + nargs ++ ; } *pnargs += nargs; *preg_arg += reg_arg; @@ -2511,51 +2511,51 @@ { t = type_value(t); if (t>=0&&(car(t)==BIT_FIELD)) { - t = type_value(cadr(t)); + t = type_value(cadr(t)); } if(scalar(t)) { - if (mode==AS_SAVE) { - return get_register_var(0); - } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { - return list3n(LVAR,caller_arg_offset_v(nargs),0); - } else { - int e = get_input_register_var(reg_arg,0,0); + if (mode==AS_SAVE) { + return get_register_var(0); + } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { + return list3n(LVAR,caller_arg_offset_v(nargs),0); + } else { + int e = get_input_register_var(reg_arg,0,0); clear_ptr_cache_reg(cadr(e)); - return e; - } + return e; + } } else if (t==LONGLONG||t==ULONGLONG) { - if (mode==AS_SAVE) { - return get_lregister_var(0); - } else if (reg_arg+1>=MAX_INPUT_REGISTER_VAR) { - return list3n(LVAR,caller_arg_offset_v(nargs),0); - } else { - int e = get_input_lregister_var(reg_arg,0,0); + if (mode==AS_SAVE) { + return get_lregister_var(0); + } else if (reg_arg+1>=MAX_INPUT_REGISTER_VAR) { + return list3n(LVAR,caller_arg_offset_v(nargs),0); + } else { + int e = get_input_lregister_var(reg_arg,0,0); clear_ptr_cache_reg(regv_l(cadr(e))); clear_ptr_cache_reg(regv_h(cadr(e))); - return e; - } + return e; + } } else if (t==FLOAT) { - if (mode==AS_SAVE) { - return get_dregister_var(0,0); - } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { - return list3n(LVAR,caller_arg_offset_v(nargs),0); - } else - return get_input_dregister_var(freg_arg,0,0,0); + if (mode==AS_SAVE) { + return get_dregister_var(0,0); + } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { + return list3n(LVAR,caller_arg_offset_v(nargs),0); + } else + return get_input_dregister_var(freg_arg,0,0,0); } else if (t==DOUBLE) { - if (mode==AS_SAVE) { - return get_dregister_var(0,1); - } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { - return list3n(LVAR,caller_arg_offset_v(nargs),0); - } else - return get_input_dregister_var(freg_arg,0,0,1); + if (mode==AS_SAVE) { + return get_dregister_var(0,1); + } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { + return list3n(LVAR,caller_arg_offset_v(nargs),0); + } else + return get_input_dregister_var(freg_arg,0,0,1); } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { - if (mode==AS_SAVE) { - return get_register_var(0); - } else - return list3n(LVAR,caller_arg_offset_v(nargs),0); + if (mode==AS_SAVE) { + return get_register_var(0); + } else + return list3n(LVAR,caller_arg_offset_v(nargs),0); } else { - error(-1); - return get_register_var(0); + error(-1); + return get_register_var(0); } } @@ -2579,55 +2579,55 @@ arg_assign = 0; e2 = cadr(e1); - if (car(e2) == FNAME) { - fn=ncaddr(e2); - } else { + if (car(e2) == FNAME) { + fn=ncaddr(e2); + } else { if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case - jmp = get_register_var(0); - if (car(jmp)!=REGISTER) error(-1); - reg_arg_list = list2(jmp,reg_arg_list); + jmp = get_register_var(0); + if (car(jmp)!=REGISTER) error(-1); + reg_arg_list = list2(jmp,reg_arg_list); if (!simple_arg(e2)) { g_expr_u(assign_expr0(jmp,e2,INT,INT)); } else - arg_assign = list2(assign_expr0(jmp,e2,INT,INT),arg_assign); + arg_assign = list2(assign_expr0(jmp,e2,INT,INT),arg_assign); } /* first we execute complex argument to avoid interaction with input variables */ stargs = 0; complex_ = 0; nargs = reg_arg = freg_arg = 0; - for (e3 = e1 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { - t=caddr(e3); - if ((e5= !simple_arg(car(e3)))) { - if (complex_) { - arg = get_input_arg(caddr(complex_),AS_SAVE, - pnargs,preg_arg,pfreg_arg); - reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); - } - pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg; - complex_ = e3; - } - if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { - // The struct should be pushed after complex arguments. - if (e5) { // compute address only, complex_ is me now. Clear it. - complex_ = 0; - e4 = car(e3); - if (car(e4)==RSTRUCT) e4 = cadr(e4); - else if (car(e4)==INDIRECT) e4 = cadr(e4); - if (!simple_arg(e4)) { - // Calculate complex struct address here. - // If simple, leave it. - arg = get_register_var(0); - g_expr_u(assign_expr0(arg,e4,INT,INT)); - car(e3)=arg; - reg_arg_list = list2(arg,reg_arg_list); - if (car(arg)==REGISTER) use_input_reg(cadr(arg),1); + for (e3 = e1 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { + t=caddr(e3); + if ((e5= !simple_arg(car(e3)))) { + if (complex_) { + arg = get_input_arg(caddr(complex_),AS_SAVE, + pnargs,preg_arg,pfreg_arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); + } + pnargs=nargs;preg_arg=reg_arg;pfreg_arg=freg_arg; + complex_ = e3; + } + if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { + // The struct should be pushed after complex arguments. + if (e5) { // compute address only, complex_ is me now. Clear it. + complex_ = 0; + e4 = car(e3); + if (car(e4)==RSTRUCT) e4 = cadr(e4); + else if (car(e4)==INDIRECT) e4 = cadr(e4); + if (!simple_arg(e4)) { + // Calculate complex struct address here. + // If simple, leave it. + arg = get_register_var(0); + g_expr_u(assign_expr0(arg,e4,INT,INT)); + car(e3)=arg; + reg_arg_list = list2(arg,reg_arg_list); + if (car(arg)==REGISTER) use_input_reg(cadr(arg),1); else car(e3) = rvalue_t(arg,INT); - } - } - stargs = list4(e3,stargs,nargs,reg_arg); - } - increment_function_arg(e3,&nargs,®_arg,&freg_arg); + } + } + stargs = list4(e3,stargs,nargs,reg_arg); + } + increment_function_arg(e3,&nargs,®_arg,&freg_arg); } /* now all input register vars are free */ @@ -2657,145 +2657,145 @@ car(e3)=0; // done } } else { - // last complex argument can use input register - if (complex_) { - arg = get_input_arg(caddr(complex_),AS_ARG,pnargs,preg_arg,pfreg_arg); - reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); - } + // last complex argument can use input register + if (complex_) { + arg = get_input_arg(caddr(complex_),AS_ARG,pnargs,preg_arg,pfreg_arg); + reg_arg_list = compute_complex_arg(complex_,reg_arg_list,arg); + } } nargs = reg_arg = freg_arg = 0; // calc stack arguments first, it may requires extra registers, // and we can still use input registers now. for (e3 = e1; e3; - increment_function_arg(e3,&nargs,®_arg,&freg_arg), - e3 = cadr(e3)) { - if (!(e4=car(e3))) continue; - t=caddr(e3); - arg = get_input_arg(t,AS_ARG,nargs,reg_arg,freg_arg); - if (car(arg)!=LVAR) continue; - g_expr_u(assign_expr0(arg,e4,t,t)); - if (t==LONGLONG||t==ULONGLONG) { - if (reg_arg+1==MAX_INPUT_REGISTER_VAR) { - // half register, half memory case - arg_assign = list2( - assign_expr0(r0=get_input_register_var(reg_arg,0,0), - arg,INT,INT), - arg_assign); - use_input_reg(cadr(r0),1); - } - } - car(e3)=0; // done + increment_function_arg(e3,&nargs,®_arg,&freg_arg), + e3 = cadr(e3)) { + if (!(e4=car(e3))) continue; + t=caddr(e3); + arg = get_input_arg(t,AS_ARG,nargs,reg_arg,freg_arg); + if (car(arg)!=LVAR) continue; + g_expr_u(assign_expr0(arg,e4,t,t)); + if (t==LONGLONG||t==ULONGLONG) { + if (reg_arg+1==MAX_INPUT_REGISTER_VAR) { + // half register, half memory case + arg_assign = list2( + assign_expr0(r0=get_input_register_var(reg_arg,0,0), + arg,INT,INT), + arg_assign); + use_input_reg(cadr(r0),1); + } + } + car(e3)=0; // done } nargs = reg_arg = freg_arg = 0; for (e3 = e1; e3; - increment_function_arg(e3,&nargs,®_arg,&freg_arg), - e3 = cadr(e3)) { - if (!(e4=car(e3))) continue; - t=type_value(caddr(e3)); - arg = get_input_arg(t,AS_ARG,nargs,reg_arg,freg_arg); - if(scalar(t)) { - reg_arg_list = list2(arg,reg_arg_list); - /* protect from input register free */ - if (car(arg)==REGISTER) { + increment_function_arg(e3,&nargs,®_arg,&freg_arg), + e3 = cadr(e3)) { + if (!(e4=car(e3))) continue; + t=type_value(caddr(e3)); + arg = get_input_arg(t,AS_ARG,nargs,reg_arg,freg_arg); + if(scalar(t)) { + reg_arg_list = list2(arg,reg_arg_list); + /* protect from input register free */ + if (car(arg)==REGISTER) { set_ireg(cadr(arg),0); - g_expr_u(assign_expr0(arg,e4,t,t)); - use_input_reg(cadr(arg),1); - } else - g_expr_u(assign_expr0(arg,e4,t,t)); - } else if (t==LONGLONG||t==ULONGLONG) { - if (reg_arg+1==MAX_INPUT_REGISTER_VAR) { - // half register, half memory case - // put whole long long anyway - arg_assign = list2( - assign_expr0(r0=get_input_register_var(reg_arg,0,0), - arg,INT,INT), - arg_assign); - use_input_reg(cadr(r0),1); - reg_arg_list = list2(r0,reg_arg_list); - } else { - if (car(arg)==LREGISTER) { - use_input_reg(cadr(arg),1); - } - } - reg_arg_list = list2(arg,reg_arg_list); - g_expr_u(assign_expr0(arg,e4,t,t)); - } else if (t==DOUBLE||t==FLOAT) { + g_expr_u(assign_expr0(arg,e4,t,t)); + use_input_reg(cadr(arg),1); + } else + g_expr_u(assign_expr0(arg,e4,t,t)); + } else if (t==LONGLONG||t==ULONGLONG) { + if (reg_arg+1==MAX_INPUT_REGISTER_VAR) { + // half register, half memory case + // put whole long long anyway + arg_assign = list2( + assign_expr0(r0=get_input_register_var(reg_arg,0,0), + arg,INT,INT), + arg_assign); + use_input_reg(cadr(r0),1); + reg_arg_list = list2(r0,reg_arg_list); + } else { + if (car(arg)==LREGISTER) { + use_input_reg(cadr(arg),1); + } + } + reg_arg_list = list2(arg,reg_arg_list); + g_expr_u(assign_expr0(arg,e4,t,t)); + } else if (t==DOUBLE||t==FLOAT) { #ifdef __APPLE__ - if (reg_arg<MAX_INPUT_REGISTER_VAR) { - /* sigh... + if (reg_arg<MAX_INPUT_REGISTER_VAR) { + /* sigh... printf requires floating value in integer registers */ - if (dots) { - int r1; - if (car(e4)==DRLVAR) { - special_lvar = cadr(e4); - e5 = list3n(LVAR,special_lvar,0); - } else { - special_lvar = new_lvar(SIZE_OF_DOUBLE); - g_expr(assign_expr0( - (e5=list3n(LVAR,special_lvar,0)),e4,DOUBLE,t)); - reg_arg_list = list2(e5,reg_arg_list); - e4 = list2(DREGISTER,freg); - /* freg should not change until XXX */ - } - r0=get_input_register_var(reg_arg,0,0); - r1 = reg_arg+1+MIN_TMP_REG; - if (regs[r1]==PTRC_REG) - clear_ptr_cache_reg(list2(REGISTER,r1)); - /* else if (regs[r1]) error(-1); */ - r1=get_input_register_var_1(reg_arg+1,0,0); - use_input_reg(cadr(r0),1); /* protect from input register free */ - use_input_reg(cadr(r1),1); /* protect from input register free */ - reg_arg_list = list2(r0,reg_arg_list); - reg_arg_list = list2(r1,reg_arg_list); - arg_assign = list2( assign_expr0(r0,e5,INT,INT), arg_assign); - arg_assign = list2( assign_expr0(r1, - list3n(LVAR,special_lvar+SIZE_OF_INT,0), - INT,INT), arg_assign); - } - } - if (dots && (freg_arg*8+reg_arg*4)>=32 && freg_arg<MAX_INPUT_DREGISTER_VAR) { - /* + if (dots) { + int r1; + if (car(e4)==DRLVAR) { + special_lvar = cadr(e4); + e5 = list3n(LVAR,special_lvar,0); + } else { + special_lvar = new_lvar(SIZE_OF_DOUBLE); + g_expr(assign_expr0( + (e5=list3n(LVAR,special_lvar,0)),e4,DOUBLE,t)); + reg_arg_list = list2(e5,reg_arg_list); + e4 = list2(DREGISTER,freg); + /* freg should not change until XXX */ + } + r0=get_input_register_var(reg_arg,0,0); + r1 = reg_arg+1+MIN_TMP_REG; + if (regs[r1]==PTRC_REG) + clear_ptr_cache_reg(list2(REGISTER,r1)); + /* else if (regs[r1]) error(-1); */ + r1=get_input_register_var_1(reg_arg+1,0,0); + use_input_reg(cadr(r0),1); /* protect from input register free */ + use_input_reg(cadr(r1),1); /* protect from input register free */ + reg_arg_list = list2(r0,reg_arg_list); + reg_arg_list = list2(r1,reg_arg_list); + arg_assign = list2( assign_expr0(r0,e5,INT,INT), arg_assign); + arg_assign = list2( assign_expr0(r1, + list3n(LVAR,special_lvar+SIZE_OF_INT,0), + INT,INT), arg_assign); + } + } + if (dots && (freg_arg*8+reg_arg*4)>=32 && freg_arg<MAX_INPUT_DREGISTER_VAR) { + /* it requires integer register and floating register and stack value. */ - arg_assign = list2( - assign_expr0(list3n(LVAR,caller_arg_offset_v(nargs),0), - get_input_dregister_var(freg_arg,0,0,1),t,t), - arg_assign); - } -#endif - reg_arg_list = list2(arg,reg_arg_list); - if (car(arg)==DREGISTER) { + arg_assign = list2( + assign_expr0(list3n(LVAR,caller_arg_offset_v(nargs),0), + get_input_dregister_var(freg_arg,0,0,1),t,t), + arg_assign); + } +#endif + reg_arg_list = list2(arg,reg_arg_list); + if (car(arg)==DREGISTER) { set_freg(cadr(arg),0); - g_expr_u(assign_expr0(arg,e4,t,t)); - use_input_reg(cadr(arg),1); - } else - g_expr_u(assign_expr0(arg,e4,t,t)); - } - // structs are finished + g_expr_u(assign_expr0(arg,e4,t,t)); + use_input_reg(cadr(arg),1); + } else + g_expr_u(assign_expr0(arg,e4,t,t)); + } + // structs are finished } if (max_func_args<nargs) max_func_args=nargs; for(;arg_assign;arg_assign=cadr(arg_assign)) { - g_expr_u(car(arg_assign)); + g_expr_u(car(arg_assign)); } clear_ptr_cache(); #ifndef __APPLE__ if (dots) { - if (freg_arg) { - // variadic function has floating value in register - printf("\tcreqv 6,6,6\n"); - } else { - // printf("\tcrxor 6,6,6\n"); // for value in stack - } - } -#endif - if (car(e2) == FNAME) { + if (freg_arg) { + // variadic function has floating value in register + printf("\tcreqv 6,6,6\n"); + } else { + // printf("\tcrxor 6,6,6\n"); // for value in stack + } + } +#endif + if (car(e2) == FNAME) { #ifdef __APPLE__ - printf("\tbl\tL_%s$stub\n",fn->nm); + printf("\tbl\tL_%s$stub\n",fn->nm); #else - printf("\tbl\t%s\n",fn->nm); + printf("\tbl\t%s\n",fn->nm); #endif } else { jrn = register_name(cadr(jmp)); @@ -2804,13 +2804,13 @@ } free_register_var(reg_arg_list); if (ret_type==DOUBLE||ret_type==FLOAT) { - set_freg(RET_FREGISTER,0); + set_freg(RET_FREGISTER,0); } else if (ret_type==ULONGLONG||ret_type==LONGLONG) { - set_lreg(RET_LREGISTER,0); - use_reg(RET_LREGISTER); + set_lreg(RET_LREGISTER,0); + use_reg(RET_LREGISTER); } else if (ret_type==VOID) { } else { - set_ireg(RET_REGISTER,0); + set_ireg(RET_REGISTER,0); } cleanup_lregister0(); return ret_type; @@ -2955,44 +2955,44 @@ char *crn = register_name(creg); #ifdef __APPLE__ if (LARGE_OFFSET(offset)) { - printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); + printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); } #if ENDIAN_L==0 if (creg!=regv_l(reg)) { - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset,crn); - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); } else { - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset,crn); } #else if (creg!=regv_h(reg)) { - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset,crn); - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); } else { - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); - printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,lo16(%d)(%s)\n",lregister_name_high(reg),offset,crn); } #endif #else if (LARGE_OFFSET(offset)) { - printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); + printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); } #if ENDIAN_L==0 if (creg!=regv_l(reg)) { - printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset,crn); - printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); } else { - printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); - printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset,crn); } #else if (creg!=regv_h(reg)) { - printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset,crn); - printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); } else { - printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); - printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); + printf("\tlwz %s,%d@l(%s)\n",lregister_name_high(reg),offset,crn); } #endif @@ -3018,7 +3018,7 @@ code_assign_gvar(int e2,int creg,int byte) { use_int(creg); code_ldf(cstore(byte),register_name(creg),cadr(e2), - get_ptr_cache(ncaddr(e2))); + get_ptr_cache(ncaddr(e2))); } void @@ -3035,7 +3035,7 @@ code_assign_register(int e2,int byte,int creg) { use_int(creg); if (e2!=creg) - printf("\tmr %s,%s\n",register_name(e2),register_name(creg)); + printf("\tmr %s,%s\n",register_name(e2),register_name(creg)); } void @@ -3072,7 +3072,7 @@ emit_pop_free(xreg); xreg = emit_pop(0); /* pop e3 value */ printf("\t%s %s,0(%s)\n",cstore(byte), - register_name(ireg),register_name(xreg)); + register_name(ireg),register_name(xreg)); emit_pop_free(xreg); } @@ -3092,83 +3092,83 @@ use_int(creg); if(oreg==-1) { - error(-1); + error(-1); } else if (oreg<= -REG_LVAR_OFFSET) { - ox = get_register(); if (ox<0) error(-1); + ox = get_register(); if (ox<0) error(-1); code_rlvar(oreg+REG_LVAR_OFFSET,ox); free_lvar(oreg+REG_LVAR_OFFSET); - oreg = ox; + oreg = ox; } switch(op) { case LSHIFT: case ULSHIFT: - shift("slw",creg,oreg); - if(ox!=-1) free_register(ox); - return; + shift("slw",creg,oreg); + if(ox!=-1) free_register(ox); + return; case RSHIFT: - shift("sraw",creg,oreg); - if(ox!=-1) free_register(ox); - return; + shift("sraw",creg,oreg); + if(ox!=-1) free_register(ox); + return; case URSHIFT: - shift("srw",creg,oreg); - if(ox!=-1) free_register(ox); - return; + shift("srw",creg,oreg); + if(ox!=-1) free_register(ox); + return; } orn = register_name(oreg); crn = register_name(creg); switch(op) { case ADD: - printf("\tadd %s,%s,%s\n",crn,crn,orn); - break; + printf("\tadd %s,%s,%s\n",crn,crn,orn); + break; case SUB: - printf("\tsub %s,%s,%s\n",crn,crn,orn); - break; + printf("\tsub %s,%s,%s\n",crn,crn,orn); + break; case CMP: - inc_cmpflag(); - printf("\tcmpw %s,%s,%s\n",crname(cmpflag),crn,orn); - break; + inc_cmpflag(); + printf("\tcmpw %s,%s,%s\n",crname(cmpflag),crn,orn); + break; case UCMP: - inc_cmpflag(); - printf("\tcmplw %s,%s,%s\n",crname(cmpflag),crn,orn); - break; + inc_cmpflag(); + printf("\tcmplw %s,%s,%s\n",crname(cmpflag),crn,orn); + break; case BAND: - printf("\tand %s,%s,%s\n",crn,crn,orn); - break; + printf("\tand %s,%s,%s\n",crn,crn,orn); + break; case EOR: - printf("\txor %s,%s,%s\n",crn,crn,orn); - break; + printf("\txor %s,%s,%s\n",crn,crn,orn); + break; case BOR: - printf("\tor %s,%s,%s\n",crn,crn,orn); - break; + printf("\tor %s,%s,%s\n",crn,crn,orn); + break; case MUL: - printf("\tmullw %s,%s,%s\n",crn,crn,orn); - break; + printf("\tmullw %s,%s,%s\n",crn,crn,orn); + break; case UMUL: - printf("\tmullw %s,%s,%s\n",crn,crn,orn); - break; + printf("\tmullw %s,%s,%s\n",crn,crn,orn); + break; case DIV: - printf("\tdivw %s,%s,%s\n",crn,crn,orn); - break; + printf("\tdivw %s,%s,%s\n",crn,crn,orn); + break; case UDIV: - printf("\tdivwu %s,%s,%s\n",crn,crn,orn); - break; + printf("\tdivwu %s,%s,%s\n",crn,crn,orn); + break; case MOD: - dx=get_register(); - drn = register_name(dx); - printf("\tdivw %s,%s,%s\n",drn,crn,orn); - printf("\tmullw %s,%s,%s\n",drn,drn,orn); - printf("\tsubf %s,%s,%s\n",crn,drn,crn); - break; + dx=get_register(); + drn = register_name(dx); + printf("\tdivw %s,%s,%s\n",drn,crn,orn); + printf("\tmullw %s,%s,%s\n",drn,drn,orn); + printf("\tsubf %s,%s,%s\n",crn,drn,crn); + break; case UMOD: - dx=get_register(); - drn = register_name(dx); - printf("\tdivwu %s,%s,%s\n",drn,crn,orn); - printf("\tmullw %s,%s,%s\n",drn,drn,orn); - printf("\tsubf %s,%s,%s\n",crn,drn,crn); - break; + dx=get_register(); + drn = register_name(dx); + printf("\tdivwu %s,%s,%s\n",drn,crn,orn); + printf("\tmullw %s,%s,%s\n",drn,drn,orn); + printf("\tsubf %s,%s,%s\n",crn,drn,crn); + break; default: - error(-1); + error(-1); } if(dx!=-1) free_register(dx); if(ox!=-1) free_register(ox); @@ -3196,75 +3196,75 @@ switch(op) { case LSHIFT: case ULSHIFT: - printf("\tslwi %s,%s,%d\n",crn,crn,v); - return; + printf("\tslwi %s,%s,%d\n",crn,crn,v); + return; case DIV: - v = ilog(v); + v = ilog(v); case RSHIFT: - printf("\tsrawi %s,%s,%d\n",crn,crn,v); - return; + printf("\tsrawi %s,%s,%d\n",crn,crn,v); + return; case UDIV: - v = ilog(v); + v = ilog(v); case URSHIFT: - printf("\tsrwi %s,%s,%d\n",crn,crn,v); - return; + printf("\tsrwi %s,%s,%d\n",crn,crn,v); + return; case ADD: #ifdef __APPLE__ - printf("\taddi %s,%s,lo16(%d)\n",crn,crn,v); + printf("\taddi %s,%s,lo16(%d)\n",crn,crn,v); #else - printf("\taddi %s,%s,%d@l\n",crn,crn,v); -#endif - break; + printf("\taddi %s,%s,%d@l\n",crn,crn,v); +#endif + break; case SUB: #ifdef __APPLE__ - printf("\taddi %s,%s,lo16(-%d)\n",crn,crn,v); + printf("\taddi %s,%s,lo16(-%d)\n",crn,crn,v); #else - printf("\taddi %s,%s,-%d@l\n",crn,crn,v); -#endif - break; + printf("\taddi %s,%s,-%d@l\n",crn,crn,v); +#endif + break; case CMP: - inc_cmpflag(); + inc_cmpflag(); #ifdef __APPLE__ - printf("\tcmpwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); + printf("\tcmpwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); #else - printf("\tcmpwi %s,%s,%d@l\n",crname(cmpflag),crn,v); -#endif - break; + printf("\tcmpwi %s,%s,%d@l\n",crname(cmpflag),crn,v); +#endif + break; case UCMP: - inc_cmpflag(); + inc_cmpflag(); #ifdef __APPLE__ - printf("\tcmplwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); + printf("\tcmplwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); #else - printf("\tcmplwi %s,%s,%d@l\n",crname(cmpflag),crn,v); -#endif - break; + printf("\tcmplwi %s,%s,%d@l\n",crname(cmpflag),crn,v); +#endif + break; case EOR: #ifdef __APPLE__ - printf("\txori %s,%s,lo16(%d)\n",crn,crn,v); + printf("\txori %s,%s,lo16(%d)\n",crn,crn,v); #else - printf("\txori %s,%s,%d@l\n",crn,crn,v); -#endif - break; + printf("\txori %s,%s,%d@l\n",crn,crn,v); +#endif + break; case BOR: #ifdef __APPLE__ - printf("\tori %s,%s,lo16(%d)\n",crn,crn,v); + printf("\tori %s,%s,lo16(%d)\n",crn,crn,v); #else - printf("\tori %s,%s,%d@l\n",crn,crn,v); -#endif - break; + printf("\tori %s,%s,%d@l\n",crn,crn,v); +#endif + break; case MUL: case UMUL: - if ((l=ilog(v))) { - printf("\tslwi %s,%s,%d\n",crn,crn,l); - } else + if ((l=ilog(v))) { + printf("\tslwi %s,%s,%d\n",crn,crn,l); + } else #ifdef __APPLE__ - printf("\tmulli %s,%s,lo16(%d)\n",crn,crn,v); + printf("\tmulli %s,%s,lo16(%d)\n",crn,crn,v); #else - printf("\tmulli %s,%s,%d@l\n",crn,crn,v); -#endif - break; + printf("\tmulli %s,%s,%d@l\n",crn,crn,v); +#endif + break; default: - error(-1); + error(-1); } } @@ -3280,12 +3280,12 @@ void ld_indexx(int byte, int n, int xreg,int creg, int sign) -{ +{ char *crn; use_int(creg); crn = register_name(creg); printf("\t%s %s,%d(%s)\n",cload(byte),register_name(creg),n, - register_name(xreg)); + register_name(xreg)); cext(sign,byte,creg); } @@ -3302,16 +3302,16 @@ /* used in dosiwtch() */ inc_cmpflag(); if (-32767<e&&e<32767) { - printf("\tcmpwi %s,%s,%d\n",crname(cmpflag),register_name(csreg),e); - jcond(label,cond); + printf("\tcmpwi %s,%s,%d\n",crname(cmpflag),register_name(csreg),e); + jcond(label,cond); } else { - regsv = regs[csreg]; regs[csreg]=USING_REG; - reg = get_register(); - regs[csreg]= regsv; - code_const(e,reg); - printf("\tcmpw %s,%s,%s\n",crname(cmpflag),register_name(csreg),register_name(reg)); - jcond(label,cond); - free_register(reg); + regsv = regs[csreg]; regs[csreg]=USING_REG; + reg = get_register(); + regs[csreg]= regsv; + code_const(e,reg); + printf("\tcmpw %s,%s,%s\n",crname(cmpflag),register_name(csreg),register_name(reg)); + jcond(label,cond); + free_register(reg); } } @@ -3386,11 +3386,11 @@ rn = register_name(reg); t = CRBITSIZ*cmpflag; if (eq>0) { - printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); + printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); } if (neg>0) { - neg = t+neg-1, - printf("\tcrnor %d,%d,%d\n",neg,neg,neg); + neg = t+neg-1, + printf("\tcrnor %d,%d,%d\n",neg,neg,neg); } printf("\tmfcr %s\n",rn); printf("\trlwinm %s,%s,%d,1\n",rn,rn,t+flag); @@ -3433,9 +3433,9 @@ jcond(int l, char cond) { if (cond==LT) { - printf("\tb%s %s,%s%d\n",code_ge(0),crname(cmpflag),lpfx,l); + printf("\tb%s %s,%s%d\n",code_ge(0),crname(cmpflag),lpfx,l); } else if (cond==1||cond==0) { - printf("\tb%s %s,%s%d\n",cond?"ne":"eq",crname(cmpflag),lpfx,l); + printf("\tb%s %s,%s%d\n",cond?"ne":"eq",crname(cmpflag),lpfx,l); } else error(-1); } @@ -3456,11 +3456,11 @@ { #ifdef __APPLE__ if (output_mode!=TEXT_EMIT_MODE) - text_mode(0); + text_mode(0); else - printf("\t.align 2\n"); + printf("\t.align 2\n"); if (stmode!=STATIC) - printf(".globl _%s\n",name); + printf(".globl _%s\n",name); #ifdef DOT_SIZE printf("\t.type\t%s,@function\n",name); #endif @@ -3479,11 +3479,11 @@ clear_ptr_cache(); #else if (output_mode!=TEXT_EMIT_MODE) - text_mode(0); + text_mode(0); else - printf("\t.align 2\n"); + printf("\t.align 2\n"); if (stmode!=STATIC) - printf(".globl %s\n",name); + printf(".globl %s\n",name); #ifdef DOT_SIZE printf("\t.type\t%s,@function\n",name); #endif @@ -3518,14 +3518,14 @@ #ifdef __APPLE__ printf(".set L_%d,%d\n",code_disp_label,-r1_offsetv); if (max_func_arg_label) { - printf(".set L_%d,%d\n",max_func_arg_label,max_func_args*SIZE_OF_INT+24); - max_func_arg_label = 0; + printf(".set L_%d,%d\n",max_func_arg_label,max_func_args*SIZE_OF_INT+24); + max_func_arg_label = 0; } #else printf(".set .LC%d,%d\n",code_disp_label,-r1_offsetv); if (max_func_arg_label) { - printf(".set .LC%d,%d\n",max_func_arg_label,max_func_args*SIZE_OF_INT+24); - max_func_arg_label = 0; + printf(".set .LC%d,%d\n",max_func_arg_label,max_func_args*SIZE_OF_INT+24); + max_func_arg_label = 0; } #endif local_table(); @@ -3537,11 +3537,11 @@ { #ifdef __APPLE__ if (output_mode!=TEXT_EMIT_MODE) - text_mode(0); + text_mode(0); else - printf("\t.align 2\n"); + printf("\t.align 2\n"); if (stmode!=STATIC) - printf(".globl %s%s\n",npfx,name); + printf(".globl %s%s\n",npfx,name); /* printf("\t.type\t%s,@function\n",name); */ @@ -3566,11 +3566,11 @@ printf("\tmflr r31\n"); #else if (output_mode!=TEXT_EMIT_MODE) - text_mode(0); + text_mode(0); else - printf("\t.align 2\n"); + printf("\t.align 2\n"); if (stmode!=STATIC) - printf(".globl %s%s\n",npfx,name); + printf(".globl %s%s\n",npfx,name); /* printf("\t.type\t%s,@function\n",name); */ @@ -3607,25 +3607,25 @@ reg_save_offset() { return -( - (REAL_MAX_REGISTER-(REG_VAR_BASE-max_reg_var))*SIZE_OF_INT+ - (REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*SIZE_OF_DOUBLE - ); + (REAL_MAX_REGISTER-(REG_VAR_BASE-max_reg_var))*SIZE_OF_INT+ + (REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*SIZE_OF_DOUBLE + ); } void code_label_call(int l) { #ifdef __APPLE__ - printf("\tbl\tL_%d\n",l); + printf("\tbl\tL_%d\n",l); #else - printf("\tbl\t.LC%d\n",l); + printf("\tbl\t.LC%d\n",l); #endif } void code_ret() { - printf("\tblr\n"); + printf("\tblr\n"); } #ifndef __APPLE__ @@ -3681,34 +3681,34 @@ make_return_continuation() { #if R1SAVE - retcont1 = fwdlabel(); -#endif - fwddef(retcont); - if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { - printf("\tfmr %s,%s\n",fregister_name(1),fregister_name(31)); - printf("\tmr %s,%s\n",register_name(30),register_name(28)); - } else if (cadr(fnptr->ty)>0&&( - car(cadr(fnptr->ty))==STRUCT || - car(cadr(fnptr->ty))==UNION)) { - int sz = size(cadr(fnptr->ty)); + retcont1 = fwdlabel(); +#endif + fwddef(retcont); + if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { + printf("\tfmr %s,%s\n",fregister_name(1),fregister_name(31)); + printf("\tmr %s,%s\n",register_name(30),register_name(28)); + } else if (cadr(fnptr->ty)>0&&( + car(cadr(fnptr->ty))==STRUCT || + car(cadr(fnptr->ty))==UNION)) { + int sz = size(cadr(fnptr->ty)); #ifdef __APPLE__ - printf("\tli r7,%d\n",sz); - printf("\tsubl r6,r7,r30\n"); - printf("\tlwz r3,lo16(%d)(r30)\n",(my_func_args-1)*SIZE_OF_INT); - // emit_copy(6,3,sz,0,1,1); + printf("\tli r7,%d\n",sz); + printf("\tsubl r6,r7,r30\n"); + printf("\tlwz r3,lo16(%d)(r30)\n",(my_func_args-1)*SIZE_OF_INT); + // emit_copy(6,3,sz,0,1,1); #else - printf("\tli 7,%d\n",sz); - printf("\tsubl 6,7,%d\n",REG_fp); - printf("\tlwz 3,%d@l(%d)\n",(my_func_args-1)*SIZE_OF_INT,REG_fp); - // emit_copy(6,3,sz,0,1,1); -#endif - printf("\tmr %s,%s\n",register_name(30),register_name(28)); - } else if (cadr(fnptr->ty)!=VOID) { - printf("\tmr %s,%s\n",register_name(3),register_name(29)); - printf("\tmr %s,%s\n",register_name(30),register_name(28)); - } + printf("\tli 7,%d\n",sz); + printf("\tsubl 6,7,%d\n",REG_fp); + printf("\tlwz 3,%d@l(%d)\n",(my_func_args-1)*SIZE_OF_INT,REG_fp); + // emit_copy(6,3,sz,0,1,1); +#endif + printf("\tmr %s,%s\n",register_name(30),register_name(28)); + } else if (cadr(fnptr->ty)!=VOID) { + printf("\tmr %s,%s\n",register_name(3),register_name(29)); + printf("\tmr %s,%s\n",register_name(30),register_name(28)); + } #if R1SAVE - jmp(retcont1); + jmp(retcont1); #else #endif } @@ -3725,17 +3725,17 @@ reg_save = reg_save_offset(); if (control) { - code_set_return_register(1); + code_set_return_register(1); } if (retcont) { - if (control) jmp(retlabel); - make_return_continuation(); + if (control) jmp(retlabel); + make_return_continuation(); } fwddef(retlabel); #if R1SAVE printf("\tlwz %s,0(%s)\n",register_name(1),register_name(1)); if (retcont) { - fwddef(retcont1); + fwddef(retcont1); } #else #ifdef __APPLE__ @@ -3746,60 +3746,60 @@ #endif if (max_freg_var>=0) { #ifdef __APPLE__ - printf("\tlmw r%d,%d(%s)\n", - REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); - freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; - printf("\tb restFP+%d ; restore f%d-f31\n", - freg_save, - FREG_VAR_BASE-max_freg_var); + printf("\tlmw r%d,%d(%s)\n", + REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); + freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; + printf("\tb restFP+%d ; restore f%d-f31\n", + freg_save, + FREG_VAR_BASE-max_freg_var); #else - printf("\tlmw %d,%d(%s)\n", - REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); - freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; - printf("\tb .restFP+%d # restore f%d-f31\n", - freg_save, - FREG_VAR_BASE-max_freg_var); + printf("\tlmw %d,%d(%s)\n", + REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); + freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; + printf("\tb .restFP+%d # restore f%d-f31\n", + freg_save, + FREG_VAR_BASE-max_freg_var); #endif } else { #ifdef __APPLE__ - printf("\tlwz r0,8(r1)\n"); - printf("\tmtlr r0\n"); - printf("\tlmw r%d,%d(r1)\n", - REG_VAR_BASE-max_reg_var,reg_save); + printf("\tlwz r0,8(r1)\n"); + printf("\tmtlr r0\n"); + printf("\tlmw r%d,%d(r1)\n", + REG_VAR_BASE-max_reg_var,reg_save); #else - printf("\tlmw %d,%d(1)\n", - REG_VAR_BASE-max_reg_var,reg_save); - printf("\tlwz %s,4(1)\n",register_name(0)); - printf("\tlwz 1,0(1)\n"); - printf("\tmtlr %s\n",register_name(0)); -#endif - code_ret(); + printf("\tlmw %d,%d(1)\n", + REG_VAR_BASE-max_reg_var,reg_save); + printf("\tlwz %s,4(1)\n",register_name(0)); + printf("\tlwz 1,0(1)\n"); + printf("\tmtlr %s\n",register_name(0)); +#endif + code_ret(); } disp &= -SIZE_OF_INT; fwddef(code_setup); #ifdef __APPLE__ printf("\tstmw %s,%d(%s)\n", - register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); + register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); printf("\tstw %s,8(%s)\n",register_name(0),register_name(1)); #else printf("\tstmw %s,%d(%s)\n", - register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); + register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); printf("\tstw %s,4(%s)\n",register_name(0),register_name(1)); #endif if (max_freg_var>=0) { #ifdef __APPLE__ - printf("\tb saveFP+%d ; save f%d-f31\n", - freg_save, - FREG_VAR_BASE-max_freg_var); + printf("\tb saveFP+%d ; save f%d-f31\n", + freg_save, + FREG_VAR_BASE-max_freg_var); #else - saveFP_used = 1; - printf("\tb .saveFP+%d # save f%d-f31\n", - freg_save, - FREG_VAR_BASE-max_freg_var); + saveFP_used = 1; + printf("\tb .saveFP+%d # save f%d-f31\n", + freg_save, + FREG_VAR_BASE-max_freg_var); #endif } else { - printf("\tblr\n"); + printf("\tblr\n"); } code_offset_set(); @@ -3812,16 +3812,16 @@ int code_set_return_register(int mode) { if (cadr(fnptr->ty)==DOUBLE||cadr(fnptr->ty)==FLOAT) { - set_freg(RET_FREGISTER,mode); - return freg; + set_freg(RET_FREGISTER,mode); + return freg; } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) { - set_lreg(RET_LREGISTER,mode); - return lreg; + set_lreg(RET_LREGISTER,mode); + return lreg; } else if (cadr(fnptr->ty)==VOID) { - return 0; + return 0; } else { - set_ireg(RET_REGISTER,mode); - return ireg; + set_ireg(RET_REGISTER,mode); + return ireg; } } @@ -3833,12 +3833,12 @@ void code_set_fixed_creg(int reg,int mode,int type) { if (type==FLOAT||type==DOUBLE) { - set_freg(reg,mode); + set_freg(reg,mode); } else if (type==LONGLONG||type==ULONGLONG) { - set_lreg(reg,mode); - // use_reg(reg); + set_lreg(reg,mode); + // use_reg(reg); } else { - set_ireg(reg,mode); + set_ireg(reg,mode); } } @@ -3847,7 +3847,7 @@ { /* if (stmode!=STATIC) - printf(".globl _%s\n",n); + printf(".globl _%s\n",n); */ } @@ -3861,17 +3861,17 @@ printf("\t.string \""); #endif while(*s) { - if (*s=='\n') - printf("%cn",92); - else if (*s<' ') - printf("%c%03o",92,*s); - else if (*s=='\\') - printf("\\\\"); - else if (*s==34) - printf("%c%c",92,34); - else - printf("%c",*s); - s++; + if (*s=='\n') + printf("%cn",92); + else if (*s<' ') + printf("%c%03o",92,*s); + else if (*s=='\\') + printf("\\\\"); + else if (*s==34) + printf("%c%c",92,34); + else + printf("%c",*s); + s++; } printf("\\0%c\n\t.align 2\n",34); } @@ -3921,12 +3921,12 @@ { int t = type_value(n->ty); if (e>0 && car(e)==STRING && t>0 && car(t)==ARRAY && - (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) { - cstring_mode(); + (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) { + cstring_mode(); } else - data_mode(n->nm); + data_mode(n->nm); if (n && n->sc!=STATIC) - printf("\t.globl\t%s%s\n",npfx,n->nm); + printf("\t.globl\t%s%s\n",npfx,n->nm); printf("%s%s:\n",npfx,n->nm); } @@ -4001,9 +4001,9 @@ { data_mode(0); if (offset) - printf("\t.long %s%s+%d\n",npfx,s,offset); + printf("\t.long %s%s+%d\n",npfx,s,offset); else - printf("\t.long %s%s\n",npfx,s); + printf("\t.long %s%s\n",npfx,s); } extern void @@ -4022,15 +4022,15 @@ if (mode==GDECL) { #ifdef DOT_SIZE #ifdef __APPLE__ - data_mode(0); - lb=fwdlabel(); - printf("%s%d:\n",lpfx,lb); - printf("\t.size\t%s,%s%d-%%ss\n",n->nm,lb,lpfx,npfx,n->nm); + data_mode(0); + lb=fwdlabel(); + printf("%s%d:\n",lpfx,lb); + printf("\t.size\t%s,%s%d-%%ss\n",n->nm,lb,lpfx,npfx,n->nm); #else - data_mode(0); - lb=fwdlabel(); - printf(".LC%d:\n",lb); - printf("\t.size\t%s,%s%d-%s%s\n",n->nm,lb,lpfx,npfx,n->nm); + data_mode(0); + lb=fwdlabel(); + printf(".LC%d:\n",lb); + printf("\t.size\t%s,%s%d-%s%s\n",n->nm,lb,lpfx,npfx,n->nm); #endif #endif } @@ -4046,39 +4046,39 @@ global_list = reversen(global_list); text_mode(0); for(n = global_list;n!=&null_nptr;n = n->next) { - if ((n->sc == GVAR) && n->dsp != -1) { - /* n->dsp = -1 means initialized global */ - if (init==0) { - // data_mode(0); - text_mode(0); - printf("\t.align 3\n"); - init=1; - } - int align; - if ((align=attr_value(n,ALIGNED))) { - int a = ilog(caddr(align)); - printf(".comm %s%s,%d,%d\n",npfx,n->nm,size(n->ty),a); - } else if (size(n->ty)>1) { - printf(".comm %s%s,%d,2\n",npfx,n->nm,size(n->ty)); - } else - printf(".comm %s%s,%d\n",npfx,n->nm,size(n->ty)); - } else if ((n->sc==STATIC) && n->dsp != -1) { - /* n->dsp = -1 means initialized global */ - if (is_code(n)||is_function(n)) continue; - if (init==0) { - text_mode(0); - printf("\t.align 8\n"); - // data_mode(0); - init=1; - } - printf(".lcomm %s%s,%d\n",npfx,n->nm,size(n->ty)); - } + if ((n->sc == GVAR) && n->dsp != -1) { + /* n->dsp = -1 means initialized global */ + if (init==0) { + // data_mode(0); + text_mode(0); + printf("\t.align 3\n"); + init=1; + } + int align; + if ((align=attr_value(n,ALIGNED))) { + int a = ilog(caddr(align)); + printf(".comm %s%s,%d,%d\n",npfx,n->nm,size(n->ty),a); + } else if (size(n->ty)>1) { + printf(".comm %s%s,%d,2\n",npfx,n->nm,size(n->ty)); + } else + printf(".comm %s%s,%d\n",npfx,n->nm,size(n->ty)); + } else if ((n->sc==STATIC) && n->dsp != -1) { + /* n->dsp = -1 means initialized global */ + if (is_code(n)||is_function(n)) continue; + if (init==0) { + text_mode(0); + printf("\t.align 8\n"); + // data_mode(0); + init=1; + } + printf(".lcomm %s%s,%d\n",npfx,n->nm,size(n->ty)); + } } for(n = global_list;n!=&null_nptr;n = n->next) { - if (is_code(n)||is_function(n)) { - extrn = n->nm; - if (n->sc==EXTRN1) { - data_mode(0); + if (is_code(n)||is_function(n)) { + extrn = n->nm; + if (n->sc==EXTRN1) { + data_mode(0); printf(".picsymbol_stub\n"); printf("L_%s$stub:\n",extrn); printf("\t.indirect_symbol _%s\n",extrn); @@ -4097,39 +4097,39 @@ printf("L_%s$lazy_ptr:\n",extrn); printf("\t.indirect_symbol _%s\n",extrn); printf("\t.long dyld_stub_binding_helper\n"); - } else if (n->sc==STATIC) { - text_mode(0); + } else if (n->sc==STATIC) { + text_mode(0); printf("\t.set L_%s$stub,_%s\n",extrn,extrn); - data_mode(0); + data_mode(0); printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",extrn,extrn); - } - } + } + } } init=0; for(n = global_list;n!=&null_nptr;n = n->next) { - if (n->sc == GVAR) { - if (init==0) { - printf(".data\n"); - init=1; - } + if (n->sc == GVAR) { + if (init==0) { + printf(".data\n"); + init=1; + } printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm); - } + } } init = 0; for(n = global_list;n!=&null_nptr;n = n->next) { - if ((is_code(n)||is_function(n))&& - !has_attr(n,FNAME)) // not used as value - continue; - if (n->sc==EXTRN1) { - if(init==0) { - printf(".data\n"); + if ((is_code(n)||is_function(n))&& + !has_attr(n,FNAME)) // not used as value + continue; + if (n->sc==EXTRN1) { + if(init==0) { + printf(".data\n"); printf(".non_lazy_symbol_pointer\n"); - init=1; - } + init=1; + } printf("L_%s$non_lazy_ptr:\n",n->nm); printf("\t.indirect_symbol _%s\n",n->nm); printf("\t.long\t0\n"); - } + } } } #else @@ -4139,25 +4139,25 @@ { int align = 1; if ((align=attr_value(n,ALIGNED))) { - align = ilog(caddr(align)); + align = ilog(caddr(align)); } else { - if (size(n->ty)>4) - align = 2; - else if (size(n->ty)>4) - align = 0; - switch(n->ty) { - case DOUBLE: - case LONGLONG: - case ULONGLONG: - align = 8; break; - case INT: - case UNSIGNED: - case FLOAT: - align = 4; break; - case SHORT: - case USHORT: - align = 2; break; - } + if (size(n->ty)>4) + align = 2; + else if (size(n->ty)>4) + align = 0; + switch(n->ty) { + case DOUBLE: + case LONGLONG: + case ULONGLONG: + align = 8; break; + case INT: + case UNSIGNED: + case FLOAT: + align = 4; break; + case SHORT: + case USHORT: + align = 2; break; + } } printf("\t.comm %s,%d,%d\n",n->nm,size(n->ty),align); } @@ -4200,15 +4200,15 @@ init=0; /* static local variables */ for(n = local_static_list;n!=&null_nptr;n = n->next) { - if (n->sc == STATIC) { - if (init==0) { - data_mode(0); - init=1; - } - if (n->dsp != -1) /* initialized static */ - printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); - printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm); - } + if (n->sc == STATIC) { + if (init==0) { + data_mode(0); + init=1; + } + if (n->dsp != -1) /* initialized static */ + printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); + printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm); + } } } #else @@ -4220,14 +4220,14 @@ init=0; /* static local variables */ for(n = local_static_list;n!=&null_nptr;n = n->next) { - if (n->sc == STATIC) { - if (init==0) { - data_mode(0); - init=1; - } - if (n->dsp != -1) /* initialized static */ - printf(".lcomm %s,%d\n",n->nm,size(n->ty)); - } + if (n->sc == STATIC) { + if (init==0) { + data_mode(0); + init=1; + } + if (n->dsp != -1) /* initialized static */ + printf(".lcomm %s,%d\n",n->nm,size(n->ty)); + } } } #endif @@ -4249,9 +4249,9 @@ text_mode(int align) { if (output_mode!=TEXT_EMIT_MODE) { - printf(".text\n"); - printf("\t.align 2\n"); - output_mode = TEXT_EMIT_MODE; + printf(".text\n"); + printf("\t.align 2\n"); + output_mode = TEXT_EMIT_MODE; } } @@ -4259,12 +4259,12 @@ data_mode(char *name) { if (output_mode!=DATA_EMIT_MODE) { - printf(".data\n"); - output_mode = DATA_EMIT_MODE; + printf(".data\n"); + output_mode = DATA_EMIT_MODE; } /* if (name) - printf("\t.type\t%s,@object\n",name); + printf("\t.type\t%s,@object\n",name); */ } @@ -4330,8 +4330,8 @@ { use_float(d,freg); if (freg!=e2) { - if (is_int_reg(e2)) error(-1); - printf("\tfmr %s,%s\n",fregister_name(freg),fregister_name(e2)); + if (is_int_reg(e2)) error(-1); + printf("\tfmr %s,%s\n",fregister_name(freg),fregister_name(e2)); } } @@ -4340,7 +4340,7 @@ { use_float(d,freg); code_ldf(fstore(d),fregister_name(freg),cadr(e2), - get_ptr_cache(ncaddr(e2))); + get_ptr_cache(ncaddr(e2))); } void @@ -4363,7 +4363,7 @@ code_dassign_dregister(int e2,int d,int freg) { use_float(d,freg); if (e2!=freg) { - printf("\tfmr %s,%s\n",fregister_name(e2),fregister_name(freg)); + printf("\tfmr %s,%s\n",fregister_name(e2),fregister_name(freg)); } } @@ -4398,17 +4398,17 @@ printf("%s%d:\n",lpfx,lb); if (d) { #if ENDIAN_D==0 - printf("\t.long\t0x%x,0x%x\n",code_d1(value->d),code_d2(value->d)); + printf("\t.long\t0x%x,0x%x\n",code_d1(value->d),code_d2(value->d)); #else - printf("\t.long\t0x%x,0x%x\n",code_d2(value->d),code_d1(value->d)); + printf("\t.long\t0x%x,0x%x\n",code_d2(value->d),code_d1(value->d)); #endif } else { - printf("\t.long\t0x%x\n",code_f(value->f)); + printf("\t.long\t0x%x\n",code_f(value->f)); } if (output_mode==TEXT_EMIT_MODE) { - printf(".text\n"); + printf(".text\n"); } else { - text_mode(0); + text_mode(0); } } @@ -4427,18 +4427,18 @@ use_float(d,freg); frn = fregister_name(freg); if (value.d==0.0) { - float_zero_lib_used=1; - r = get_ptr_cache(&float_zero); - rrn = register_name(r); - printf("\tlfs %s,0(%s)\n",frn,rrn); - return; + float_zero_lib_used=1; + r = get_ptr_cache(&float_zero); + rrn = register_name(r); + printf("\tlfs %s,0(%s)\n",frn,rrn); + return; } if (value.d==1.0) { - float_one_lib_used=1; - r = get_ptr_cache(&float_one); - rrn = register_name(r); - printf("\tlfs %s,0(%s)\n",frn,rrn); - return; + float_one_lib_used=1; + r = get_ptr_cache(&float_one); + rrn = register_name(r); + printf("\tlfs %s,0(%s)\n",frn,rrn); + return; } if (d) { sz = sizeof(double); @@ -4454,9 +4454,9 @@ // use_reg(r); // to clear ptr cache code_label_value(lb,r); if (d) { - printf("\tlfd %s,0(%s)\n",frn,rrn); + printf("\tlfd %s,0(%s)\n",frn,rrn); } else { - printf("\tlfs %s,0(%s)\n",frn,rrn); + printf("\tlfs %s,0(%s)\n",frn,rrn); } free_register(r); } @@ -4498,23 +4498,23 @@ printf("L_%d:\n",lb); if (d) { #if ENDIAN_D==0 - printf("\t.long\t0x%x,0x%x\n",0,0x7ff00000); + printf("\t.long\t0x%x,0x%x\n",0,0x7ff00000); #else - printf("\t.long\t0x%x,0x%x\n",0x7ff00000,0); + printf("\t.long\t0x%x,0x%x\n",0x7ff00000,0); #endif } else { - printf("\t.long\t0x%x\n",0x7f800000); + printf("\t.long\t0x%x\n",0x7f800000); } if (output_mode==TEXT_EMIT_MODE) { - printf(".text\n"); + printf(".text\n"); } else { - text_mode(0); + text_mode(0); } code_label_value(lb,r); if (d) { - printf("\tlfd %s,0(%s)\n",frn,rrn); + printf("\tlfd %s,0(%s)\n",frn,rrn); } else { - printf("\tlfs %s,0(%s)\n",frn,rrn); + printf("\tlfs %s,0(%s)\n",frn,rrn); } free_register(r); } @@ -4787,7 +4787,7 @@ { use_float(d,freg); code_ldf(fload(d),fregister_name(freg),cadr(e2), - get_ptr_cache(ncaddr(e2))); + get_ptr_cache(ncaddr(e2))); } @@ -4810,7 +4810,7 @@ frn=fregister_name(reg); code_ldf(fload(1),grn,cadr(e2), - get_ptr_cache(ncaddr(e2))); + get_ptr_cache(ncaddr(e2))); inc_cmpflag(); printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); free_register(g); @@ -4865,18 +4865,18 @@ case DMUL: opn="fmul"; break; case FCMP: case DCMP: - inc_cmpflag(); - printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); - if (ox!=-1) free_register(ox); - return; + inc_cmpflag(); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); + if (ox!=-1) free_register(ox); + return; case FCMPGE: case DCMPGE: - inc_cmpflag(); - printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); - if (ox!=-1) free_register(ox); - return; + inc_cmpflag(); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); + if (ox!=-1) free_register(ox); + return; default: - error(-1); return; + error(-1); return; } printf("\t%s %s,%s,%s\n",opn,frn,frn,grn); if (ox!=-1) free_register(ox); @@ -4928,29 +4928,29 @@ int g; if (car(e2)==DREGISTER||car(e2)==FREGISTER) { - crn=register_name(cadr(e2)); + crn=register_name(cadr(e2)); grn = fregister_name(g = code_dload_1(d)); - if (reg==USE_CREG) { - reg=get_dregister(d); if (!reg) error(-1); - set_freg(reg,0); - } - frn=fregister_name(reg); - printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",crn,crn,grn); - if (use && reg!=cadr(e2)) - printf("\tfmr %s,%s\n",frn,crn); + if (reg==USE_CREG) { + reg=get_dregister(d); if (!reg) error(-1); + set_freg(reg,0); + } + frn=fregister_name(reg); + printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",crn,crn,grn); + if (use && reg!=cadr(e2)) + printf("\tfmr %s,%s\n",frn,crn); } else { - g_expr(e2); - if (!is_int_reg(creg)) error(-1); - crn=register_name(ireg); - if (reg==USE_CREG) { - reg=get_dregister(d); if (!reg) error(-1); - set_freg(reg,0); - } - frn=fregister_name(reg); + g_expr(e2); + if (!is_int_reg(creg)) error(-1); + crn=register_name(ireg); + if (reg==USE_CREG) { + reg=get_dregister(d); if (!reg) error(-1); + set_freg(reg,0); + } + frn=fregister_name(reg); grn = fregister_name(g = code_dload_1(d)); - printf("\t%s %s,0(%s)\n",fload(d),frn,crn); - printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",frn,frn,grn); - printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); + printf("\t%s %s,0(%s)\n",fload(d),frn,crn); + printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",frn,frn,grn); + printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); } free_register(g); } @@ -4961,29 +4961,29 @@ int g; if (car(e2)==DREGISTER||car(e2)==FREGISTER) { - crn=register_name(cadr(e2)); + crn=register_name(cadr(e2)); grn = fregister_name(g = code_dload_1(d)); - if (reg==USE_CREG) { - reg=get_dregister(d); if (!reg) error(-1); - set_freg(reg,0); - } - frn=fregister_name(reg); - if (use && reg!=cadr(e2)) - printf("\tfmr %s,%s\n",frn,crn); - printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",crn,crn,grn); + if (reg==USE_CREG) { + reg=get_dregister(d); if (!reg) error(-1); + set_freg(reg,0); + } + frn=fregister_name(reg); + if (use && reg!=cadr(e2)) + printf("\tfmr %s,%s\n",frn,crn); + printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",crn,crn,grn); } else { - g_expr(e2); - if (!is_int_reg(creg)) error(-1); - crn=register_name(ireg); - if (reg==USE_CREG) { - reg=get_dregister(d); if (!reg) error(-1); - set_freg(reg,0); - } - frn=fregister_name(reg); + g_expr(e2); + if (!is_int_reg(creg)) error(-1); + crn=register_name(ireg); + if (reg==USE_CREG) { + reg=get_dregister(d); if (!reg) error(-1); + set_freg(reg,0); + } + frn=fregister_name(reg); grn = fregister_name(g = code_dload_1(d)); - printf("\t%s %s,0(%s)\n",fload(d),frn,crn); - printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",grn,frn,grn); - printf("\t%s %s,0(%s)\n",fstore(d),grn,crn); + printf("\t%s %s,0(%s)\n",fload(d),frn,crn); + printf("\t%s %s,%s,%s\n",(caddr(e1)>0)?"fadd":"fsub",grn,frn,grn); + printf("\t%s %s,0(%s)\n",fstore(d),grn,crn); } free_register(g); } @@ -5007,11 +5007,11 @@ rn = register_name(reg); t = CRBITSIZ*cmpflag; if (eq>0) { - printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); + printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); } if (neg>0) { - neg = t+neg-1, - printf("\tcrnor %d,%d,%d\n",neg,neg,neg); + neg = t+neg-1, + printf("\tcrnor %d,%d,%d\n",neg,neg,neg); } printf("\tmfcr %s\n",rn); printf("\trlwinm %s,%s,%d,1\n",rn,rn,t+flag); @@ -5022,39 +5022,39 @@ drexpr(int e1, int e2,int l1, int op,int cond) { if (!cond) { - switch(op) { - case FOP+GT: - return drexpr(e2,e1,l1,FOP+GE,1); - case FOP+GE: - return drexpr(e2,e1,l1,FOP+GT,1); - case FOP+EQ: - op=FOP+NEQ; break; - case FOP+NEQ: - op=FOP+EQ; break; - case DOP+GT: - return drexpr(e2,e1,l1,DOP+GE,1); - case DOP+GE: - return drexpr(e2,e1,l1,DOP+GT,1); - case DOP+EQ: - op=DOP+NEQ; break; - case DOP+NEQ: - op=DOP+EQ; break; - } + switch(op) { + case FOP+GT: + return drexpr(e2,e1,l1,FOP+GE,1); + case FOP+GE: + return drexpr(e2,e1,l1,FOP+GT,1); + case FOP+EQ: + op=FOP+NEQ; break; + case FOP+NEQ: + op=FOP+EQ; break; + case DOP+GT: + return drexpr(e2,e1,l1,DOP+GE,1); + case DOP+GE: + return drexpr(e2,e1,l1,DOP+GT,1); + case DOP+EQ: + op=DOP+NEQ; break; + case DOP+NEQ: + op=DOP+EQ; break; + } } g_expr(list3(DCMP, e1,e2)); switch(op) { - case DOP+GT: case FOP+GT: - printf("\tbgt\t%s,%s%d\n",crname(cmpflag),lpfx,l1); - break; - case DOP+GE: case FOP+GE: - printf("\tbge\t%s,%s%d\n",crname(cmpflag),lpfx,l1); - break; - case DOP+EQ: case FOP+EQ: - printf("\tbeq\t%s,%s%d\n",crname(cmpflag),lpfx,l1); - break; - case DOP+NEQ: case FOP+NEQ: - printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,l1); - break; + case DOP+GT: case FOP+GT: + printf("\tbgt\t%s,%s%d\n",crname(cmpflag),lpfx,l1); + break; + case DOP+GE: case FOP+GE: + printf("\tbge\t%s,%s%d\n",crname(cmpflag),lpfx,l1); + break; + case DOP+EQ: case FOP+EQ: + printf("\tbeq\t%s,%s%d\n",crname(cmpflag),lpfx,l1); + break; + case DOP+NEQ: case FOP+NEQ: + printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,l1); + break; } return l1; } @@ -5064,10 +5064,10 @@ int xreg,reg; xreg=pop_fregister(); if (xreg<= -REG_LVAR_OFFSET) { - reg = get_dregister(d); + reg = get_dregister(d); code_drlvar(REG_LVAR_OFFSET+xreg,1,reg); - free_lvar(REG_LVAR_OFFSET+xreg); - xreg=reg; + free_lvar(REG_LVAR_OFFSET+xreg); + xreg=reg; } return xreg; } @@ -5076,7 +5076,7 @@ emit_dpop_free(int e1,int d) { if (e1>=0 && e1!=creg && regs[e1]!=REG_VAR) - free_register(e1); + free_register(e1); } void @@ -5101,17 +5101,17 @@ { int tmp; if (regv_h(to)==regv_l(from)&&(regv_l(to)==regv_h(from))) { - tmp = get_register(); - printf("\tmr %s,%s\n",register_name(tmp),lregister_name_low(from)); - printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); - printf("\tmr %s,%s\n",lregister_name_low(to),register_name(tmp)); - free_register(tmp); + tmp = get_register(); + printf("\tmr %s,%s\n",register_name(tmp),lregister_name_low(from)); + printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); + printf("\tmr %s,%s\n",lregister_name_low(to),register_name(tmp)); + free_register(tmp); } else if (regv_h(to)==regv_l(from)) { - printf("\tmr %s,%s\n",lregister_name_low(to),lregister_name_low(from)); - printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); + printf("\tmr %s,%s\n",lregister_name_low(to),lregister_name_low(from)); + printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); } else { - printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); - printf("\tmr %s,%s\n",lregister_name_low(to),lregister_name_low(from)); + printf("\tmr %s,%s\n",lregister_name_high(to),lregister_name_high(from)); + printf("\tmr %s,%s\n",lregister_name_low(to),lregister_name_low(from)); } } @@ -5158,42 +5158,42 @@ switch(op+(!cond)*BNOT) { case LOP+GT: case LOP+GE: - pcond(code_gt(1),cr0,1?l1:l2); - pcond(code_eq(0),cr0,1?l2:l1); - break; + pcond(code_gt(1),cr0,1?l1:l2); + pcond(code_eq(0),cr0,1?l2:l1); + break; case LOP+UGT: case LOP+UGE: - pcond(code_ugt(1),cr0,1?l1:l2); - pcond(code_eq(0), cr0,1?l2:l1); - break; + pcond(code_ugt(1),cr0,1?l1:l2); + pcond(code_eq(0), cr0,1?l2:l1); + break; case LOP+EQ: - pcond(code_eq(0),cr0,(1?l2:l1)); - pcond(code_eq(cond),cr1,l1); - break; + pcond(code_eq(0),cr0,(1?l2:l1)); + pcond(code_eq(cond),cr1,l1); + break; case LOP+NEQ: - pcond(code_eq(0),cr0,(1?l1:l2)); - pcond(code_eq(!1),cr1,l1); - break; + pcond(code_eq(0),cr0,(1?l1:l2)); + pcond(code_eq(!1),cr1,l1); + break; case LOP+GT+BNOT: case LOP+GE+BNOT: - pcond(code_gt(1),cr0,0?l1:l2); - pcond(code_eq(0),cr0,0?l2:l1); - break; + pcond(code_gt(1),cr0,0?l1:l2); + pcond(code_eq(0),cr0,0?l2:l1); + break; case LOP+UGT+BNOT: case LOP+UGE+BNOT: - pcond(code_ugt(1),cr0,0?l1:l2); - pcond(code_eq(0), cr0,0?l2:l1); - break; + pcond(code_ugt(1),cr0,0?l1:l2); + pcond(code_eq(0), cr0,0?l2:l1); + break; case LOP+EQ+BNOT: - pcond(code_eq(0),cr0,(0?l2:l1)); - pcond(code_eq(0),cr1,l1); - break; + pcond(code_eq(0),cr0,(0?l2:l1)); + pcond(code_eq(0),cr1,l1); + break; case LOP+NEQ+BNOT: - pcond(code_eq(0),cr0,(0?l1:l2)); - pcond(code_eq(!0),cr1,l1); - break; + pcond(code_eq(0),cr0,(0?l1:l2)); + pcond(code_eq(!0),cr1,l1); + break; default: - error(-1); + error(-1); } switch(op+BNOT*(!cond)) { case LOP+GT: pcond(code_gt(1), cr1,l1); break; @@ -5229,7 +5229,7 @@ { use_longlong(reg); if (reg!=e2) { - lmove(reg,e2); + lmove(reg,e2); } } @@ -5238,9 +5238,9 @@ { use_longlong(reg); printf("\tor %s,%s,%s\n", - lregister_name_low(reg), - lregister_name_low(reg), - lregister_name_high(reg)); + lregister_name_low(reg), + lregister_name_low(reg), + lregister_name_high(reg)); inc_cmpflag(); printf("\tcmpwi %s,%s,0\n",crname(cmpflag),lregister_name_low(reg)); jcond(label,cond); @@ -5320,7 +5320,7 @@ { use_longlong(reg); if (e2!=reg) { - lmove(e2,reg); + lmove(e2,reg); } } @@ -5358,9 +5358,9 @@ { use_longlong(creg); printf("\tsubfic %s,%s,0\n", - lregister_name_low(creg),lregister_name_low(creg)); + lregister_name_low(creg),lregister_name_low(creg)); printf("\tsubfze %s,%s\n", - lregister_name_high(creg),lregister_name_high(creg)); + lregister_name_high(creg),lregister_name_high(creg)); } void @@ -5655,9 +5655,9 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { - printf("\tmr %s,%s\n", - register_name(5), - lregister_name_low(oreg)); + printf("\tmr %s,%s\n", + register_name(5), + lregister_name_low(oreg)); } printf("\tbl .asld__\n"); } @@ -5671,9 +5671,9 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { - printf("\tmr %s,%s\n", - register_name(5), - lregister_name_low(oreg)); + printf("\tmr %s,%s\n", + register_name(5), + lregister_name_low(oreg)); } printf("\tbl .asrd__\n"); } @@ -5687,9 +5687,9 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { - printf("\tmr %s,%s\n", - register_name(5), - lregister_name_low(oreg)); + printf("\tmr %s,%s\n", + register_name(5), + lregister_name_low(oreg)); } printf("\tbl .lsrd__\n"); } @@ -5754,31 +5754,31 @@ use_longlong(reg); if(oreg==-1) { - error(-1); + error(-1); } else if (oreg<= -REG_LVAR_OFFSET) { - ox = get_lregister(); if (ox<0) error(-1); - use_reg(ox); + ox = get_lregister(); if (ox<0) error(-1); + use_reg(ox); code_lrlvar(oreg+REG_LVAR_OFFSET,ox); - oreg = ox; + oreg = ox; } switch(op) { case LLSHIFT: case LULSHIFT: - code_asld_lib(reg,oreg); // ___ashldi3$stub - check_lreg(reg); - if(ox!=-1) free_register(ox); - return; + code_asld_lib(reg,oreg); // ___ashldi3$stub + check_lreg(reg); + if(ox!=-1) free_register(ox); + return; case LRSHIFT: - code_asrd_lib(reg,oreg); // ___ashrdi3$stub - check_lreg(reg); - if(ox!=-1) free_register(ox); - return; + code_asrd_lib(reg,oreg); // ___ashrdi3$stub + check_lreg(reg); + if(ox!=-1) free_register(ox); + return; case LURSHIFT: - code_lsrd_lib(reg,oreg); // ___lshrdi3$stub - check_lreg(reg); - if(ox!=-1) free_register(ox); - return; + code_lsrd_lib(reg,oreg); // ___lshrdi3$stub + check_lreg(reg); + if(ox!=-1) free_register(ox); + return; } orn_h = lregister_name_high(oreg); orn_l = lregister_name_low(oreg); @@ -5786,71 +5786,71 @@ crn_l = lregister_name_low(reg); switch(op) { case LADD: - printf("\taddc %s,%s,%s\n",crn_l,crn_l,orn_l); - printf("\tadde %s,%s,%s\n",crn_h,crn_h,orn_h); - break; + printf("\taddc %s,%s,%s\n",crn_l,crn_l,orn_l); + printf("\tadde %s,%s,%s\n",crn_h,crn_h,orn_h); + break; case LSUB: - printf("\tsubfc %s,%s,%s\n",crn_l,orn_l,crn_l); - printf("\tsubfe %s,%s,%s\n",crn_h,orn_h,crn_h); - break; + printf("\tsubfc %s,%s,%s\n",crn_l,orn_l,crn_l); + printf("\tsubfe %s,%s,%s\n",crn_h,orn_h,crn_h); + break; case LCMP: - error(-1); - break; + error(-1); + break; case LBAND: - printf("\tand %s,%s,%s\n",crn_l,crn_l,orn_l); - printf("\tand %s,%s,%s\n",crn_h,crn_h,orn_h); - break; + printf("\tand %s,%s,%s\n",crn_l,crn_l,orn_l); + printf("\tand %s,%s,%s\n",crn_h,crn_h,orn_h); + break; case LEOR: - printf("\txor %s,%s,%s\n",crn_l,crn_l,orn_l); - printf("\txor %s,%s,%s\n",crn_h,crn_h,orn_h); - break; + printf("\txor %s,%s,%s\n",crn_l,crn_l,orn_l); + printf("\txor %s,%s,%s\n",crn_h,crn_h,orn_h); + break; case LBOR: - printf("\tor %s,%s,%s\n",crn_l,crn_l,orn_l); - printf("\tor %s,%s,%s\n",crn_h,crn_h,orn_h); - break; + printf("\tor %s,%s,%s\n",crn_l,crn_l,orn_l); + printf("\tor %s,%s,%s\n",crn_h,crn_h,orn_h); + break; case LMUL: case LUMUL: - // code_save_stacks(); - // clear_ptr_cache(); - dx=get_lregister(); if (dx<0) error(-1); - use_reg(dx); - drn_l = lregister_name_low(dx); - drn_h = lregister_name_high(dx); + // code_save_stacks(); + // clear_ptr_cache(); + dx=get_lregister(); if (dx<0) error(-1); + use_reg(dx); + drn_l = lregister_name_low(dx); + drn_h = lregister_name_high(dx); /* drn_l = l32( crn_l * orn_l); drn_h = h32( crn_l * orn_l); crn_h = l32( crn_h * orn_l); - drn_h = drn_h + crn_h; + drn_h = drn_h + crn_h; crn_l = l32( crn_l * orn_h); - crn_h = drn_h + crn_l; - crn_l = drn_l; + crn_h = drn_h + crn_l; + crn_l = drn_l; */ - printf("\tmulhwu %s,%s,%s\n",drn_h,crn_l,orn_l); - printf("\tmullw %s,%s,%s\n", drn_l,crn_l,orn_l); - printf("\tmullw %s,%s,%s\n", crn_h,crn_h,orn_l); - printf("\tadd %s,%s,%s\n", drn_h,drn_h,crn_h); - printf("\tmullw %s,%s,%s\n", crn_l,orn_h,crn_l); - printf("\tadd %s,%s,%s\n", crn_h,drn_h,crn_l); - printf("\tmr %s,%s\n", crn_l,drn_l); - break; + printf("\tmulhwu %s,%s,%s\n",drn_h,crn_l,orn_l); + printf("\tmullw %s,%s,%s\n", drn_l,crn_l,orn_l); + printf("\tmullw %s,%s,%s\n", crn_h,crn_h,orn_l); + printf("\tadd %s,%s,%s\n", drn_h,drn_h,crn_h); + printf("\tmullw %s,%s,%s\n", crn_l,orn_h,crn_l); + printf("\tadd %s,%s,%s\n", crn_h,drn_h,crn_l); + printf("\tmr %s,%s\n", crn_l,drn_l); + break; case LDIV: - code_ldiv_lib(reg,oreg); // ___divdi3$stub - if (!creg_mode) check_lreg(reg); - break; + code_ldiv_lib(reg,oreg); // ___divdi3$stub + if (!creg_mode) check_lreg(reg); + break; case LUDIV: - code_ludiv_lib(reg,oreg); // ___udivdi3$stub - if (!creg_mode) check_lreg(reg); - break; + code_ludiv_lib(reg,oreg); // ___udivdi3$stub + if (!creg_mode) check_lreg(reg); + break; case LMOD: - code_lmod_lib(reg,oreg); // ___moddi3$stub - if (!creg_mode) check_lreg(reg); - break; + code_lmod_lib(reg,oreg); // ___moddi3$stub + if (!creg_mode) check_lreg(reg); + break; case LUMOD: - code_lumod_lib(reg,oreg); // ___umoddi3$stub - if (!creg_mode) check_lreg(reg); - break; + code_lumod_lib(reg,oreg); // ___umoddi3$stub + if (!creg_mode) check_lreg(reg); + break; default: - error(-1); + error(-1); } if(ox!=-1) free_register(ox); if(dx!=-1) free_register(dx); @@ -5861,11 +5861,11 @@ { int v; if (car(e)==LCONST) { - if (!(-32766<lcadr(e)&&lcadr(e)<32767)) return 0; - v = lcadr(e); + if (!(-32766<lcadr(e)&&lcadr(e)<32767)) return 0; + v = lcadr(e); } else if (car(e)==CONST) { - if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0; - v = cadr(e); + if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0; + v = cadr(e); } else return 0; switch(op) { @@ -5876,14 +5876,14 @@ case LULSHIFT: case LRSHIFT: case LURSHIFT: - return (0<=v&&v<=64); + return (0<=v&&v<=64); case LADD: case LSUB: - return 1; + return 1; case LBOR: - return (v>0); + return (v>0); default: - return 0; + return 0; } } @@ -5908,87 +5908,87 @@ v=ilog(v); case LLSHIFT: case LULSHIFT: - if (v==0) return; - if (v==32) { - code_register(regv_l(creg),regv_h(creg)); - code_const(0,regv_l(creg)); - return; - } else if (v>31) { - printf("\tslwi %s,%s,%d\n",crn_h,crn_l,v-32); - code_const(0,regv_l(creg)); - return; - } - greg = get_register(); - grn = register_name(greg); - use_reg(greg); - printf("\tsrwi %s,%s,%d\n",grn,crn_l,32-v); - printf("\tslwi %s,%s,%d\n",crn_h,crn_h,v); - printf("\tor %s,%s,%s\n",crn_h,grn,crn_h); - printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v); - free_register(greg); - return; + if (v==0) return; + if (v==32) { + code_register(regv_l(creg),regv_h(creg)); + code_const(0,regv_l(creg)); + return; + } else if (v>31) { + printf("\tslwi %s,%s,%d\n",crn_h,crn_l,v-32); + code_const(0,regv_l(creg)); + return; + } + greg = get_register(); + grn = register_name(greg); + use_reg(greg); + printf("\tsrwi %s,%s,%d\n",grn,crn_l,32-v); + printf("\tslwi %s,%s,%d\n",crn_h,crn_h,v); + printf("\tor %s,%s,%s\n",crn_h,grn,crn_h); + printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v); + free_register(greg); + return; case LDIV: v=ilog(v); case LRSHIFT: - if (v==0) return; - if (v==32) { - code_register(regv_h(creg),regv_l(creg)); - printf("\tsrawi %s,%s,31\n",crn_h,crn_l); - return; - } else if (v>31) { - printf("\tsrawi %s,%s,%d\n",crn_l,crn_h,v-32); - printf("\tsrawi %s,%s,31\n",crn_h,crn_l); - return; - } - greg = get_register(); - use_reg(greg); - grn = register_name(greg); - printf("\tsrwi %s,%s,%d\n",grn,crn_l,v); - printf("\tinsrwi %s,%s,%d,0\n",grn,crn_h,v); - printf("\tsrawi %s,%s,%d\n",crn_h,crn_h,v); - printf("\tmr %s,%s\n",crn_l,grn); - free_register(greg); - return; + if (v==0) return; + if (v==32) { + code_register(regv_h(creg),regv_l(creg)); + printf("\tsrawi %s,%s,31\n",crn_h,crn_l); + return; + } else if (v>31) { + printf("\tsrawi %s,%s,%d\n",crn_l,crn_h,v-32); + printf("\tsrawi %s,%s,31\n",crn_h,crn_l); + return; + } + greg = get_register(); + use_reg(greg); + grn = register_name(greg); + printf("\tsrwi %s,%s,%d\n",grn,crn_l,v); + printf("\tinsrwi %s,%s,%d,0\n",grn,crn_h,v); + printf("\tsrawi %s,%s,%d\n",crn_h,crn_h,v); + printf("\tmr %s,%s\n",crn_l,grn); + free_register(greg); + return; case LUDIV: v=ilog(v); case LURSHIFT: - if (v==0) return; - if (v==32) { - code_register(regv_h(creg),regv_l(creg)); - code_const(0,regv_h(creg)); - return; - } else if (v>31) { - printf("\tsrwi %s,%s,%d\n",crn_l,crn_h,v-32); - code_const(0,regv_h(creg)); - return; - } - greg = get_register(); - use_reg(greg); - grn = register_name(greg); - printf("\tslwi %s,%s,%d\n",grn,crn_h,32-v); - printf("\tsrwi %s,%s,%d\n",crn_l,crn_l,v); - printf("\tor %s,%s,%s\n",crn_l,grn,crn_l); - printf("\tsrwi %s,%s,%d\n",crn_h,crn_h,v); - free_register(greg); - return; + if (v==0) return; + if (v==32) { + code_register(regv_h(creg),regv_l(creg)); + code_const(0,regv_h(creg)); + return; + } else if (v>31) { + printf("\tsrwi %s,%s,%d\n",crn_l,crn_h,v-32); + code_const(0,regv_h(creg)); + return; + } + greg = get_register(); + use_reg(greg); + grn = register_name(greg); + printf("\tslwi %s,%s,%d\n",grn,crn_h,32-v); + printf("\tsrwi %s,%s,%d\n",crn_l,crn_l,v); + printf("\tor %s,%s,%s\n",crn_l,grn,crn_l); + printf("\tsrwi %s,%s,%d\n",crn_h,crn_h,v); + free_register(greg); + return; case LSUB: - v = -v; + v = -v; case LADD: - printf("\taddic %s,%s,%d\n",crn_l,crn_l,v); - if (v<0) - printf("\taddme %s,%s\n",crn_h,crn_h); - else - printf("\taddze %s,%s\n",crn_h,crn_h); - break; + printf("\taddic %s,%s,%d\n",crn_l,crn_l,v); + if (v<0) + printf("\taddme %s,%s\n",crn_h,crn_h); + else + printf("\taddze %s,%s\n",crn_h,crn_h); + break; case LBOR: #ifdef __APPLE__ - printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v); + printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v); #else - printf("\tori %s,%s,%d@l\n",crn_l,crn_l,v); -#endif - break; + printf("\tori %s,%s,%d@l\n",crn_l,crn_l,v); +#endif + break; default: - error(-1); + error(-1); } } @@ -6021,7 +6021,7 @@ crn_h = lregister_name_high(lreg); crn_l = lregister_name_low(lreg); if (reg0!=regv_l(lreg)) - printf("\tmr %s,%s\n",crn_l,crn); + printf("\tmr %s,%s\n",crn_l,crn); printf("\tsrawi %s,%s,31\n",crn_h,crn_l); } @@ -6041,7 +6041,7 @@ crn_h = lregister_name_high(lreg); crn_l = lregister_name_low(lreg); if (reg0!=regv_l(lreg)) - printf("\tmr %s,%s\n",crn_l,crn); + printf("\tmr %s,%s\n",crn_l,crn); printf("\tli %s,0\n",crn_h); } @@ -6059,7 +6059,7 @@ crn_l = lregister_name_low(reg0=lreg); use_int(reg); if (ireg!=regv_l(reg0)) - printf("\tmr %s,%s\n",register_name(ireg),crn_l); + printf("\tmr %s,%s\n",register_name(ireg),crn_l); } void @@ -6090,7 +6090,7 @@ extern_conv("__fixdfdi"); set_lreg(RET_LREGISTER,0); if (reg!=USE_CREG&®!=RET_LREGISTER) - use_longlong(reg); + use_longlong(reg); } void @@ -6100,7 +6100,7 @@ extern_conv("__fixunsdfdi"); set_lreg(RET_LREGISTER,0); if (reg!=USE_CREG&®!=RET_LREGISTER) - use_longlong(reg); + use_longlong(reg); } void @@ -6110,7 +6110,7 @@ extern_conv("__fixdfdi"); set_lreg(RET_LREGISTER,0); if (reg!=USE_CREG&®!=RET_LREGISTER) - use_longlong(reg); + use_longlong(reg); } void @@ -6120,7 +6120,7 @@ extern_conv("__fixsfdi"); set_lreg(RET_LREGISTER,0); if (reg!=USE_CREG&®!=RET_LREGISTER) - use_longlong(reg); + use_longlong(reg); } void @@ -6130,7 +6130,7 @@ extern_conv("__floatdidf"); set_freg(RET_FREGISTER,0); if (reg!=USE_CREG&®!=RET_FREGISTER) - use_float(1,reg); + use_float(1,reg); } @@ -6141,7 +6141,7 @@ extern_conv("__floatdisf"); set_freg(RET_FREGISTER,0); if (reg!=USE_CREG&®!=RET_FREGISTER) - use_float(0,reg); + use_float(0,reg); } void @@ -6161,9 +6161,9 @@ ladd(int creg,int reg,int dir) // creg=reg+dir { printf("\taddic %s,%s,%d\n", - lregister_name_low(creg),lregister_name_low(reg), dir); + lregister_name_low(creg),lregister_name_low(reg), dir); printf("\tadd%s %s,%s\n", dir>0?"ze":"me", - lregister_name_high(creg),lregister_name_high(reg)); + lregister_name_high(creg),lregister_name_high(reg)); } void @@ -6172,19 +6172,19 @@ int dreg,xreg; int dir=caddr(e1); if (car(e2)==LREGISTER) { - use_longlong(reg); - ladd(cadr(e2),cadr(e2),dir); + use_longlong(reg); + ladd(cadr(e2),cadr(e2),dir); if (reg!=cadr(e2)) { - lmove(reg,cadr(e2)); - } + lmove(reg,cadr(e2)); + } return; } g_expr(e2); if(!is_int_reg(creg)) error(-1); emit_push(); if (reg==USE_CREG) { - dreg=get_lregister(); if (!dreg) error(-1); - set_lreg(dreg,0); // free old lreg==creg + dreg=get_lregister(); if (!dreg) error(-1); + set_lreg(dreg,0); // free old lreg==creg } else { dreg = reg; } @@ -6201,10 +6201,10 @@ int dreg,nreg,xreg; int dir=caddr(e1); if (car(e2)==LREGISTER) { - use_longlong(reg); - if (use && reg!=cadr(e2)) - lmove(reg,cadr(e2)); - ladd(cadr(e2),cadr(e2),dir); + use_longlong(reg); + if (use && reg!=cadr(e2)) + lmove(reg,cadr(e2)); + ladd(cadr(e2),cadr(e2),dir); return; } g_expr(e2); @@ -6212,8 +6212,8 @@ emit_push(); nreg=get_lregister(); if (!nreg) error(-1); if (reg==USE_CREG) { - dreg=get_lregister(); if (!dreg) error(-1); - set_lreg(dreg,0); // free old lreg==creg + dreg=get_lregister(); if (!dreg) error(-1); + set_lreg(dreg,0); // free old lreg==creg } else { dreg = reg; } @@ -6238,10 +6238,10 @@ emit_push(); use_longlong(reg); if (regv_l(lreg)==edx || regv_h(lreg)==edx) { - // this can't happen - edx0 = get_register(); if(!edx0) error(-1); - printf("## lassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx)); - edx = edx0; + // this can't happen + edx0 = get_register(); if(!edx0) error(-1); + printf("## lassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx)); + edx = edx0; } lload(edx0=edx,reg,0); ltosop(op,reg,xreg); @@ -6249,7 +6249,7 @@ edx = emit_pop(0); code_lassign(edx,reg); if (edx0!=-1) - free_register(edx0); + free_register(edx0); emit_pop_free(edx); emit_lpop_free(xreg); } @@ -6274,7 +6274,7 @@ code_assign_lvar( (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); + free_register(reg); } } #if FLOAT_CODE @@ -6283,7 +6283,7 @@ code_dassign_lvar( (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); + free_register(reg); } } #endif @@ -6293,7 +6293,7 @@ code_lassign_lvar( (lreg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); lreg_stack[i]= lreg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); + free_register(reg); } } #endif @@ -6303,7 +6303,7 @@ emit_lib(char *p[]) { while(*p) { - printf("%s\n",*p++); + printf("%s\n",*p++); } } @@ -6363,18 +6363,18 @@ inc_cmpflag(); if (min>32767||min<-32765) { - if (t==csvalue) { - code_const(min,s); - printf("\tsub\t%s,%s,%s\n",trn,crn,srn); - } else { - code_const(min,t); - printf("\tsub\t%s,%s,%s\n",trn,crn,trn); - } + if (t==csvalue) { + code_const(min,s); + printf("\tsub\t%s,%s,%s\n",trn,crn,srn); + } else { + code_const(min,t); + printf("\tsub\t%s,%s,%s\n",trn,crn,trn); + } } else { #ifdef __APPLE__ - printf("\taddi\t%s,%s,lo16(%d)\n",trn,crn,-min); + printf("\taddi\t%s,%s,lo16(%d)\n",trn,crn,-min); #else - printf("\taddi\t%s,%s,%d@l\n",trn,crn,-min); + printf("\taddi\t%s,%s,%d@l\n",trn,crn,-min); #endif } printf("\tcmplwi %s,%s,%d\n",crname(cmpflag),trn,max-min); @@ -6383,33 +6383,33 @@ switch(delta) { case 1: printf("\tslwi %s,%s,2\n",trn,trn); break; case 2: - printf("\tli %s,1\n",srn); - printf("\tand %s,%s,%s\n",srn,srn,trn); - printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); - printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); - printf("\tslwi %s,%s,1\n",trn,trn); - break; + printf("\tli %s,1\n",srn); + printf("\tand %s,%s,%s\n",srn,srn,trn); + printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); + printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); + printf("\tslwi %s,%s,1\n",trn,trn); + break; case 4: - printf("\tli %s,3\n",srn); - printf("\tand %s,%s,%s\n",srn,srn,trn); - printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); - printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); - break; + printf("\tli %s,3\n",srn); + printf("\tand %s,%s,%s\n",srn,srn,trn); + printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); + printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); + break; default: - urn = register_name(u=get_register()); - printf("\tli %s,%d\n",srn,delta); - printf("\tdivwu %s,%s,%s\n",urn,trn,srn); - printf("\tmullw %s,%s,%s\n",srn,urn,srn); - printf("\tsubf %s,%s,%s\n",srn,trn,srn); - printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); - printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); - printf("\tslwi %s,%s,2\n",trn,urn); + urn = register_name(u=get_register()); + printf("\tli %s,%d\n",srn,delta); + printf("\tdivwu %s,%s,%s\n",urn,trn,srn); + printf("\tmullw %s,%s,%s\n",srn,urn,srn); + printf("\tsubf %s,%s,%s\n",srn,trn,srn); + printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); + printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); + printf("\tslwi %s,%s,2\n",trn,urn); } #ifdef __APPLE__ printf("\taddis %s,r31,ha16(L_%d-L_%d)\n", - srn,l,code_base); + srn,l,code_base); printf("\tla %s,lo16(L_%d-L_%d)(%s)\n", - srn,l,code_base,srn); + srn,l,code_base,srn); printf("\tadd %s,%s,%s\n",trn,srn,trn); printf("\tlwz r0,0(%s)\n",trn); printf("\tadd r0,r0,%s\n",srn); @@ -6460,15 +6460,15 @@ emit_asm_operand(int rstr) { if (car(rstr)==REGISTER) { - printf("%s",register_name(cadr(rstr))); + printf("%s",register_name(cadr(rstr))); } else if (car(rstr)==CONST) { - printf("%d",cadr(rstr)); + printf("%d",cadr(rstr)); } else if (car(rstr)==FNAME) { - printf("%s",ncaddr(rstr)->nm); + printf("%s",ncaddr(rstr)->nm); } else if (car(rstr)==LABEL) { - printf("%s%d:\n",lpfx,cadr(rstr)); + printf("%s%d:\n",lpfx,cadr(rstr)); } else { - error(-1); + error(-1); } } @@ -6506,56 +6506,56 @@ case '#': case '*': case '=': - // output register - p++; - goto retry; + // output register + p++; + goto retry; case '&': - // earlyclobber - p++; - clobber = 1; - goto retry; + // earlyclobber + p++; + clobber = 1; + goto retry; case 'b': // address base register (what?) case 'r': - if (mode==ASM_INPUT) { - for(;repl0;repl0 = cadr(repl0)) { - if (car(car(repl0))==REGISTER && caddr(repl0)==0) { - r = cadr(car(repl0)); - caddr(repl0) = ASM_USED; - break; - } + if (mode==ASM_INPUT) { + for(;repl0;repl0 = cadr(repl0)) { + if (car(car(repl0))==REGISTER && caddr(repl0)==0) { + r = cadr(car(repl0)); + caddr(repl0) = ASM_USED; + break; + } } - r = get_register(); - } else { - r = get_register(); - } - repl = list3(list2(REGISTER,r),repl,clobber); - break; + r = get_register(); + } else { + r = get_register(); + } + repl = list3(list2(REGISTER,r),repl,clobber); + break; case 'm': - repl = list3(list2(0,0),repl,clobber); - break; + repl = list3(list2(0,0),repl,clobber); + break; case 'i': - if (car(e1)==GVAR) { - e1=list3n(FNAME,0,ncaddr(e1)); - } else if (car(e1)==FNAME) { - e1=list3n(FNAME,0,ncaddr(e1)); - } else if (car(e1)==STRING) { - val = emit_string_label(); - ascii(ncaddr(e1)->nm); - e1=list2(LABEL,val); - } else if (car(e1)==CONST) { - } else error(-1); - repl = list3(e1,repl,clobber); - break; + if (car(e1)==GVAR) { + e1=list3n(FNAME,0,ncaddr(e1)); + } else if (car(e1)==FNAME) { + e1=list3n(FNAME,0,ncaddr(e1)); + } else if (car(e1)==STRING) { + val = emit_string_label(); + ascii(ncaddr(e1)->nm); + e1=list2(LABEL,val); + } else if (car(e1)==CONST) { + } else error(-1); + repl = list3(e1,repl,clobber); + break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - val = 0; - do { val = val*10 + c-'0'; } while (digit(c=*p++)); - if (val>MAX_ASM_REG) error(-1); // too large register - if (n-val<0) error(-1); - repl = list3(car(nth(n-val-1,repl0)),repl,clobber); - break; + val = 0; + do { val = val*10 + c-'0'; } while (digit(c=*p++)); + if (val>MAX_ASM_REG) error(-1); // too large register + if (n-val<0) error(-1); + repl = list3(car(nth(n-val-1,repl0)),repl,clobber); + break; default: - printf("### unknown asm constraint %c\n",c); + printf("### unknown asm constraint %c\n",c); } return repl; } @@ -6564,8 +6564,8 @@ code_free_asm_operand(int repl) { for(;repl;repl=cadr(repl)) { - if (car(car(repl))==REGISTER) - free_register(cadr(car(repl))); + if (car(car(repl))==REGISTER) + free_register(cadr(car(repl))); } } @@ -6581,28 +6581,28 @@ c = *asm_str; if (c!='\t'&&c!=' ') printf("\t"); for(i=0;repl && i<MAX_ASM_REG;i++) { - reg[i] = car(repl); - repl = cadr(repl); + reg[i] = car(repl); + repl = cadr(repl); } p = asm_str; while((c = *p++)) { - if (c=='%') { - c = *p++; - if (!c) { break; - } else if (c=='%') { - printf("%%"); continue; - } else if (!digit(c)) { - printf("%%%c",c); continue; - } - val = 0; - do { val = val*10 + c-'0'; } while (digit(c=*p++)) ; - p--; - if (val>MAX_ASM_REG) error(-1); // too large register - rstr = reg[val]; - emit_asm_operand(rstr); - } else { - printf("%c",c); - } + if (c=='%') { + c = *p++; + if (!c) { break; + } else if (c=='%') { + printf("%%"); continue; + } else if (!digit(c)) { + printf("%%%c",c); continue; + } + val = 0; + do { val = val*10 + c-'0'; } while (digit(c=*p++)) ; + p--; + if (val>MAX_ASM_REG) error(-1); // too large register + rstr = reg[val]; + emit_asm_operand(rstr); + } else { + printf("%c",c); + } } printf("\n"); } @@ -6616,25 +6616,25 @@ static void set_bitsz(int type,int *pbitpos,int *pbitsize, - int *psign,int *pbitsz,int *palign,int *pl) + int *psign,int *pbitsz,int *palign,int *pl) { int sign=0,bitsz=0; int align=4,l=0; *pbitpos = cadr(caddr(type)); *pbitsize = caddr(caddr(type)); switch(cadr(type)) { /* value type */ - case INT: sign=1; bitsz=32; align=4;break; - case UNSIGNED: bitsz=32; align=4;break; + case INT: sign=1; bitsz=32; align=4;break; + case UNSIGNED: bitsz=32; align=4;break; case CHAR: sign=1; bitsz= 8; align=1;break; - case UCHAR: bitsz= 8; align=1;break; + case UCHAR: bitsz= 8; align=1;break; case SHORT: sign=1; bitsz=16; align=2;break; case USHORT: sign=1; bitsz=16; align=2;break; #ifdef __APPLE__ case LONGLONG: sign=1; bitsz=64; align=4;l=1; break; - case ULONGLONG: bitsz=64; align=4;l=1; break; + case ULONGLONG: bitsz=64; align=4;l=1; break; #else case LONGLONG: sign=1; bitsz=64; align=8;l=1; break; - case ULONGLONG: bitsz=64; align=8;l=1; break; + case ULONGLONG: bitsz=64; align=8;l=1; break; #endif default: error(-1); } @@ -6665,28 +6665,28 @@ /* bfd means previous bit field bit offset */ if (bitpos) { - /* previous field is bit field and spaces may remain */ - /* calc previsous offset */ - - i= offset-(bitpos+7)/8; - - for(l = bitpos;l>0;l -= 8,i++) { - if ((i & (align-1))==0 && l+bitsize <= bitsz) { - /* alignment is correct and space remains */ - *poffset=offset=i; - i = l+bitsize; + /* previous field is bit field and spaces may remain */ + /* calc previsous offset */ + + i= offset-(bitpos+7)/8; + + for(l = bitpos;l>0;l -= 8,i++) { + if ((i & (align-1))==0 && l+bitsize <= bitsz) { + /* alignment is correct and space remains */ + *poffset=offset=i; + i = l+bitsize; *bfd = (i==bitsz)?0:i; - *sz = (i+7)/8; + *sz = (i+7)/8; // printf("## bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); - return l; - } - } + return l; + } + } } /* first bit-field */ if ((i=(offset & (align-1)))) { - *poffset = (offset += (align-i)); + *poffset = (offset += (align-i)); } bitpos = 0; *bfd = (bitsize==bitsz)?0:bitsize; @@ -6710,33 +6710,33 @@ /* this implementation returns -1 for int i:1; */ if (l==1) { #if LONGLONG_CODE - // use_int(adr); - use_longlong(reg); - lload(adr,reg,0); - /* shift left */ - if (bitpos) - loprtc(LLSHIFT,reg,list2(CONST,bitpos)); - /* shift right */ - if ((i=bitsz-bitsize)) - loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i)); + // use_int(adr); + use_longlong(reg); + lload(adr,reg,0); + /* shift left */ + if (bitpos) + loprtc(LLSHIFT,reg,list2(CONST,bitpos)); + /* shift right */ + if ((i=bitsz-bitsize)) + loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i)); #endif } else { - // use_int(adr); - use_int(reg); + // use_int(adr); + use_int(reg); #ifdef __APPLE__ - printf("\t%s %s,lo16(%d)(%s)\n",cload(size), - register_name(reg),0,register_name(adr)); + printf("\t%s %s,lo16(%d)(%s)\n",cload(size), + register_name(reg),0,register_name(adr)); #else - printf("\t%s %s,%d@l(%s)\n",cload(size), - register_name(reg),0,register_name(adr)); -#endif - cext(sign,size,reg); - /* shift left */ - if ((i=bitpos+(32-bitsz))) - oprtc(LSHIFT,reg,list2(CONST,i)); - /* shift right */ - if ((i=bitsz-bitsize+(32-bitsz))) - oprtc(sign?RSHIFT:URSHIFT,reg,list2(CONST,i)); + printf("\t%s %s,%d@l(%s)\n",cload(size), + register_name(reg),0,register_name(adr)); +#endif + cext(sign,size,reg); + /* shift left */ + if ((i=bitpos+(32-bitsz))) + oprtc(LSHIFT,reg,list2(CONST,i)); + /* shift right */ + if ((i=bitsz-bitsize+(32-bitsz))) + oprtc(sign?RSHIFT:URSHIFT,reg,list2(CONST,i)); } } @@ -6746,15 +6746,15 @@ make_mask_and_or(int mask,int tmp,char *trn,char *crn,char *lrn) { // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); - code_const(~mask,tmp); - printf("\tor %s,%s,%s\n",trn,crn,trn); - /* do conjunction */ - printf("\tand %s,%s,%s\n",lrn,trn,lrn); - /* make or-mask */ - code_const(mask,tmp); - printf("\tand %s,%s,%s\n",trn,crn,trn); - /* do disjunction */ - printf("\tor %s,%s,%s\n",crn,trn,lrn); + code_const(~mask,tmp); + printf("\tor %s,%s,%s\n",trn,crn,trn); + /* do conjunction */ + printf("\tand %s,%s,%s\n",lrn,trn,lrn); + /* make or-mask */ + code_const(mask,tmp); + printf("\tand %s,%s,%s\n",trn,crn,trn); + /* do disjunction */ + printf("\tor %s,%s,%s\n",crn,trn,lrn); } extern void @@ -6773,59 +6773,59 @@ // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); if (l) { #if LONGLONG_CODE - // use_int(adr); - lvalue = get_lregister(); - lload(adr,lvalue,0); - use_longlong(value); - crn = lregister_name_low(value); - lrn = lregister_name_low(lvalue); - /* shift left */ - if ((i=bitsz-bitsize-bitpos)) - loprtc(LLSHIFT,value,list2(CONST,i)); - trn = register_name(tmp = get_register()); - if (bitpos+bitsize>=32) { - /* make and-mask lower */ - mask = make_mask(bitpos>=32?bitpos-32:0,bitpos+bitsize-32-1); - make_mask_and_or(mask,tmp,trn,crn,lrn); - } - crn = lregister_name_high(value); - lrn = lregister_name_high(lvalue); - if (bitpos<32) { - /* make and-mask upper */ - mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1); - make_mask_and_or(mask,tmp,trn,crn,lrn); - } - code_lassign(adr,value); - free_register(lvalue); - // free_register(adr); + // use_int(adr); + lvalue = get_lregister(); + lload(adr,lvalue,0); + use_longlong(value); + crn = lregister_name_low(value); + lrn = lregister_name_low(lvalue); + /* shift left */ + if ((i=bitsz-bitsize-bitpos)) + loprtc(LLSHIFT,value,list2(CONST,i)); + trn = register_name(tmp = get_register()); + if (bitpos+bitsize>=32) { + /* make and-mask lower */ + mask = make_mask(bitpos>=32?bitpos-32:0,bitpos+bitsize-32-1); + make_mask_and_or(mask,tmp,trn,crn,lrn); + } + crn = lregister_name_high(value); + lrn = lregister_name_high(lvalue); + if (bitpos<32) { + /* make and-mask upper */ + mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1); + make_mask_and_or(mask,tmp,trn,crn,lrn); + } + code_lassign(adr,value); + free_register(lvalue); + // free_register(adr); #endif } else { - // use_int(adr); - use_int(value); - lvalue = get_register(); + // use_int(adr); + use_int(value); + lvalue = get_register(); #ifdef __APPLE__ - printf("\t%s %s,lo16(%d)(%s)\n",cload(size), - register_name(lvalue),0,register_name(adr)); + printf("\t%s %s,lo16(%d)(%s)\n",cload(size), + register_name(lvalue),0,register_name(adr)); #else - printf("\t%s %s,%d@l(%s)\n",cload(size), - register_name(lvalue),0,register_name(adr)); -#endif - cext(sign,size,lvalue); - crn = register_name(value); - lrn = register_name(lvalue); - /* shift left */ - if ((i=bitsz-bitsize-bitpos)) - oprtc(LSHIFT,value,list2(CONST,i)); - trn = register_name(tmp = get_register()); - /* make and-mask */ - mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz)); - make_mask_and_or(mask,tmp,trn,crn,lrn); - free_register(lvalue); - code_assign(adr,size,value); + printf("\t%s %s,%d@l(%s)\n",cload(size), + register_name(lvalue),0,register_name(adr)); +#endif + cext(sign,size,lvalue); + crn = register_name(value); + lrn = register_name(lvalue); + /* shift left */ + if ((i=bitsz-bitsize-bitpos)) + oprtc(LSHIFT,value,list2(CONST,i)); + trn = register_name(tmp = get_register()); + /* make and-mask */ + mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz)); + make_mask_and_or(mask,tmp,trn,crn,lrn); + free_register(lvalue); + code_assign(adr,size,value); } if (tmp!=-1) free_register(tmp); if (use) { - code_bit_field(type,adr,USE_CREG); + code_bit_field(type,adr,USE_CREG); } } @@ -6836,26 +6836,26 @@ int tmp = -1; // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); if ((~mask|c)!=-1) { - trn = register_name(tmp=get_register()); - code_const((~mask|c),tmp); - /* do conjunction */ - printf("\tand %s,%s,%s\n",crn,trn,crn); + trn = register_name(tmp=get_register()); + code_const((~mask|c),tmp); + /* do conjunction */ + printf("\tand %s,%s,%s\n",crn,trn,crn); } /* make or-mask */ c = mask&c; if (c!=0) { - /* do disjunction */ - if (!((mask&c)&0xffff0000)) { + /* do disjunction */ + if (!((mask&c)&0xffff0000)) { #ifdef __APPLE__ - printf("\tori %s,%s,lo16(%d)\n",crn,crn,c); + printf("\tori %s,%s,lo16(%d)\n",crn,crn,c); #else - printf("\tori %s,%s,%d@l\n",crn,crn,c); -#endif - } else { - trn = register_name(tmp=get_register()); - code_const(c,tmp); - printf("\tor %s,%s,%s\n",crn,trn,crn); - } + printf("\tori %s,%s,%d@l\n",crn,crn,c); +#endif + } else { + trn = register_name(tmp=get_register()); + code_const(c,tmp); + printf("\tor %s,%s,%s\n",crn,trn,crn); + } } if (tmp!=-1) free_register(tmp); } @@ -6878,52 +6878,52 @@ // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); if (l) { #if LONGLONG_CODE - use_int(adr); - lvalue = get_lregister(); - lload(adr,lvalue,0); - crn = lregister_name_low(lvalue); - /* shift left */ - lc = lcadr(value); - if ((i=bitsz-bitsize-bitpos)) - lc <<= i; - if (bitpos+bitsize>=32) { - /* make and-mask lower */ - mask = make_mask(bitpos>=32?bitpos-32:0,bitpos+bitsize-32-1); - make_mask_and_or_const(mask,crn,(int)lc); - } - crn = lregister_name_high(lvalue); - if (bitpos<32) { - /* make and-mask upper */ - mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1); - make_mask_and_or_const(mask,crn,(int)(lc>>32)); - } - code_lassign(adr,lvalue); - free_register(lvalue); + use_int(adr); + lvalue = get_lregister(); + lload(adr,lvalue,0); + crn = lregister_name_low(lvalue); + /* shift left */ + lc = lcadr(value); + if ((i=bitsz-bitsize-bitpos)) + lc <<= i; + if (bitpos+bitsize>=32) { + /* make and-mask lower */ + mask = make_mask(bitpos>=32?bitpos-32:0,bitpos+bitsize-32-1); + make_mask_and_or_const(mask,crn,(int)lc); + } + crn = lregister_name_high(lvalue); + if (bitpos<32) { + /* make and-mask upper */ + mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1); + make_mask_and_or_const(mask,crn,(int)(lc>>32)); + } + code_lassign(adr,lvalue); + free_register(lvalue); #endif } else { - use_int(adr); - lvalue = get_register(); + use_int(adr); + lvalue = get_register(); #ifdef __APPLE__ - printf("\t%s %s,lo16(%d)(%s)\n",cload(size), - register_name(lvalue),0,register_name(adr)); + printf("\t%s %s,lo16(%d)(%s)\n",cload(size), + register_name(lvalue),0,register_name(adr)); #else - printf("\t%s %s,%d@l(%s)\n",cload(size), - register_name(lvalue),0,register_name(adr)); -#endif - cext(sign,size,lvalue); - crn = register_name(lvalue); - /* shift left */ - c = cadr(value); - if ((i=bitsz-bitsize-bitpos)) - c <<= i; - /* make and-mask */ - mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz)); - make_mask_and_or_const(mask,crn,c); - code_assign(adr,size,lvalue); - free_register(lvalue); + printf("\t%s %s,%d@l(%s)\n",cload(size), + register_name(lvalue),0,register_name(adr)); +#endif + cext(sign,size,lvalue); + crn = register_name(lvalue); + /* shift left */ + c = cadr(value); + if ((i=bitsz-bitsize-bitpos)) + c <<= i; + /* make and-mask */ + mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz)); + make_mask_and_or_const(mask,crn,c); + code_assign(adr,size,lvalue); + free_register(lvalue); } if (use) { - code_bit_field(type,adr,USE_CREG); + code_bit_field(type,adr,USE_CREG); } }