| @@ -4589,7 +4589,9 @@ void lbuild(int t) · 4588 unmodified lines |
| 4589 | 4589 | vpop(); |
| 4590 | 4590 | } |
| 4591 | 4591 | |
| 4592 | | −/* rotate n first stack elements to the bottom */ |
| 4592 | +/* rotate n first stack elements to the bottom |
| 4593 | + I1 ... In -> I2 ... In I1 [top is right] |
| 4594 | +*/ |
| 4593 | 4595 | void vrotb(int n) |
| 4594 | 4596 | { |
| 4595 | 4597 | int i; |
| @@ -4601,6 +4603,20 @@ void vrotb(int n) · 5 unmodified lines |
| 4601 | 4603 | vtop[0] = tmp; |
| 4602 | 4604 | } |
| 4603 | 4605 | |
| 4606 | +/* rotate n first stack elements to the top |
| 4607 | + I1 ... In -> In I1 ... I(n-1) [top is right] |
| 4608 | + */ |
| 4609 | +void vrott(int n) |
| 4610 | +{ |
| 4611 | + int i; |
| 4612 | + SValue tmp; |
| 4613 | + |
| 4614 | + tmp = vtop[0]; |
| 4615 | + for(i = 0;i < n - 1; i++) |
| 4616 | + vtop[-i] = vtop[-i - 1]; |
| 4617 | + vtop[-n + 1] = tmp; |
| 4618 | +} |
| 4619 | + |
| 4604 | 4620 | /* pop stack value */ |
| 4605 | 4621 | void vpop(void) |
| 4606 | 4622 | { |
| @@ -4665,7 +4681,6 @@ void gen_opl(int op) · 58 unmodified lines |
| 4665 | 4681 | { |
| 4666 | 4682 | int t, a, b, op1, c, i; |
| 4667 | 4683 | int func; |
| 4668 | | − GFuncContext gf; |
| 4669 | 4684 | SValue tmp; |
| 4670 | 4685 | |
| 4671 | 4686 | switch(op) { |
| @@ -4683,11 +4698,9 @@ void gen_opl(int op) · 11 unmodified lines |
| 4683 | 4698 | func = TOK___umoddi3; |
| 4684 | 4699 | gen_func: |
| 4685 | 4700 | /* call generic long long function */ |
| 4686 | | − gfunc_start(&gf, FUNC_CDECL); |
| 4687 | | − gfunc_param(&gf); |
| 4688 | | − gfunc_param(&gf); |
| 4689 | 4701 | vpush_global_sym(&func_old_type, func); |
| 4690 | | − gfunc_call(&gf); |
| 4702 | + vrott(3); |
| 4703 | + gfunc_call(2); |
| 4691 | 4704 | vpushi(0); |
| 4692 | 4705 | vtop->r = REG_IRET; |
| 4693 | 4706 | vtop->r2 = REG_LRET; |
| @@ -5227,20 +5240,17 @@ void gen_op(int op) · 533 unmodified lines |
| 5227 | 5240 | /* generic itof for unsigned long long case */ |
| 5228 | 5241 | void gen_cvt_itof1(int t) |
| 5229 | 5242 | { |
| 5230 | | − GFuncContext gf; |
| 5231 | | − |
| 5232 | 5243 | if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == |
| 5233 | 5244 | (VT_LLONG | VT_UNSIGNED)) { |
| 5234 | 5245 | |
| 5235 | | − gfunc_start(&gf, FUNC_CDECL); |
| 5236 | | − gfunc_param(&gf); |
| 5237 | 5246 | if (t == VT_FLOAT) |
| 5238 | 5247 | vpush_global_sym(&func_old_type, TOK___ulltof); |
| 5239 | 5248 | else if (t == VT_DOUBLE) |
| 5240 | 5249 | vpush_global_sym(&func_old_type, TOK___ulltod); |
| 5241 | 5250 | else |
| 5242 | 5251 | vpush_global_sym(&func_old_type, TOK___ulltold); |
| 5243 | | − gfunc_call(&gf); |
| 5252 | + vrott(2); |
| 5253 | + gfunc_call(1); |
| 5244 | 5254 | vpushi(0); |
| 5245 | 5255 | vtop->r = REG_FRET; |
| 5246 | 5256 | } else { |
| @@ -5251,21 +5261,19 @@ void gen_cvt_itof1(int t) · 4 unmodified lines |
| 5251 | 5261 | /* generic ftoi for unsigned long long case */ |
| 5252 | 5262 | void gen_cvt_ftoi1(int t) |
| 5253 | 5263 | { |
| 5254 | | − GFuncContext gf; |
| 5255 | 5264 | int st; |
| 5256 | 5265 | |
| 5257 | 5266 | if (t == (VT_LLONG | VT_UNSIGNED)) { |
| 5258 | 5267 | /* not handled natively */ |
| 5259 | | − gfunc_start(&gf, FUNC_CDECL); |
| 5260 | 5268 | st = vtop->type.t & VT_BTYPE; |
| 5261 | | − gfunc_param(&gf); |
| 5262 | 5269 | if (st == VT_FLOAT) |
| 5263 | 5270 | vpush_global_sym(&func_old_type, TOK___fixunssfdi); |
| 5264 | 5271 | else if (st == VT_DOUBLE) |
| 5265 | 5272 | vpush_global_sym(&func_old_type, TOK___fixunsdfdi); |
| 5266 | 5273 | else |
| 5267 | 5274 | vpush_global_sym(&func_old_type, TOK___fixunsxfdi); |
| 5268 | | − gfunc_call(&gf); |
| 5275 | + vrott(2); |
| 5276 | + gfunc_call(1); |
| 5269 | 5277 | vpushi(0); |
| 5270 | 5278 | vtop->r = REG_IRET; |
| 5271 | 5279 | vtop->r2 = REG_LRET; |
| @@ -5700,7 +5708,6 @@ static void gen_assign_cast(CType *dt) · 428 unmodified lines |
| 5700 | 5708 | void vstore(void) |
| 5701 | 5709 | { |
| 5702 | 5710 | int sbt, dbt, ft, r, t, size, align, bit_size, bit_pos, rc, delayed_cast; |
| 5703 | | − GFuncContext gf; |
| 5704 | 5711 | |
| 5705 | 5712 | ft = vtop[-1].type.t; |
| 5706 | 5713 | sbt = vtop->type.t & VT_BTYPE; |
| @@ -5720,25 +5727,24 @@ void vstore(void) · 13 unmodified lines |
| 5720 | 5727 | /* structure assignment : generate memcpy */ |
| 5721 | 5728 | /* XXX: optimize if small size */ |
| 5722 | 5729 | if (!nocode_wanted) { |
| 5723 | | − vdup(); |
| 5724 | | − gfunc_start(&gf, FUNC_CDECL); |
| 5725 | | − /* type size */ |
| 5726 | 5730 | size = type_size(&vtop->type, &align); |
| 5727 | | − vpushi(size); |
| 5728 | | − gfunc_param(&gf); |
| 5729 | | − /* source */ |
| 5731 | + |
| 5732 | + vpush_global_sym(&func_old_type, TOK_memcpy); |
| 5733 | + |
| 5734 | + /* destination */ |
| 5735 | + vpushv(vtop - 2); |
| 5730 | 5736 | vtop->type.t = VT_INT; |
| 5731 | 5737 | gaddrof(); |
| 5732 | | − gfunc_param(&gf); |
| 5733 | | − /* destination */ |
| 5734 | | − vswap(); |
| 5738 | + /* source */ |
| 5739 | + vpushv(vtop - 2); |
| 5735 | 5740 | vtop->type.t = VT_INT; |
| 5736 | 5741 | gaddrof(); |
| 5737 | | − gfunc_param(&gf); |
| 5742 | + /* type size */ |
| 5743 | + vpushi(size); |
| 5744 | + gfunc_call(3); |
| 5738 | 5745 | |
| 5739 | | − save_regs(0); |
| 5740 | | − vpush_global_sym(&func_old_type, TOK_memcpy); |
| 5741 | | − gfunc_call(&gf); |
| 5746 | + vswap(); |
| 5747 | + vpop(); |
| 5742 | 5748 | } else { |
| 5743 | 5749 | vswap(); |
| 5744 | 5750 | vpop(); |
| @@ -6436,7 +6442,7 @@ static void indir(void) · 691 unmodified lines |
| 6436 | 6442 | } |
| 6437 | 6443 | |
| 6438 | 6444 | /* pass a parameter to a function and do type checking and casting */ |
| 6439 | | −void gfunc_param_typed(GFuncContext *gf, Sym *func, Sym *arg) |
| 6445 | +static void gfunc_param_typed(Sym *func, Sym *arg) |
| 6440 | 6446 | { |
| 6441 | 6447 | int func_type; |
| 6442 | 6448 | CType type; |
| @@ -6454,11 +6460,6 @@ void gfunc_param_typed(GFuncContext *gf, Sym *func, Sym *arg) · 11 unmodified lines |
| 6454 | 6460 | } else { |
| 6455 | 6461 | gen_assign_cast(&arg->type); |
| 6456 | 6462 | } |
| 6457 | | − if (!nocode_wanted) { |
| 6458 | | − gfunc_param(gf); |
| 6459 | | − } else { |
| 6460 | | − vpop(); |
| 6461 | | − } |
| 6462 | 6463 | } |
| 6463 | 6464 | |
| 6464 | 6465 | /* parse an expression of the form '(type)' or '(expr)' and return its |
| @@ -6489,7 +6490,6 @@ static void unary(void) · 24 unmodified lines |
| 6489 | 6490 | int n, t, align, size, r; |
| 6490 | 6491 | CType type; |
| 6491 | 6492 | Sym *s; |
| 6492 | | − GFuncContext gf; |
| 6493 | 6493 | AttributeDef ad; |
| 6494 | 6494 | |
| 6495 | 6495 | /* XXX: GCC 2.95.3 does not generate a table although it should be |
| @@ -6764,6 +6764,7 @@ static void unary(void) · 268 unmodified lines |
| 6764 | 6764 | } else if (tok == '(') { |
| 6765 | 6765 | SValue ret; |
| 6766 | 6766 | Sym *sa; |
| 6767 | + int nb_args; |
| 6767 | 6768 | |
| 6768 | 6769 | /* function call */ |
| 6769 | 6770 | if ((vtop->type.t & VT_BTYPE) != VT_FUNC) { |
| @@ -6781,63 +6782,9 @@ static void unary(void) · 11 unmodified lines |
| 6781 | 6782 | } |
| 6782 | 6783 | /* get return type */ |
| 6783 | 6784 | s = vtop->type.ref; |
| 6784 | | − if (!nocode_wanted) { |
| 6785 | | − save_regs(0); /* save used temporary registers */ |
| 6786 | | − gfunc_start(&gf, s->r); |
| 6787 | | − } |
| 6788 | 6785 | next(); |
| 6789 | 6786 | sa = s->next; /* first parameter */ |
| 6790 | | −#ifdef INVERT_FUNC_PARAMS |
| 6791 | | − { |
| 6792 | | − int parlevel; |
| 6793 | | − Sym *args, *s1; |
| 6794 | | − ParseState saved_parse_state; |
| 6795 | | − TokenString str; |
| 6796 | | − |
| 6797 | | − /* read each argument and store it on a stack */ |
| 6798 | | − args = NULL; |
| 6799 | | − if (tok != ')') { |
| 6800 | | − for(;;) { |
| 6801 | | − tok_str_new(&str); |
| 6802 | | − parlevel = 0; |
| 6803 | | − while ((parlevel > 0 || (tok != ')' && tok != ',')) && |
| 6804 | | − tok != TOK_EOF) { |
| 6805 | | − if (tok == '(') |
| 6806 | | − parlevel++; |
| 6807 | | − else if (tok == ')') |
| 6808 | | − parlevel--; |
| 6809 | | − tok_str_add_tok(&str); |
| 6810 | | − next(); |
| 6811 | | − } |
| 6812 | | − tok_str_add(&str, -1); /* end of file added */ |
| 6813 | | − tok_str_add(&str, 0); |
| 6814 | | − s1 = sym_push2(&args, 0, 0, (int)str.str); |
| 6815 | | − s1->next = sa; /* add reference to argument */ |
| 6816 | | − if (sa) |
| 6817 | | − sa = sa->next; |
| 6818 | | − if (tok == ')') |
| 6819 | | − break; |
| 6820 | | − skip(','); |
| 6821 | | − } |
| 6822 | | − } |
| 6823 | | − |
| 6824 | | − /* now generate code in reverse order by reading the stack */ |
| 6825 | | − save_parse_state(&saved_parse_state); |
| 6826 | | − while (args) { |
| 6827 | | − macro_ptr = (int *)args->c; |
| 6828 | | − next(); |
| 6829 | | − expr_eq(); |
| 6830 | | − if (tok != -1) |
| 6831 | | − expect("',' or ')'"); |
| 6832 | | − gfunc_param_typed(&gf, s, args->next); |
| 6833 | | − s1 = args->prev; |
| 6834 | | − tok_str_free((int *)args->c); |
| 6835 | | − tcc_free(args); |
| 6836 | | − args = s1; |
| 6837 | | − } |
| 6838 | | − restore_parse_state(&saved_parse_state); |
| 6839 | | − } |
| 6840 | | −#endif |
| 6787 | + nb_args = 0; |
| 6841 | 6788 | /* compute first implicit argument if a structure is returned */ |
| 6842 | 6789 | if ((s->type.t & VT_BTYPE) == VT_STRUCT) { |
| 6843 | 6790 | /* get some space for the returned structure */ |
| @@ -6849,10 +6796,7 @@ static void unary(void) · 5 unmodified lines |
| 6849 | 6796 | problems */ |
| 6850 | 6797 | vseti(VT_LOCAL, loc); |
| 6851 | 6798 | ret.c = vtop->c; |
| 6852 | | − if (!nocode_wanted) |
| 6853 | | − gfunc_param(&gf); |
| 6854 | | − else |
| 6855 | | − vtop--; |
| 6799 | + nb_args++; |
| 6856 | 6800 | } else { |
| 6857 | 6801 | ret.type = s->type; |
| 6858 | 6802 | ret.r2 = VT_CONST; |
| @@ -6866,11 +6810,11 @@ static void unary(void) · 7 unmodified lines |
| 6866 | 6810 | } |
| 6867 | 6811 | ret.c.i = 0; |
| 6868 | 6812 | } |
| 6869 | | −#ifndef INVERT_FUNC_PARAMS |
| 6870 | 6813 | if (tok != ')') { |
| 6871 | 6814 | for(;;) { |
| 6872 | 6815 | expr_eq(); |
| 6873 | | − gfunc_param_typed(&gf, s, sa); |
| 6816 | + gfunc_param_typed(s, sa); |
| 6817 | + nb_args++; |
| 6874 | 6818 | if (sa) |
| 6875 | 6819 | sa = sa->next; |
| 6876 | 6820 | if (tok == ')') |
| @@ -6878,14 +6822,14 @@ static void unary(void) · 1 unmodified line |
| 6878 | 6822 | skip(','); |
| 6879 | 6823 | } |
| 6880 | 6824 | } |
| 6881 | | −#endif |
| 6882 | 6825 | if (sa) |
| 6883 | 6826 | error("too few arguments to function"); |
| 6884 | 6827 | skip(')'); |
| 6885 | | − if (!nocode_wanted) |
| 6886 | | − gfunc_call(&gf); |
| 6887 | | − else |
| 6888 | | − vtop--; |
| 6828 | + if (!nocode_wanted) { |
| 6829 | + gfunc_call(nb_args); |
| 6830 | + } else { |
| 6831 | + vtop -= (nb_args + 1); |
| 6832 | + } |
| 6889 | 6833 | /* return value */ |
| 6890 | 6834 | vsetc(&ret.type, ret.r, &ret.c); |
| 6891 | 6835 | vtop->r2 = ret.r2; |
| @@ -7793,20 +7737,14 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 901 unmodified lines |
| 7793 | 7737 | /* put zeros for variable based init */ |
| 7794 | 7738 | static void init_putz(CType *t, Section *sec, unsigned long c, int size) |
| 7795 | 7739 | { |
| 7796 | | − GFuncContext gf; |
| 7797 | | − |
| 7798 | 7740 | if (sec) { |
| 7799 | 7741 | /* nothing to do because globals are already set to zero */ |
| 7800 | 7742 | } else { |
| 7801 | | − gfunc_start(&gf, FUNC_CDECL); |
| 7802 | | − vpushi(size); |
| 7803 | | − gfunc_param(&gf); |
| 7804 | | − vpushi(0); |
| 7805 | | − gfunc_param(&gf); |
| 7806 | | − vseti(VT_LOCAL, c); |
| 7807 | | − gfunc_param(&gf); |
| 7808 | 7743 | vpush_global_sym(&func_old_type, TOK_memset); |
| 7809 | | − gfunc_call(&gf); |
| 7744 | + vseti(VT_LOCAL, c); |
| 7745 | + vpushi(0); |
| 7746 | + vpushi(size); |
| 7747 | + gfunc_call(3); |
| 7810 | 7748 | } |
| 7811 | 7749 | } |
| 7812 | 7750 | |