changeset 452:8e3284b0a8c9

minor update
author kono
date Mon, 29 Nov 2004 04:15:38 +0900
parents 656ec59cd79f
children 1e5ca85d3f97
files Changes mc-code.h mc-codegen.c mc-codegen.h mc-parse.c mc-parse.h mc.h
diffstat 7 files changed, 198 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sun Nov 28 04:16:27 2004 +0900
+++ b/Changes	Mon Nov 29 04:15:38 2004 +0900
@@ -6620,7 +6620,7 @@
    inline function (or parsed tree)
        list4(INLINE,name,type)
    declaration (argument, local, static)
-       list4(DECL,next,type,name)        done by def (?)
+       list4(DECL,next,init,NMTBL *nptr)        done by def (?)
    statement
        list3(IF,next,list3(cond,then,else))
        list3(DO,next,list2(cond,while))
@@ -6630,12 +6630,14 @@
        list2(BREAK,next)
        list2(CONTINUE,next)
        list3(CASE,next,label)
-       list3(RETURN,next,expr)
+       list3(ST_RETURN,next,expr)
        list3(GOTO,next,expr,env)
-       list3(ASM,next,list4(A,B,C,D))
-       list3(LABEL,next,label)
+       list3(ST_ASM,next,list4(A,B,C,D))
+       list3(ST_LABEL,next,label)
        list3(COMMENT,next,comment)  (?)
 
+  いくつかはexprと重なるけど... (まずい?) RETURN, ASM
+
  (1) make inline tree
  (2) evaluate inline function (copy and partial evaluation)
         peval(inline_func,args)
@@ -6644,6 +6646,10 @@
     const いるのかなあ。
     builtin_constant_p かぁ。
 
+ partial evaluation しながら code 生成する? (難しい...)
+ partial evaluation してから code 生成する。まぁ、こっちでしょうねぇ。
+    g_expr を変更しなくてもすむ
+
 Mon Nov 15 17:37:57 JST 2004
 
 code hoge() {  a; }
@@ -6909,3 +6915,21 @@
 float/double/longlong のcode segement argument のテストをしてない。
 
 ia32 の ({}) がおかしい。
+
+Sun Nov 28 15:49:54 JST 2004
+
+listn を object に変える?
+
+   struct nodes {
+      union {
+	  int tag:12;
+	  int type:4;          LONGLONG,INT,SHORT,CHAR
+	  int unsigned:1;
+	  int arity:4;
+	  int size4:4;
+      } tag;
+      int next;
+      union:tag {
+	  int arg0,...argn;
+      }
+   }
--- a/mc-code.h	Sun Nov 28 04:16:27 2004 +0900
+++ b/mc-code.h	Mon Nov 29 04:15:38 2004 +0900
@@ -3,13 +3,13 @@
  */
 
 
-#define MAX_MAX 50
-#define INPUT_REG 2    /* input register ( can be reused ) */
-#define USING_REG 1    /* unreusable register usage */
+#define MAX_MAX 50          /* architecture independent max registers */
+#define INPUT_REG 2         /* input register ( can be reused ) */
+#define USING_REG 1         /* unreusable register usage */
 
-extern char *l_include_path[];
+extern char *l_include_path[];   /* library including path */
 
-extern int disp_offset;
+extern int disp_offset;     /* displacement offset in code and function */
 
 extern int MAX_REGISTER; 
 extern int MAX_REGISTGER_VAR;
@@ -25,13 +25,13 @@
 
 extern int data_alignment;
 
-extern int code_lassop_p;
+extern int code_lassop_p;  /* architecture has code_lassop */
 
 /* used by mc-codegen */
 
-extern void gexpr_init(void);
+extern void gexpr_init(void);  /* code generator initialize for each statement */
 extern void emit_init(void);   /* called before delcalartion */
-extern void gen_gdecl(char *n, int gpc);
+extern void gen_gdecl(char *n, int gpc);   /* global definition */
 
 extern void code_init();   /* called only once */
 extern void emit_reinit(); /* called for each file */
