diff mc-code-powerpc.c @ 305:117baacd1ed0

stdarg powerpc passed except long long (macro problem)
author kono
date Wed, 09 Jun 2004 15:18:32 +0900
parents 9df8aa0497ea
children fda28752d301
line wrap: on
line diff
--- a/mc-code-powerpc.c	Tue Jun 08 16:40:32 2004 +0900
+++ b/mc-code-powerpc.c	Wed Jun 09 15:18:32 2004 +0900
@@ -230,7 +230,7 @@
 #endif
 
 static void code_save_stacks();
-static void code_save_input_registers();
+static void code_save_input_registers(int dots);
 static void clear_ptr_cache_reg(int r);
 static void    set_ireg(int,int);
 static void    set_freg(int,int);
@@ -396,6 +396,8 @@
 #define __BIG_ENDIAN__ 1\n\
 #define __STDC__ 1\n\
 #define __builtin_va_list int\n\
+#define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg))\n\
+#define __builtin_va_arg(ap,type)  (*((type *)ap)++)\n\
 ";
 
 void
@@ -453,7 +455,9 @@
     int reg;
     int i;
     int is_code0 = is_code(fnptr);
-
+    int dots;
+
+    function_type(fnptr->ty,&dots);
     while (args) {
         /* process in reverse order */
         n = (NMTBL*)caddr(args);
@@ -496,7 +500,7 @@
         args = cadr(args);
     }
     if (is_function(fnptr))
-	code_save_input_registers();
+	code_save_input_registers(dots);
 }
 
 
@@ -1713,7 +1717,7 @@
 }
 
 void
-code_save_input_registers()
+code_save_input_registers(int dots)
 {
     int args;
     NMTBL *n;
@@ -1724,6 +1728,7 @@
     /* fnptr->dsp=list4(type,fnptr->dsp,(int)n,0); */
     int reg_offset = 0;
     int offset = 0;
+    int reg_var = 0;
 
     for(args = fnptr->dsp;args;args = cadr(args)) {
 	n = (NMTBL *)caddr(args);
@@ -1736,6 +1741,7 @@
 	    offset+=SIZE_OF_INT;
 	    t = INT;
 	    reg += reg_offset; /* for duplicated floating point argument */
+	    reg_var++;
 	} else if (tag==DREGISTER) {
 	    /* regs[reg]==INPUT_REG case should be considered */
 	    n->dsp = offset;
@@ -1743,22 +1749,33 @@
 	    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 (tag==LREGISTER) {
 	    /* regs[reg]==INPUT_REG case should be considered */
 	    n->dsp = offset;
 	    t = n->ty;
 	    offset+=SIZE_OF_LONGLONG; reg_offset+=2;
+	    reg_var += 2;
 	} else {
 	    offset += size(n->ty);
 	    continue;
 	}
 	n->sc  = LVAR;
 	lvar = list2(LVAR,n->dsp);
-	g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),n->ty,t));
+	g_expr_u(assign_expr0(
+	    list2(LVAR,n->dsp),list3(tag,reg,(int)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(
+		list2(LVAR,offset),reg,INT,INT));
+	    offset+=SIZE_OF_INT;
+	    reg_var++;
+	}
+    }
     my_func_args = offset;
 }
 
@@ -1918,6 +1935,7 @@
     int stargs;
 
     special_lvar = -1;
+#if 0
     ret_type = cadr(cadddr(e1));
     if (ret_type==CHAR) ret_type=INT;
 
@@ -1930,6 +1948,9 @@
 	    if (car(t)==DOTS) dots = 1;
 	}
     }
+#else
+    ret_type = function_type(cadddr(e1),&dots);
+#endif
 
     arg_assign = 0;
     e2 = cadr(e1);