changeset 514:a2047e4555be

inline continue....
author kono
date Mon, 26 Dec 2005 09:18:31 +0900
parents 4c2607e72ab5
children 3d921f7a8e74
files Changes mc-codegen.c mc-inline.c
diffstat 3 files changed, 56 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Dec 26 00:45:46 2005 +0900
+++ b/Changes	Mon Dec 26 09:18:31 2005 +0900
@@ -7560,4 +7560,21 @@
 
 pfdecl で struct_return は、なんとかしてるの?
 
-
+やっぱ、ret() で、 code_set_return_register(1);
+は、だめじゃん。if 文の分岐で値を同じレジスタ
+に置くためには.... ?: と同じ方法か。
+
+code_get_fixed_creg ねぇ。
+        t = code_get_fixed_creg(USE_CREG,d);
+        gen_jmp(e3=fwdlabel());
+        fwddef(e2);
+        t1=g_expr0(cadddr(e1));
+        code_set_fixed_creg(t,1,d);
+ですか。
+
+
+
+
+
+
+
--- a/mc-codegen.c	Mon Dec 26 00:45:46 2005 +0900
+++ b/mc-codegen.c	Mon Dec 26 09:18:31 2005 +0900
@@ -2438,8 +2438,10 @@
 extern void
 ret(void)
 {       
-    if (!chk)
-	code_set_return_register(1);
+    if (!is_inline(fnptr))  {
+	if (!chk)
+	    code_set_return_register(1);
+    }
     gen_jmp(retlabel); 
 }
 
--- a/mc-inline.c	Mon Dec 26 00:45:46 2005 +0900
+++ b/mc-inline.c	Mon Dec 26 09:18:31 2005 +0900
@@ -12,6 +12,8 @@
 static int pvartable;
 static int pdisp;
 
+static int ret_register,ret_reg_mode;
+
 /*
     Basic code generator from parse tree
  */
@@ -267,7 +269,7 @@
  
 extern void
 st_return(int e1){
-    int e;
+    int e,t;
 
     if (!cslabel) gen_jmp(cslabel = fwdlabel());
     if(!(e=caddr(e1))) {
@@ -277,6 +279,7 @@
     }
     // conv->return_();
     if (struct_return) {
+	// certainly this is wrong for inline 
 	if ((car(type)==STRUCT || car(type)==UNION)&&
 		size(type)==cadr(struct_return)) {
 	    if(car(e)==RSTRUCT && car(cadr(e))==FUNCTION) {
@@ -290,17 +293,29 @@
 		e1 = cadr(struct_return); /* size */
 		g_expr_u(list4(STASS,rvalue(car(struct_return)),e,e1));
 	    }
+	    if (ret_reg_mode==0) {
+		ret_reg_mode=1;
+		ret_register = code_get_fixed_creg(USE_CREG,INT);
+	    } else {
+		code_set_fixed_creg(ret_register,1,INT);
+	    }
 	} else {
 	    error(TYERR); /* should check compatible */
 	}
     } else {
 	g_expr(correct_type(e,cadr(fnptr->ty)));
+	t = type_value(cadr(fnptr->ty));
+	if (ret_reg_mode==0) {
+	    ret_reg_mode=1;
+	    ret_register = code_get_fixed_creg(USE_CREG,t);
+	} else {
+	    code_set_fixed_creg(ret_register,1,t);
+	}
     }
     // conv->return_end_();
     retpending = 1;
 }
 
- 
 extern void
 st_goto(int e){
     NMTBL *nlist,*nptr0;
@@ -421,7 +436,7 @@
     int ftype = cadddr(e);
     int e3;
     for (e3 = arglist; e3; e3 = cadr(e3)) {
-	newargs = list3( pexpr(car(e3)), cadr(e3), caddr(e3));
+	newargs = list3( pexpr(car(e3)), newargs, caddr(e3));
     }
     newargs = reverse0(newargs);
     return list4(car(e),e1,newargs,ftype);
@@ -970,12 +985,15 @@
 extern int
 gen_inline(int e)
 {
+    // these saved value should be some struct
+    int sretlabel;
+    NMTBL *sfnptr;
     int svartable = pvartable;
-    int sretlabel = retlabel;
     int sretcont = retcont;
     int scslabel = cslabel;
-    NMTBL *sfnptr = fnptr;
     int sdisp = pdisp;
+    int sret_register = ret_register;
+    int sret_reg_mode = ret_reg_mode;
 
     int narg,arg;
     NMTBL *n = (NMTBL*)cadr(cadr(e));
@@ -985,20 +1003,25 @@
     int e2,e3,t,e4,dots;
     int ret_type = function_type(cadddr(e),&dots);
 
+    // checkret();
+
+    sretlabel = retlabel;
+    sfnptr = fnptr;
     retcont = 0;
     cslabel = -1;
     retpending = 0;
-
-    checkret();
+    ret_reg_mode = 0;
+    ret_register = 5555;
+    retlabel = fwdlabel();
 
     enter_scope(); // to make label scope happy
-    retlabel = fwdlabel();
 
     fnptr = n;   // st_return see this
     pvartable = p_vartable(e,arg_disp,caddr(e1));
     /* inline function arguments */
     narg = 0;
     for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
+    // for (e3 = e1 = caddr(e); e3; e3 = cadr(e3)) {
         t=caddr(e3);  // type
 	e4 = car(e3);
 	if (is_const(e4) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
@@ -1020,6 +1043,7 @@
     else
 	g_expr_u(e2);
     fwddef(retlabel);
+    control=1;
 
     if (retcont) error(STERR); // inline can't handle return/environment
 
@@ -1028,6 +1052,8 @@
     retlabel = sretlabel;
     retcont = sretcont;
     cslabel = scslabel;
+    ret_register = sret_register;
+    ret_reg_mode = sret_reg_mode;
 
     return ret_type;
 }