changeset 684:6e2f1e7f9fc3

*** empty log message ***
author kono
date Tue, 02 Oct 2007 21:18:12 +0900
parents 9708820f2b8a
children 3e3cf02297e4
files .gdbinit Changes mc-codegen.c mc-parse.c test/strinit.c
diffstat 5 files changed, 174 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Mon Oct 01 18:14:29 2007 +0900
+++ b/.gdbinit	Tue Oct 02 21:18:12 2007 +0900
@@ -17,4 +17,5 @@
 # r -s test/code-gen-all.c
 # r -s mc-code-powerpc.c
 # r -s test/strinit.c
-r -s -DINLINE=inline test/strinit.c
+# r -s -DINLINE=inline test/strinit.c
+r -s test/fact-a.c
--- a/Changes	Mon Oct 01 18:14:29 2007 +0900
+++ b/Changes	Tue Oct 02 21:18:12 2007 +0900
@@ -9481,3 +9481,13 @@
 ので、c2cbc が書けます。
 
 でも、まぁ、spu やるか?
+
+Tue Oct  2 17:49:09 JST 2007
+
+いろいろ微妙に動かない。
+
+scope のinline が動かない。
+
+fact-a の print のnptr の扱いが変。
+
+code segment の宣言の扱いは不便すぎる。(2 path を書くか?)
--- a/mc-codegen.c	Mon Oct 01 18:14:29 2007 +0900
+++ b/mc-codegen.c	Tue Oct 02 21:18:12 2007 +0900
@@ -1740,6 +1740,7 @@
 {
     int e,e1;
 
+    if (inmode) return e0;
     if (car(e0)!=ADD) return e0;
     if (car(e=caddr(e0))!=CONST) return e0;
     e1 = cadr(e0);
@@ -1762,9 +1763,10 @@
     } else if(car(e1)==GVAR) {
 	return(list3(GVAR,cadr(e1)+cadr(e),caddr(e1)));
     } else if(car(e1)==LVAR) {
-	return(list3(LVAR,cadr(e1)+cadr(e),0));
-    }
-    error(-1); // ?
+	return(list3(LVAR,cadr(e1)+cadr(e),caddr(e)));
+    } else if(car(e1)==RLVAR) {
+	return(list3(RLVAR,cadr(e1)+cadr(e),caddr(e)));
+    }
     return e0;
 }
 
--- a/mc-parse.c	Mon Oct 01 18:14:29 2007 +0900
+++ b/mc-parse.c	Tue Oct 02 21:18:12 2007 +0900
@@ -1978,73 +1978,6 @@
     return type;
 }
 
-/* code sgement
-     simpler than fdecl, because it does not have return value.
- */
-static void
-code_decl(NMTBL *n)
-{
-    int t,arglist;
-
-    if (stmode==0 && n->sc==STATIC) {
-	// static proto type, no storage class in definition
-	stmode=n->sc;
-    }
-    if(!chk) gen_code_enter(n->nm);
-    if (inmode) error(ILERR);
-    extrn_use(n);
-    local_static_list = &null_nptr;
-    fnptr=n;
-    // n->sc = CODE;
-    n->ty = type;
-    fcheck(n);
-    disp = -args;
-    mode=ADECL;
-    if (sym!=LC) {
-	arglist=fnptr->dsp;
-	args=fnptr->dsp=0;
-	while (sym!=LC) { /* argument declaration !ANSI */
-	    decl(); getsym(0);
-	}
-	disp = -args;
-	fnptr->dsp = arg_reorder(arglist,fnptr->dsp);
-	// fnptr->dsp = reverse0(fnptr->dsp);
-    }
-    /* reverse all argument offset (with size) */
-    arglist = fnptr->dsp;
-    for(t=arglist;t;t=cadr(t)) {
-	n=(NMTBL *)caddr(t);
-	if(n->sc==LVAR)
-	    n->dsp = -n->dsp-cadddr(t);
-    }
-    arg_register(fnptr);
-    conv->code_(fnptr); conv->lc_();
-    typedefed=0;
-    /* local variable declaration */
-    stmode=0;
-    mode=STAT;
-    init_vars=0;
-    while (typeid(getsym(0)) || sym==STATIC || sym==EXTRN || sym==TYPEDEF) {
-	mode=LDECL;
-	decl();
-	mode=STAT;
-    }
-    conv->localvar_end_();
-    control=1;
-    cslabel = -1;
-    if(!chk) gen_code_enter1(args);
-    emit_init_vars();
-    while(sym!=RC) statement(0);
-    if(control)
-	error(CODE_ERR);
-    control=0;
-    conv->code_end_();
-    if(!chk) gen_code_leave(fnptr->nm);
-    args = 0;
-}
-
-static NMTBL *tmp_struct;
-
 /* local decl can be used, after {}         */
 /*  but it's lexical scope remains after {} */
 /*  my be in for(int i=....) not yet  (fixed already?)      */
@@ -2068,6 +2001,77 @@
     conv->localvar_end_();
 }
 