--- a/mc-codegen.c	Sun Nov 28 04:16:27 2004 +0900
+++ b/mc-codegen.c	Mon Nov 29 04:15:38 2004 +0900
@@ -129,6 +129,10 @@
 {
     int e2,e3,t,d,t1;
     NMTBL *n;
+
+    if (mode==INLINE) {
+	return (parse = list2(e1,parse));
+    }
     if (!control) return VOID;
 
     code_gexpr(e1);
--- a/mc-codegen.h	Sun Nov 28 04:16:27 2004 +0900
+++ b/mc-codegen.h	Mon Nov 29 04:15:38 2004 +0900
@@ -1,7 +1,10 @@
 /* for mc-codegen.c */
 
-extern int use;         /* generated value will be used in gexpr */
-extern char *init_src;
+extern int use;                /* generated value will be used in gexpr */
+extern char *init_src;         /* internal defenition string for each file */
+
+/* these architecture dependent values are defined in mc-code-*.c */
+
 extern int size_of_int;
 extern int size_of_short;
 extern int size_of_float;
@@ -19,7 +22,6 @@
 
 /* used by mc-parse */
 
-
 extern NMTBL * def(NMTBL *n,int ctmode);
 extern int arg_reorder(int arg,int new_arg);
 extern int assign_data(int e, int t, NMTBL *n,int offset);
--- a/mc-parse.c	Sun Nov 28 04:16:27 2004 +0900
+++ b/mc-parse.c	Mon Nov 29 04:15:38 2004 +0900
@@ -68,10 +68,10 @@
 int sym,type,mode,stmode,ctmode,inmode;
 int typedefed;
 int decl_str_init;
+int parse;
 
 NMTBL *local_static_list,*global_list;
 
-
 struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES];
 
 static NMTBL *decl0(void),*decl1(void),*l_top_search(char *name,int sc);
--- a/mc-parse.h	Sun Nov 28 04:16:27 2004 +0900
+++ b/mc-parse.h	Mon Nov 29 04:15:38 2004 +0900
@@ -1,21 +1,34 @@
 /* for mc-parse.c */
 
-extern int sym,type,mode,stmode,ctmode;
-extern int labelno,gpc,disp;
-extern int args,init_vars;
-extern int cslabel,control;
-extern NMTBL *nptr,*gnptr;
-extern NMTBL *fnptr;
-extern int gtypedefed;
-extern int retlabel,retpending,retcont;
-extern int pending_jmp;
-extern int chk;
-extern int bit_field_disp;
-extern int fields;
-extern int struct_return;
-extern int lastexp;
-extern int debug; 
-extern int decl_str_init;
+extern int sym;             /* next symbol */
+extern int type;            /* current type */
+extern int mode;            /* grammer mode (STAT,ADECL) */
+extern int stmode;          /* storage mode (STATIC,EXTRN) */
+extern int ctmode;          /* constant mode */
+extern int labelno;         /* label number */
+extern int gpc;             /* global variable size (unused?) */
+extern int disp;            /* local variable offset */
+extern int args;            /* function arguments */
+extern int init_vars;       /* variable initialize list in local decl */
+extern int cslabel;         /* case label */
+extern int control;         /* control is reached */
+extern NMTBL *nptr;         /* current name table */
+extern NMTBL *gnptr;        /* currrent global name table (unsed?) */
+extern NMTBL *fnptr;        /* current function name table */
+extern int gtypedefed;      /* global typedef list */
+extern int retlabel;        /* return label */
+extern int retpending;      /* jump to return label suspended */
+extern int retcont;         /* continuation label */
+extern int pending_jmp;     /* suspended jump label */
+extern int chk;             /* no code generation */
+extern int bit_field_disp;  /* bit field bit offset */
+extern int fields;          /* struct field */
+extern int struct_return;   /* temporal return structure variable */
+extern int lastexp;         /* last expression in statement expressoin */
+extern int debug;           /* debug flag */
+extern int decl_str_init;   /* partial structure initializer */
+
+extern int parse;   /* parse tree */
 
 /*
           STRING         nptr
@@ -27,28 +40,31 @@
           TYPE           nptr
  */
 
+/* memory pool structure */
+/*    extendable         */
 typedef struct cheap
 {
-    char *ptr;
+    char *ptr;			/* current pointer */
     char *last;
     char *first;
-    struct cheap *next;
+    struct cheap *next; 	/* previous cheap  */
 } CHEAP;
 
 
 /* used in mc-macro.c */
 
