Mercurial > hg > CbC > old > device
changeset 166:9e55cc5551fb
*** empty log message ***
author | kono |
---|---|
date | Mon, 24 Nov 2003 13:09:14 +0900 |
parents | 6409ff6bc219 |
children | 0197ca125567 |
files | Changes Makefile mc-code-ia32.c mc-codegen.c mc-parse.c mc.h |
diffstat | 6 files changed, 150 insertions(+), 117 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Mon Nov 24 10:42:03 2003 +0900 +++ b/Changes Mon Nov 24 13:09:14 2003 +0900 @@ -3497,3 +3497,15 @@ あと、short は、code_crxxxx の中でbyteの大きさに従って 処理するのがいいかな。 +Mon Nov 24 10:53:31 JST 2003 + +short も実装したけど、まだ、コンパイルは通らない。 + +そろそろ stdio.h を通さないとダメだね。(いろいろあるだろうなぁ...) +とりあえず、#include <> をなんとかしないと。 + +long long の演算はともかく long long の代入はできた方がいい +か。でも、それなら、構造体の定義でいいんじゃない? + typedef struct { char a[4]; } long long +みたいな感じ? それはできないが、コンパイラ内部ではそうするという +手もある。
--- a/Makefile Mon Nov 24 10:42:03 2003 +0900 +++ b/Makefile Mon Nov 24 13:09:14 2003 +0900 @@ -35,6 +35,10 @@ conv/null.c: conv_func.tbl conv_func.pl perl conv_func.pl +mc.h-new: + perl mc-h-renum.pl mc.h > mc.h.1 + mv mc.h.1 mc.h + check-all: make check TARGET=test/basic make check TARGET=test/call @@ -54,6 +58,7 @@ make check TARGET=test/tmp8 make check TARGET=test/tmp9 make check TARGET=test/static + make check TARGET=test/short check: $(MC) -gcc $(TARGET).c -o b.out $(MLIB)
--- a/mc-code-ia32.c Mon Nov 24 10:42:03 2003 +0900 +++ b/mc-code-ia32.c Mon Nov 24 13:09:14 2003 +0900 @@ -543,7 +543,7 @@ printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0)); regv[creg]=1; } -static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movbl"):sz==size_of_short?(sign?"movswl":"movwl"):"movl"; } +static char *cload(int sign,int sz) { return sz==1?(sign?"movsbl":"movzbl"):sz==size_of_short?(sign?"movswl":"movzwl"):"movl"; } void code_crgvar(int e1,int creg,int sign,int sz){ printf("\t%s %s,%s\n",cload(sign,sz), @@ -694,7 +694,7 @@ return; } g_expr(e2); - printf("\t%s (%s),%s\n",sign?"movsbl":"movbl",register_name(creg,0),register_name(creg,0)); + printf("\t%s (%s),%s\n",sign?"movsbl":"movzbl",register_name(creg,0),register_name(creg,0)); printf("\tsubl $%d,(%s)\n",sz,register_name(creg,0)); } @@ -1108,12 +1108,16 @@ break; case CRINDIRECT: byte = 1; op="movsbl";t=CHAR; + break; case CURINDIRECT: - byte = 1; op="movbl";t=UCHAR; + byte = 1; op="movzbl";t=UCHAR; + break; case SRINDIRECT: byte = 1; op="movswl";t=SHORT; + break; case SURINDIRECT: - byte = 1; op="movwl";t=USHORT; + byte = 1; op="movzwl";t=USHORT; + break; case RINDIRECT: default: byte = 0; op="movl";t=INT; } @@ -1323,7 +1327,7 @@ { char *op; - op = byte ? (sign?"movsbl":"movbl") : "movl"; + op = byte ? (sign?"movsbl":"movzbl") : "movl"; if (n) printf("\t%s %d(%s),%s\n",op,n, register_name(xreg,0),register_name(creg,byte));
--- a/mc-codegen.c Mon Nov 24 10:42:03 2003 +0900 +++ b/mc-codegen.c Mon Nov 24 13:09:14 2003 +0900 @@ -1096,7 +1096,7 @@ { int e2,e4,byte,e5; - byte=(car(e1) == CASS)?1:(car(e1) == SASS)?size_of_int:0; + byte=(car(e1) == CASS)?1:(car(e1) == SASS)?size_of_short:0; /* e2=e4 */ e2 = cadr(e1); e4 = caddr(e1);e5=car(e4);
--- a/mc-parse.c Mon Nov 24 10:42:03 2003 +0900 +++ b/mc-parse.c Mon Nov 24 13:09:14 2003 +0900 @@ -475,11 +475,11 @@ t = UNSIGNED; if(getsym()==INT) getsym(); else if (sym==CHAR) { getsym(); t = UCHAR; } - else if (sym==SHORT) { getsym(); t = sym; } - else if (sym==LONGLONG) {getsym(); t = sym; } + else if (sym==SHORT) { getsym(); t = USHORT; } + else if (sym==LONGLONG) {getsym(); t = ULONGLONG; } break; case SHORT: - t=INT; + t=SHORT; if(getsym()==INT) getsym(); break; case LONG: @@ -705,15 +705,21 @@ int size(int t) { - if(t==CHAR) return 1; - if(t==VOID) return 0; - if(t==REGISTER) return size_of_int; - if(t==DREGISTER) return size_of_double; - if(t==FREGISTER) return size_of_float; - if(scalar(t)) return size_of_int; - if(t==FLOAT) return size_of_float; - if(t==DOUBLE) return size_of_double; - if(t==LONGLONG) return size_of_longlong; + if (t<0) { + if(t==CHAR) return 1; + if(t==UCHAR) return 1; + if(t==VOID) return 0; + if(t==SHORT) return size_of_short; + if(t==USHORT) return size_of_short; + if(t==REGISTER) return size_of_int; + if(t==DREGISTER) return size_of_double; + if(t==FREGISTER) return size_of_float; + if(scalar(t)) return size_of_int; + if(t==FLOAT) return size_of_float; + if(t==DOUBLE) return size_of_double; + if(t==LONGLONG) return size_of_longlong; + error(DCERR); + } if(car(t)==STRUCT||car(t)==UNION) { if(cadr(t)==-1) error(DCERR); return(cadr(t)); @@ -724,6 +730,8 @@ return size_of_int; else if(car(t)==FUNCTION) return size_of_int; + else if(car(t)==POINTER) + return size_of_int; else error(DCERR); return 0; @@ -1832,9 +1840,13 @@ if(t==VOID) error(TYERR); if(t==CHAR||t==UCHAR) { - e2=int_value(e2,type); + e2=(t==UCHAR)?unsigned_value(e2,type):int_value(e2,type); if (!integral(type)) error(TYERR); type= INT;return(list3(CASS,e1,e2)); + } else if(t==SHORT||t==USHORT) { + e2=(t==USHORT)?unsigned_value(e2,type):int_value(e2,type); + if (!integral(type)) error(TYERR); + type= t;return(list3(SASS,e1,e2)); } else if(t==DOUBLE) { e2=double_value(e2,type); type= t;return(list3(DASS,e1,e2));
--- a/mc.h Mon Nov 24 10:42:03 2003 +0900 +++ b/mc.h Mon Nov 24 13:09:14 2003 +0900 @@ -54,18 +54,20 @@ #define EXTRN1 (-38) #define VOID (-39) #define REGISTER (-40) -#define CODE (-41) -#define ENVIRONMENT (-42) -#define DEFINED (-43) -#define KONST (-44) -#define FMACRO (-45) -#define LMACRO (-46) -#define DOTS (-47) +#define FREGISTER (-41) +#define DREGISTER (-42) +#define CODE (-43) +#define ENVIRONMENT (-44) +#define DEFINED (-45) +#define KONST (-46) +#define FMACRO (-47) +#define LMACRO (-48) +#define DOTS (-49) -#define FLOAT (-48) -#define DOUBLE (-49) -#define LONGLONG (-50) -#define ULONGLONG (-51) +#define FLOAT (-50) +#define DOUBLE (-51) +#define LONGLONG (-52) +#define ULONGLONG (-53) /* reserved word end */ @@ -121,36 +123,34 @@ #define LRLVAR (LOP+CRLVAR) #define LURGVAR (LOP+CURGVAR) #define LURLVAR (LOP+CURLVAR) -#define FREGISTER 9 -#define DREGISTER 10 -#define CONST 11 +#define CONST 9 #define DCONST (DOP+CONST) #define FCONST (FOP+CONST) #define LCONST (LOP+CONST) -#define STRING 12 -#define FNAME 13 +#define STRING 10 +#define FNAME 11 -#define NULLARY_ARGS(i) (i==REGISTER||(GVAR<=(i%SOP)&&(i%SOP)<=FNAME)) +#define NULLARY_ARGS(i) (i==REGISTER||i==DREGISTER||i==FREGISTER||(GVAR<=(i%SOP)&&(i%SOP)<=FNAME)) /* unary argments */ -#define ADDRESS 14 -#define MINUS 15 -#define LNOT 16 -#define BNOT 17 -#define INC 18 -#define POSTINC 19 -#define PREINC 20 -#define DEC 21 -#define CPOSTINC 22 -#define CPREINC 23 -#define CPOSTDEC 24 -#define CPREDEC 25 -#define CUPOSTINC 26 -#define CUPREINC 27 -#define CUPOSTDEC 28 -#define CUPREDEC 29 +#define ADDRESS 12 +#define MINUS 13 +#define LNOT 14 +#define BNOT 15 +#define INC 16 +#define POSTINC 17 +#define PREINC 18 +#define DEC 19 +#define CPOSTINC 20 +#define CPREINC 21 +#define CPOSTDEC 22 +#define CPREDEC 23 +#define CUPOSTINC 24 +#define CUPREINC 25 +#define CUPOSTDEC 26 +#define CUPREDEC 27 #define SPOSTINC (SOP+CPOSTINC) #define SPREINC (SOP+CPREINC) #define SPOSTDEC (SOP+CPOSTDEC) @@ -167,58 +167,58 @@ #define LPREINC (LOP+CPREINC) #define LUPOSTINC (LOP+CUPOSTINC) #define LUPREINC (LOP+CUPREINC) -#define INDIRECT 30 -#define RINDIRECT 31 -#define CRINDIRECT 32 -#define CURINDIRECT 33 +#define INDIRECT 28 +#define RINDIRECT 29 +#define CRINDIRECT 30 +#define CURINDIRECT 31 #define SRINDIRECT (SOP+CRINDIRECT) #define SURINDIRECT (SOP+CURINDIRECT) #define FRINDIRECT (FOP+RINDIRECT) #define DRINDIRECT (DOP+RINDIRECT) #define LRINDIRECT (DOP+CRINDIRECT) -#define RSTRUCT 34 -#define CONV 35 +#define RSTRUCT 32 +#define CONV 33 #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 CMPGE 65 -#define ASSOP 66 -#define COMMA 67 +#define MUL 34 +#define UMUL 35 +#define DIV 36 +#define UDIV 37 +#define MOD 38 +#define UMOD 39 +#define ADD 40 +#define SUB 41 +#define CMP 42 +#define RSHIFT 43 +#define URSHIFT 44 +#define LSHIFT 45 +#define ULSHIFT 46 +#define GT 47 +#define UGT 48 +#define GE 49 +#define UGE 50 +#define LT 51 +#define ULT 52 +#define LE 53 +#define ULE 54 +#define EQ 55 +#define NEQ 56 +#define BAND 57 +#define EOR 58 +#define BOR 59 +#define LAND 60 +#define LOR 61 +#define ASS 62 +#define CMPGE 63 +#define ASSOP 64 +#define COMMA 65 -#define CASS 68 -#define CASSOP 69 -#define CUASSOP 70 +#define CASS 66 +#define CASSOP 67 +#define CUASSOP 68 #define SASS (SOP+CASS) #define SASSOP (SOP+CASSOP) @@ -255,13 +255,13 @@ #define LADD (LOP+ADD) #define LSUB (LOP+SUB) -#define STASS 71 +#define STASS 69 #define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS) /* tarnary argments */ -#define COND 72 +#define COND 70 #define SCOND (SOP+COND) #define DCOND (DOP+COND) #define FCOND (FOP+COND) @@ -271,28 +271,28 @@ /* not appeared as tags */ -#define I2D 73 -#define D2I 74 -#define U2D 75 -#define D2U 76 -#define F2D 77 -#define D2F 78 -#define I2F 79 -#define F2I 80 -#define U2F 81 -#define F2U 82 +#define I2D 71 +#define D2I 72 +#define U2D 73 +#define D2U 74 +#define F2D 75 +#define D2F 76 +#define I2F 77 +#define F2I 78 +#define U2F 79 +#define F2U 80 -#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 LPAR 81 +#define RPAR 82 +#define LBRA 83 +#define RBRA 84 +#define LC 85 +#define RC 86 +#define COLON 87 +#define SM 88 +#define PERIOD 89 +#define ARROW 90 +#define CNAME 91 /* tree node tags end */ @@ -347,7 +347,7 @@ EXTERN int chptrsave; EXTERN char linebuf[LBUFSIZE],namebuf[LBUFSIZE],*chptr; EXTERN char *name,*cheapp,**av,/*obuf[320],*/*sptr,escape(void); -EXTERN int arg_offset,stat_no,size_of_int,disp_offset,endian,csvalue1; +EXTERN int arg_offset,stat_no,size_of_int,size_of_short,disp_offset,endian,csvalue1; EXTERN int code_arg_offset; EXTERN int size_of_double,size_of_float,size_of_longlong; EXTERN int retlabel,retpending,retcont;