Mercurial > hg > CbC > old > device
changeset 813:a1dff13fefbf
i64 stdarg simple (?)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 25 Nov 2010 13:07:18 +0900 |
parents | 639064060223 |
children | 1dad60c0a073 |
files | mc-code-i64.c mc-codegen.c |
diffstat | 2 files changed, 51 insertions(+), 96 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-i64.c Thu Nov 25 12:15:56 2010 +0900 +++ b/mc-code-i64.c Thu Nov 25 13:07:18 2010 +0900 @@ -47,34 +47,39 @@ long float_last; \\\n\ long stack_top; \\\n\ long arg; \\\n\ -} __builtin_va_list1, *__builtin_va_list; \\\n\ + long top; \\\n\ +} __builtin_va_list; \\\n\ \\\n\ -#define __builtin_va_start(ap,v) \\\n\ +#define __builtin_va_start(__ap0,v) \\\n\ { \\\n\ - ap = &__my_va_list; \\\n\ - ap->float_first = ap->long_last-8; \\\n\ - long adr = (long)&v; \\\n\ - if (adr >= ap->stack_top) ap->arg = ap->float_first = adr; \\\n\ + __builtin_va_list *__ap = &__ap0; \\\n\ + long __top = __ap->top = (long)&__my_va_list; \\\n\ + __ap->long_last = __top +8*6; \\\n\ + __ap->float_first = __ap->long_last; \\\n\ + __asm__ __volatile__(\" movq %%rbp, %0\" : \"=r\" __ap->stack_top);\\\n\ + long __adr = (long)(&v) + sizeof(v); \\\n\ + if (__adr >= __ap->stack_top) __ap->arg = __ap->float_first = __adr; \\\n\ if (__builtin_types_compatible_p(typeof(v),double)) \\\n\ - ap->float_first = adr; \\\n\ - ap->arg = adr; \\\n\ + __ap->float_first = __adr; \\\n\ + __ap->arg = __adr; \\\n\ } \\\n\ \n\ -#define __builtin_va_arg(ap,type) ({ \\\n\ - long arg; \\\n\ +#define __builtin_va_arg(__ap0,type) ({ \\\n\ + __builtin_va_list *__ap = &__ap0; \\\n\ + long __arg; \\\n\ if (__builtin_types_compatible_p(type,double) \\\n\ - && ap->float_first < ap->stack_top) { \\\n\ - ap->float_first = ap->float_first+8; \\\n\ - if (ap->float_first==ap->float_last+16) \\\n\ - ap->float_first = ap->stack_top;\\\n\ - arg = ap->float_first; \\\n\ + && __ap->float_first < __ap->stack_top) { \\\n\ + __arg = __ap->float_first; \\\n\ + __ap->float_first = __ap->float_first+8; \\\n\ + if (__ap->float_first==__ap->float_last) \\\n\ + __ap->float_first = __ap->stack_top+16;\\\n\ } else { \\\n\ - ap->arg = ap->arg+8; \\\n\ - if (ap->arg==ap->long_last) \\\n\ - ap->arg = ap->stack_top; \\\n\ - arg = ap->arg; \\\n\ + __arg = __ap->arg; \\\n\ + __ap->arg = __ap->arg+8; \\\n\ + if (__ap->arg==__ap->long_last) \\\n\ + __ap->arg = __ap->stack_top+16; \\\n\ } \\\n\ - *((type *)(arg)); \\\n\ + *((type *)(__arg)); \\\n\ }) \\\n\ \n" @@ -1240,53 +1245,6 @@ // my_func_args = offset; } -static void -def_va_list_truct(int long_last, int float_last) -{ - int stype = type; - int smode = mode; - int sstmode = stmode; - NMTBL *n; - - if (!parse_mode || inmode) { - NMTBL *nptr =name_space_search(get_name("__builtin_va_list1",0,NONDEF),0); - if (!nptr) error(-1); - type = nptr->ty; - typedefed=glist3n(TYPEDEF,typedefed,nptr); - mode = LDECL; - stmode = 0; - n = def(lsearch("__my_va_list",0),0); - } - - // ssetup va_list structure - // __my_va_list is defined as local in code_arg_register -/* -__builtin_va_list1 __my_va_list; - long long_last; \n\ - long float_first; \n\ - long float_last; \n\ - long stack_top; \n\ - */ - if (parse_mode && inmode) { - parse = list5n(ST_DECL,parse,list3(mode,0,0),0,n); - // long_last - parse = list3(ST_COMP,parse,assign_expr0( list3n(IVAR,n->dsp,n),list2(ADDRESS,list3n(LVAR,long_last,0)),LONGLONG,LONGLONG)); - // float_last - parse = list3(ST_COMP,parse,assign_expr0( list3(LADD,list3n(IVAR,n->dsp,n),llist2(LCONST,16)),list2(ADDRESS,list3n(LVAR,float_last,0)),LONGLONG,LONGLONG)); - // stack_top - parse = list3(ST_COMP,parse,assign_expr0( list3(LADD,list3n(IVAR,n->dsp,n),llist2(LCONST,24)),list3(LADD,list2(LREGISTER,REG_EBP),llist2(LCONST,16)),LONGLONG,LONGLONG)); - } else if (!parse_mode && !inmode) { - // long_last - g_expr_u(assign_expr0( list3n(LVAR,n->dsp,n),list2(ADDRESS,list3n(LVAR,long_last,0)),LONGLONG,LONGLONG)); - // float_last - g_expr_u(assign_expr0( list3n(LVAR,n->dsp+16,n),list2(ADDRESS,list3n(LVAR,float_last,0)),LONGLONG,LONGLONG)); - // stack_top - g_expr_u(assign_expr0( list3n(LVAR,n->dsp+24,n),list3(LADD,list2(LREGISTER,REG_EBP),llist2(LCONST,16)),LONGLONG,LONGLONG)); - } - mode = smode; - type = stype; - stmode = sstmode; -} void code_arg_register(NMTBL *fnptr, int in) @@ -1302,6 +1260,14 @@ arg_offset_v = 0; function_type(fnptr->ty,&dots); + if (dots && (in || !parse_mode)) { + type = INT; + mode = LDECL; + stmode = 0; + n = def(lsearch("__my_va_list",0),0); + n->dsp = 0; // first argument + } + if (in) return; while (args) { // we should use increment_arg @@ -1310,41 +1276,33 @@ type = n->ty; if (type==LONGLONG||type==ULONGLONG) { // scalar includes LONGLONG, check first if ((reg = get_input_lregister_var(reg_var,n,is_code0))) { - if (!in) { - n->sc = LREGISTER; - n->dsp = cadr(reg); - regs[n->dsp]= INPUT_REG; - } + n->sc = LREGISTER; + n->dsp = cadr(reg); + regs[n->dsp]= INPUT_REG; reg_var+=1; arg_offset_v += SIZE_OF_LONGLONG; // (caddr(args)=size(type)); } } else if (scalar(type)) { if ((reg = get_input_register_var(reg_var,n,is_code0))) { - if (!in) { - n->sc = (car(type)==POINTER && lp64) ?LREGISTER:REGISTER; - n->dsp = cadr(reg); - regs[n->dsp]= INPUT_REG; - } + n->sc = (car(type)==POINTER && lp64) ?LREGISTER:REGISTER; + n->dsp = cadr(reg); + regs[n->dsp]= INPUT_REG; reg_var++; arg_offset_v += SIZE_OF_LONGLONG; // (caddr(args)=size(type)); } } else if (type==FLOAT) { if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { - if (!in) { - n->sc = FREGISTER; - n->dsp = cadr(reg); - regs[n->dsp]= INPUT_REG; - } + n->sc = FREGISTER; + n->dsp = cadr(reg); + regs[n->dsp]= INPUT_REG; freg_var++; arg_offset_v += SIZE_OF_LONGLONG; // (caddr(args)=size(type)); } } else if (type==DOUBLE) { if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { - if (!in) { - n->sc = DREGISTER; - n->dsp = cadr(reg); - regs[n->dsp]= INPUT_REG; - } + n->sc = DREGISTER; + n->dsp = cadr(reg); + regs[n->dsp]= INPUT_REG; freg_var++; arg_offset_v += SIZE_OF_LONGLONG; // (caddr(args)=size(type)); } @@ -1357,18 +1315,12 @@ arg_offset_v = MAX_INPUT_REGISTER_VAR*SIZE_OF_LONGLONG + MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE; - - int long_last = -arg_offset_v + (MAX_INPUT_REGISTER_VAR)*SIZE_OF_LONGLONG; - int float_last = long_last + (MAX_INPUT_DREGISTER_VAR)*SIZE_OF_DOUBLE; - - def_va_list_truct(long_last,float_last); #ifndef __APPLE__ - if (!in) printf(".set %s%d, %d\n",lpfx, arg_offset_label, arg_offset_v+ arg_offset); #endif } - if (!in) code_save_input_registers(dots, arg_offset_v); + code_save_input_registers(dots, arg_offset_v); } } @@ -4850,6 +4802,8 @@ { if (car(rstr)==REGISTER) { printf("%s",register_name(cadr(rstr),0)); + } else if (car(rstr)==LREGISTER) { + printf("%s",register_name(cadr(rstr),0)); } else if (car(rstr)==CONST) { printf("%d",cadr(rstr)); } else if (car(rstr)==FNAME) {
--- a/mc-codegen.c Thu Nov 25 12:15:56 2010 +0900 +++ b/mc-codegen.c Thu Nov 25 13:07:18 2010 +0900 @@ -3275,6 +3275,7 @@ int repl0; int assign = 0; char *p; + int ty = lp64?LONGLONG:INT; e = reverse0(e); @@ -3283,7 +3284,7 @@ e1 = car(e); e = cadr(e); repl = code_asm_operand(p,e1,ASM_OUTPUT,repl,0,0); if (!chk && repl && car(car(repl))==REGISTER) { - assign = list2(assign_expr0(e1,car(repl),INT,INT),assign); + assign = list2(assign_expr0(e1,car(repl),ty,ty),assign); } } repl0 = repl; @@ -3293,7 +3294,7 @@ e1 = car(e); e = cadr(e); repl = code_asm_operand(p,e1,ASM_INPUT,repl,n,repl0); if (!chk && repl && car(car(repl))==REGISTER) { - g_expr_u(assign_expr0(car(repl),e1,INT,INT)); + g_expr_u(assign_expr0(car(repl),e1,ty,ty)); } }