-extern int asmf;
-extern int ch;
-extern int chptrsave; 
-extern int chsave; 
-extern char linebuf[LBUFSIZE],*chptr;
-extern int glineno; 
-extern int in_comment; 
-extern int in_quote; 
-extern int lfree; 
-extern int lineno; 
-extern int lsrc; 
+extern int asmf;             /* assembler generating mode (old) */
+extern int ch;               /* current character */
+extern int chptrsave;        /* nested character pointer */
+extern int chsave;           /* saved current character */
+extern char linebuf[LBUFSIZE];   /* line buffer */
+extern char *chptr;          /* current character pointer */
+extern int glineno;          /* total lineno */
+extern int in_comment;       /* tokenizer mode */
+extern int in_quote;         /* tokenizer mode */
+extern int lfree;            /* local free heap top */
+extern int lineno;           /* lineno in current file */
+extern int lsrc;             /* source listing flag */
 extern char *include_path[MAX_INCLUDE_PATH_COUNT];
 
 /* used in mc-code-* */
@@ -61,12 +77,13 @@
 
 extern void free_glist3(int e1);
 extern void free_glist3_a(int e1);
-extern int csvalue1;
-extern int blabel,dlabel;
+extern int csvalue1;	     /* current switch variable */
+extern int blabel;           /* break label in switch */
+extern int dlabel;           /* default label in switch */
 
 /* used in mc-tree.c */
 
-extern int typedefed;
+extern int typedefed;        /* accumlated typedef name */
 
 /* global variable end */
 
--- a/mc.h	Sun Nov 28 04:16:27 2004 +0900
+++ b/mc.h	Mon Nov 29 04:15:38 2004 +0900
@@ -139,26 +139,29 @@
 #define STRING 	8
 #define FNAME  	9
 #define LCALL  	10
-#define LABEL  	11
+#define COMMENT  	11
+#define DECL  	12
+#define COMP  	13
+#define LABEL  	14
 
 #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	12
-#define MINUS  	13
-#define LNOT   	14
-#define BNOT   	15
-#define INC    	16
-#define POSTINC	17
-#define UPOSTINC       	18
-#define PREINC 	19
-#define UPREINC	20
-#define POSTDEC	21
-#define UPOSTDEC       	22
-#define PREDEC 	23
-#define UPREDEC	24
-#define DEC    	25
+#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 CPOSTINC (COP+POSTINC)
 #define CUPOSTINC (COP+UPOSTINC)
 #define CPREINC (COP+PREINC)
@@ -183,9 +186,9 @@
 #define LPREINC (LOP+PREINC)
 #define LUPOSTINC       (LOP+UPOSTINC)
 #define LUPREINC        (LOP+UPREINC)
-#define INDIRECT       	26
-#define RINDIRECT      	27
-#define URINDIRECT     	28
+#define INDIRECT       	29
+#define RINDIRECT      	30
+#define URINDIRECT     	31
 #define CRINDIRECT      (COP+RINDIRECT)
 #define CURINDIRECT     (COP+URINDIRECT)
 #define SRINDIRECT      (SOP+RINDIRECT)
@@ -194,58 +197,58 @@
 #define DRINDIRECT      (DOP+RINDIRECT)
 #define LRINDIRECT      (LOP+RINDIRECT)
 #define LURINDIRECT     (LOP+URINDIRECT)
-#define RSTRUCT	29
-#define ALLOCA 	30
-#define BIT_FIELD 	31
-#define RBIT_FIELD 	32
-#define BPREINC 	33
-#define BPOSTINC 	34
-#define CONV   	35
+#define RSTRUCT	32
+#define ALLOCA 	33
+#define BIT_FIELD 	34
+#define RBIT_FIELD 	35
+#define BPREINC 	36
+#define BPOSTINC 	37
+#define CONV   	38
 
 #define UNARY_ARGS(i) (ADDRESS<=(i%SOP)&&(i%SOP)<=CONV)
 
 /* binary  argments */
 
