Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

ops.c (3195B)


      1 #include "c.h"
      2 
      3 /* ops [ {csilhfdxp}=n ]...
      4  * prints lcc dag operator set for a given set of type sizes.
      5  */
      6 
      7 
      8 static char list[] = { 'c', 's', 'i', 'l', 'h', 'f', 'd', 'x', 'p', 0 };
      9 static int sizes[] = {  1,   2,   4,   4,   8,   4,   8,  16,   8 };
     10 
     11 static int doop(int op, int type, const char *sz, const char *opname) {
     12 	int count = 0;
     13 	static int last;
     14 
     15 	if (op == LOAD)
     16 		return 0;
     17 	if (last != 0 && last != op)
     18 		printf("\n");
     19 	last = op;
     20 	if (type == B || type == V) {
     21 		printf(" %s=%d", opname, op + type);
     22 		count++;
     23 	} else {
     24 		int i, done = 0;
     25 		const char *s;
     26 		for (i = 0; sz[i] != '\0' && (s = strchr(list, sz[i])) != NULL; i++) {
     27 			int n = sizes[s-list];
     28 			if ((done&(1<<n)) == 0) {
     29 				printf(" %s%d=%d", opname, n, op + type + sizeop(n));
     30 				count++;
     31 			}
     32 			done |= 1<<n;
     33 		}
     34 	}
     35 	printf("\n");
     36 	return count;
     37 }
     38 
     39 int main(int argc, char *argv[]) {
     40 	int i, count = 0;
     41 
     42 	for (i = 1; i < argc; i++) {
     43 		char c, *s;
     44 		int n;
     45 		if (sscanf(argv[i], "%c=%d", &c, &n) == 2
     46 		&& n > 0 && (s = strchr(list, c)) != NULL)
     47 			sizes[s-list] = n;
     48 		else {
     49 			fprintf(stderr, "usage: %s [ {csilhfdxp}=n ]...\n", argv[0]);
     50 			exit(EXIT_FAILURE);
     51 		}
     52 	}
     53 #define gop(x,n)
     54 #define op(x,t,s) count += doop(x,t,#s,#x #t);
     55 gop(CNST,1)
     56 	op(CNST,F,fdx)
     57 	op(CNST,I,csilh)
     58 	op(CNST,P,p)
     59 	op(CNST,U,csilh)
     60 gop(ARG,2)
     61 	op(ARG,B,-)
     62 	op(ARG,F,fdx)
     63 	op(ARG,I,ilh)
     64 	op(ARG,P,p)
     65 	op(ARG,U,ilh)
     66 gop(ASGN,3)
     67 	op(ASGN,B,-)
     68 	op(ASGN,F,fdx)
     69 	op(ASGN,I,csilh)
     70 	op(ASGN,P,p)
     71 	op(ASGN,U,csilh)
     72 gop(INDIR,4)
     73 	op(INDIR,B,-)
     74 	op(INDIR,F,fdx)
     75 	op(INDIR,I,csilh)
     76 	op(INDIR,P,p)
     77 	op(INDIR,U,csilh)
     78 gop(CVF,7)
     79 	op(CVF,F,fdx)
     80 	op(CVF,I,ilh)
     81 gop(CVI,8)
     82 	op(CVI,F,fdx)
     83 	op(CVI,I,csilh)
     84 	op(CVI,U,csilhp)
     85 gop(CVP,9)
     86 	op(CVP,U,p)
     87 gop(CVU,11)
     88 	op(CVU,I,csilh)
     89 	op(CVU,P,p)
     90 	op(CVU,U,csilh)
     91 gop(NEG,12)
     92 	op(NEG,F,fdx)
     93 	op(NEG,I,ilh)
     94 gop(CALL,13)
     95 	op(CALL,B,-)
     96 	op(CALL,F,fdx)
     97 	op(CALL,I,ilh)
     98 	op(CALL,P,p)
     99 	op(CALL,U,ilh)
    100 	op(CALL,V,-)
    101 gop(RET,15)
    102 	op(RET,F,fdx)
    103 	op(RET,I,ilh)
    104 	op(RET,P,p)
    105 	op(RET,U,ilh)
    106 	op(RET,V,-)
    107 gop(ADDRG,16)
    108 	op(ADDRG,P,p)
    109 gop(ADDRF,17)
    110 	op(ADDRF,P,p)
    111 gop(ADDRL,18)
    112 	op(ADDRL,P,p)
    113 gop(ADD,19)
    114 	op(ADD,F,fdx)
    115 	op(ADD,I,ilh)
    116 	op(ADD,P,p)
    117 	op(ADD,U,ilhp)
    118 gop(SUB,20)
    119 	op(SUB,F,fdx)
    120 	op(SUB,I,ilh)
    121 	op(SUB,P,p)
    122 	op(SUB,U,ilhp)
    123 gop(LSH,21)
    124 	op(LSH,I,ilh)
    125 	op(LSH,U,ilh)
    126 gop(MOD,22)
    127 	op(MOD,I,ilh)
    128 	op(MOD,U,ilh)
    129 gop(RSH,23)
    130 	op(RSH,I,ilh)
    131 	op(RSH,U,ilh)
    132 gop(BAND,24)
    133 	op(BAND,I,ilh)
    134 	op(BAND,U,ilh)
    135 gop(BCOM,25)
    136 	op(BCOM,I,ilh)
    137 	op(BCOM,U,ilh)
    138 gop(BOR,26)
    139 	op(BOR,I,ilh)
    140 	op(BOR,U,ilh)
    141 gop(BXOR,27)
    142 	op(BXOR,I,ilh)
    143 	op(BXOR,U,ilh)
    144 gop(DIV,28)
    145 	op(DIV,F,fdx)
    146 	op(DIV,I,ilh)
    147 	op(DIV,U,ilh)
    148 gop(MUL,29)
    149 	op(MUL,F,fdx)
    150 	op(MUL,I,ilh)
    151 	op(MUL,U,ilh)
    152 gop(EQ,30)
    153 	op(EQ,F,fdx)
    154 	op(EQ,I,ilh)
    155 	op(EQ,U,ilhp)
    156 gop(GE,31)
    157 	op(GE,F,fdx)
    158 	op(GE,I,ilh)
    159 	op(GE,U,ilhp)
    160 gop(GT,32)
    161 	op(GT,F,fdx)
    162 	op(GT,I,ilh)
    163 	op(GT,U,ilhp)
    164 gop(LE,33)
    165 	op(LE,F,fdx)
    166 	op(LE,I,ilh)
    167 	op(LE,U,ilhp)
    168 gop(LT,34)
    169 	op(LT,F,fdx)
    170 	op(LT,I,ilh)
    171 	op(LT,U,ilhp)
    172 gop(NE,35)
    173 	op(NE,F,fdx)
    174 	op(NE,I,ilh)
    175 	op(NE,U,ilhp)
    176 gop(JUMP,36)
    177 	op(JUMP,V,-)
    178 gop(LABEL,37)
    179 	op(LABEL,V,-)
    180 gop(LOAD,14)
    181 	op(LOAD,B,-)
    182 	op(LOAD,F,fdx)
    183 	op(LOAD,I,csilh)
    184 	op(LOAD,P,p)
    185 	op(LOAD,U,csilhp)
    186 #undef gop
    187 #undef op
    188 	fprintf(stderr, "%d operators\n", count);
    189 	return EXIT_SUCCESS;
    190 }