changeset 500:0a4ca939f403

inline continue...
author kono
date Fri, 23 Dec 2005 14:27:32 +0900
parents d2570c00ca54
children a63eb2319d11
files Changes mc-codegen.c mc-inline.c mc-parse.c mc.h
diffstat 5 files changed, 180 insertions(+), 146 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Thu Dec 22 12:11:22 2005 +0900
+++ b/Changes	Fri Dec 23 14:27:32 2005 +0900
@@ -7461,4 +7461,15 @@
 
 printf もなんとか。assign_expr でのtype checkが変だった。
 
-
+Fri Dec 23 00:24:38 JST 2005
+
+inline の引数のpoinetrとったらどうするの? エラー?
+
+inline function のLVARのオフセットはあまり意味がない。
+index にするか? それともオフセットの連想配列にするか。
+
+IVAR とか IRVAR とか作るのかな。type は入らない? LVAR とかと混在すると思うので
+いるんだろうなぁ。
+
+parital evaluator では、pexpr を再帰呼出ししないといけないわけね。
+
--- a/mc-codegen.c	Thu Dec 22 12:11:22 2005 +0900
+++ b/mc-codegen.c	Fri Dec 23 14:27:32 2005 +0900
@@ -533,6 +533,7 @@
     case ST_ASM:          st_asm(e1);	break;
     case ST_LABEL:        st_label(e1);	break;
     case ST_COMMENT:      st_comment(e1);	break;
+    case IVAR:      	  error(-1);	break;
     default:
 	code_bool(e1,USE_CREG); /* type? */
 	return INT;
@@ -2721,7 +2722,10 @@
             /* in decl() */
 	}
     }