-#define MUL    	36
-#define UMUL   	37
-#define DIV    	38
-#define UDIV   	39
-#define MOD    	40
-#define UMOD   	41
-#define ADD    	42
-#define SUB    	43
-#define CMP    	44      
-#define RSHIFT 	45
-#define URSHIFT	46
-#define LSHIFT 	47
-#define ULSHIFT	48
-#define GT     	49
-#define UGT    	50
-#define GE     	51
-#define UGE    	52
-#define LT     	53
-#define ULT    	54
-#define LE     	55
-#define ULE    	56
-#define EQ     	57
-#define NEQ    	58
-#define BAND   	59
-#define EOR    	60
-#define BOR    	61
-#define LAND   	62
-#define LOR    	63
-#define ASS    	64
-#define UCMP   	65
-#define UCMPGE 	66
-#define CMPGE  	67
-#define CMPEQ  	68
-#define CMPNEQ 	69
-#define ASSOP  	70
-#define COMMA  	71
+#define MUL    	39
+#define UMUL   	40
+#define DIV    	41
+#define UDIV   	42
+#define MOD    	43
+#define UMOD   	44
+#define ADD    	45
+#define SUB    	46
+#define CMP    	47      
+#define RSHIFT 	48
+#define URSHIFT	49
+#define LSHIFT 	50
+#define ULSHIFT	51
+#define GT     	52
+#define UGT    	53
+#define GE     	54
+#define UGE    	55
+#define LT     	56
+#define ULT    	57
+#define LE     	58
+#define ULE    	59
+#define EQ     	60
+#define NEQ    	61
+#define BAND   	62
+#define EOR    	63
+#define BOR    	64
+#define LAND   	65
+#define LOR    	66
+#define ASS    	67
+#define UCMP   	68
+#define UCMPGE 	69
+#define CMPGE  	70
+#define CMPEQ  	71
+#define CMPNEQ 	72
+#define ASSOP  	73
+#define COMMA  	74
 
-#define CASS   	72
-#define CASSOP 	73
-#define CUASSOP	74
+#define CASS   	75
+#define CASSOP 	76
+#define CUASSOP	77
 
 #define SASS    (SOP+CASS)
 #define SASSOP (SOP+CASSOP)
@@ -301,18 +304,18 @@
 #define LEOR    (LOP+EOR)
 #define LBOR    (LOP+BOR)
 
-#define BASS   	75
-#define BASSOP 	76
-#define BFD_REPL 	77
+#define BASS   	78
+#define BASSOP 	79
+#define BFD_REPL 	80
 
-#define STASS  	78
+#define STASS  	81
 
 
 #define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS)
 
 /* tarnary  argments */
 
-#define COND   	79
+#define COND   	82
 #define SCOND   (SOP+COND)
 #define DCOND   (DOP+COND)
 #define FCOND   (FOP+COND)
@@ -322,35 +325,35 @@
 
 /* not appeared as tags */
 
-#define LPAR   	80
-#define RPAR   	81
-#define LBRA   	82
-#define RBRA   	83
-#define LC     	84
-#define RC     	85
-#define COLON  	86
-#define SM     	87
-#define PERIOD 	88
-#define ARROW  	89
-#define CNAME  	90
+#define LPAR   	83
+#define RPAR   	84
+#define LBRA   	85
+#define RBRA   	86
+#define LC     	87
+#define RC     	88
+#define COLON  	89
+#define SM     	90
+#define PERIOD 	91
+#define ARROW  	92
+#define CNAME  	93
 
-#define I2C  	91
-#define I2S  	92
-#define I2I    	93
-#define I2U    	94
-#define I2D    	95
-#define I2F    	96
-#define I2LL   	97
-#define I2ULL  	98
+#define I2C  	94
+#define I2S  	95
+#define I2I    	96
+#define I2U    	97
+#define I2D    	98
+#define I2F    	99
+#define I2LL   	100
+#define I2ULL  	101
 
-#define U2UC  	99
-#define U2US  	100
-#define U2I    	101
-#define U2U    	102
-#define U2D    	103
-#define U2F    	104
-#define U2LL   	105
-#define U2ULL  	106
+#define U2UC  	102
+#define U2US  	103
+#define U2I    	104
+#define U2U    	105
+#define U2D    	106
+#define U2F    	107
+#define U2LL   	108
+#define U2ULL  	109
 
 
 #define D2I     (DOP+I2I)
@@ -423,7 +426,7 @@
  */
 #define GSYMS		(8192*4)
 #define HEAPSIZE        30000
-#define CHEAPSIZE       (sizeof(NMTBL)*GSYMS)
+#define CHEAPSIZE       (sizeof(NMTBL)*8192)
 #define LBUFSIZE        4096
 #define STRSIZE		4096
 
@@ -433,8 +436,9 @@
         int sc,attr;
 	int ty,dsp; } NMTBL;
 
-extern int *heap;
-extern NMTBL *global_list,*local_static_list;
+extern int *heap;                   /* heap area (in cheap ) */
+extern NMTBL *global_list;          /* list of all global NMTBL */
+extern NMTBL *local_static_list;    /* list of local static variable */
 
 #if FLOAT_CODE
 extern int dlist2(int e1, double e2);