Mercurial > hg > CbC > old > device
changeset 781:b8cb4e1ac922
code segment arguments
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 19 Nov 2010 18:57:36 +0900 |
parents | c5315f472912 |
children | 003067098032 |
files | mc-code-i64.c mc-codegen.c |
diffstat | 2 files changed, 38 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-i64.c Fri Nov 19 16:39:48 2010 +0900 +++ b/mc-code-i64.c Fri Nov 19 18:57:36 2010 +0900 @@ -521,13 +521,13 @@ #define func_disp_offset (16) -#define code_disp_offset (16) +// #define code_disp_offset (16) #define arg_offset (16) #define arg_offset1 (0) #define ARG_LVAR_OFFSET 0x10000000 -#define code_disp_offset0 (-16) +#define code_disp_offset0 (4) // disp_offset int disp_offset = code_disp_offset0; @@ -542,6 +542,23 @@ static int reg_in_arg; static int max_func_args,max_func_arg_label; +static void +lvar(int l) +{ + if (is_code(fnptr)) { + if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ + printf("%d(%%rsp)",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + } else + printf("%d(%%rbp)",CODE_LVAR(l)); + } else if (l<0) { /* local variable */ + printf("%d(%%rbp)",FUNC_LVAR(l)); + } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ + printf("%d(%%rsp)",CALLER_ARG(l-ARG_LVAR_OFFSET)); + } else { /* callee's arguments */ + printf("%d-_%d(%%rbp)",CALLEE_ARG(l), lvar_offset_label); + } +} + /* function call stack frame prev esp @@ -622,23 +639,6 @@ } -static void -lvar(int l) -{ - if (is_code(fnptr)) { - if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("%d(%%rsp)",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); - } else - printf("%d(%%rbp)",CODE_LVAR(l)); - } else if (l<0) { /* local variable */ - printf("%d(%%rbp)",FUNC_LVAR(l)); - } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("%d(%%rsp)",CALLER_ARG(l-ARG_LVAR_OFFSET)); - } else { /* callee's arguments */ - printf("%d-_%d(%%rbp)",CALLEE_ARG(l), lvar_offset_label); - } -} - #define use_int(reg) if (reg==-1) reg=use_int0()
--- a/mc-codegen.c Fri Nov 19 16:39:48 2010 +0900 +++ b/mc-codegen.c Fri Nov 19 18:57:36 2010 +0900 @@ -1483,12 +1483,13 @@ int processing = 0; int use = 0; int envreg = 0; + int int_type = lp64?LONGLONG:INT; /* e1 = list4(FUNCTION,code_segment,arglist,ftype); */ if (env) { envreg = get_register_var(0); - g_expr_u(assign_expr0(envreg,env,INT,INT)); + g_expr_u(assign_expr0(envreg,env,int_type,int_type)); } /* まず、サイズを計算しながら、target を決まった形に落す。 */ @@ -1505,7 +1506,7 @@ } else if (ty==DOUBLE && (r = get_input_dregister_var(fregs,0,1,1))) { target=list5(r, target,ty,e2,0); fregs++; } else if ((ty==LONGLONG||ty==ULONGLONG) && (r = get_input_lregister_var(fregs,0,1))) { - target=list5(r, target,ty,e2,0); regs+=2; + target=list5(r, target,ty,e2,0); regs+=lp64?1:2; } else if (env) { while(car(e2)==RSTRUCT) e2=cadr(e2); /* @@ -1516,7 +1517,7 @@ */ g_expr_u(assign_expr0( list2(INDIRECT, - lp64?list3(LADD,rvalue_t(envreg,INT),llist2(LCONST,-arg_size-sz+disp_offset)) + lp64?list3(LADD,rvalue_t(envreg,LONGLONG),llist2(LCONST,-arg_size-sz+disp_offset)) :list3(ADD,rvalue_t(envreg,INT),list2(CONST,-arg_size-sz+disp_offset)) ), e2,ty,ty)); @@ -1525,6 +1526,8 @@ target=list5(list3n(LVAR,0,0), target,ty,e2,0); } /* keep arg space for register variables */ + // NMTBL n; + // arg_size = code_arg_alignment(arg_size, &n, ty, sz); arg_size += sz; #if DEBUG_PARALLEL_ASSIGN if (lsrc)printf("## target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz); @@ -1546,13 +1549,16 @@ /* 複雑な式を前もって計算しておく */ /* 必要なら局所変数を用いる。 */ /* 局所変数へのオフセットを覚えておく */ - + // int arg_offset = 0; for (e2 = target; e2; e2 = cadr(e2)) { t0=car(e2); s0=cadddr(e2); sz=size(ty=caddr(e2)); if(car(t0)==LVAR) { /* ここで、書込先アドレスを決める */ if (envreg) error(-1); + // NMTBL n; + // arg_offset = code_arg_alignment(arg_offset, &n, ty, sz); + // cadr(t0) = arg_offset - n.dsp; cadr(t0)=-arg_size; // disp_offset?! } arg_size-=sz; @@ -1576,6 +1582,8 @@ error(-1); } } + int int_unsigned = lp64?ULONGLONG:UNSIGNED; + int int_size = lp64?sizeof(long long):sizeof(int); if(is_writable(s0)) { if (sz>8 && car(s0)==LVAR && car(t0)==LVAR &&sz<ASSIGN_STRUCT_DIVIDE) { @@ -1584,23 +1592,25 @@ #if DEBUG_PARALLEL_ASSIGN if (lsrc)printf("## division sz %d\n",sz); #endif - caddr(e2) = UNSIGNED; + caddr(e2) = int_unsigned; caddddr(e2) = list3( cadddr(e2)=list3n(LVAR,cadr(s0),0), 0, size_of_int); #if DEBUG_PARALLEL_ASSIGN -if (lsrc)printf("## div 0 source %d ty %d+%d sz %d\n",car(s0),ty,cadr(s0),size_of_int); +if (lsrc)printf("## div 0 source %d ty %d+%d sz %d\n",car(s0),ty,cadr(s0),int_size); #endif - for(e4=size_of_int;e4<sz;) { + for(e4=int_size;e4<sz;) { cadr(e2) = list5(car(e2),cadr(e2), caddr(e2),cadddr(e2),caddddr(e2)); switch(sz-e4) { case 1: caddr(e2) = UCHAR; r = 1; break; case 2: case 3: caddr(e2) = USHORT; r = size_of_short; break; - default: caddr(e2) = UNSIGNED; r = size_of_int; + case 4: if (lp64) { caddr(e2) = UNSIGNED; r = size_of_int; break; } + default: if (lp64) { caddr(e2) = ULONGLONG; r = int_size; break; } + caddr(e2) = UNSIGNED; r = size_of_int; } - if (e4==size_of_int) e3=cadr(e2); + if (e4==int_size) e3=cadr(e2); car(e2) = list3n(LVAR,cadr(t0)+e4,0); caddddr(e2) = list3( cadddr(e2) = list3n(LVAR,cadr(s0)+e4,0),0, r);