+/* code sgement
+     simpler than fdecl, because it does not have return value.
+ */
+static void
+code_decl(NMTBL *n)
+{
+    int t,arglist;
+
+    if (!inmode) {
+	if (stmode==0 && n->sc==STATIC) {
+	    // static proto type, no storage class in definition
+	    stmode=n->sc;
+	}
+	if(!chk) gen_code_enter(n->nm);
+	extrn_use(n);
+    } else {
+        if (parse && (car(parse)!=ST_DECL&&car(parse)!=ST_COMMENT))
+            error(-1);  // What kind of error?
+        if (parse && car(parse)==ST_COMMENT)
+            cadr(parse)=0;
+        else
+            parse = 0;
+    }
+    local_static_list = &null_nptr;
+    fnptr=n;
+    // n->sc = CODE;
+    n->ty = type;
+    fcheck(n);
+    disp = -args;
+    mode=ADECL;
+    if (sym!=LC) {
+	arglist=fnptr->dsp;
+	args=fnptr->dsp=0;
+	while (sym!=LC) { /* argument declaration !ANSI */
+	    decl(); getsym(0);
+	}
+	disp = -args;
+	fnptr->dsp = arg_reorder(arglist,fnptr->dsp);
+	// fnptr->dsp = reverse0(fnptr->dsp);
+    }
+    if (!inmode) {
+	/* reverse all argument offset (with size) */
+	arglist = fnptr->dsp;
+	for(t=arglist;t;t=cadr(t)) {
+	    n=(NMTBL *)caddr(t);
+	    if(n->sc==LVAR)
+		n->dsp = -n->dsp-cadddr(t);
+	}
+	arg_register(fnptr);
+    }
+    typedefed=0;
+    conv->code_(fnptr); conv->lc_();
+    /* local variable declaration */
+    control=1;
+    cslabel = -1;
+    if(!inmode && !chk) gen_code_enter1(args);
+    local_decl(1);
+    emit_init_vars();
+    // lfree_type_limit = lfree;
+    while(sym!=RC) statement(0);
+    if(control)
+	error(CODE_ERR);
+    control=0;
+    conv->code_end_();
+    if(!inmode && !chk) gen_code_leave(fnptr->nm);
+    args = 0;
+    // lfree_type_limit = 0;
+}
+
+static NMTBL *tmp_struct;
+
 /* function define */
 
 
@@ -2123,13 +2127,12 @@
 	arg_register(fnptr);
     typedefed=0;
     conv->function_(fnptr,sd); conv->lc_();
-    init_vars=0;
-
-    /* local variable declaration */
-    local_decl(1);
+
     control=1;
     cslabel = -1;
     if (!inmode && !chk) gen_enter1();
+    /* local variable declaration */
+    local_decl(1);
     emit_init_vars();
     lfree_type_limit  = lfree;
     while(sym!=RC) statement(0);
@@ -2241,6 +2244,85 @@
     control=0;
 }
 
+extern void
+pcode_decl(NMTBL *n)
+{
+    int e;
+    int args,nargs,cargs;
+    int offset=0;
+    NMTBL *a,*n1;
+
+    top_init();
+
+    stmode = STATIC;
+    if (is_code(n)||is_function(n)) {
+	if (n->sc==EXTRN1||n->sc==EXTRN) {
+	    stmode = EXTRN;
+	}
+    }
+
+    if(!chk) gen_code_enter(n->nm);
+    extrn_use(n);
+    local_static_list = &null_nptr;
+    retlabel=fwdlabel();
+
+    fnptr=get_nptr();
+    fnptr->ty=n->ty;
+    fnptr->nm=n->nm;
+    fnptr->sc=n->sc;
+    fnptr->attr=n->attr;
+    fnptr->next=0;
+    
+    // make copied called function argment
+    for(args=n->dsp,nargs=0;args;args=cadr(args)) {
+	n1 = get_nptr();
+	a = (NMTBL*)caddr(args);
+	n1->ty = a->ty;
+	n1->nm = a->nm;
+	n1->sc = a->sc==IVAR?LVAR:a->sc;
+	n1->attr = a->attr;
+
+	n1->dsp = offset;
+	offset+= (scalar(n1->ty))?size_of_int:size(n1->ty);
+
+	nargs=list4(car(args),nargs,(int)n1,cadddr(args));
+    }
+    // fdecl_struct(fnptr->ty);  already done by fdecl before
+    fnptr->dsp=reverse0(nargs);
+    
+    retcont = 0;
+    tmp_struct = 0;
+
+    disp=0;
+    arg_register(fnptr); // should fix n1->dsp
+
+    // make calling argments
+    for(args=fnptr->dsp,cargs=0;args;args=cadr(args)) {
+	a = (NMTBL*)caddr(args);
+	// make call function argment for gen_inline
+        e=list3(a->sc==IVAR?LVAR:a->sc,a->dsp,(int)a);
+	cargs = list3(e,cargs,a->ty);
+    }
+    //  build inline function call
+    e = list4(INLINE,list2(FNAME,(int)n),cargs,
+	    list3(car(fnptr->ty),cadr(fnptr->ty),caddr(fnptr->ty)));
+
+    typedefed=0;
+    init_vars=0;
+
+    if(!chk) gen_enter1();
+
+    control=1;
+    cslabel = -1;
+
+    mode = STAT;
+    if(!chk) gen_inline(e);
+    if(!chk) gen_code_leave(n->nm);
+
+    retpending = 0;
+    control=0;
+}
+
 /*
     basic C statement
  */
--- a/test/strinit.c	Mon Oct 01 18:14:29 2007 +0900
+++ b/test/strinit.c	Tue Oct 02 21:18:12 2007 +0900
@@ -175,6 +175,8 @@
 INLINE void
 linux_kernel()
 {
+    int i=1,j=2;
+    printf("%d %d\n",i,j);
     ip_route_connect0(1,2,3,4,5,6,7);
     ip_route_connect(1,2,3,4,5,6,7);
     ip_route_connect(11,12,13,14,15,16,17);
@@ -266,6 +268,8 @@
     main7();
     main8();
     linux_kernel();
+    int i=1,j=2;
+    printf("%d %d\n",i,j);
     return 0;
 }