-    if (mode==GSDECL||mode==LSDECL) {
+
+    // compute size 
+
+    if (mode==GSDECL||mode==LSDECL) {   // struct
         /* Struct fields name lists are in the struct type or tag. */
         /* Only name in the table is used. Do not set n->ty! */
 	/* Struct field may volatile... where do I put? list2(VOLATILE,type)? */
@@ -2744,7 +2748,7 @@
 	}
 	if (n!=&null_nptr)
 	    fields = list4(type,fields,(int)(n->nm),disp);
-    } else if (mode==GUDECL||mode==LUDECL) {
+    } else if (mode==GUDECL||mode==LUDECL) { // union
 	if (type0>0 && car(type0)==BIT_FIELD) {
 	    cadr(caddr(type0)) = 0; sz = size(cadr(type0));
 	}  else {
@@ -2765,9 +2769,9 @@
 	sz = size(n->ty = type);
     }
     switch(mode) {
-    case GDECL:
+    case GDECL:            // global variable
 	gen_gdecl(n->nm,gpc);
-    case STADECL:
+    case STADECL:          // static variable
 	nsc = GVAR;
 	ndsp = gpc;
 	if (n->dsp!=-1)     /* don't set dsp if initialized static */
@@ -2790,32 +2794,35 @@
 	gpc +=sz;
 	set_ctmode(n,ctmode);
 	return n;
-    case GSDECL: case LSDECL:
+    case GSDECL: case LSDECL:   // struct
 	disp += sz;
 	return n;
-    case GUDECL: case LUDECL:
+    case GUDECL: case LUDECL:   // union
 	if (disp < sz) disp = sz;
 	return n;
-    case GTDECL:
+    case GTDECL:                // typedef
 	nsc = TYPE;
 	gtypedefed=glist2((int)gnptr,gtypedefed);
 	break;
-    case LTDECL:
+    case LTDECL:                // local typedef
 	nsc = TYPE;
 	break;
-    case LLDECL:
+    case LLDECL:                // label def (gcc extension)
 	nsc = FLABEL;
 	if (!inmode)
 	    ndsp = fwdlabel();
 	break;
-    case ADECL:
+    case ADECL:                 // funcion arguments
 	if(!integral(type0)&&type0>0&&(car(type0)==FUNCTION||car(type0)==CODE)) {
 	    type=list2(POINTER,type); n->ty = type;
 	    type0=type;
 	}
 	fnptr->dsp=list4(type,fnptr->dsp,(int)n,0);
 	n->sc = LVAR;
-	if(type0==CHAR||type0==UCHAR) {
+	if(inmode==INLINE) {
+	    n->dsp = args++;
+	    n->sc = IVAR;
+	} else if(type0==CHAR||type0==UCHAR) {
 	    if (n->dsp==0) {
 		n->dsp = args;
 		if (endian) n->dsp += size_of_int-1;
@@ -2847,7 +2854,7 @@
 	set_ctmode(n,ctmode);
 	return n;
     case STAT: /* return (struct hoge)f() case? */
-    case LDECL:
+    case LDECL:    // local variable
 	if (stmode==REGISTER && !inmode) {
 	    if(scalar(type0)) {
 		ndsp = get_register_var(n);
--- a/mc-inline.c	Thu Dec 22 12:11:22 2005 +0900
+++ b/mc-inline.c	Fri Dec 23 14:27:32 2005 +0900
@@ -523,6 +523,8 @@
     NMTBL *n=(NMTBL*)caddr(e);
     int dsp = n->dsp;
     int v;
+    // in real partial evaluation, we have to check whether this variable
+    // is used or not.
     switch(stmode) {
     case REGISTER:
 	switch(n->ty) {
@@ -549,9 +551,19 @@
 }
 
 static int
-p_if(int e)
+p_if(int e1)
 {
-    return e;
+    int cond,l1,l2;
+    int e2=caddr(e1),e3;
+    cond = pexpr(car(e2));
+    // conv->if_then_();
+    l1 = pexpr(cadr(e2));
+    if ((e3=caddr(e2))) {  // else
+	l2 = pexpr(e3);
+    } else {
+	l2 = 0;
+    }
+    return list3(ST_IF,pexpr(cadr(e1)),list3(cond,l1,l2));
 }
 
 static int
@@ -641,7 +653,7 @@
 static int
 p_comment(int e)
 {
-    return e;
+    return pexpr(cadr(e));
 }
 
 extern int
@@ -656,9 +668,11 @@
     case SURGVAR: case REGISTER:
 #if FLOAT_CODE
     case DREGISTER: case FREGISTER:
+    case FRGVAR: case  DRGVAR:
 #endif
 #if LONGLONG_CODE
     case LREGISTER:
+    case LRGVAR: case LURGVAR:
 #endif
     case LABEL: case CONST: 
 #if FLOAT_CODE
@@ -674,12 +688,14 @@
     case LVAR:
     case RLVAR: case CRLVAR: case CURLVAR: case SRLVAR: case SURLVAR:
 #if FLOAT_CODE
-    case FRLVAR: case FRGVAR: case DRLVAR: case DRGVAR:
+    case FRLVAR: case DRLVAR: 
 #endif
 #if LONGLONG_CODE
-    case LRLVAR: case LRGVAR: case LURLVAR: case LURGVAR:
+    case LRLVAR: case LURLVAR: 
+#endif
+	return e1;
+    case IVAR:
 	return p_lvar(e1);
-#endif
     case FUNCTION:
 	return pfunction(e1);
     case CODE:
@@ -879,23 +895,25 @@
     int narg,arg;
     NMTBL *n = (NMTBL*)cadr(cadr(e));
     int e1 = attr_value(n,INLINE);
-    int parse = car(e1);
-    int arg_disp = cadr(e1);
-    int e3,t;
+    int parse = car(e1);      // inline parse tree
+    int arg_disp = cadr(e1);  // size of local variable
+    int e3,t,e4;
 
     pvartable = p_vartable(e,pdisp=arg_disp,caddr(e1));
     /* inline function arguments */
     narg = 0;
     for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
-        t=caddr(e3);
-	if (is_const(e3) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
-	    heap[pdisp+narg]=e3;
+        t=caddr(e3);  // type
+	e4 = car(e3);
+	if (is_const(e4) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
+	    heap[pdisp+narg]=e4;
 	} else {
 	    arg = heap[pdisp+narg]=new_lvar(size(t));
-	    g_expr_u(assign_expr0(arg,e3,t,t));
+	    g_expr_u(assign_expr0(arg,e4,t,t));
 	}
-	narg += (size(t)+3)/4;
+	narg ++;
     }
+    caddr(e) = reverse0(caddr(e));  // make it normal
     e = pexpr(parse);
     pdisp = sdisp;
     pvartable = svartable;
--- a/mc-parse.c	Thu Dec 22 12:11:22 2005 +0900
+++ b/mc-parse.c	Fri Dec 23 14:27:32 2005 +0900
@@ -3157,10 +3157,7 @@
 	case FUNCTION: case CODE:
 	    return fname(nptr);
 	case LVAR:
-	    e1=list3(LVAR,nptr->dsp,(int)nptr);
-	    type=nptr->ty;
-	    getsym(0);
-	    break;
+	case IVAR:
 	case LREGISTER:
 	case DREGISTER:
 	case FREGISTER:
--- a/mc.h	Thu Dec 22 12:11:22 2005 +0900
+++ b/mc.h	Fri Dec 23 14:27:32 2005 +0900
@@ -156,25 +156,26 @@
 #define DECL  	12
 #define COMP  	13
 #define LABEL  	14
+#define IVAR  	15
 
 #define NULLARY_ARGS(i) (i==RETURN||i==ENVIRONMENT||i==LCALL||i==REGISTER||i==DREGISTER||i==FREGISTER||i==LREGISTER||(GVAR<=(i%SOP)&&(i%SOP)<=LABEL))
 
 /* unary  argments */
 
-#define ADDRESS	15
-#define MINUS  	16
-#define LNOT   	17
-#define BNOT   	18
-#define INC    	19
-#define POSTINC	20
-#define UPOSTINC       	21
-#define PREINC 	22
-#define UPREINC	23
-#define POSTDEC	24
-#define UPOSTDEC       	25
-#define PREDEC 	26
-#define UPREDEC	27
-#define DEC    	28
+#define ADDRESS	16
+#define MINUS  	17
+#define LNOT   	18
+#define BNOT   	19
+#define INC    	20
+#define POSTINC	21
+#define UPOSTINC       	22
+#define PREINC 	23
+#define UPREINC	24
+#define POSTDEC	25
+#define UPOSTDEC       	26
+#define PREDEC 	27
+#define UPREDEC	28
+#define DEC    	29
 #define CPOSTINC (COP+POSTINC)
 #define CUPOSTINC (COP+UPOSTINC)
 #define CPREINC (COP+PREINC)
@@ -199,9 +200,9 @@
 #define LPREINC (LOP+PREINC)
 #define LUPOSTINC       (LOP+UPOSTINC)
 #define LUPREINC        (LOP+UPREINC)
-#define INDIRECT       	29
-#define RINDIRECT      	30
-#define URINDIRECT     	31
+#define INDIRECT       	30
+#define RINDIRECT      	31
+#define URINDIRECT     	32
 #define CRINDIRECT      (COP+RINDIRECT)
 #define CURINDIRECT     (COP+URINDIRECT)
 #define SRINDIRECT      (SOP+RINDIRECT)
@@ -210,61 +211,61 @@
 #define DRINDIRECT      (DOP+RINDIRECT)
 #define LRINDIRECT      (LOP+RINDIRECT)
 #define LURINDIRECT     (LOP+URINDIRECT)
-#define RSTRUCT	32
-#define ALLOCA 	33
-#define BUILTINP 	34
-#define BUILTIN_EXPECT 	35
-#define ATTRIBUTE 	36
-#define BIT_FIELD 	37
-#define RBIT_FIELD 	38
-#define BPREINC 	39
-#define BPOSTINC 	40
-#define CONV   	41
+#define RSTRUCT	33
+#define ALLOCA 	34
+#define BUILTINP 	35
+#define BUILTIN_EXPECT 	36
+#define ATTRIBUTE 	37
+#define BIT_FIELD 	38
+#define RBIT_FIELD 	39
+#define BPREINC 	40
+#define BPOSTINC 	41
+#define CONV   	42
 
 #define UNARY_ARGS(i) (ADDRESS<=(i%SOP)&&(i%SOP)<=CONV)
 
 /* binary  argments */
 
-#define MUL    	42
-#define UMUL   	43
-#define DIV    	44
-#define UDIV   	45
-#define MOD    	46
-#define UMOD   	47
-#define ADD    	48
-#define SUB    	49
-#define CMP    	50      
-#define RSHIFT 	51
-#define URSHIFT	52
-#define LSHIFT 	53
-#define ULSHIFT	54
-#define GT     	55
-#define UGT    	56
-#define GE     	57
-#define UGE    	58
-#define LT     	59
-#define ULT    	60
-#define LE     	61
-#define ULE    	62
-#define EQ     	63
-#define NEQ    	64
-#define BAND   	65
-#define EOR    	66
-#define BOR    	67
-#define LAND   	68
-#define LOR    	69
-#define ASS    	70
-#define UCMP   	71
-#define UCMPGE 	72
-#define CMPGE  	73
-#define CMPEQ  	74
-#define CMPNEQ 	75
-#define ASSOP  	76
-#define COMMA  	77
+#define MUL    	43
+#define UMUL   	44
+#define DIV    	45
+#define UDIV   	46
+#define MOD    	47
+#define UMOD   	48
+#define ADD    	49
+#define SUB    	50
+#define CMP    	51      
+#define RSHIFT 	52
+#define URSHIFT	53
+#define LSHIFT 	54
+#define ULSHIFT	55
+#define GT     	56
+#define UGT    	57
+#define GE     	58
+#define UGE    	59
+#define LT     	60
+#define ULT    	61
+#define LE     	62
+#define ULE    	63
+#define EQ     	64
+#define NEQ    	65
+#define BAND   	66
+#define EOR    	67
+#define BOR    	68
+#define LAND   	69
+#define LOR    	70
+#define ASS    	71
+#define UCMP   	72
+#define UCMPGE 	73
+#define CMPGE  	74
+#define CMPEQ  	75
+#define CMPNEQ 	76
+#define ASSOP  	77
+#define COMMA  	78
 
-#define CASS   	78
-#define CASSOP 	79
-#define CUASSOP	80
+#define CASS   	79
+#define CASSOP 	80
+#define CUASSOP	81
 
 #define SASS    (SOP+CASS)
 #define SASSOP (SOP+CASSOP)
@@ -320,19 +321,19 @@
 #define LEOR    (LOP+EOR)
 #define LBOR    (LOP+BOR)
 
-#define BASS   	81
-#define BASSOP 	82
-#define BFD_REPL 	83
+#define BASS   	82
+#define BASSOP 	83
+#define BFD_REPL 	84
 
-#define STASS  	84
+#define STASS  	85
 
 
 #define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS)
 
 /* tarnary  argments */
 
-#define COND   	85
-#define UCOND  	86
+#define COND   	86
+#define UCOND  	87
 #define SCOND   (SOP+COND)
 #define SUCOND   (SOP+UCOND)
 #define DCOND   (DOP+COND)
@@ -344,35 +345,35 @@
 
 /* not appeared as tags */
 
-#define LPAR   	87
-#define RPAR   	88
-#define LBRA   	89
-#define RBRA   	90
-#define LC     	91
-#define RC     	92
-#define COLON  	93
-#define SM     	94
-#define PERIOD 	95
-#define ARROW  	96
-#define CNAME  	97
+#define LPAR   	88
+#define RPAR   	89
+#define LBRA   	90
+#define RBRA   	91
+#define LC     	92
+#define RC     	93
+#define COLON  	94
+#define SM     	95
+#define PERIOD 	96
+#define ARROW  	97
+#define CNAME  	98
 
-#define I2C  	98
-#define I2S  	99
-#define I2I    	100
-#define I2U    	101
-#define I2D    	102
-#define I2F    	103
-#define I2LL   	104
-#define I2ULL  	105
+#define I2C  	99
+#define I2S  	100
+#define I2I    	101
+#define I2U    	102
+#define I2D    	103
+#define I2F    	104
+#define I2LL   	105
+#define I2ULL  	106
 
-#define U2UC  	106
-#define U2US  	107
-#define U2I    	108
-#define U2U    	109
-#define U2D    	110
-#define U2F    	111
-#define U2LL   	112
-#define U2ULL  	113
+#define U2UC  	107
+#define U2US  	108
+#define U2I    	109
+#define U2U    	110
+#define U2D    	111
+#define U2F    	112
+#define U2LL   	113
+#define U2ULL  	114
 
 
 #define D2I     (DOP+I2I)
@@ -407,22 +408,22 @@
 
 /* statement start */
 
-#define ST_DECL		114
-#define ST_IF		115
-#define ST_DO		116
-#define ST_WHILE	117
-#define ST_FOR		118
-#define ST_SWITCH	119
-#define ST_COMP		120
-#define ST_BREAK	121
-#define ST_CONTINUE	122
-#define ST_CASE		123
-#define ST_DEFAULT	124
-#define ST_RETURN	125
-#define ST_GOTO		126
-#define ST_ASM		127
-#define ST_LABEL	128
-#define ST_COMMENT	129
+#define ST_DECL		115
+#define ST_IF		116
+#define ST_DO		117
+#define ST_WHILE	118
+#define ST_FOR		119
+#define ST_SWITCH	120
+#define ST_COMP		121
+#define ST_BREAK	122
+#define ST_CONTINUE	123
+#define ST_CASE		124
+#define ST_DEFAULT	125
+#define ST_RETURN	126
+#define ST_GOTO		127
+#define ST_ASM		128
+#define ST_LABEL	129
+#define ST_COMMENT	130
 
 #define IS_STATEMENT(i) (ST_DECL<=i&&i<=ST_COMMENT)