1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/util/opt/Makefile Thu May 17 13:42:36 1984 +0000
1.3 @@ -0,0 +1,197 @@
1.4 +CFILES=main.c getline.c lookup.c var.c process.c backward.c util.c\
1.5 + alloc.c putline.c cleanup.c peephole.c flow.c reg.c
1.6 +OFILES=main.o getline.o lookup.o var.o process.o backward.o util.o\
1.7 + alloc.o putline.o cleanup.o peephole.o flow.o reg.o
1.8 +KFILES=main.k getline.k lookup.k var.k process.k backward.k util.k\
1.9 + alloc.k putline.k cleanup.k peephole.k flow.k reg.k
1.10 +LIBS=../../lib/em_data.a
1.11 +CFLAGS=-O -DNDEBUG
1.12 +LDFLAGS=-i
1.13 +LINT=lint
1.14 +OPR=wide|opr
1.15 +XREF=xref -c -w80
1.16 +PROPTS=
1.17 +# LEXLIB is implementation dependent, try -ll or -lln first
1.18 +LEXLIB=-lln
1.19 +
1.20 +opt: $(OFILES) pattern.o $(LIBS)
1.21 + cc $(LDFLAGS) $(CFLAGS) $(OFILES) pattern.o $(LIBS) -o opt
1.22 +
1.23 +test: opt
1.24 + testopt
1.25 +
1.26 +cmp : opt
1.27 + cmp opt ../../lib/em_opt
1.28 +
1.29 +install:opt
1.30 + -size opt ../../lib/em_opt
1.31 + cp opt ../../lib/em_opt
1.32 +
1.33 +pattern.c: patterns mktab
1.34 + ../../lib/cpp patterns | mktab > pattern.c
1.35 +
1.36 +mktab: mktab.o $(LIBS)
1.37 + cc $(CFLAGS) mktab.o $(LIBS) $(LEXLIB) -o mktab
1.38 +
1.39 +depend:
1.40 + makedepend
1.41 +
1.42 +lint: $(CFILES) pattern.c
1.43 + $(LINT) $(CFILES) pattern.c>lint 2>&1
1.44 +
1.45 +printall:
1.46 + -pr $(PROPTS) Makefile -n *.h `ls $(CFILES)` mktab.y scan.l patterns|$(OPR)
1.47 + touch print
1.48 +
1.49 +print: Makefile *.h $(CFILES) mktab.y scan.l patterns
1.50 + -pr $(PROPTS) $? | $(OPR)
1.51 +
1.52 +opr:
1.53 + make pr ^ $(OPR)
1.54 +
1.55 +pr:
1.56 + @pr $(PROPTS) Makefile *.h $(CFILES) mktab.y scan.l patterns
1.57 +
1.58 +xref:
1.59 + $(XREF) *.h $(CFILES) | pr $(PROPTS) -h "XREF EMOPT"|$(OPR)&
1.60 +
1.61 +sizes: opt
1.62 + -nm opt | sort -n| /usr/plain/bin/map
1.63 +
1.64 +clean:
1.65 + rm -f *.o opt mktab mktab.c scan.c pattern.c
1.66 +
1.67 +kfiles: $(KFILES)
1.68 +
1.69 +.SUFFIXES: .k
1.70 +.c.k: ; cem -c $*.c
1.71 +
1.72 +# the next lines are generated automatically
1.73 +# AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
1.74 +alloc.o: alloc.h
1.75 +alloc.o: assert.h
1.76 +alloc.o: line.h
1.77 +alloc.o: lookup.h
1.78 +alloc.o: param.h
1.79 +alloc.o: proinf.h
1.80 +alloc.o: types.h
1.81 +backward.o: ../../h/em_mnem.h
1.82 +backward.o: ../../h/em_pseu.h
1.83 +backward.o: ../../h/em_spec.h
1.84 +backward.o: alloc.h
1.85 +backward.o: assert.h
1.86 +backward.o: ext.h
1.87 +backward.o: line.h
1.88 +backward.o: lookup.h
1.89 +backward.o: param.h
1.90 +backward.o: proinf.h
1.91 +backward.o: types.h
1.92 +cleanup.o: ../../h/em_mes.h
1.93 +cleanup.o: ../../h/em_pseu.h
1.94 +cleanup.o: ../../h/em_spec.h
1.95 +cleanup.o: assert.h
1.96 +cleanup.o: ext.h
1.97 +cleanup.o: lookup.h
1.98 +cleanup.o: param.h
1.99 +cleanup.o: types.h
1.100 +flow.o: ../../h/em_flag.h
1.101 +flow.o: ../../h/em_mnem.h
1.102 +flow.o: ../../h/em_spec.h
1.103 +flow.o: alloc.h
1.104 +flow.o: ext.h
1.105 +flow.o: line.h
1.106 +flow.o: optim.h
1.107 +flow.o: param.h
1.108 +flow.o: proinf.h
1.109 +flow.o: types.h
1.110 +getline.o: ../../h/em_flag.h
1.111 +getline.o: ../../h/em_mes.h
1.112 +getline.o: ../../h/em_pseu.h
1.113 +getline.o: ../../h/em_spec.h
1.114 +getline.o: alloc.h
1.115 +getline.o: assert.h
1.116 +getline.o: ext.h
1.117 +getline.o: line.h
1.118 +getline.o: lookup.h
1.119 +getline.o: param.h
1.120 +getline.o: proinf.h
1.121 +getline.o: types.h
1.122 +lookup.o: alloc.h
1.123 +lookup.o: lookup.h
1.124 +lookup.o: param.h
1.125 +lookup.o: proinf.h
1.126 +lookup.o: types.h
1.127 +main.o: ../../h/em_spec.h
1.128 +main.o: alloc.h
1.129 +main.o: ext.h
1.130 +main.o: param.h
1.131 +main.o: types.h
1.132 +mktab.o: ../../h/em_mnem.h
1.133 +mktab.o: ../../h/em_spec.h
1.134 +mktab.o: optim.h
1.135 +mktab.o: param.h
1.136 +mktab.o: pattern.h
1.137 +mktab.o: scan.c
1.138 +mktab.o: types.h
1.139 +pattern.o: param.h
1.140 +pattern.o: pattern.h
1.141 +pattern.o: types.h
1.142 +peephole.o: ../../h/em_mnem.h
1.143 +peephole.o: ../../h/em_spec.h
1.144 +peephole.o: alloc.h
1.145 +peephole.o: assert.h
1.146 +peephole.o: ext.h
1.147 +peephole.o: line.h
1.148 +peephole.o: lookup.h
1.149 +peephole.o: optim.h
1.150 +peephole.o: param.h
1.151 +peephole.o: pattern.h
1.152 +peephole.o: proinf.h
1.153 +peephole.o: types.h
1.154 +process.o: ../../h/em_pseu.h
1.155 +process.o: ../../h/em_spec.h
1.156 +process.o: alloc.h
1.157 +process.o: assert.h
1.158 +process.o: ext.h
1.159 +process.o: line.h
1.160 +process.o: lookup.h
1.161 +process.o: param.h
1.162 +process.o: proinf.h
1.163 +process.o: types.h
1.164 +putline.o: ../../h/em_flag.h
1.165 +putline.o: ../../h/em_mnem.h
1.166 +putline.o: ../../h/em_pseu.h
1.167 +putline.o: ../../h/em_spec.h
1.168 +putline.o: alloc.h
1.169 +putline.o: assert.h
1.170 +putline.o: ext.h
1.171 +putline.o: line.h
1.172 +putline.o: lookup.h
1.173 +putline.o: optim.h
1.174 +putline.o: param.h
1.175 +putline.o: proinf.h
1.176 +putline.o: types.h
1.177 +reg.o: ../../h/em_mes.h
1.178 +reg.o: ../../h/em_pseu.h
1.179 +reg.o: ../../h/em_spec.h
1.180 +reg.o: alloc.h
1.181 +reg.o: assert.h
1.182 +reg.o: ext.h
1.183 +reg.o: line.h
1.184 +reg.o: param.h
1.185 +reg.o: proinf.h
1.186 +reg.o: types.h
1.187 +scan.o: stdio.h
1.188 +special.o: param.h
1.189 +special.o: types.h
1.190 +util.o: assert.h
1.191 +util.o: ext.h
1.192 +util.o: lookup.h
1.193 +util.o: optim.h
1.194 +util.o: param.h
1.195 +util.o: proinf.h
1.196 +util.o: types.h
1.197 +var.o: lookup.h
1.198 +var.o: param.h
1.199 +var.o: proinf.h
1.200 +var.o: types.h
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/util/opt/alloc.c Thu May 17 13:42:36 1984 +0000
2.3 @@ -0,0 +1,441 @@
2.4 +#include <stdio.h>
2.5 +#include "param.h"
2.6 +#include "types.h"
2.7 +#include "assert.h"
2.8 +#include "alloc.h"
2.9 +#include "line.h"
2.10 +#include "lookup.h"
2.11 +#include "proinf.h"
2.12 +
2.13 +/*
2.14 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
2.15 + *
2.16 + * This product is part of the Amsterdam Compiler Kit.
2.17 + *
2.18 + * Permission to use, sell, duplicate or disclose this software must be
2.19 + * obtained in writing. Requests for such permissions may be sent to
2.20 + *
2.21 + * Dr. Andrew S. Tanenbaum
2.22 + * Wiskundig Seminarium
2.23 + * Vrije Universiteit
2.24 + * Postbox 7161
2.25 + * 1007 MC Amsterdam
2.26 + * The Netherlands
2.27 + *
2.28 + * Author: Hans van Staveren
2.29 + */
2.30 +
2.31 +#ifdef USEMALLOC
2.32 +
2.33 +short * myalloc();
2.34 +
2.35 +#define newcore(size) myalloc(size)
2.36 +#define oldcore(p,size) free(p)
2.37 +
2.38 +#else
2.39 +
2.40 +/* #define CORECHECK /* if defined tests are made to insure
2.41 + each block occurs at most once */
2.42 +
2.43 +#define CCHUNK 1024 /* number of shorts asked from system */
2.44 +
2.45 +short *newcore(),*freshcore();
2.46 +extern char *sbrk();
2.47 +
2.48 +#ifdef COREDEBUG
2.49 +int shortsasked=0;
2.50 +#endif
2.51 +
2.52 +#endif
2.53 +
2.54 +/*
2.55 + * The following two sizetables contain the sizes of the various kinds
2.56 + * of line and argument structures.
2.57 + * Care has been taken to make this table implementation independent,
2.58 + * but if you think very hard you might find a compiler failing the
2.59 + * assumptions made.
2.60 + * A wasteful but safe approach is to replace every line of them by
2.61 + * sizeof(line_t)
2.62 + * and
2.63 + * sizeof(arg_t)
2.64 + * respectively.
2.65 + */
2.66 +
2.67 +#define LBASE (sizeof(line_t)-sizeof(un_l_a))
2.68 +
2.69 +int lsizetab[] = {
2.70 + LBASE,
2.71 + LBASE+sizeof(short),
2.72 + LBASE+sizeof(offset),
2.73 + LBASE+sizeof(num_p),
2.74 + LBASE+sizeof(sym_p),
2.75 + LBASE+sizeof(s_la_sval),
2.76 + LBASE+sizeof(s_la_lval),
2.77 + LBASE+sizeof(arg_p),
2.78 + LBASE
2.79 +};
2.80 +
2.81 +#define ABASE (sizeof(arg_t)-sizeof(un_a_a))
2.82 +
2.83 +int asizetab[] = {
2.84 + ABASE+sizeof(offset),
2.85 + ABASE+sizeof(num_p),
2.86 + ABASE+sizeof(sym_p),
2.87 + ABASE+sizeof(s_a_val),
2.88 + ABASE+sizeof(argb_t),
2.89 + ABASE+sizeof(s_a_con),
2.90 + ABASE+sizeof(s_a_con),
2.91 + ABASE+sizeof(s_a_con),
2.92 +};
2.93 +
2.94 +/*
2.95 + * alloc routines:
2.96 + * Two parts:
2.97 + * 1) typed alloc and free routines
2.98 + * 2) untyped raw core allocation
2.99 + */
2.100 +
2.101 +/*
2.102 + * PART 1
2.103 + */
2.104 +
2.105 +line_p newline(optyp) int optyp; {
2.106 + register line_p lnp;
2.107 + register kind=optyp;
2.108 +
2.109 + if (kind>OPMINI)
2.110 + kind = OPMINI;
2.111 + lnp = (line_p) newcore(lsizetab[kind]);
2.112 + lnp->l_optyp = optyp;
2.113 + return(lnp);
2.114 +}
2.115 +
2.116 +oldline(lnp) register line_p lnp; {
2.117 + register kind=lnp->l_optyp&BMASK;
2.118 +
2.119 + if (kind>OPMINI)
2.120 + kind = OPMINI;
2.121 + if (kind == OPLIST)
2.122 + oldargs(lnp->l_a.la_arg);
2.123 + oldcore((short *) lnp,lsizetab[kind]);
2.124 +}
2.125 +
2.126 +arg_p newarg(kind) int kind; {
2.127 + register arg_p ap;
2.128 +
2.129 + ap = (arg_p) newcore(asizetab[kind]);
2.130 + ap->a_typ = kind;
2.131 + return(ap);
2.132 +}
2.133 +
2.134 +oldargs(ap) register arg_p ap; {
2.135 + register arg_p next;
2.136 +
2.137 + while (ap != (arg_p) 0) {
2.138 + next = ap->a_next;
2.139 + switch(ap->a_typ) {
2.140 + case ARGSTR:
2.141 + oldargb(ap->a_a.a_string.ab_next);
2.142 + break;
2.143 + case ARGICN:
2.144 + case ARGUCN:
2.145 + case ARGFCN:
2.146 + oldargb(ap->a_a.a_con.ac_con.ab_next);
2.147 + break;
2.148 + }
2.149 + oldcore((short *) ap,asizetab[ap->a_typ]);
2.150 + ap = next;
2.151 + }
2.152 +}
2.153 +
2.154 +oldargb(abp) register argb_p abp; {
2.155 + register argb_p next;
2.156 +
2.157 + while (abp != (argb_p) 0) {
2.158 + next = abp->ab_next;
2.159 + oldcore((short *) abp,sizeof (argb_t));
2.160 + abp = next;
2.161 + }
2.162 +}
2.163 +
2.164 +reg_p newreg() {
2.165 +
2.166 + return((reg_p) newcore(sizeof(reg_t)));
2.167 +}
2.168 +
2.169 +oldreg(rp) reg_p rp; {
2.170 +
2.171 + oldcore((short *) rp,sizeof(reg_t));
2.172 +}
2.173 +
2.174 +num_p newnum() {
2.175 +
2.176 + return((num_p) newcore(sizeof(num_t)));
2.177 +}
2.178 +
2.179 +oldnum(lp) num_p lp; {
2.180 +
2.181 + oldcore((short *) lp,sizeof(num_t));
2.182 +}
2.183 +
2.184 +offset *newrom() {
2.185 +
2.186 + return((offset *) newcore(MAXROM*sizeof(offset)));
2.187 +}
2.188 +
2.189 +sym_p newsym() {
2.190 +
2.191 + return((sym_p) newcore(sizeof(sym_t)));
2.192 +}
2.193 +
2.194 +argb_p newargb() {
2.195 +
2.196 + return((argb_p) newcore(sizeof(argb_t)));
2.197 +}
2.198 +
2.199 +#ifndef USEMALLOC
2.200 +
2.201 +/******************************************************************/
2.202 +/****** Start of raw core management package *****************/
2.203 +/******************************************************************/
2.204 +
2.205 +#define MAXSHORT 30 /* Maximum number of shorts one can ask for */
2.206 +
2.207 +short *freelist[MAXSHORT];
2.208 +
2.209 +typedef struct coreblock {
2.210 + struct coreblock *co_next;
2.211 + short co_size;
2.212 +} core_t,*core_p;
2.213 +
2.214 +#define SINC (sizeof(core_t)/sizeof(short))
2.215 +#ifdef COREDEBUG
2.216 +coreverbose() {
2.217 + register size;
2.218 + register short *p;
2.219 + register sum;
2.220 +
2.221 + sum = 0;
2.222 + for(size=1;size<MAXSHORT;size++)
2.223 + for (p=freelist[size];p!=0;p = *(short **) p)
2.224 + sum += size;
2.225 + fprintf(stderr,"Used core %u\n",(shortsasked-sum)*sizeof(short));
2.226 +}
2.227 +#endif
2.228 +
2.229 +#ifdef SEPID
2.230 +
2.231 +compactcore() {
2.232 + register core_p corelist=0,tp,cl;
2.233 + int size;
2.234 +
2.235 +#ifdef COREDEBUG
2.236 + fprintf(stderr,"Almost out of core\n");
2.237 +#endif
2.238 + for(size=SINC;size<MAXSHORT;size++) {
2.239 + while ((tp = (core_p) freelist[size]) != (core_p) 0) {
2.240 + freelist[size] = (short *) tp->co_next;
2.241 + tp->co_size = size;
2.242 + if (corelist==0 || tp<corelist) {
2.243 + tp->co_next = corelist;
2.244 + corelist = tp;
2.245 + } else {
2.246 + for(cl=corelist;cl->co_next != 0 && tp>cl->co_next;
2.247 + cl = cl->co_next)
2.248 + ;
2.249 + tp->co_next = cl->co_next;
2.250 + cl->co_next = tp;
2.251 + }
2.252 + }
2.253 + }
2.254 + while (corelist != 0) {
2.255 + while ((short *) corelist->co_next ==
2.256 + (short *) corelist + corelist->co_size) {
2.257 + corelist->co_size += corelist->co_next->co_size;
2.258 + corelist->co_next = corelist->co_next->co_next;
2.259 + }
2.260 + assert(corelist->co_next==0 ||
2.261 + (short *) corelist->co_next >
2.262 + (short *) corelist + corelist->co_size);
2.263 + while (corelist->co_size >= MAXSHORT+SINC) {
2.264 + oldcore((short *) corelist + corelist->co_size-(MAXSHORT-1),
2.265 + sizeof(short)*(MAXSHORT-1));
2.266 + corelist->co_size -= MAXSHORT;
2.267 + }
2.268 + if (corelist->co_size >= MAXSHORT) {
2.269 + oldcore((short *) corelist + corelist->co_size-SINC,
2.270 + sizeof(short)*SINC);
2.271 + corelist->co_size -= SINC;
2.272 + }
2.273 + cl = corelist->co_next;
2.274 + oldcore((short *) corelist, sizeof(short)*corelist->co_size);
2.275 + corelist = cl;
2.276 + }
2.277 +}
2.278 +
2.279 +short *grabcore(size) int size; {
2.280 + register short *p;
2.281 + register trysize;
2.282 +
2.283 + /*
2.284 + * Desperate situation, can't get more core from system.
2.285 + * Postpone giving up just a little bit by splitting up
2.286 + * larger free blocks if possible.
2.287 + * Algorithm is worst fit.
2.288 + */
2.289 +
2.290 + assert(size<2*MAXSHORT);
2.291 + for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) {
2.292 + p = freelist[trysize/sizeof(short)];
2.293 + if ( p != (short *) 0) {
2.294 + freelist[trysize/sizeof(short)] = *(short **) p;
2.295 + oldcore(p+size/sizeof(short),trysize-size);
2.296 + return(p);
2.297 + }
2.298 + }
2.299 +
2.300 + /*
2.301 + * Can't get more core from the biggies, try to combine the
2.302 + * little ones. This is expensive but probably better than
2.303 + * giving up.
2.304 + */
2.305 +
2.306 + compactcore();
2.307 + if ((p=freelist[size/sizeof(short)]) != 0) {
2.308 + freelist[size/sizeof(short)] = * (short **) p;
2.309 + return(p);
2.310 + }
2.311 + for(trysize=2*MAXSHORT-2; trysize>size; trysize -= 2) {
2.312 + p = freelist[trysize/sizeof(short)];
2.313 + if ( p != (short *) 0) {
2.314 + freelist[trysize/sizeof(short)] = *(short **) p;
2.315 + oldcore(p+size/sizeof(short),trysize-size);
2.316 + return(p);
2.317 + }
2.318 + }
2.319 +
2.320 + /*
2.321 + * That's it then. Finished.
2.322 + */
2.323 +
2.324 + return(0);
2.325 +}
2.326 +#endif /* SEPID */
2.327 +
2.328 +short *newcore(size) int size; {
2.329 + register short *p,*q;
2.330 +
2.331 + if( size < 2*MAXSHORT ) {
2.332 + if ((p=freelist[size/sizeof(short)]) != (short *) 0)
2.333 + freelist[size/sizeof(short)] = *(short **) p;
2.334 + else {
2.335 + p = freshcore(size);
2.336 +#ifdef SEPID
2.337 + if (p == (short *) 0)
2.338 + p = grabcore(size);
2.339 +#endif
2.340 + }
2.341 + } else
2.342 + p = freshcore(size);
2.343 + if (p == 0)
2.344 + error("out of memory");
2.345 + for (q=p; size > 0 ; size -= sizeof(short))
2.346 + *q++ = 0;
2.347 + return(p);
2.348 +}
2.349 +
2.350 +#ifdef NOMALLOC
2.351 +
2.352 +/*
2.353 + * stdio uses malloc and free.
2.354 + * you can use these as substitutes
2.355 + */
2.356 +
2.357 +char *malloc(size) int size; {
2.358 +
2.359 + /*
2.360 + * malloc(III) is called by stdio,
2.361 + * this routine is a substitute.
2.362 + */
2.363 +
2.364 + return( (char *) newcore(size));
2.365 +}
2.366 +
2.367 +free() {
2.368 +
2.369 +}
2.370 +#endif
2.371 +
2.372 +oldcore(p,size) short *p; int size; {
2.373 +#ifdef CORECHECK
2.374 + register short *cp;
2.375 +#endif
2.376 +
2.377 + assert(size<2*MAXSHORT);
2.378 +#ifdef CORECHECK
2.379 + for (cp=freelist[size/sizeof(short)]; cp != (short *) 0;
2.380 + cp = (short *) *cp)
2.381 + assert(cp != p);
2.382 +#endif
2.383 + *(short **) p = freelist[size/sizeof(short)];
2.384 + freelist[size/sizeof(short)] = p;
2.385 +}
2.386 +
2.387 +short *ccur,*cend;
2.388 +
2.389 +coreinit(p1,p2) short *p1,*p2; {
2.390 +
2.391 + /*
2.392 + * coreinit is called with the boundaries of a piece of
2.393 + * memory that can be used for starters.
2.394 + */
2.395 +
2.396 + ccur = p1;
2.397 + cend = p2;
2.398 +}
2.399 +
2.400 +short *freshcore(size) int size; {
2.401 + register short *temp;
2.402 + static int cchunk=CCHUNK;
2.403 +
2.404 + while(&ccur[size/sizeof(short)] >= cend && cchunk>0) {
2.405 + do {
2.406 + temp = (short *) sbrk(cchunk*sizeof(short));
2.407 + if (temp == (short *) -1)
2.408 + cchunk >>= 1;
2.409 + else if (temp != cend)
2.410 + ccur = cend = temp;
2.411 + } while (temp == (short *) -1 && cchunk>0);
2.412 + cend += cchunk;
2.413 +#ifdef COREDEBUG
2.414 + shortsasked += cchunk;
2.415 +#endif
2.416 + }
2.417 + if (cchunk==0)
2.418 + return(0);
2.419 + temp = ccur;
2.420 + ccur = &ccur[size/sizeof(short)];
2.421 + return(temp);
2.422 +}
2.423 +
2.424 +#else /* USEMALLOC */
2.425 +
2.426 +coreinit() {
2.427 +
2.428 + /*
2.429 + * Empty function, no initialization needed
2.430 + */
2.431 +}
2.432 +
2.433 +short *myalloc(size) register size; {
2.434 + register short *p,*q;
2.435 + extern char *malloc();
2.436 +
2.437 + p = (short *)malloc(size);
2.438 + if (p == 0)
2.439 + error("out of memory");
2.440 + for(q=p;size>0;size -= sizeof(short))
2.441 + *q++ = 0;
2.442 + return(p);
2.443 +}
2.444 +#endif
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/util/opt/alloc.h Thu May 17 13:42:36 1984 +0000
3.3 @@ -0,0 +1,53 @@
3.4 +extern line_p newline();
3.5 +extern offset *newrom();
3.6 +extern sym_p newsym();
3.7 +extern num_p newnum();
3.8 +extern arg_p newarg();
3.9 +extern argb_p newargb();
3.10 +extern reg_p newreg();
3.11 +
3.12 +extern oldline();
3.13 +extern oldloc();
3.14 +extern oldreg();
3.15 +
3.16 +/* #define USEMALLOC /* if defined malloc() and free() are used */
3.17 +
3.18 +/* #define COREDEBUG /* keep records and print statistics */
3.19 +
3.20 +/*
3.21 + * The next define gives if defined the number of pseudo's outside
3.22 + * procedures that are collected without processing.
3.23 + * If undefined all pseudo's will be collected but that may
3.24 + * give trouble on small machines, because of lack of room.
3.25 + */
3.26 +#define PSEUBETWEEN 200
3.27 +
3.28 +#ifndef USEMALLOC
3.29 +/*
3.30 + * Now the real bitsqueezing starts.
3.31 + * When running on a machine where code and data live in
3.32 + * separate address-spaces it is worth putting in some extra
3.33 + * code to save on probably less data.
3.34 + */
3.35 +#define SEPID /* code and data in separate spaces */
3.36 +/*
3.37 + * If the stack segment and the data are separate as on a PDP11 under UNIX
3.38 + * it is worth squeezing some shorts out of the stack page.
3.39 + */
3.40 +#ifndef EM_WSIZE
3.41 +/*
3.42 + * Compiled with 'standard' C compiler
3.43 + */
3.44 +#define STACKROOM 3200 /* number of shorts space in stack */
3.45 +#else
3.46 +/*
3.47 + * Compiled with pcc, has trouble with lots of variables
3.48 + */
3.49 +#define STACKROOM 2000
3.50 +#endif
3.51 +
3.52 +#else
3.53 +
3.54 +#define STACKROOM 1 /* 0 gives problems */
3.55 +
3.56 +#endif /* USEMALLOC */
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/util/opt/assert.h Thu May 17 13:42:36 1984 +0000
4.3 @@ -0,0 +1,5 @@
4.4 +#ifndef NDEBUG
4.5 +#define assert(x) if(!(x)) badassertion(__FILE__,__LINE__)
4.6 +#else
4.7 +#define assert(x) /* nothing */
4.8 +#endif
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/util/opt/backward.c Thu May 17 13:42:36 1984 +0000
5.3 @@ -0,0 +1,183 @@
5.4 +#include "param.h"
5.5 +#include "types.h"
5.6 +#include "assert.h"
5.7 +#include "line.h"
5.8 +#include "lookup.h"
5.9 +#include "alloc.h"
5.10 +#include "proinf.h"
5.11 +#include "../../h/em_spec.h"
5.12 +#include "../../h/em_pseu.h"
5.13 +#include "../../h/em_mnem.h"
5.14 +#include "ext.h"
5.15 +
5.16 +/*
5.17 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
5.18 + *
5.19 + * This product is part of the Amsterdam Compiler Kit.
5.20 + *
5.21 + * Permission to use, sell, duplicate or disclose this software must be
5.22 + * obtained in writing. Requests for such permissions may be sent to
5.23 + *
5.24 + * Dr. Andrew S. Tanenbaum
5.25 + * Wiskundig Seminarium
5.26 + * Vrije Universiteit
5.27 + * Postbox 7161
5.28 + * 1007 MC Amsterdam
5.29 + * The Netherlands
5.30 + *
5.31 + * Author: Hans van Staveren
5.32 + */
5.33 +
5.34 +#define local(x) if (((x)->s_flags&SYMKNOWN) == 0)\
5.35 + x->s_flags &= ~ SYMGLOBAL
5.36 +#define global(x) if(((x)->s_flags&SYMKNOWN) == 0)\
5.37 + x->s_flags |= SYMGLOBAL
5.38 +
5.39 +#define DTYPHOL 1
5.40 +#define DTYPBSS 2
5.41 +#define DTYPCON 3
5.42 +#define DTYPROM 4
5.43 +byte curdtyp;
5.44 +bool goodrom;
5.45 +short curfrag = 3; /* see also peephole.c */
5.46 +offset rombuf[MAXROM];
5.47 +int rc;
5.48 +
5.49 +backward() {
5.50 + register line_p lnp;
5.51 + line_p next;
5.52 + register arg_p ap;
5.53 + line_p i,p;
5.54 + int n;
5.55 + register sym_p sp;
5.56 +
5.57 + i = p = (line_p) 0;
5.58 + curdtyp=0;
5.59 + for (lnp = curpro.lastline; lnp != (line_p) 0; lnp = next) {
5.60 + next = lnp->l_next;
5.61 + switch(lnp->l_optyp) {
5.62 + case OPSYMBOL:
5.63 + global(lnp->l_a.la_sp);
5.64 + break;
5.65 + case OPSVAL:
5.66 + global(lnp->l_a.la_sval.lasv_sp);
5.67 + break;
5.68 + case OPLVAL:
5.69 + global(lnp->l_a.la_lval.lalv_sp);
5.70 + break;
5.71 + case OPLIST:
5.72 + ap = lnp->l_a.la_arg;
5.73 + while (ap != (arg_p) 0 ) {
5.74 + switch(ap->a_typ) {
5.75 + case ARGSYM:
5.76 + global(ap->a_a.a_sp);
5.77 + break;
5.78 + case ARGVAL:
5.79 + global(ap->a_a.a_val.av_sp);
5.80 + }
5.81 + ap = ap->a_next;
5.82 + }
5.83 + break;
5.84 + }
5.85 +
5.86 + /*
5.87 + * references to symbols are processed now.
5.88 + * for plain instructions nothing else is needed
5.89 + */
5.90 +
5.91 + switch(lnp->l_instr&BMASK) {
5.92 + /*
5.93 + * count all local occurences for register counts;
5.94 + * op_lal is omitted and not by accident.
5.95 + */
5.96 + case op_del:
5.97 + case op_inl:
5.98 + case op_ldl:
5.99 + case op_lil:
5.100 + case op_lol:
5.101 + case op_sdl:
5.102 + case op_sil:
5.103 + case op_stl:
5.104 + case op_zrl:
5.105 + switch(lnp->l_optyp) {
5.106 + case OPNO:
5.107 + case OPNUMLAB:
5.108 + case OPSYMBOL:
5.109 + case OPSVAL:
5.110 + case OPLVAL:
5.111 + case OPLIST:
5.112 + break;
5.113 + case OPOFFSET:
5.114 + incregusage(lnp->l_a.la_offset);
5.115 + break;
5.116 + case OPSHORT:
5.117 + incregusage((offset)lnp->l_a.la_short);
5.118 + break;
5.119 + default:
5.120 + incregusage((offset)(lnp->l_optyp&BMASK)-Z_OPMINI);
5.121 + break;
5.122 + }
5.123 + /* fall through !! */
5.124 + default:
5.125 + assert((lnp->l_instr&BMASK)<=op_last);
5.126 + lnp->l_next = i;
5.127 + i = lnp;
5.128 + continue;
5.129 + case ps_sym:
5.130 + sp = lnp->l_a.la_sp;
5.131 + local(sp);
5.132 + if (curdtyp == DTYPROM && goodrom) {
5.133 + sp->s_rom = newrom();
5.134 + for (n=0;n<rc;n++)
5.135 + sp->s_rom[n] = rombuf[n];
5.136 + }
5.137 + sp->s_frag = curfrag;
5.138 + break;
5.139 + case ps_hol:
5.140 + curdtyp = DTYPHOL;
5.141 + curfrag++;
5.142 + break;
5.143 + case ps_bss:
5.144 + curdtyp = DTYPBSS;
5.145 + curfrag++;
5.146 + break;
5.147 + case ps_con:
5.148 + if (curdtyp != DTYPCON) {
5.149 + curdtyp = DTYPCON;
5.150 + curfrag++;
5.151 + }
5.152 + break;
5.153 + case ps_rom:
5.154 + if (curdtyp != DTYPROM) {
5.155 + curdtyp = DTYPROM;
5.156 + curfrag++;
5.157 + }
5.158 + ap = lnp->l_a.la_arg;
5.159 + rc = 0;
5.160 + while (ap != (arg_p) 0 && rc < MAXROM) {
5.161 + if (ap->a_typ == ARGOFF) {
5.162 + rombuf[rc++] = ap->a_a.a_offset;
5.163 + ap = ap->a_next;
5.164 + } else
5.165 + ap = (arg_p) 0;
5.166 + }
5.167 + goodrom = (rc >= 2);
5.168 + break;
5.169 + case ps_mes:
5.170 + break;
5.171 + case ps_inp:
5.172 + case ps_ina:
5.173 + local(lnp->l_a.la_sp);
5.174 + case ps_exp:
5.175 + case ps_exa:
5.176 + case ps_exc:
5.177 + oldline(lnp);
5.178 + continue;
5.179 + }
5.180 + lnp->l_next = p;
5.181 + p = lnp;
5.182 + }
5.183 + if (prodepth != 0)
5.184 + local(curpro.symbol);
5.185 + instrs = i; pseudos = p; curpro.lastline = (line_p) 0;
5.186 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/util/opt/cleanup.c Thu May 17 13:42:36 1984 +0000
6.3 @@ -0,0 +1,61 @@
6.4 +#include <stdio.h>
6.5 +#include "param.h"
6.6 +#include "types.h"
6.7 +#include "assert.h"
6.8 +#include "../../h/em_pseu.h"
6.9 +#include "../../h/em_spec.h"
6.10 +#include "../../h/em_mes.h"
6.11 +#include "lookup.h"
6.12 +#include "ext.h"
6.13 +
6.14 +/*
6.15 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
6.16 + *
6.17 + * This product is part of the Amsterdam Compiler Kit.
6.18 + *
6.19 + * Permission to use, sell, duplicate or disclose this software must be
6.20 + * obtained in writing. Requests for such permissions may be sent to
6.21 + *
6.22 + * Dr. Andrew S. Tanenbaum
6.23 + * Wiskundig Seminarium
6.24 + * Vrije Universiteit
6.25 + * Postbox 7161
6.26 + * 1007 MC Amsterdam
6.27 + * The Netherlands
6.28 + *
6.29 + * Author: Hans van Staveren
6.30 + */
6.31 +
6.32 +
6.33 +cleanup() {
6.34 + FILE *infile;
6.35 + register c;
6.36 + register sym_p *spp,sp;
6.37 +
6.38 + for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
6.39 + for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
6.40 + if ((sp->s_flags & SYMOUT) == 0)
6.41 + outdef(sp);
6.42 + if(!Lflag)
6.43 + return;
6.44 + c=fclose(outfile);
6.45 + assert(c != EOF);
6.46 + outfile = stdout;
6.47 + infile = fopen(template,"r");
6.48 + if (infile == NULL)
6.49 + error("temp file disappeared");
6.50 + outshort(sp_magic);
6.51 + outinst(ps_mes);
6.52 + outint(ms_ext);
6.53 + for (spp=symhash;spp< &symhash[NSYMHASH];spp++)
6.54 + for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
6.55 + if ((sp->s_flags&(SYMDEF|SYMGLOBAL)) == (SYMDEF|SYMGLOBAL))
6.56 + outsym(sp);
6.57 + putc(sp_cend,outfile);
6.58 + while ( (c=getc(infile)) != EOF)
6.59 + putc(c,outfile);
6.60 + c=fclose(infile);
6.61 + assert(c != EOF);
6.62 + c=unlink(template);
6.63 + assert(c == 0);
6.64 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/util/opt/ext.h Thu May 17 13:42:36 1984 +0000
7.3 @@ -0,0 +1,14 @@
7.4 +#ifndef FILE
7.5 +#include <stdio.h>
7.6 +#endif
7.7 +extern unsigned linecount;
7.8 +extern int prodepth;
7.9 +extern bool Lflag;
7.10 +extern bool nflag;
7.11 +extern byte em_flag[];
7.12 +extern line_p instrs,pseudos;
7.13 +extern FILE *outfile;
7.14 +extern char template[];
7.15 +extern offset wordsize;
7.16 +extern offset pointersize;
7.17 +extern char *progname;
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/util/opt/flow.c Thu May 17 13:42:36 1984 +0000
8.3 @@ -0,0 +1,122 @@
8.4 +#include "param.h"
8.5 +#include "types.h"
8.6 +#include "../../h/em_flag.h"
8.7 +#include "../../h/em_spec.h"
8.8 +#include "../../h/em_mnem.h"
8.9 +#include "alloc.h"
8.10 +#include "line.h"
8.11 +#include "proinf.h"
8.12 +#include "optim.h"
8.13 +#include "ext.h"
8.14 +
8.15 +/*
8.16 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
8.17 + *
8.18 + * This product is part of the Amsterdam Compiler Kit.
8.19 + *
8.20 + * Permission to use, sell, duplicate or disclose this software must be
8.21 + * obtained in writing. Requests for such permissions may be sent to
8.22 + *
8.23 + * Dr. Andrew S. Tanenbaum
8.24 + * Wiskundig Seminarium
8.25 + * Vrije Universiteit
8.26 + * Postbox 7161
8.27 + * 1007 MC Amsterdam
8.28 + * The Netherlands
8.29 + *
8.30 + * Author: Hans van Staveren
8.31 + */
8.32 +
8.33 +flow() {
8.34 +
8.35 + findreach(); /* determine reachable labels */
8.36 + cleaninstrs(); /* throw away unreachable code */
8.37 +}
8.38 +
8.39 +findreach() {
8.40 + register num_p *npp,np;
8.41 +
8.42 + reach(instrs);
8.43 + for(npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++)
8.44 + for(np= *npp; np != (num_p) 0 ; np = np->n_next)
8.45 + if (np->n_flags&NUMDATA) {
8.46 + np->n_repl->n_flags |= NUMREACH;
8.47 + np->n_repl->n_jumps++;
8.48 + if (!(np->n_flags&NUMSCAN)) {
8.49 + np->n_flags |= NUMSCAN;
8.50 + reach(np->n_line->l_next);
8.51 + }
8.52 + }
8.53 +}
8.54 +
8.55 +reach(lnp) register line_p lnp; {
8.56 + register num_p np;
8.57 +
8.58 + for (;lnp != (line_p) 0; lnp = lnp->l_next) {
8.59 + if(lnp->l_optyp == OPNUMLAB) {
8.60 + /*
8.61 + * Branch instruction or label
8.62 + */
8.63 + np = lnp->l_a.la_np;
8.64 + if ((lnp->l_instr&BMASK) != op_lab)
8.65 + np = np->n_repl;
8.66 + np->n_flags |= NUMREACH;
8.67 + if (!(np->n_flags&NUMSCAN)) {
8.68 + np->n_flags |= NUMSCAN;
8.69 + reach(np->n_line->l_next);
8.70 + }
8.71 + if ((lnp->l_instr&BMASK) == op_lab)
8.72 + return;
8.73 + else
8.74 + np->n_jumps++;
8.75 + }
8.76 + if ((em_flag[(lnp->l_instr&BMASK)-sp_fmnem]&EM_FLO)==FLO_T)
8.77 + return;
8.78 + }
8.79 +}
8.80 +
8.81 +cleaninstrs() {
8.82 + register line_p *lpp,lp,*lastbra;
8.83 + bool reachable,superfluous;
8.84 + int instr;
8.85 +
8.86 + lpp = &instrs; lastbra = (line_p *) 0; reachable = TRUE;
8.87 + while ((lp = *lpp) != (line_p) 0) {
8.88 + instr = lp->l_instr&BMASK;
8.89 + if (instr == op_lab) {
8.90 + if ((lp->l_a.la_np->n_flags&NUMREACH) != 0) {
8.91 + reachable = TRUE;
8.92 + if (lastbra != (line_p *) 0
8.93 + && (*lastbra)->l_next == lp
8.94 + && (*lastbra)->l_a.la_np->n_repl==lp->l_a.la_np) {
8.95 + oldline(*lastbra);
8.96 + OPTIM(O_BRALAB);
8.97 + lpp = lastbra;
8.98 + *lpp = lp;
8.99 + lp->l_a.la_np->n_jumps--;
8.100 + }
8.101 + }
8.102 + if ( lp->l_a.la_np->n_repl != lp->l_a.la_np ||
8.103 + ((lp->l_a.la_np->n_flags&NUMDATA)==0 &&
8.104 + lp->l_a.la_np->n_jumps == 0))
8.105 + superfluous = TRUE;
8.106 + else
8.107 + superfluous = FALSE;
8.108 + } else
8.109 + superfluous = FALSE;
8.110 + if ( (!reachable) || superfluous) {
8.111 + lp = lp->l_next;
8.112 + oldline(*lpp);
8.113 + OPTIM(O_UNREACH);
8.114 + *lpp = lp;
8.115 + } else {
8.116 + if ( instr <= sp_lmnem &&
8.117 + (em_flag[instr-sp_fmnem]&EM_FLO)==FLO_T) {
8.118 + reachable = FALSE;
8.119 + if ((lp->l_instr&BMASK) == op_bra)
8.120 + lastbra = lpp;
8.121 + }
8.122 + lpp = &lp->l_next;
8.123 + }
8.124 + }
8.125 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/util/opt/getline.c Thu May 17 13:42:36 1984 +0000
9.3 @@ -0,0 +1,549 @@
9.4 +#include <stdio.h>
9.5 +#include "param.h"
9.6 +#include "types.h"
9.7 +#include "assert.h"
9.8 +#include "line.h"
9.9 +#include "lookup.h"
9.10 +#include "alloc.h"
9.11 +#include "proinf.h"
9.12 +#include "../../h/em_spec.h"
9.13 +#include "../../h/em_pseu.h"
9.14 +#include "../../h/em_flag.h"
9.15 +#include "../../h/em_mes.h"
9.16 +#include "ext.h"
9.17 +
9.18 +/*
9.19 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
9.20 + *
9.21 + * This product is part of the Amsterdam Compiler Kit.
9.22 + *
9.23 + * Permission to use, sell, duplicate or disclose this software must be
9.24 + * obtained in writing. Requests for such permissions may be sent to
9.25 + *
9.26 + * Dr. Andrew S. Tanenbaum
9.27 + * Wiskundig Seminarium
9.28 + * Vrije Universiteit
9.29 + * Postbox 7161
9.30 + * 1007 MC Amsterdam
9.31 + * The Netherlands
9.32 + *
9.33 + * Author: Hans van Staveren
9.34 + */
9.35 +
9.36 +
9.37 +static short tabval; /* temp store for shorts */
9.38 +static offset tabval2; /* temp store for offsets */
9.39 +static char string[IDL+1]; /* temp store for names */
9.40 +
9.41 +/*
9.42 + * The next constants are close to sp_cend for fast switches
9.43 + */
9.44 +#define INST 256 /* instruction: number in tabval */
9.45 +#define PSEU 257 /* pseudo: number in tabval */
9.46 +#define ILBX 258 /* label: number in tabval */
9.47 +#define DLBX 259 /* symbol: name in string[] */
9.48 +#define CSTX1 260 /* short constant: stored in tabval */
9.49 +#define CSTX2 261 /* offset: value in tabval2 */
9.50 +#define VALX1 262 /* symbol+short: in string[] and tabval */
9.51 +#define VALX2 263 /* symbol+offset: in string[] and tabval2 */
9.52 +#define ATEOF 264 /* bumped into end of file */
9.53 +
9.54 +#define readbyte getchar
9.55 +
9.56 +short readshort() {
9.57 + register int l_byte, h_byte;
9.58 +
9.59 + l_byte = readbyte();
9.60 + h_byte = readbyte();
9.61 + if ( h_byte>=128 ) h_byte -= 256 ;
9.62 + return l_byte | (h_byte*256) ;
9.63 +}
9.64 +
9.65 +#ifdef LONGOFF
9.66 +offset readoffset() {
9.67 + register long l;
9.68 + register int h_byte;
9.69 +
9.70 + l = readbyte();
9.71 + l |= ((unsigned) readbyte())*256 ;
9.72 + l |= readbyte()*256L*256L ;
9.73 + h_byte = readbyte() ;
9.74 + if ( h_byte>=128 ) h_byte -= 256 ;
9.75 + return l | (h_byte*256L*256*256L) ;
9.76 +}
9.77 +#endif
9.78 +
9.79 +draininput() {
9.80 +
9.81 + /*
9.82 + * called when MES ERR is encountered.
9.83 + * Drain input in case it is a pipe.
9.84 + */
9.85 +
9.86 + while (getchar() != EOF)
9.87 + ;
9.88 +}
9.89 +
9.90 +short getint() {
9.91 +
9.92 + switch(table2()) {
9.93 + default: error("int expected");
9.94 + case CSTX1:
9.95 + return(tabval);
9.96 + }
9.97 +}
9.98 +
9.99 +sym_p getsym(status) int status; {
9.100 +
9.101 + switch(table2()) {
9.102 + default:
9.103 + error("symbol expected");
9.104 + case DLBX:
9.105 + return(symlookup(string,status,0));
9.106 + case sp_pnam:
9.107 + return(symlookup(string,status,SYMPRO));
9.108 + }
9.109 +}
9.110 +
9.111 +offset getoff() {
9.112 +
9.113 + switch (table2()) {
9.114 + default: error("offset expected");
9.115 + case CSTX1:
9.116 + return((offset) tabval);
9.117 +#ifdef LONGOFF
9.118 + case CSTX2:
9.119 + return(tabval2);
9.120 +#endif
9.121 + }
9.122 +}
9.123 +
9.124 +make_string(n) int n; {
9.125 + register char *s;
9.126 + extern char *sprintf();
9.127 +
9.128 + s=sprintf(string,".%u",n);
9.129 + assert(s == string);
9.130 +}
9.131 +
9.132 +inident() {
9.133 + register n;
9.134 + register char *p = string;
9.135 + register c;
9.136 +
9.137 + n = getint();
9.138 + while (n--) {
9.139 + c = readbyte();
9.140 + if (p<&string[IDL])
9.141 + *p++ = c;
9.142 + }
9.143 + *p++ = 0;
9.144 +}
9.145 +
9.146 +int table3(n) int n; {
9.147 +
9.148 + switch (n) {
9.149 + case sp_ilb1: tabval = readbyte(); return(ILBX);
9.150 + case sp_ilb2: tabval = readshort(); return(ILBX);
9.151 + case sp_dlb1: make_string(readbyte()); return(DLBX);
9.152 + case sp_dlb2: make_string(readshort()); return(DLBX);
9.153 + case sp_dnam: inident(); return(DLBX);
9.154 + case sp_pnam: inident(); return(n);
9.155 + case sp_cst2: tabval = readshort(); return(CSTX1);
9.156 +#ifdef LONGOFF
9.157 + case sp_cst4: tabval2 = readoffset(); return(CSTX2);
9.158 +#endif
9.159 + case sp_doff: if (table2()!=DLBX) error("symbol expected");
9.160 + switch(table2()) {
9.161 + default: error("offset expected");
9.162 + case CSTX1: return(VALX1);
9.163 +#ifdef LONGOFF
9.164 + case CSTX2: return(VALX2);
9.165 +#endif
9.166 + }
9.167 + default: return(n);
9.168 + }
9.169 +}
9.170 +
9.171 +int table1() {
9.172 + register n;
9.173 +
9.174 + n = readbyte();
9.175 + if (n == EOF)
9.176 + return(ATEOF);
9.177 + if ((n <= sp_lmnem) && (n >= sp_fmnem)) {
9.178 + tabval = n;
9.179 + return(INST);
9.180 + }
9.181 + if ((n <= sp_lpseu) && (n >= sp_fpseu)) {
9.182 + tabval = n;
9.183 + return(PSEU);
9.184 + }
9.185 + if ((n < sp_filb0 + sp_nilb0) && (n >= sp_filb0)) {
9.186 + tabval = n - sp_filb0;
9.187 + return(ILBX);
9.188 + }
9.189 + return(table3(n));
9.190 +}
9.191 +
9.192 +int table2() {
9.193 + register n;
9.194 +
9.195 + n = readbyte();
9.196 + if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) {
9.197 + tabval = n - sp_zcst0;
9.198 + return(CSTX1);
9.199 + }
9.200 + return(table3(n));
9.201 +}
9.202 +
9.203 +getlines() {
9.204 + register line_p lnp;
9.205 + register instr;
9.206 +
9.207 + for(;;) {
9.208 + linecount++;
9.209 + switch(table1()) {
9.210 + default:
9.211 + error("unknown instruction byte");
9.212 + /* NOTREACHED */
9.213 +
9.214 + case ATEOF:
9.215 + if (prodepth!=0)
9.216 + error("procedure unterminated at eof");
9.217 + process();
9.218 + return;
9.219 + case INST:
9.220 + tstinpro();
9.221 + instr = tabval;
9.222 + break;
9.223 + case DLBX:
9.224 + lnp = newline(OPSYMBOL);
9.225 + lnp->l_instr = ps_sym;
9.226 + lnp->l_a.la_sp= symlookup(string,DEFINING,0);
9.227 + lnp->l_next = curpro.lastline;
9.228 + curpro.lastline = lnp;
9.229 + continue;
9.230 + case ILBX:
9.231 + tstinpro();
9.232 + lnp = newline(OPNUMLAB);
9.233 + lnp->l_instr = op_lab;
9.234 + lnp->l_a.la_np = numlookup((unsigned) tabval);
9.235 + if (lnp->l_a.la_np->n_line != (line_p) 0)
9.236 + error("label %u multiple defined",(unsigned) tabval);
9.237 + lnp->l_a.la_np->n_line = lnp;
9.238 + lnp->l_next = curpro.lastline;
9.239 + curpro.lastline = lnp;
9.240 + continue;
9.241 + case PSEU:
9.242 + if(inpseudo(tabval))
9.243 + return;
9.244 + continue;
9.245 + }
9.246 +
9.247 + /*
9.248 + * Now we have an instruction number in instr
9.249 + * There might be an operand, look for it
9.250 + */
9.251 +
9.252 + if ((em_flag[instr-sp_fmnem]&EM_PAR)==PAR_NO) {
9.253 + lnp = newline(OPNO);
9.254 + } else switch(table2()) {
9.255 + default:
9.256 + error("unknown offset byte");
9.257 + case sp_cend:
9.258 + lnp = newline(OPNO);
9.259 + break;
9.260 + case CSTX1:
9.261 + if ((em_flag[instr-sp_fmnem]&EM_PAR)!= PAR_B) {
9.262 + if (CANMINI(tabval))
9.263 + lnp = newline(tabval+Z_OPMINI);
9.264 + else {
9.265 + lnp = newline(OPSHORT);
9.266 + lnp->l_a.la_short = tabval;
9.267 + }
9.268 + } else {
9.269 + lnp = newline(OPNUMLAB);
9.270 + lnp->l_a.la_np = numlookup((unsigned) tabval);
9.271 + }
9.272 + break;
9.273 +#ifdef LONGOFF
9.274 + case CSTX2:
9.275 + lnp = newline(OPOFFSET);
9.276 + lnp->l_a.la_offset = tabval2;
9.277 + break;
9.278 +#endif
9.279 + case ILBX:
9.280 + tstinpro();
9.281 + lnp = newline(OPNUMLAB);
9.282 + lnp->l_a.la_np = numlookup((unsigned) tabval);
9.283 + break;
9.284 + case DLBX:
9.285 + lnp = newline(OPSYMBOL);
9.286 + lnp->l_a.la_sp = symlookup(string,OCCURRING,0);
9.287 + break;
9.288 + case sp_pnam:
9.289 + lnp = newline(OPSYMBOL);
9.290 + lnp->l_a.la_sp = symlookup(string,OCCURRING,SYMPRO);
9.291 + break;
9.292 + case VALX1:
9.293 + lnp = newline(OPSVAL);
9.294 + lnp->l_a.la_sval.lasv_sp = symlookup(string,OCCURRING,0);
9.295 + lnp->l_a.la_sval.lasv_short = tabval;
9.296 + break;
9.297 +#ifdef LONGOFF
9.298 + case VALX2:
9.299 + lnp = newline(OPLVAL);
9.300 + lnp->l_a.la_lval.lalv_sp = symlookup(string,OCCURRING,0);
9.301 + lnp->l_a.la_lval.lalv_offset = tabval2;
9.302 + break;
9.303 +#endif
9.304 + }
9.305 + lnp->l_instr = instr;
9.306 + lnp->l_next = curpro.lastline;
9.307 + curpro.lastline = lnp;
9.308 + }
9.309 +}
9.310 +
9.311 +argstring(length,abp) offset length; register argb_p abp; {
9.312 +
9.313 + while (length--) {
9.314 + if (abp->ab_index == NARGBYTES)
9.315 + abp = abp->ab_next = newargb();
9.316 + abp->ab_contents[abp->ab_index++] = readbyte();
9.317 + }
9.318 +}
9.319 +
9.320 +line_p arglist(n) int n; {
9.321 + line_p lnp;
9.322 + register arg_p ap,*app;
9.323 + bool moretocome;
9.324 + offset length;
9.325 +
9.326 +
9.327 + /*
9.328 + * creates an arglist with n elements
9.329 + * if n == 0 the arglist is variable and terminated by sp_cend
9.330 + */
9.331 +
9.332 + lnp = newline(OPLIST);
9.333 + app = &lnp->l_a.la_arg;
9.334 + moretocome = TRUE;
9.335 + do {
9.336 + switch(table2()) {
9.337 + default:
9.338 + error("unknown byte in arglist");
9.339 + case CSTX1:
9.340 + tabval2 = (offset) tabval;
9.341 + case CSTX2:
9.342 + *app = ap = newarg(ARGOFF);
9.343 + ap->a_a.a_offset = tabval2;
9.344 + app = &ap->a_next;
9.345 + break;
9.346 + case ILBX:
9.347 + tstinpro();
9.348 + *app = ap = newarg(ARGNUM);
9.349 + ap->a_a.a_np = numlookup((unsigned) tabval);
9.350 + ap->a_a.a_np->n_flags |= NUMDATA;
9.351 + app = &ap->a_next;
9.352 + break;
9.353 + case DLBX:
9.354 + *app = ap = newarg(ARGSYM);
9.355 + ap->a_a.a_sp = symlookup(string,OCCURRING,0);
9.356 + app = &ap->a_next;
9.357 + break;
9.358 + case sp_pnam:
9.359 + *app = ap = newarg(ARGSYM);
9.360 + ap->a_a.a_sp = symlookup(string,OCCURRING,SYMPRO);
9.361 + app = &ap->a_next;
9.362 + break;
9.363 + case VALX1:
9.364 + tabval2 = (offset) tabval;
9.365 + case VALX2:
9.366 + *app = ap = newarg(ARGVAL);
9.367 + ap->a_a.a_val.av_sp = symlookup(string,OCCURRING,0);
9.368 + ap->a_a.a_val.av_offset = tabval2;
9.369 + app = &ap->a_next;
9.370 + break;
9.371 + case sp_scon:
9.372 + *app = ap = newarg(ARGSTR);
9.373 + length = getoff();
9.374 + argstring(length,&ap->a_a.a_string);
9.375 + app = &ap->a_next;
9.376 + break;
9.377 + case sp_icon:
9.378 + *app = ap = newarg(ARGICN);
9.379 + goto casecon;
9.380 + case sp_ucon:
9.381 + *app = ap = newarg(ARGUCN);
9.382 + goto casecon;
9.383 + case sp_fcon:
9.384 + *app = ap = newarg(ARGFCN);
9.385 + casecon:
9.386 + length = getint();
9.387 + ap->a_a.a_con.ac_length = (short) length;
9.388 + argstring(getoff(),&ap->a_a.a_con.ac_con);
9.389 + app = &ap->a_next;
9.390 + break;
9.391 + case sp_cend:
9.392 + moretocome = FALSE;
9.393 + }
9.394 + if (n && (--n) == 0)
9.395 + moretocome = FALSE;
9.396 + } while (moretocome);
9.397 + return(lnp);
9.398 +}
9.399 +
9.400 +offset aoff(ap,n) register arg_p ap; {
9.401 +
9.402 + while (n>0) {
9.403 + if (ap != (arg_p) 0)
9.404 + ap = ap->a_next;
9.405 + n--;
9.406 + }
9.407 + if (ap == (arg_p) 0)
9.408 + error("too few parameters");
9.409 + if (ap->a_typ != ARGOFF)
9.410 + error("offset expected");
9.411 + return(ap->a_a.a_offset);
9.412 +}
9.413 +
9.414 +int inpseudo(n) short n; {
9.415 + register line_p lnp,head,tail;
9.416 + short n1,n2;
9.417 + proinf savearea;
9.418 +#ifdef PSEUBETWEEN
9.419 + static int pcount=0;
9.420 +
9.421 + if (pcount++ >= PSEUBETWEEN && prodepth==0) {
9.422 + process();
9.423 + pcount=0;
9.424 + }
9.425 +#endif
9.426 +
9.427 + switch(n) {
9.428 + default:
9.429 + error("unknown pseudo");
9.430 + case ps_bss:
9.431 + case ps_hol:
9.432 + lnp = arglist(3);
9.433 + break;
9.434 + case ps_rom:
9.435 + case ps_con:
9.436 + lnp = arglist(0);
9.437 + break;
9.438 + case ps_ina:
9.439 + case ps_inp:
9.440 + case ps_exa:
9.441 + case ps_exp:
9.442 + lnp = newline(OPSYMBOL);
9.443 + lnp->l_a.la_sp = getsym(NOTHING);
9.444 + break;
9.445 + case ps_exc:
9.446 + n1 = getint(); n2 = getint();
9.447 + if (n1 != 0 && n2 != 0) {
9.448 + tail = curpro.lastline;
9.449 + while (--n2) tail = tail->l_next;
9.450 + head = tail;
9.451 + while (n1--) head = head->l_next;
9.452 + lnp = tail->l_next;
9.453 + tail->l_next = head->l_next;
9.454 + head->l_next = curpro.lastline;
9.455 + curpro.lastline = lnp;
9.456 + }
9.457 + lnp = newline(OPNO);
9.458 + break;
9.459 + case ps_mes:
9.460 + lnp = arglist(0);
9.461 + switch((int) aoff(lnp->l_a.la_arg,0)) {
9.462 + case ms_err:
9.463 + draininput(); exit(-1);
9.464 + case ms_opt:
9.465 + nflag = TRUE; break;
9.466 + case ms_emx:
9.467 + wordsize = aoff(lnp->l_a.la_arg,1);
9.468 + pointersize = aoff(lnp->l_a.la_arg,2);
9.469 +#ifndef LONGOFF
9.470 + if (wordsize>2)
9.471 + error("This optimizer cannot handle wordsize>2");
9.472 +#endif
9.473 + break;
9.474 + case ms_reg:
9.475 + if (prodepth==0)
9.476 + error("MES REG outside procedure");
9.477 + regvar(lnp->l_a.la_arg->a_next);
9.478 + oldline(lnp);
9.479 + lnp=newline(OPNO);
9.480 + n=ps_exc; /* kludge to force out this line */
9.481 + break;
9.482 + }
9.483 + break;
9.484 + case ps_pro:
9.485 + if (prodepth>0)
9.486 + savearea = curpro;
9.487 + else
9.488 + process();
9.489 + curpro.symbol = getsym(DEFINING);
9.490 + switch(table2()) {
9.491 + case sp_cend:
9.492 + curpro.localbytes = (offset) -1;
9.493 + break;
9.494 + case CSTX1:
9.495 + tabval2 = (offset) tabval;
9.496 + case CSTX2:
9.497 + curpro.localbytes = tabval2;
9.498 + break;
9.499 + default:
9.500 + error("bad second arg of PRO");
9.501 + }
9.502 + prodepth++;
9.503 + if (prodepth>1) {
9.504 + register i;
9.505 +
9.506 + curpro.lastline = (line_p) 0;
9.507 + curpro.freg = (reg_p) 0;
9.508 + for(i=0;i<NNUMHASH;i++)
9.509 + curpro.numhash[i] = (num_p) 0;
9.510 + getlines();
9.511 + curpro = savearea;
9.512 + prodepth--;
9.513 + }
9.514 + return(0);
9.515 + case ps_end:
9.516 + if (prodepth==0)
9.517 + error("END misplaced");
9.518 + switch(table2()) {
9.519 + case sp_cend:
9.520 + if (curpro.localbytes == (offset) -1)
9.521 + error("bytes for locals still unknown");
9.522 + break;
9.523 + case CSTX1:
9.524 + tabval2 = (offset) tabval;
9.525 + case CSTX2:
9.526 + if (curpro.localbytes != (offset) -1 && curpro.localbytes != tabval2)
9.527 + error("inconsistency in number of bytes for locals");
9.528 + curpro.localbytes = tabval2;
9.529 + break;
9.530 + }
9.531 + process();
9.532 + curpro.symbol = (sym_p) 0;
9.533 + if (prodepth==1) {
9.534 + prodepth=0;
9.535 +#ifdef PSEUBETWEEN
9.536 + pcount=0;
9.537 +#endif
9.538 + return(0);
9.539 + } else
9.540 + return(1);
9.541 + }
9.542 + lnp->l_instr = n;
9.543 + lnp->l_next = curpro.lastline;
9.544 + curpro.lastline = lnp;
9.545 + return(0);
9.546 +}
9.547 +
9.548 +tstinpro() {
9.549 +
9.550 + if (prodepth==0)
9.551 + error("Instruction or label not allowed outside procedure");
9.552 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/util/opt/line.h Thu May 17 13:42:36 1984 +0000
10.3 @@ -0,0 +1,86 @@
10.4 +#define NARGBYTES 14
10.5 +struct argbytes {
10.6 + argb_p ab_next;
10.7 + short ab_index;
10.8 + char ab_contents[NARGBYTES];
10.9 +};
10.10 +
10.11 +typedef struct {
10.12 + sym_p av_sp;
10.13 + offset av_offset;
10.14 +} s_a_val;
10.15 +
10.16 +typedef struct {
10.17 + short ac_length;
10.18 + argb_t ac_con;
10.19 +} s_a_con;
10.20 +
10.21 +typedef union {
10.22 + offset a_offset;
10.23 + num_p a_np;
10.24 + sym_p a_sp;
10.25 + s_a_val a_val;
10.26 + argb_t a_string;
10.27 + s_a_con a_con;
10.28 +} un_a_a;
10.29 +
10.30 +struct arg {
10.31 + arg_p a_next;
10.32 + short a_typ;
10.33 + un_a_a a_a;
10.34 +};
10.35 +
10.36 +/* possible values for .a_typ
10.37 + */
10.38 +
10.39 +#define ARGOFF 0
10.40 +#define ARGNUM 1
10.41 +#define ARGSYM 2
10.42 +#define ARGVAL 3
10.43 +#define ARGSTR 4
10.44 +#define ARGICN 5
10.45 +#define ARGUCN 6
10.46 +#define ARGFCN 7
10.47 +
10.48 +typedef struct {
10.49 + sym_p lasv_sp;
10.50 + short lasv_short;
10.51 +} s_la_sval;
10.52 +
10.53 +typedef struct {
10.54 + sym_p lalv_sp;
10.55 + offset lalv_offset;
10.56 +} s_la_lval;
10.57 +
10.58 +typedef union {
10.59 + short la_short;
10.60 + offset la_offset;
10.61 + num_p la_np;
10.62 + sym_p la_sp;
10.63 + s_la_sval la_sval;
10.64 + s_la_lval la_lval;
10.65 + arg_p la_arg;
10.66 +} un_l_a;
10.67 +
10.68 +struct line {
10.69 + line_p l_next; /* maintains linked list */
10.70 + byte l_instr; /* instruction number */
10.71 + byte l_optyp; /* specifies what follows */
10.72 + un_l_a l_a;
10.73 +};
10.74 +
10.75 +/* Possible values for .l_optyp */
10.76 +
10.77 +#define OPNO 0 /* no operand */
10.78 +#define OPSHORT 1 /* 16 bit number */
10.79 +#define OPOFFSET 2 /* 16 or 32 bit number */
10.80 +#define OPNUMLAB 3 /* local label for branches */
10.81 +#define OPSYMBOL 4 /* global label or procedurename */
10.82 +#define OPSVAL 5 /* symbol + 16 bit constant */
10.83 +#define OPLVAL 6 /* symbol + 16 or 32 bit constant */
10.84 +#define OPLIST 7 /* operand list for some pseudos */
10.85 +#define OPMINI 8 /* start of minis */
10.86 +
10.87 +#define Z_OPMINI (OPMINI+100) /* tunable */
10.88 +
10.89 +#define CANMINI(x) ((x)>=OPMINI-Z_OPMINI && (x)<256-Z_OPMINI)
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/util/opt/lookup.c Thu May 17 13:42:36 1984 +0000
11.3 @@ -0,0 +1,84 @@
11.4 +#include "param.h"
11.5 +#include "types.h"
11.6 +#include "lookup.h"
11.7 +#include "alloc.h"
11.8 +#include "proinf.h"
11.9 +
11.10 +/*
11.11 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
11.12 + *
11.13 + * This product is part of the Amsterdam Compiler Kit.
11.14 + *
11.15 + * Permission to use, sell, duplicate or disclose this software must be
11.16 + * obtained in writing. Requests for such permissions may be sent to
11.17 + *
11.18 + * Dr. Andrew S. Tanenbaum
11.19 + * Wiskundig Seminarium
11.20 + * Vrije Universiteit
11.21 + * Postbox 7161
11.22 + * 1007 MC Amsterdam
11.23 + * The Netherlands
11.24 + *
11.25 + * Author: Hans van Staveren
11.26 + */
11.27 +
11.28 +unsigned hash(string) char *string; {
11.29 + register char *p;
11.30 + register unsigned i,sum;
11.31 +
11.32 + for (sum=i=0,p=string;*p;i += 3)
11.33 + sum ^= (*p++)<<(i&07);
11.34 + return(sum);
11.35 +}
11.36 +
11.37 +sym_p symlookup(name,status,flags) char *name; int status,flags; {
11.38 + register sym_p *spp,sp;
11.39 + static short genfrag = 32767;
11.40 +
11.41 + spp = &symhash[hash(name)%NSYMHASH];
11.42 + while (*spp != (sym_p) 0)
11.43 + if (strncmp((*spp)->s_name,name,IDL)==0) {
11.44 + sp = *spp;
11.45 + if ((sp->s_flags^flags)&SYMPRO)
11.46 + error("%s is both proc and datalabel",name);
11.47 + if (status == DEFINING) {
11.48 + if (sp->s_flags&SYMDEF)
11.49 + error("redefined symbol %s",name);
11.50 + sp->s_flags |= SYMDEF;
11.51 + }
11.52 + return(sp);
11.53 + } else
11.54 + spp = &(*spp)->s_next;
11.55 +
11.56 + /*
11.57 + * symbol not found, enter in table
11.58 + */
11.59 +
11.60 + *spp = sp = newsym();
11.61 + strncpy(sp->s_name,name,IDL);
11.62 + sp->s_flags = flags;
11.63 + if (status == DEFINING)
11.64 + sp->s_flags |= SYMDEF;
11.65 + sp->s_frag = genfrag--;
11.66 + return(sp);
11.67 +}
11.68 +
11.69 +num_p numlookup(number) unsigned number; {
11.70 + register num_p *npp, np;
11.71 +
11.72 + npp = &curpro.numhash[number%NNUMHASH];
11.73 + while (*npp != (num_p) 0)
11.74 + if ((*npp)->n_number == number)
11.75 + return(*npp);
11.76 + else
11.77 + npp = &(*npp)->n_next;
11.78 +
11.79 + /*
11.80 + * local label not found, enter in tabel
11.81 + */
11.82 +
11.83 + *npp = np = newnum();
11.84 + np->n_number = number;
11.85 + np->n_repl = np;
11.86 + return(np);
11.87 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/util/opt/lookup.h Thu May 17 13:42:36 1984 +0000
12.3 @@ -0,0 +1,23 @@
12.4 +#define IDL 8
12.5 +
12.6 +struct sym {
12.7 + sym_p s_next;
12.8 + char s_name[IDL];
12.9 + offset *s_rom;
12.10 + short s_flags;
12.11 + short s_frag;
12.12 + offset s_value;
12.13 +};
12.14 +
12.15 +/* contents of .s_flags */
12.16 +#define SYMPRO 000001
12.17 +#define SYMGLOBAL 000002
12.18 +#define SYMKNOWN 000004
12.19 +#define SYMOUT 000010
12.20 +#define SYMDEF 000020
12.21 +
12.22 +#define NSYMHASH 127
12.23 +extern sym_p symhash[NSYMHASH],symlookup();
12.24 +#define OCCURRING 0
12.25 +#define DEFINING 1
12.26 +#define NOTHING 2
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/util/opt/main.c Thu May 17 13:42:36 1984 +0000
13.3 @@ -0,0 +1,73 @@
13.4 +#include <stdio.h>
13.5 +#include "param.h"
13.6 +#include "types.h"
13.7 +#include "alloc.h"
13.8 +#include "../../h/em_spec.h"
13.9 +#include "ext.h"
13.10 +
13.11 +/*
13.12 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
13.13 + *
13.14 + * This product is part of the Amsterdam Compiler Kit.
13.15 + *
13.16 + * Permission to use, sell, duplicate or disclose this software must be
13.17 + * obtained in writing. Requests for such permissions may be sent to
13.18 + *
13.19 + * Dr. Andrew S. Tanenbaum
13.20 + * Wiskundig Seminarium
13.21 + * Vrije Universiteit
13.22 + * Postbox 7161
13.23 + * 1007 MC Amsterdam
13.24 + * The Netherlands
13.25 + *
13.26 + * Author: Hans van Staveren
13.27 + */
13.28 +
13.29 +/*
13.30 + * Main program for EM optimizer
13.31 + */
13.32 +
13.33 +main(argc,argv) int argc; char *argv[]; {
13.34 + short somespace[STACKROOM];
13.35 +
13.36 + progname = argv[0];
13.37 + while (argc-->1 && **++argv == '-')
13.38 + flags(*argv);
13.39 + if (argc>1) {
13.40 + fprintf(stderr,"Usage: %s [-Ln] [name]\n",progname);
13.41 + exit(-1);
13.42 + }
13.43 + if (argc)
13.44 + if (freopen(*argv,"r",stdin) == NULL)
13.45 + error("Cannot open %s",*argv);
13.46 + fileinit();
13.47 + coreinit(somespace,somespace+STACKROOM);
13.48 + getlines();
13.49 + cleanup();
13.50 + return(0);
13.51 +}
13.52 +
13.53 +flags(s) register char *s; {
13.54 +
13.55 + for (s++;*s;s++)
13.56 + switch(*s) {
13.57 + case 'L': Lflag = TRUE; break;
13.58 + case 'n': nflag = TRUE; break;
13.59 + }
13.60 +}
13.61 +
13.62 +fileinit() {
13.63 + char *mktemp();
13.64 + short readshort();
13.65 +
13.66 + if (readshort() != (short) sp_magic)
13.67 + error("wrong input file");
13.68 + if (Lflag) {
13.69 + outfile = fopen(mktemp(template),"w");
13.70 + if (outfile == NULL)
13.71 + error("can't create %s",template);
13.72 + } else {
13.73 + outfile = stdout;
13.74 + outshort(sp_magic);
13.75 + }
13.76 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/util/opt/makedepend Thu May 17 13:42:36 1984 +0000
14.3 @@ -0,0 +1,14 @@
14.4 +for extension in c y
14.5 +do
14.6 + for file in *.$extension
14.7 + do ofile=`basename $file .$extension`.o
14.8 + grep '^# *include.*"' $file|sed "s/.*\"\(.*\)\".*/$ofile: \1/"
14.9 + done
14.10 +done | sort -u >depend
14.11 +ed - Makefile <<'!'
14.12 +/AUTOAUTOAUTO/+,$d
14.13 +$r depend
14.14 +w
14.15 +q
14.16 +!
14.17 +rm -f depend
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/util/opt/mktab.y Thu May 17 13:42:36 1984 +0000
15.3 @@ -0,0 +1,362 @@
15.4 +%{
15.5 +#include <stdio.h>
15.6 +#include "param.h"
15.7 +#include "types.h"
15.8 +#include "pattern.h"
15.9 +#include "../../h/em_spec.h"
15.10 +#include "../../h/em_mnem.h"
15.11 +#include "optim.h"
15.12 +
15.13 +/*
15.14 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
15.15 + *
15.16 + * This product is part of the Amsterdam Compiler Kit.
15.17 + *
15.18 + * Permission to use, sell, duplicate or disclose this software must be
15.19 + * obtained in writing. Requests for such permissions may be sent to
15.20 + *
15.21 + * Dr. Andrew S. Tanenbaum
15.22 + * Wiskundig Seminarium
15.23 + * Vrije Universiteit
15.24 + * Postbox 7161
15.25 + * 1007 MC Amsterdam
15.26 + * The Netherlands
15.27 + *
15.28 + * Author: Hans van Staveren
15.29 + */
15.30 +
15.31 +#define MAXNODES 1000
15.32 +expr_t nodes[MAXNODES];
15.33 +expr_p lastnode = nodes+1;
15.34 +int curind,prevind;
15.35 +int patlen,maxpatlen,rpllen;
15.36 +int lino = 1;
15.37 +int patno=1;
15.38 +#define MAX 100
15.39 +int patmnem[MAX],rplmnem[MAX],rplexpr[MAX];
15.40 +byte nparam[N_EX_OPS];
15.41 +bool nonumlab[N_EX_OPS];
15.42 +bool onlyconst[N_EX_OPS];
15.43 +int nerrors=0;
15.44 +%}
15.45 +
15.46 +%union {
15.47 + int y_int;
15.48 +}
15.49 +
15.50 +%left OR2
15.51 +%left AND2
15.52 +%left OR1
15.53 +%left XOR1
15.54 +%left AND1
15.55 +%left CMPEQ,CMPNE
15.56 +%left CMPLT,CMPLE,CMPGT,CMPGE
15.57 +%left RSHIFT,LSHIFT
15.58 +%left ARPLUS,ARMINUS
15.59 +%left ARTIMES,ARDIVIDE,ARMOD
15.60 +%nonassoc NOT,COMP,UMINUS
15.61 +%nonassoc '$'
15.62 +
15.63 +%token SFIT,UFIT,NOTREG,PSIZE,WSIZE,DEFINED,SAMESIGN,ROM,ROTATE
15.64 +%token <y_int> MNEM
15.65 +%token <y_int> NUMBER
15.66 +%type <y_int> expr,argno,optexpr
15.67 +
15.68 +%start patternlist
15.69 +
15.70 +%%
15.71 +patternlist
15.72 + : /* empty */
15.73 + | patternlist '\n'
15.74 + | patternlist pattern
15.75 + ;
15.76 +pattern :
15.77 + mnemlist optexpr ':' replacement '\n'
15.78 + { register i;
15.79 + outbyte(0); outshort(prevind); prevind=curind-3;
15.80 + out(patlen);
15.81 + for (i=0;i<patlen;i++) outbyte(patmnem[i]);
15.82 + out($2);
15.83 + out(rpllen);
15.84 + for (i=0;i<rpllen;i++) {
15.85 + outbyte(rplmnem[i]);
15.86 + out(rplexpr[i]);
15.87 + }
15.88 +#ifdef DIAGOPT
15.89 + outshort(patno);
15.90 +#endif
15.91 + patno++;
15.92 + printf("\n");
15.93 + if (patlen>maxpatlen) maxpatlen=patlen;
15.94 + }
15.95 + | error '\n'
15.96 + { yyerrok; }
15.97 + ;
15.98 +replacement
15.99 + : expr /* special optimization */
15.100 + {
15.101 +#ifdef ALLOWSPECIAL
15.102 + rpllen=1; rplmnem[0]=0; rplexpr[0]=$1;
15.103 +#else
15.104 + yyerror("No specials allowed");
15.105 +#endif
15.106 + }
15.107 + | repllist
15.108 + ;
15.109 +repllist: /* empty */
15.110 + { rpllen=0; }
15.111 + | repllist repl
15.112 + ;
15.113 +repl : MNEM optexpr
15.114 + { rplmnem[rpllen] = $1; rplexpr[rpllen++] = $2; }
15.115 + ;
15.116 +mnemlist: MNEM
15.117 + { patlen=0; patmnem[patlen++] = $1; }
15.118 + | mnemlist MNEM
15.119 + { patmnem[patlen++] = $2; }
15.120 + ;
15.121 +optexpr : /* empty */
15.122 + { $$ = 0; }
15.123 + | expr
15.124 + ;
15.125 +expr
15.126 + : '$' argno
15.127 + { $$ = lookup(0,EX_ARG,$2,0); }
15.128 + | NUMBER
15.129 + { $$ = lookup(0,EX_CON,(int)(short)$1,0); }
15.130 + | PSIZE
15.131 + { $$ = lookup(0,EX_POINTERSIZE,0,0); }
15.132 + | WSIZE
15.133 + { $$ = lookup(0,EX_WORDSIZE,0,0); }
15.134 + | DEFINED '(' expr ')'
15.135 + { $$ = lookup(0,EX_DEFINED,$3,0); }
15.136 + | SAMESIGN '(' expr ',' expr ')'
15.137 + { $$ = lookup(1,EX_SAMESIGN,$3,$5); }
15.138 + | SFIT '(' expr ',' expr ')'
15.139 + { $$ = lookup(0,EX_SFIT,$3,$5); }
15.140 + | UFIT '(' expr ',' expr ')'
15.141 + { $$ = lookup(0,EX_UFIT,$3,$5); }
15.142 + | ROTATE '(' expr ',' expr ')'
15.143 + { $$ = lookup(0,EX_ROTATE,$3,$5); }
15.144 + | NOTREG '(' expr ')'
15.145 + { $$ = lookup(0,EX_NOTREG,$3,0); }
15.146 + | ROM '(' argno ',' expr ')'
15.147 + { $$ = lookup(0,EX_ROM,$3,$5); }
15.148 + | '(' expr ')'
15.149 + { $$ = $2; }
15.150 + | expr CMPEQ expr
15.151 + { $$ = lookup(1,EX_CMPEQ,$1,$3); }
15.152 + | expr CMPNE expr
15.153 + { $$ = lookup(1,EX_CMPNE,$1,$3); }
15.154 + | expr CMPGT expr
15.155 + { $$ = lookup(0,EX_CMPGT,$1,$3); }
15.156 + | expr CMPGE expr
15.157 + { $$ = lookup(0,EX_CMPGE,$1,$3); }
15.158 + | expr CMPLT expr
15.159 + { $$ = lookup(0,EX_CMPLT,$1,$3); }
15.160 + | expr CMPLE expr
15.161 + { $$ = lookup(0,EX_CMPLE,$1,$3); }
15.162 + | expr OR2 expr
15.163 + { $$ = lookup(0,EX_OR2,$1,$3); }
15.164 + | expr AND2 expr
15.165 + { $$ = lookup(0,EX_AND2,$1,$3); }
15.166 + | expr OR1 expr
15.167 + { $$ = lookup(1,EX_OR1,$1,$3); }
15.168 + | expr XOR1 expr
15.169 + { $$ = lookup(1,EX_XOR1,$1,$3); }
15.170 + | expr AND1 expr
15.171 + { $$ = lookup(1,EX_AND1,$1,$3); }
15.172 + | expr ARPLUS expr
15.173 + { $$ = lookup(1,EX_PLUS,$1,$3); }
15.174 + | expr ARMINUS expr
15.175 + { $$ = lookup(0,EX_MINUS,$1,$3); }
15.176 + | expr ARTIMES expr
15.177 + { $$ = lookup(1,EX_TIMES,$1,$3); }
15.178 + | expr ARDIVIDE expr
15.179 + { $$ = lookup(0,EX_DIVIDE,$1,$3); }
15.180 + | expr ARMOD expr
15.181 + { $$ = lookup(0,EX_MOD,$1,$3); }
15.182 + | expr LSHIFT expr
15.183 + { $$ = lookup(0,EX_LSHIFT,$1,$3); }
15.184 + | expr RSHIFT expr
15.185 + { $$ = lookup(0,EX_RSHIFT,$1,$3); }
15.186 + | ARPLUS expr %prec UMINUS
15.187 + { $$ = $2; }
15.188 + | ARMINUS expr %prec UMINUS
15.189 + { $$ = lookup(0,EX_UMINUS,$2,0); }
15.190 + | NOT expr
15.191 + { $$ = lookup(0,EX_NOT,$2,0); }
15.192 + | COMP expr
15.193 + { $$ = lookup(0,EX_COMP,$2,0); }
15.194 + ;
15.195 +argno : NUMBER
15.196 + { if ($1<1 || $1>patlen) {
15.197 + YYERROR;
15.198 + }
15.199 + $$ = (int) $1;
15.200 + }
15.201 + ;
15.202 +
15.203 +%%
15.204 +
15.205 +extern char em_mnem[][4];
15.206 +
15.207 +#define HASHSIZE (2*(sp_lmnem-sp_fmnem))
15.208 +
15.209 +struct hashmnem {
15.210 + char h_name[3];
15.211 + byte h_value;
15.212 +} hashmnem[HASHSIZE];
15.213 +
15.214 +inithash() {
15.215 + register i;
15.216 +
15.217 + enter("lab",op_lab);
15.218 + enter("LLP",op_LLP);
15.219 + enter("LEP",op_LEP);
15.220 + enter("SLP",op_SLP);
15.221 + enter("SEP",op_SEP);
15.222 + for(i=0;i<=sp_lmnem-sp_fmnem;i++)
15.223 + enter(em_mnem[i],i+sp_fmnem);
15.224 +}
15.225 +
15.226 +unsigned hashname(name) register char *name; {
15.227 + register unsigned h;
15.228 +
15.229 + h = (*name++)&BMASK;
15.230 + h = (h<<4)^((*name++)&BMASK);
15.231 + h = (h<<4)^((*name++)&BMASK);
15.232 + return(h);
15.233 +}
15.234 +
15.235 +enter(name,value) char *name; {
15.236 + register unsigned h;
15.237 +
15.238 + h=hashname(name)%HASHSIZE;
15.239 + while (hashmnem[h].h_name[0] != 0)
15.240 + h = (h+1)%HASHSIZE;
15.241 + strncpy(hashmnem[h].h_name,name,3);
15.242 + hashmnem[h].h_value = value;
15.243 +}
15.244 +
15.245 +int mlookup(name) char *name; {
15.246 + register unsigned h;
15.247 +
15.248 + h = hashname(name)%HASHSIZE;
15.249 + while (strncmp(hashmnem[h].h_name,name,3) != 0 &&
15.250 + hashmnem[h].h_name[0] != 0)
15.251 + h = (h+1)%HASHSIZE;
15.252 + return(hashmnem[h].h_value&BMASK); /* 0 if not found */
15.253 +}
15.254 +
15.255 +main() {
15.256 +
15.257 + inithash();
15.258 + initio();
15.259 + yyparse();
15.260 + if (nerrors==0)
15.261 + printnodes();
15.262 + return nerrors;
15.263 +}
15.264 +
15.265 +yyerror(s) char *s; {
15.266 +
15.267 + fprintf(stderr,"line %d: %s\n",lino,s);
15.268 + nerrors++;
15.269 +}
15.270 +
15.271 +lookup(comm,operator,lnode,rnode) {
15.272 + register expr_p p;
15.273 +
15.274 + for (p=nodes+1;p<lastnode;p++) {
15.275 + if (p->ex_operator != operator)
15.276 + continue;
15.277 + if (!(p->ex_lnode == lnode && p->ex_rnode == rnode ||
15.278 + comm && p->ex_lnode == rnode && p->ex_rnode == lnode))
15.279 + continue;
15.280 + return(p-nodes);
15.281 + }
15.282 + if (lastnode >= &nodes[MAXNODES])
15.283 + yyerror("node table overflow");
15.284 + lastnode++;
15.285 + p->ex_operator = operator;
15.286 + p->ex_lnode = lnode;
15.287 + p->ex_rnode = rnode;
15.288 + return(p-nodes);
15.289 +}
15.290 +
15.291 +printnodes() {
15.292 + register expr_p p;
15.293 +
15.294 + printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind);
15.295 + for (p=nodes;p<lastnode;p++)
15.296 + printf("/* %3d */\t%3d,%6u,%6u,\n",
15.297 + p-nodes,p->ex_operator,p->ex_lnode,p->ex_rnode);
15.298 + printf("};\n\niarg_t iargs[%d];\n",maxpatlen);
15.299 +}
15.300 +
15.301 +initio() {
15.302 + register i;
15.303 +
15.304 + printf("#include \"param.h\"\n#include \"types.h\"\n");
15.305 + printf("#include \"pattern.h\"\n\n");
15.306 + for(i=0;i<N_EX_OPS;i++) {
15.307 + nparam[i]=2;
15.308 + nonumlab[i]=TRUE;
15.309 + onlyconst[i]=TRUE;
15.310 + }
15.311 + nparam[EX_POINTERSIZE] = 0;
15.312 + nparam[EX_WORDSIZE] = 0;
15.313 + nparam[EX_CON] = 0;
15.314 + nparam[EX_ROM] = 0;
15.315 + nparam[EX_ARG] = 0;
15.316 + nparam[EX_DEFINED] = 0;
15.317 + nparam[EX_OR2] = 1;
15.318 + nparam[EX_AND2] = 1;
15.319 + nparam[EX_UMINUS] = 1;
15.320 + nparam[EX_NOT] = 1;
15.321 + nparam[EX_COMP] = 1;
15.322 + nparam[EX_NOTREG] = 1;
15.323 + nonumlab[EX_CMPEQ] = FALSE;
15.324 + nonumlab[EX_CMPNE] = FALSE;
15.325 + onlyconst[EX_CMPEQ] = FALSE;
15.326 + onlyconst[EX_CMPNE] = FALSE;
15.327 + onlyconst[EX_CMPLE] = FALSE;
15.328 + onlyconst[EX_CMPLT] = FALSE;
15.329 + onlyconst[EX_CMPGE] = FALSE;
15.330 + onlyconst[EX_CMPGT] = FALSE;
15.331 + onlyconst[EX_PLUS] = FALSE;
15.332 + onlyconst[EX_MINUS] = FALSE;
15.333 + printf("byte nparam[] = {");
15.334 + for (i=0;i<N_EX_OPS;i++) printf("%d,",nparam[i]);
15.335 + printf("};\nbool nonumlab[] = {");
15.336 + for (i=0;i<N_EX_OPS;i++) printf("%d,",nonumlab[i]);
15.337 + printf("};\nbool onlyconst[] = {");
15.338 + for (i=0;i<N_EX_OPS;i++) printf("%d,",onlyconst[i]);
15.339 + printf("};\n\nbyte pattern[] = { 0\n");
15.340 + curind = 1;
15.341 +}
15.342 +
15.343 +outbyte(b) {
15.344 +
15.345 + printf(",%3d",b);
15.346 + curind++;
15.347 +}
15.348 +
15.349 +outshort(s) {
15.350 +
15.351 + outbyte(s&0377);
15.352 + outbyte((s>>8)&0377);
15.353 +}
15.354 +
15.355 +out(w) {
15.356 +
15.357 + if (w<255) {
15.358 + outbyte(w);
15.359 + } else {
15.360 + outbyte(255);
15.361 + outshort(w);
15.362 + }
15.363 +}
15.364 +
15.365 +#include "scan.c"
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/util/opt/optim.h Thu May 17 13:42:36 1984 +0000
16.3 @@ -0,0 +1,10 @@
16.4 +/* #define DIAGOPT /* if defined diagnostics are produced */
16.5 +#ifdef DIAGOPT
16.6 +#define OPTIM(x) optim(x)
16.7 +#define O_UNREACH 1001
16.8 +#define O_BRALAB 1002
16.9 +#define O_LINLNI 1003
16.10 +#define O_LINGONE 1004
16.11 +#else
16.12 +#define OPTIM(x) /* NOTHING */
16.13 +#endif
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/util/opt/param.h Thu May 17 13:42:36 1984 +0000
17.3 @@ -0,0 +1,13 @@
17.4 +#define LONGOFF /* if defined long offsets are used */
17.5 +
17.6 +#define TRUE 1
17.7 +#define FALSE 0
17.8 +
17.9 +#define MAXROM 3
17.10 +
17.11 +#define op_lab (sp_lmnem+1)
17.12 +#define op_last op_lab
17.13 +#define ps_sym (sp_lpseu+1)
17.14 +#define ps_last ps_sym
17.15 +
17.16 +#define BMASK 0377
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/util/opt/pattern.h Thu May 17 13:42:36 1984 +0000
18.3 @@ -0,0 +1,124 @@
18.4 +/*
18.5 + * pattern contains the optimization patterns in an apparently
18.6 + * unordered fashion. All patterns follow each other unaligned.
18.7 + * Each pattern looks as follows:
18.8 + * Byte 0: high byte of hash value associated with this pattern.
18.9 + * Byte 1-2: index of next pattern with same low byte of hash value.
18.10 + * Byte 3- : pattern and replacement.
18.11 + * First comes the pattern length
18.12 + * then the pattern opcodes,
18.13 + * then a boolean expression,
18.14 + * then the one-byte replacement length
18.15 + * then the intermixed pattern opcodes and operands or
18.16 + * 0 followed by the one-byte special optimization expression.
18.17 + * If the DIAGOPT option is set, the optimization is followed
18.18 + * by the line number in the tables.
18.19 + */
18.20 +
18.21 +/* #define ALLOWSPECIAL /* Special optimizations allowed */
18.22 +
18.23 +#define PO_HASH 0
18.24 +#define PO_NEXT 1
18.25 +#define PO_MATCH 3
18.26 +
18.27 +struct exprnode {
18.28 + short ex_operator;
18.29 + short ex_lnode;
18.30 + short ex_rnode;
18.31 +};
18.32 +typedef struct exprnode expr_t;
18.33 +typedef struct exprnode *expr_p;
18.34 +
18.35 +/*
18.36 + * contents of .ex_operator
18.37 + */
18.38 +
18.39 +#define EX_CON 0
18.40 +#define EX_ARG 1
18.41 +#define EX_CMPEQ 2
18.42 +#define EX_CMPNE 3
18.43 +#define EX_CMPGT 4
18.44 +#define EX_CMPGE 5
18.45 +#define EX_CMPLT 6
18.46 +#define EX_CMPLE 7
18.47 +#define EX_OR2 8
18.48 +#define EX_AND2 9
18.49 +#define EX_OR1 10
18.50 +#define EX_XOR1 11
18.51 +#define EX_AND1 12
18.52 +#define EX_PLUS 13
18.53 +#define EX_MINUS 14
18.54 +#define EX_TIMES 15
18.55 +#define EX_DIVIDE 16
18.56 +#define EX_MOD 17
18.57 +#define EX_LSHIFT 18
18.58 +#define EX_RSHIFT 19
18.59 +#define EX_UMINUS 20
18.60 +#define EX_NOT 21
18.61 +#define EX_COMP 22
18.62 +#define EX_ROM 23
18.63 +#define EX_NOTREG 24
18.64 +#define EX_POINTERSIZE 25
18.65 +#define EX_WORDSIZE 26
18.66 +#define EX_DEFINED 27
18.67 +#define EX_SAMESIGN 28
18.68 +#define EX_SFIT 29
18.69 +#define EX_UFIT 30
18.70 +#define EX_ROTATE 31
18.71 +#define N_EX_OPS 32 /* must be one higher then previous */
18.72 +
18.73 +
18.74 +/*
18.75 + * Definition of special opcodes used in patterns
18.76 + */
18.77 +
18.78 +#define op_pfirst op_LLP
18.79 +#define op_LLP (op_last+1)
18.80 +#define op_LEP (op_last+2)
18.81 +#define op_SLP (op_last+3)
18.82 +#define op_SEP (op_last+4)
18.83 +#define op_plast op_SEP
18.84 +
18.85 +/*
18.86 + * Definition of the structure in which instruction operands
18.87 + * are kept during pattern matching.
18.88 + */
18.89 +
18.90 +typedef struct eval eval_t;
18.91 +typedef struct eval *eval_p;
18.92 +
18.93 +struct eval {
18.94 + short e_typ;
18.95 + union {
18.96 + offset e_con;
18.97 + num_p e_np;
18.98 + } e_v;
18.99 +};
18.100 +
18.101 +/*
18.102 + * contents of .e_typ
18.103 + */
18.104 +#define EV_UNDEF 0
18.105 +#define EV_CONST 1
18.106 +#define EV_NUMLAB 2
18.107 +#define EV_FRAG 3 /* and all higher numbers */
18.108 +
18.109 +typedef struct iarg iarg_t;
18.110 +typedef struct iarg *iarg_p;
18.111 +
18.112 +struct iarg {
18.113 + eval_t ia_ev;
18.114 + sym_p ia_sp;
18.115 +};
18.116 +
18.117 +/*
18.118 + * The next extern declarations refer to data generated by mktab
18.119 + */
18.120 +
18.121 +extern byte pattern[];
18.122 +extern short lastind;
18.123 +extern iarg_t iargs[];
18.124 +extern byte nparam[];
18.125 +extern bool nonumlab[];
18.126 +extern bool onlyconst[];
18.127 +extern expr_t enodes[];
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/util/opt/patterns Thu May 17 13:42:36 1984 +0000
19.3 @@ -0,0 +1,474 @@
19.4 +loc adi loc sbi $2==w && $4==w: loc $1-$3 adi w
19.5 +ldc adi ldc sbi $2==2*w && $4==2*w: ldc $1-$3 adi 2*w
19.6 +loc adi loc adi $2==w && $4==w: loc $1+$3 adi w
19.7 +ldc adi ldc adi $2==2*w && $4==2*w: ldc $1+$3 adi 2*w
19.8 +adp $1==0:
19.9 +adp adp : adp $1+$2
19.10 +adp lof : lof $1+$2
19.11 +adp ldf : ldf $1+$2
19.12 +adp loi $1!=0 && $2==w: lof $1
19.13 +adp loi $1!=0 && $2==2*w: ldf $1
19.14 +adp stf : stf $1+$2
19.15 +adp sdf : sdf $1+$2
19.16 +adp sti $1!=0 && $2==w: stf $1
19.17 +adp sti $1!=0 && $2==2*w: sdf $1
19.18 +asp $1==0:
19.19 +asp asp : asp $1+$2
19.20 +blm $1==0 : asp 2*p
19.21 +cmi zeq $1==w: beq $2
19.22 +cmi zge $1==w: bge $2
19.23 +cmi zgt $1==w: bgt $2
19.24 +cmi zle $1==w: ble $2
19.25 +cmi zlt $1==w: blt $2
19.26 +cmi zne $1==w: bne $2
19.27 +dvi ngi $1==$2: ngi $1 dvi $1
19.28 +lae adp : lae $1+$2
19.29 +lae blm $2==w: loi w ste $1
19.30 +lae blm $2==2*w: loi 2*w sde $1
19.31 +lae ldf : lde $1+$2
19.32 +lae lof : loe $1+$2
19.33 +lae loi $2==w: loe $1
19.34 +lae loi $2==2*w: lde $1
19.35 +#ifdef INT
19.36 +lae loi loe $3==$1-w && $2%w==0: lae $3 loi $2+w
19.37 +lae loi lde $3==$1-2*w && $2%w==0: lae $3 loi $2+2*w
19.38 +lae loi lae loi $1==$3+$4 && $2%w==0 && $4%w==0: lae $3 loi $2+$4
19.39 +lae sti ste $3==$1+$2: lae $1 sti $2+w
19.40 +lae sti sde $3==$1+$2: lae $1 sti $2+2*w
19.41 +lae sti loc ste $4==$1-w: loc $3 lae $4 sti $2+w
19.42 +lae sti lol ste $4==$1-w: lol $3 lae $4 sti $2+w
19.43 +#endif
19.44 +lae lae blm loe ste $4==$1+$3 && $5==$2+$3: lae $1 lae $2 blm $3+w
19.45 +lae lae blm lde sde $4==$1+$3 && $5==$2+$3: lae $1 lae $2 blm $3+2*w
19.46 +lae lae blm lae lae blm $4==$1+$3 && $5==$2+$3: lae $1 lae $2 blm $3+$6
19.47 +lae lal blm lae lal blm $4==$1+$3 && $5==$2+$3 && samesign($2,$5):
19.48 + lae $1 lal $2 blm $3+$6
19.49 +lal lae blm lal lae blm $4==$1+$3 && $5==$2+$3 && samesign($1,$4):
19.50 + lal $1 lae $2 blm $3+$6
19.51 +lal lal blm lal lal blm $4==$1+$3 && $5==$2+$3 && samesign($1,$4) && samesign($2,$5):
19.52 + lal $1 lal $2 blm $3+$6
19.53 +lal lal sbs $3==w && samesign($1,$2): loc $1-$2
19.54 +lae sdf : sde $1+$2
19.55 +lae stf : ste $1+$2
19.56 +lae sti $2==w: ste $1
19.57 +lae sti $2==2*w: sde $1
19.58 +lal adp samesign($1,$1+$2): lal $1+$2
19.59 +lal blm $2==w: loi w stl $1
19.60 +lal blm $2==2*w: loi 2*w sdl $1
19.61 +#ifdef INT
19.62 +lal sti loc stl notreg($4) && $4==$1-w && samesign($1,$4):
19.63 + loc $3 lal $4 sti $2+w
19.64 +lal sti loe stl notreg($4) && $4==$1-w && samesign($1,$4):
19.65 + loe $3 lal $4 sti $2+w
19.66 +#endif
19.67 +lal ldf samesign($1,$1+$2): ldl $1+$2
19.68 +lal lof samesign($1,$1+$2): lol $1+$2
19.69 +lal loi $2==w: lol $1
19.70 +lal loi $2==2*w: ldl $1
19.71 +#ifdef INT
19.72 +lal loi lol notreg($3) && $3==$1-w && samesign($1,$3) && $2%w==0:
19.73 + lal $3 loi $2+w
19.74 +lal loi ldl notreg($3) && $3==$1-2*w && samesign($1,$3) && $2%w==0:
19.75 + lal $3 loi $2+2*w
19.76 +lal loi lal loi $1==$3+$4 && samesign($1,$3) && $2%w==0 && $4%w==0:
19.77 + lal $3 loi $2+$4
19.78 +lal sti stl notreg($3) && $3==$1+$2 && samesign($1,$3): lal $1 sti $2+w
19.79 +lal sti sdl notreg($3) && $3==$1+$2 && samesign($1,$3): lal $1 sti $2+2*w
19.80 +#endif
19.81 +lal sdf samesign($1,$1+$2): sdl $1+$2
19.82 +lal stf samesign($1,$1+$2): stl $1+$2
19.83 +lal sti $2==w: stl $1
19.84 +lal sti $2==2*w: sdl $1
19.85 +#ifdef INT
19.86 +lde lde $2==$1-2*w: lae $2 loi 4*w
19.87 +lde loe $2==$1-w: lae $2 loi 3*w
19.88 +#endif
19.89 +lde sde $2==$1:
19.90 +lde sde lde sde $3==$1+2*w && $4==$2+2*w: lae $1 lae $2 blm 4*w
19.91 +#ifdef INT
19.92 +ldl ldl $2==$1-2*w && notreg($1) && notreg($2) && samesign($1,$2):
19.93 + lal $2 loi 4*w
19.94 +ldl lol $2==$1-w && notreg($1) && notreg($2) && samesign($1,$2):
19.95 + lal $2 loi 3*w
19.96 +#endif
19.97 +ldl sdl $1==$2:
19.98 +lxa loi lxa sti $3==$1 && $4==$2:
19.99 +lxa lof lxa stf $3==$1 && $4==$2:
19.100 +lxa ldf lxa sdf $3==$1 && $4==$2:
19.101 +lxa stf lxa lof $3==$1 && $4==$2: dup w lxa $1 stf $2
19.102 +lxa sdf lxa ldf $3==$1 && $4==$2: dup 2*w lxa $1 sdf $2
19.103 +lxl lof lxl stf $3==$1 && $4==$2:
19.104 +lxl ldf lxl sdf $3==$1 && $4==$2:
19.105 +lxl stf lxl lof $3==$1 && $4==$2: dup w lxl $1 stf $2
19.106 +lxl sdf lxl ldf $3==$1 && $4==$2: dup 2*w lxl $1 sdf $2
19.107 +lxa sti lxa loi $3==$1 && $4==$2 && $2%w==0: dup $2 lxa $1 sti $2
19.108 +loc adi $1==-1 && $2==w: dec
19.109 +loc dec sfit($1-1,8*w) : loc $1-1
19.110 +loc bgt $1==-1: zge $2
19.111 +loc ble $1==-1: zlt $2
19.112 +loc dvi $1==-1 && $2==w: ngi w
19.113 +ldc dvi $1==-1 && $2==2*w: ngi 2*w
19.114 +loc loe adi $1==-1 && $3==w: loe $2 dec
19.115 +loc loe mli $1==-1 && $3==w: loe $2 ngi w
19.116 +loc lol adi $1==-1 && $3==w: lol $2 dec
19.117 +loc mli $1==-1 && $2==w: ngi w
19.118 +ldc mli $1==-1 && $2==2*w: ngi 2*w
19.119 +loc sbi $1==-1 && $2==w: inc
19.120 +loc inc sfit($1+1,8*w) : loc $1+1
19.121 +loc adi $1==0 && $2==w:
19.122 +ldc adi $1==0 && $2==2*w:
19.123 +zer adi $1==$2:
19.124 +loc beq $1==0: zeq $2
19.125 +loc bge $1==0: zge $2
19.126 +loc bgt $1==0: zgt $2
19.127 +loc ble $1==0: zle $2
19.128 +loc blt $1==0: zlt $2
19.129 +loc bne $1==0: zne $2
19.130 +loc cmi teq $1==0 && $2==w: teq
19.131 +loc cmi tge $1==0 && $2==w: tge
19.132 +loc cmi tgt $1==0 && $2==w: tgt
19.133 +loc cmi tle $1==0 && $2==w: tle
19.134 +loc cmi tlt $1==0 && $2==w: tlt
19.135 +loc cmi tne $1==0 && $2==w: tne
19.136 +loc ior $1==0 && $2==w:
19.137 +ldc ior $1==0 && $2==2*w:
19.138 +zer ior $1==$2:
19.139 +loc ste $1==0: zre $2
19.140 +loc stl $1==0: zrl $2
19.141 +loc sbi $1==0 && $2==w:
19.142 +ldc sbi $1==0 && $2==2*w:
19.143 +zer sbi $1==$2:
19.144 +loc xor $1==0 && $2==w:
19.145 +ldc xor $1==0 && $2==2*w:
19.146 +zer xor $1==$2:
19.147 +loc adi $1==1 && $2==w: inc
19.148 +loc bge $1==1: zgt $2
19.149 +loc blt $1==1: zle $2
19.150 +loc dvi $1==1 && $2==w:
19.151 +ldc dvi $1==1 && $2==2*w:
19.152 +loc loe adi $1==1 && $3==w: loe $2 inc
19.153 +loc loe mli $1==1 && $3==w: loe $2
19.154 +loc lol adi $1==1 && $3==w: lol $2 inc
19.155 +loc lol mli $1==1 && $3==w: lol $2
19.156 +loc mli $1==1 && $2==w:
19.157 +loc sbi $1==1 && $2==w: dec
19.158 +loc loe mli $3==w: loe $2 loc $1 mli w
19.159 +loc lol mli $3==w: lol $2 loc $1 mli w
19.160 +ldc lde mli $3==2*w: lde $2 ldc $1 mli 2*w
19.161 +ldc lde adi $3==2*w: lde $2 ldc $1 adi 2*w
19.162 +ldc ldl mli $3==2*w: ldl $2 ldc $1 mli 2*w
19.163 +ldc ldl adi $3==2*w: ldl $2 ldc $1 adi 2*w
19.164 +loc mli $1==2 && $2==w: loc 1 sli w
19.165 +loc mli $1==4 && $2==w: loc 2 sli w
19.166 +loc mli $1==8 && $2==w: loc 3 sli w
19.167 +loc mli $1==16 && $2==w: loc 4 sli w
19.168 +loc mli $1==32 && $2==w: loc 5 sli w
19.169 +loc mli $1==64 && $2==w: loc 6 sli w
19.170 +loc mli $1==128 && $2==w: loc 7 sli w
19.171 +loc mli $1==256 && $2==w: loc 8 sli w
19.172 +loc adi !defined($2): adi $1
19.173 +loc sbi !defined($2): sbi $1
19.174 +loc mli !defined($2): mli $1
19.175 +loc dvi !defined($2): dvi $1
19.176 +loc rmi !defined($2): rmi $1
19.177 +loc ngi !defined($2): ngi $1
19.178 +loc sli !defined($2): sli $1
19.179 +loc sri !defined($2): sri $1
19.180 +loc adu !defined($2): adu $1
19.181 +loc sbu !defined($2): sbu $1
19.182 +loc mlu !defined($2): mlu $1
19.183 +loc dvu !defined($2): dvu $1
19.184 +loc rmu !defined($2): rmu $1
19.185 +loc slu !defined($2): slu $1
19.186 +loc sru !defined($2): sru $1
19.187 +loc adf !defined($2): adf $1
19.188 +loc sbf !defined($2): sbf $1
19.189 +loc mlf !defined($2): mlf $1
19.190 +loc dvf !defined($2): dvf $1
19.191 +loc ngf !defined($2): ngf $1
19.192 +loc fif !defined($2): fif $1
19.193 +loc fef !defined($2): fef $1
19.194 +loc zer !defined($2): zer $1
19.195 +loc zrf !defined($2): zrf $1
19.196 +loc los $2==w: loi $1
19.197 +loc sts $2==w: sti $1
19.198 +loc ads $2==w: adp $1
19.199 +loc ass $2==w: asp $1
19.200 +loc bls $2==w: blm $1
19.201 +loc dus $2==w: dup $1
19.202 +loc loc cii $1==$2:
19.203 +loc loc cuu $1==$2:
19.204 +loc loc cff $1==$2:
19.205 +loc and !defined($2): and $1
19.206 +loc ior !defined($2): ior $1
19.207 +loc xor !defined($2): xor $1
19.208 +loc com !defined($2): com $1
19.209 +loc rol !defined($2): rol $1
19.210 +loc rol $1==0:
19.211 +loc ror !defined($2): ror $1
19.212 +loc ror $1==0:
19.213 +loc inn !defined($2): inn $1
19.214 +loc set !defined($2): set $1
19.215 +loc cmi !defined($2): cmi $1
19.216 +loc cmu !defined($2): cmu $1
19.217 +loc cmf !defined($2): cmf $1
19.218 +loe dec ste $1==$3: dee $1
19.219 +loe inc ste $1==$3: ine $1
19.220 +loe loc mli $2==0 && $3==w: loc 0
19.221 +#ifdef INT
19.222 +loe loe $2==$1-w: lde $2
19.223 +loe loe beq $2==$1+w: lde $1 beq $3
19.224 +loe loe bge $2==$1+w: lde $1 ble $3
19.225 +loe loe bgt $2==$1+w: lde $1 blt $3
19.226 +loe loe ble $2==$1+w: lde $1 bge $3
19.227 +loe loe blt $2==$1+w: lde $1 bgt $3
19.228 +loe loe bne $2==$1+w: lde $1 bne $3
19.229 +loe loe cmi $2==$1+w && $3==w: lde $1 cmi w ngi w
19.230 +#endif
19.231 +ngi teq $1==w: teq
19.232 +ngi tge $1==w: tle
19.233 +ngi tgt $1==w: tlt
19.234 +ngi tle $1==w: tge
19.235 +ngi tlt $1==w: tgt
19.236 +ngi tne $1==w: tne
19.237 +#ifdef INT
19.238 +loe loe mli $2==$1+w && $3==w: lde $1 mli w
19.239 +loe loe adi $2==$1+w && $3==w: lde $1 adi w
19.240 +loe loe $1==$2: loe $1 dup w
19.241 +#endif
19.242 +loe ste $1==$2:
19.243 +LLP blm $2==w: loi w sil $1
19.244 +lol dec stl $1==$3: del $1
19.245 +lol inc stl $1==$3: inl $1
19.246 +lol loc mli $2==0 && $3==w: loc 0
19.247 +LLP loi $2==w: lil $1
19.248 +#ifdef INT
19.249 +lol lol $2==$1-w && notreg($1) && notreg($2) && samesign($1,$2):
19.250 + ldl $2
19.251 +lol lol beq $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.252 + ldl $1 beq $3
19.253 +lol lol bge $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.254 + ldl $1 ble $3
19.255 +lol lol bgt $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.256 + ldl $1 blt $3
19.257 +lol lol ble $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.258 + ldl $1 bge $3
19.259 +lol lol blt $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.260 + ldl $1 bgt $3
19.261 +lol lol bne $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.262 + ldl $1 bne $3
19.263 +lol lol cmi $3==w && $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.264 + ldl $1 cmi w ngi w
19.265 +lol lol mli $3==w && $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.266 + ldl $1 mli w
19.267 +lol lol adi $3==w && $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2):
19.268 + ldl $1 adi w
19.269 +lol lol $1==$2: lol $1 dup w
19.270 +#endif
19.271 +lol stl $1==$2:
19.272 +LLP sti $2==w: sil $1
19.273 +mli ngi $1==$2: ngi $1 mli $1
19.274 +ngi adi $1==$2: sbi $1
19.275 +ngf adf $1==$2: sbf $1
19.276 +ngi sbi $1==$2: adi $1
19.277 +ngf sbf $1==$2: adf $1
19.278 +ngi ngi $1==$2:
19.279 +ngf ngf $1==$2:
19.280 +#ifdef INT
19.281 +sde sde $2==$1+2*w: lae $1 sti 4*w
19.282 +sde ste $2==$1+2*w: lae $1 sti 3*w
19.283 +sde loc ste $3==$1-w: loc $2 lae $3 sti 3*w
19.284 +sde lol ste $3==$1-w: lol $2 lae $3 sti 3*w
19.285 +sde lde $1==$2: dup 2*w sde $1
19.286 +#endif
19.287 +sdf $1==0: sti 2*w
19.288 +#ifdef INT
19.289 +sdl sdl $2==$1+2*w && notreg($1) && notreg($2) && samesign($1,$2):
19.290 + lal $1 sti 4*w
19.291 +sdl stl $2==$1+2*w && notreg($1) && notreg($2) && samesign($1,$2):
19.292 + lal $1 sti 3*w
19.293 +sdl loc stl $3==$1-w && notreg($1) && notreg($3) && samesign($1,$3):
19.294 + loc $2 lal $3 sti 3*w
19.295 +sdl loe stl $3==$1-w && notreg($1) && notreg($3) && samesign($1,$3):
19.296 + loe $2 lal $3 sti 3*w
19.297 +sdl ldl $1==$2: dup 2*w sdl $1
19.298 +ste loe $1==$2: dup w ste $1
19.299 +ste ste $2==$1-w: sde $2
19.300 +ste loc ste $3==$1-w: loc $2 sde $3
19.301 +ste lol ste $3==$1-w: lol $2 sde $3
19.302 +stl lol $1==$2: dup w stl $1
19.303 +#endif
19.304 +stf $1==0: sti w
19.305 +sdl ldl ret $1==$2 && $3==2*w: ret 2*w
19.306 +#ifdef INT
19.307 +stl stl $2==$1+w && notreg($1) && notreg($2) && samesign($1,$2): sdl $1
19.308 +stl loc stl $3==$1-w && notreg($1) && notreg($3) && samesign($1,$3):
19.309 + loc $2 sdl $3
19.310 +stl loe stl $3==$1-w && notreg($1) && notreg($3) && samesign($1,$3):
19.311 + loe $2 sdl $3
19.312 +#endif
19.313 +stl lol ret $1==$2 && $3==w: ret w
19.314 +lal sti lal loi ret $1==$3 && $2==$4 && $2==$5: ret $2
19.315 +loc sbi loc sbi $2==w && $4==w: loc $1+$3 sbi w
19.316 +ldc sbi ldc sbi $2==2*w && $4==2*w: ldc $1+$3 sbi 2*w
19.317 +loc sbi loc adi $2==w && $4==w: loc $1-$3 sbi w
19.318 +ldc sbi ldc adi $2==2*w && $4==2*w: ldc $1-$3 sbi 2*w
19.319 +teq teq : tne
19.320 +teq tne : teq
19.321 +teq zne : zeq $2
19.322 +teq zeq : zne $2
19.323 +tge teq : tlt
19.324 +tge tne : tge
19.325 +tge zeq : zlt $2
19.326 +tge zne : zge $2
19.327 +tgt teq : tle
19.328 +tgt tne : tgt
19.329 +tgt zeq : zle $2
19.330 +tgt zne : zgt $2
19.331 +tle teq : tgt
19.332 +tle tne : tle
19.333 +tle zeq : zgt $2
19.334 +tle zne : zle $2
19.335 +tlt teq : tge
19.336 +tlt tne : tlt
19.337 +tlt zeq : zge $2
19.338 +tlt zne : zlt $2
19.339 +tne teq : teq
19.340 +tne tne : tne
19.341 +tne zeq : zeq $2
19.342 +tne zne : zne $2
19.343 +#ifdef INT
19.344 +loc loc loc $1==0 && $2==0 && $3==0 : zer 6
19.345 +zer loc defined($1) && $2==0: zer $1+w
19.346 +#endif
19.347 +loi loc and $1==1 && $3==w && ($2&255)==255: loi 1
19.348 +loi loc loc cii $1<w && $2==w: loi $1 loc $2 loc $3 cuu
19.349 +cmp teq : cms p teq
19.350 +cmp tne : cms p tne
19.351 +cmu teq defined($1): cms $1 teq
19.352 +cmu tne defined($1): cms $1 tne
19.353 +cms zeq $1==w: beq $2
19.354 +cms zne $1==w: bne $2
19.355 +lol lae aar adp $3==w: adp $4 lol $1 lae $2 aar w
19.356 +loe lae aar adp $3==w: adp $4 loe $1 lae $2 aar w
19.357 +cmi zeq defined($1): cms $1 zeq $2
19.358 +cmi zne defined($1): cms $1 zne $2
19.359 +loe inc dup ste $1==$4 && $3==w: ine $1 loe $1
19.360 +loe dec dup ste $1==$4 && $3==w: dee $1 loe $1
19.361 +lol inc dup stl $1==$4 && $3==w: inl $1 lol $1
19.362 +lol dec dup stl $1==$4 && $3==w: del $1 lol $1
19.363 +adp dup SEP adp $1==-$4 && $2==p: dup p adp $1 SEP $3
19.364 +adp dup SLP adp $1==-$4 && $2==p: dup p adp $1 SLP $3
19.365 +inc dup ste dec $2==w: dup w inc ste $3
19.366 +inc dup stl dec $2==w: dup w inc stl $3
19.367 +zeq bra lab $1==$3: zne $2 lab $1
19.368 +zge bra lab $1==$3: zlt $2 lab $1
19.369 +zgt bra lab $1==$3: zle $2 lab $1
19.370 +zlt bra lab $1==$3: zge $2 lab $1
19.371 +zle bra lab $1==$3: zgt $2 lab $1
19.372 +zne bra lab $1==$3: zeq $2 lab $1
19.373 +beq bra lab $1==$3: bne $2 lab $1
19.374 +bge bra lab $1==$3: blt $2 lab $1
19.375 +bgt bra lab $1==$3: ble $2 lab $1
19.376 +blt bra lab $1==$3: bge $2 lab $1
19.377 +ble bra lab $1==$3: bgt $2 lab $1
19.378 +bne bra lab $1==$3: beq $2 lab $1
19.379 +lin lin : lin $2
19.380 +lin lab lin : lab $2 lin $3
19.381 +lin ret : ret $2
19.382 +lin bra : bra $2
19.383 +dup SLP loi $1==p && $3==w: SLP $2 lil $2
19.384 +dup SLP sti $1==p && $3==w: SLP $2 sil $2
19.385 +loc cms $1==0 && $2==w: tne
19.386 +zer $1==w: loc 0
19.387 +loc loc adi $3==w && sfit($1+$2,8*w) : loc $1+$2
19.388 +loc loc sbi $3==w && sfit($1-$2,8*w) : loc $1-$2
19.389 +loc loc mli $3==w && sfit($1*$2,8*w) : loc $1*$2
19.390 +loc loc dvi $3==w && $2!=0 : loc $1/$2
19.391 +loc loc and $3==w : loc $1&$2
19.392 +loc loc ior $3==w : loc $1|$2
19.393 +loc loc ior $1==0 && $2==0 && $3==2*w :
19.394 +loc loc xor $3==w : loc $1^$2
19.395 +loc loc xor $1==0 && $2==0 && $3==2*w :
19.396 +loc loc rol $3==w : loc rotate($1,$2)
19.397 +loc loc ror $3==w : loc rotate($1,8*w-$2)
19.398 +loc ngi $2==w && sfit(-$1,8*w) : loc -$1
19.399 +loc com $2==w : loc ~$1
19.400 +ldc ngi $2==2*w : ldc -$1
19.401 +loc lae aar $3==w && $1>=rom(2,0) && $1 <= rom(2,0)+rom(2,1) :
19.402 + adp ($1-rom(2,0))*rom(2,2)
19.403 +loc lae lar $3==w && $1>=rom(2,0) && $1 <= rom(2,0)+rom(2,1) :
19.404 + adp ($1-rom(2,0))*rom(2,2) loi rom(2,2)
19.405 +loc lae sar $3==w && $1>=rom(2,0) && $1 <= rom(2,0)+rom(2,1) :
19.406 + adp ($1-rom(2,0))*rom(2,2) sti rom(2,2)
19.407 +loc teq : loc $1==0
19.408 +loc tne : loc $1!=0
19.409 +loc tge : loc $1>=0
19.410 +loc tle : loc $1<=0
19.411 +loc tgt : loc $1>0
19.412 +loc tlt : loc $1<0
19.413 +loc zeq $1==0 : bra $2
19.414 +loc zeq :
19.415 +loc zne $1!=0 : bra $2
19.416 +loc zne :
19.417 +loc zge $1>=0 : bra $2
19.418 +loc zge :
19.419 +loc zle $1<=0 : bra $2
19.420 +loc zle :
19.421 +loc zgt $1>0 : bra $2
19.422 +loc zgt :
19.423 +loc zlt $1<0 : bra $2
19.424 +loc zlt :
19.425 +loc loc beq $1==$2 : bra $3
19.426 +loc loc beq :
19.427 +loc loc bne $1!=$2 : bra $3
19.428 +loc loc bne :
19.429 +loc loc bge $1>=$2 : bra $3
19.430 +loc loc bge :
19.431 +loc loc ble $1<=$2 : bra $3
19.432 +loc loc ble :
19.433 +loc loc bgt $1>$2 : bra $3
19.434 +loc loc bgt :
19.435 +loc loc blt $1<$2 : bra $3
19.436 +loc loc blt :
19.437 +lae loi lal sti $2==$4 && $2>4*w : lae $1 lal $3 blm $2
19.438 +lal loi lae sti $2==$4 && $2>4*w : lal $1 lae $3 blm $2
19.439 +lal loi lal sti $2==$4 && $2>4*w && ( $3<=$1-$2 || $3>=$1+$2 ) :
19.440 + lal $1 lal $3 blm $2
19.441 +lae loi lae sti $2==$4 && $2>4*w && ( !defined($1==$3) || $3<=$1-$2 || $3>=$1+$2 ) :
19.442 + lae $1 lae $3 blm $2
19.443 +loc loc loc cif $1==0 && $2==w : zrf $3
19.444 +loc loc loc cii $2==w && $3==2*w : ldc $1
19.445 +loc loc loc ciu $1>=0 && $2==w && $3==2*w : ldc $1
19.446 +loi loc inn $1==$3 && $2>=0 && $2<$1*8 :
19.447 + lof ($2/(8*w))*w loc $2&(8*w-1) inn w
19.448 +ldl loc inn $3==2*w && $2>=0 && $2<16*w :
19.449 + lol $1+($2/(8*w))*w loc $2&(8*w-1) inn w
19.450 +lde loc inn $3==2*w && $2>=0 && $2<16*w :
19.451 + loe $1+($2/(8*w))*w loc $2&(8*w-1) inn w
19.452 +ldf loc inn $3==2*w && $2>=0 && $2<16*w :
19.453 + lof $1+($2/(8*w))*w loc $2&(8*w-1) inn w
19.454 +loc inn $1<0 || $1>=8*$2 : asp $2 loc 0
19.455 +lol loc adi stl $3==w && $1==$4 : loc $2 lol $1 adi w stl $4
19.456 +lol loe adi stl $3==w && $1==$4 : loe $2 lol $1 adi w stl $4
19.457 +lol lol adi stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 adi w stl $4
19.458 +loe loc adi ste $3==w && $1==$4 : loc $2 loe $1 adi w ste $4
19.459 +loe loe adi ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 adi w ste $4
19.460 +loe lol adi ste $3==w && $1==$4 : lol $2 loe $1 adi w ste $4
19.461 +lol loc ior stl $3==w && $1==$4 : loc $2 lol $1 ior w stl $4
19.462 +lol loe ior stl $3==w && $1==$4 : loe $2 lol $1 ior w stl $4
19.463 +lol lol ior stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 ior w stl $4
19.464 +loe loc ior ste $3==w && $1==$4 : loc $2 loe $1 ior w ste $4
19.465 +loe loe ior ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 ior w ste $4
19.466 +loe lol ior ste $3==w && $1==$4 : lol $2 loe $1 ior w ste $4
19.467 +lol loc and stl $3==w && $1==$4 : loc $2 lol $1 and w stl $4
19.468 +lol loe and stl $3==w && $1==$4 : loe $2 lol $1 and w stl $4
19.469 +lol lol and stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 and w stl $4
19.470 +loe loc and ste $3==w && $1==$4 : loc $2 loe $1 and w ste $4
19.471 +loe loe and ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 and w ste $4
19.472 +loe lol and ste $3==w && $1==$4 : lol $2 loe $1 and w ste $4
19.473 +loi asp $1==$2 : asp p
19.474 +lal loi loc loc loc loc ior $2==4*w && $7==4*w && ($3==0)+($4==0)+($5==0)+($6==0)>2 :
19.475 + lol $1+3*w loc $3 ior w lol $1+2*w loc $4 ior w lol $1+w loc $5 ior w lol $1 loc $6 ior w
19.476 +loc dup stl loc dup stl $2==2 && $5==2:
19.477 + loc $1 stl $3 loc $4 stl $6 loc $1 loc $4
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/util/opt/peephole.c Thu May 17 13:42:36 1984 +0000
20.3 @@ -0,0 +1,648 @@
20.4 +#include "param.h"
20.5 +#include "types.h"
20.6 +#include "assert.h"
20.7 +#include "line.h"
20.8 +#include "lookup.h"
20.9 +#include "proinf.h"
20.10 +#include "alloc.h"
20.11 +#include "pattern.h"
20.12 +#include "../../h/em_spec.h"
20.13 +#include "../../h/em_mnem.h"
20.14 +#include "optim.h"
20.15 +#include "ext.h"
20.16 +
20.17 +/*
20.18 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
20.19 + *
20.20 + * This product is part of the Amsterdam Compiler Kit.
20.21 + *
20.22 + * Permission to use, sell, duplicate or disclose this software must be
20.23 + * obtained in writing. Requests for such permissions may be sent to
20.24 + *
20.25 + * Dr. Andrew S. Tanenbaum
20.26 + * Wiskundig Seminarium
20.27 + * Vrije Universiteit
20.28 + * Postbox 7161
20.29 + * 1007 MC Amsterdam
20.30 + * The Netherlands
20.31 + *
20.32 + * Author: Hans van Staveren
20.33 + */
20.34 +
20.35 +/* #define CHK_HASH /* print numbers patterns are hashed to */
20.36 +#ifdef CHK_HASH
20.37 +#include <stdio.h>
20.38 +#endif
20.39 +
20.40 +#define ILLHASH 0177777
20.41 +short pathash[256]; /* table of indices into pattern[] */
20.42 +
20.43 +int opind = 0; /* second index of next matrix */
20.44 +byte transl[op_plast-op_pfirst+1][3] = {
20.45 + /* LLP */ { op_LLP, op_lol, op_ldl },
20.46 + /* LEP */ { op_LEP, op_loe, op_lde },
20.47 + /* SLP */ { op_SLP, op_stl, op_sdl },
20.48 + /* SEP */ { op_SEP, op_ste, op_sde }
20.49 +};
20.50 +
20.51 +opcheck(bp) register byte *bp; {
20.52 +
20.53 + if (((*bp)&BMASK) >= op_pfirst)
20.54 + *bp = transl[((*bp)&BMASK)-op_pfirst][opind];
20.55 +}
20.56 +
20.57 +/*
20.58 + * The hashing method used is believed to be reasonably efficient.
20.59 + * A minor speed improvement could be obtained by keeping a boolean
20.60 + * array telling which opcode has any patterns starting with it.
20.61 + * Currently only about one third of the opcodes actually have a
20.62 + * pattern starting with it, but they are the most common ones.
20.63 + * Estimated improvement possible: about 2%
20.64 + */
20.65 +
20.66 +hashpatterns() {
20.67 + short index;
20.68 + register byte *bp,*tp;
20.69 + register short i;
20.70 + unsigned short hashvalue;
20.71 + byte *save;
20.72 + int patlen;
20.73 +
20.74 + if (pointersize == wordsize)
20.75 + opind=1;
20.76 + else if (pointersize == 2*wordsize)
20.77 + opind=2;
20.78 + index = lastind; /* set by mktab */
20.79 + while (index != 0) {
20.80 + bp = &pattern[index];
20.81 + tp = &bp[PO_MATCH];
20.82 + i = *tp++&BMASK;
20.83 + if (i==BMASK) {
20.84 + i = *tp++&BMASK;
20.85 + i |= (*tp++&BMASK)<<8;
20.86 + }
20.87 + save = tp;
20.88 + patlen = i;
20.89 + while (i--)
20.90 + opcheck(tp++);
20.91 + if ((*tp++&BMASK)==BMASK)
20.92 + tp += 2;
20.93 + i = *tp++&BMASK;
20.94 + if (i==BMASK) {
20.95 + i = *tp++&BMASK;
20.96 + i |= (*tp++&BMASK)<<8;
20.97 + }
20.98 + while (i--) {
20.99 + opcheck(tp++);
20.100 + if ((*tp++&BMASK)==BMASK)
20.101 + tp += 2;
20.102 + }
20.103 +
20.104 + /*
20.105 + * Now the special opcodes are filled
20.106 + * in properly, we can hash the pattern
20.107 + */
20.108 +
20.109 + hashvalue = 0;
20.110 + tp = save;
20.111 + switch(patlen) {
20.112 + default: /* 3 or more */
20.113 + hashvalue = (hashvalue<<4)^(*tp++&BMASK);
20.114 + case 2:
20.115 + hashvalue = (hashvalue<<4)^(*tp++&BMASK);
20.116 + case 1:
20.117 + hashvalue = (hashvalue<<4)^(*tp++&BMASK);
20.118 + }
20.119 + assert(hashvalue!= ILLHASH);
20.120 + i=index;
20.121 + index = (bp[PO_NEXT]&BMASK)|(bp[PO_NEXT+1]<<8);
20.122 + bp[PO_HASH] = hashvalue>>8;
20.123 + hashvalue &= BMASK;
20.124 + bp[PO_NEXT] = pathash[hashvalue]&BMASK;
20.125 + bp[PO_NEXT+1] = pathash[hashvalue]>>8;
20.126 + pathash[hashvalue] = i;
20.127 +#ifdef CHK_HASH
20.128 + fprintf(stderr,"%d\n",hashvalue);
20.129 +#endif
20.130 + }
20.131 +}
20.132 +
20.133 +peephole() {
20.134 + static bool phashed = FALSE;
20.135 +
20.136 + if (!phashed) {
20.137 + hashpatterns();
20.138 + phashed=TRUE;
20.139 + }
20.140 + optimize();
20.141 +}
20.142 +
20.143 +optimize() {
20.144 + register num_p *npp,np;
20.145 + register instr;
20.146 +
20.147 + basicblock(&instrs);
20.148 + for (npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++)
20.149 + for (np = *npp; np != (num_p) 0; np=np->n_next) {
20.150 + if(np->n_line->l_next == (line_p) 0)
20.151 + continue;
20.152 + instr = np->n_line->l_next->l_instr&BMASK;
20.153 + if (instr == op_lab || instr == op_bra)
20.154 + np->n_repl = np->n_line->l_next->l_a.la_np;
20.155 + else
20.156 + basicblock(&np->n_line->l_next);
20.157 + }
20.158 +}
20.159 +
20.160 +offset oabs(off) offset off; {
20.161 +
20.162 + return(off >= 0 ? off : -off);
20.163 +}
20.164 +
20.165 +line_p repline(ev,patlen) eval_t ev; {
20.166 + register line_p lp;
20.167 + register iarg_p iap;
20.168 + register sym_p sp;
20.169 + offset diff,newdiff;
20.170 +
20.171 + assert(ev.e_typ != EV_UNDEF);
20.172 + switch(ev.e_typ) {
20.173 + case EV_CONST:
20.174 + if ((short) ev.e_v.e_con == ev.e_v.e_con) {
20.175 + if (CANMINI((short) ev.e_v.e_con))
20.176 + lp = newline((short) (ev.e_v.e_con)+Z_OPMINI);
20.177 + else {
20.178 + lp = newline(OPSHORT);
20.179 + lp->l_a.la_short = (short) ev.e_v.e_con;
20.180 + }
20.181 + } else {
20.182 + lp = newline(OPOFFSET);
20.183 + lp->l_a.la_offset = ev.e_v.e_con;
20.184 + }
20.185 + return(lp);
20.186 + case EV_NUMLAB:
20.187 + lp = newline(OPNUMLAB);
20.188 + lp->l_a.la_np = ev.e_v.e_np;
20.189 + return(lp);
20.190 + default: /* fragment + offset */
20.191 + /*
20.192 + * There is a slight problem here, because we have to
20.193 + * map fragment+offset to symbol+offset.
20.194 + * Fortunately the fragment we have must be the fragment
20.195 + * of one of the symbols in the matchpattern.
20.196 + * So a short search should do the job.
20.197 + */
20.198 + sp = (sym_p) 0;
20.199 + for (iap= &iargs[patlen-1]; iap >= iargs; iap--)
20.200 + if (iap->ia_ev.e_typ == ev.e_typ) {
20.201 + /*
20.202 + * Although lint complains, diff is not used
20.203 + * before set.
20.204 + *
20.205 + * The proof is left as an exercise to the
20.206 + * reader.
20.207 + */
20.208 + newdiff = oabs(iap->ia_sp->s_value-ev.e_v.e_con);
20.209 + if (sp==(sym_p) 0 || newdiff < diff) {
20.210 + sp = iap->ia_sp;
20.211 + diff = newdiff;
20.212 + }
20.213 + }
20.214 + assert(sp != (sym_p) 0);
20.215 + if (diff == 0) {
20.216 + lp = newline(OPSYMBOL);
20.217 + lp->l_a.la_sp = sp;
20.218 + } else {
20.219 + diff = ev.e_v.e_con - sp->s_value;
20.220 + if ((short) diff == diff) {
20.221 + lp = newline(OPSVAL);
20.222 + lp->l_a.la_sval.lasv_short = (short) diff;
20.223 + lp->l_a.la_sval.lasv_sp = sp;
20.224 + } else {
20.225 + lp = newline(OPLVAL);
20.226 + lp->l_a.la_lval.lalv_offset = diff;
20.227 + lp->l_a.la_lval.lalv_sp = sp;
20.228 + }
20.229 + }
20.230 + return(lp);
20.231 + }
20.232 +}
20.233 +
20.234 +offset rotate(w,amount) offset w,amount; {
20.235 + offset highmask,lowmask;
20.236 +
20.237 +#ifndef LONGOFF
20.238 + assert(wordsize<=4);
20.239 +#endif
20.240 + highmask = (offset)(-1) << amount;
20.241 + lowmask = ~highmask;
20.242 + if (wordsize != 4)
20.243 + highmask &= wordsize==2 ? 0xFFFF : 0xFF;
20.244 + return(((w<<amount)&highmask)|((w>>(8*wordsize-amount))&lowmask));
20.245 +}
20.246 +
20.247 +eval_t undefres = { EV_UNDEF };
20.248 +
20.249 +eval_t compute(pexp) register expr_p pexp; {
20.250 + eval_t leaf1,leaf2,res;
20.251 + register i;
20.252 + register sym_p sp;
20.253 + offset mask;
20.254 +
20.255 + switch(nparam[pexp->ex_operator]) {
20.256 + default:
20.257 + assert(FALSE);
20.258 + case 2:
20.259 + leaf2 = compute(&enodes[pexp->ex_rnode]);
20.260 + if (leaf2.e_typ == EV_UNDEF ||
20.261 + nonumlab[pexp->ex_operator] && leaf2.e_typ == EV_NUMLAB ||
20.262 + onlyconst[pexp->ex_operator] && leaf2.e_typ != EV_CONST)
20.263 + return(undefres);
20.264 + case 1:
20.265 + leaf1 = compute(&enodes[pexp->ex_lnode]);
20.266 + if (leaf1.e_typ == EV_UNDEF ||
20.267 + nonumlab[pexp->ex_operator] && leaf1.e_typ == EV_NUMLAB ||
20.268 + onlyconst[pexp->ex_operator] && leaf1.e_typ != EV_CONST)
20.269 + return(undefres);
20.270 + case 0:
20.271 + break;
20.272 + }
20.273 +
20.274 + res.e_typ = EV_CONST;
20.275 + res.e_v.e_con = 0;
20.276 + switch(pexp->ex_operator) {
20.277 + default:
20.278 + assert(FALSE);
20.279 + case EX_CON:
20.280 + res.e_v.e_con = (offset) pexp->ex_lnode;
20.281 + break;
20.282 + case EX_ARG:
20.283 + return(iargs[pexp->ex_lnode - 1].ia_ev);
20.284 + case EX_CMPEQ:
20.285 + if (leaf1.e_typ != leaf2.e_typ)
20.286 + return(undefres);
20.287 + if (leaf1.e_typ == EV_NUMLAB) {
20.288 + if (leaf1.e_v.e_np == leaf2.e_v.e_np)
20.289 + res.e_v.e_con = 1;
20.290 + break;
20.291 + }
20.292 + if (leaf1.e_v.e_con == leaf2.e_v.e_con)
20.293 + res.e_v.e_con = 1;
20.294 + break;
20.295 + case EX_CMPNE:
20.296 + if (leaf1.e_typ != leaf2.e_typ) {
20.297 + res.e_v.e_con = 1;
20.298 + break;
20.299 + }
20.300 + if (leaf1.e_typ == EV_NUMLAB) {
20.301 + if (leaf1.e_v.e_np != leaf2.e_v.e_np)
20.302 + res.e_v.e_con = 1;
20.303 + break;
20.304 + }
20.305 + if (leaf1.e_v.e_con != leaf2.e_v.e_con)
20.306 + res.e_v.e_con = 1;
20.307 + break;
20.308 + case EX_CMPGT:
20.309 + if (leaf1.e_typ != leaf2.e_typ)
20.310 + return(undefres);
20.311 + res.e_v.e_con = leaf1.e_v.e_con > leaf2.e_v.e_con;
20.312 + break;
20.313 + case EX_CMPGE:
20.314 + if (leaf1.e_typ != leaf2.e_typ)
20.315 + return(undefres);
20.316 + res.e_v.e_con = leaf1.e_v.e_con >= leaf2.e_v.e_con;
20.317 + break;
20.318 + case EX_CMPLT:
20.319 + if (leaf1.e_typ != leaf2.e_typ)
20.320 + return(undefres);
20.321 + res.e_v.e_con = leaf1.e_v.e_con < leaf2.e_v.e_con;
20.322 + break;
20.323 + case EX_CMPLE:
20.324 + if (leaf1.e_typ != leaf2.e_typ)
20.325 + return(undefres);
20.326 + res.e_v.e_con = leaf1.e_v.e_con <= leaf2.e_v.e_con;
20.327 + break;
20.328 + case EX_OR2:
20.329 + if (leaf1.e_v.e_con != 0)
20.330 + return(leaf1);
20.331 + leaf2 = compute(&enodes[pexp->ex_rnode]);
20.332 + if (leaf2.e_typ != EV_CONST)
20.333 + return(undefres);
20.334 + return(leaf2);
20.335 + case EX_AND2:
20.336 + if (leaf1.e_v.e_con == 0)
20.337 + return(leaf1);
20.338 + leaf2 = compute(&enodes[pexp->ex_rnode]);
20.339 + if (leaf2.e_typ != EV_CONST)
20.340 + return(undefres);
20.341 + return(leaf2);
20.342 + case EX_OR1:
20.343 + res.e_v.e_con = leaf1.e_v.e_con | leaf2.e_v.e_con;
20.344 + break;
20.345 + case EX_XOR1:
20.346 + res.e_v.e_con = leaf1.e_v.e_con ^ leaf2.e_v.e_con;
20.347 + break;
20.348 + case EX_AND1:
20.349 + res.e_v.e_con = leaf1.e_v.e_con & leaf2.e_v.e_con;
20.350 + break;
20.351 + case EX_TIMES:
20.352 + res.e_v.e_con = leaf1.e_v.e_con * leaf2.e_v.e_con;
20.353 + break;
20.354 + case EX_DIVIDE:
20.355 + res.e_v.e_con = leaf1.e_v.e_con / leaf2.e_v.e_con;
20.356 + break;
20.357 + case EX_MOD:
20.358 + res.e_v.e_con = leaf1.e_v.e_con % leaf2.e_v.e_con;
20.359 + break;
20.360 + case EX_LSHIFT:
20.361 + res.e_v.e_con = leaf1.e_v.e_con << leaf2.e_v.e_con;
20.362 + break;
20.363 + case EX_RSHIFT:
20.364 + res.e_v.e_con = leaf1.e_v.e_con >> leaf2.e_v.e_con;
20.365 + break;
20.366 + case EX_UMINUS:
20.367 + res.e_v.e_con = -leaf1.e_v.e_con;
20.368 + break;
20.369 + case EX_NOT:
20.370 + res.e_v.e_con = !leaf1.e_v.e_con;
20.371 + break;
20.372 + case EX_COMP:
20.373 + res.e_v.e_con = ~leaf1.e_v.e_con;
20.374 + break;
20.375 + case EX_PLUS:
20.376 + if (leaf1.e_typ >= EV_FRAG) {
20.377 + if (leaf2.e_typ >= EV_FRAG)
20.378 + return(undefres);
20.379 + res.e_typ = leaf1.e_typ;
20.380 + } else
20.381 + res.e_typ = leaf2.e_typ;
20.382 + res.e_v.e_con = leaf1.e_v.e_con + leaf2.e_v.e_con;
20.383 + break;
20.384 + case EX_MINUS:
20.385 + if (leaf1.e_typ >= EV_FRAG) {
20.386 + if (leaf2.e_typ == EV_CONST)
20.387 + res.e_typ = leaf1.e_typ;
20.388 + else if (leaf2.e_typ != leaf1.e_typ)
20.389 + return(undefres);
20.390 + } else if (leaf2.e_typ >= EV_FRAG)
20.391 + return(undefres);
20.392 + res.e_v.e_con = leaf1.e_v.e_con - leaf2.e_v.e_con;
20.393 + break;
20.394 + case EX_POINTERSIZE:
20.395 + res.e_v.e_con = pointersize;
20.396 + break;
20.397 + case EX_WORDSIZE:
20.398 + res.e_v.e_con = wordsize;
20.399 + break;
20.400 + case EX_NOTREG:
20.401 + res.e_v.e_con = !inreg(leaf1.e_v.e_con);
20.402 + break;
20.403 + case EX_DEFINED:
20.404 + leaf1 = compute(&enodes[pexp->ex_lnode]);
20.405 + res.e_v.e_con = leaf1.e_typ != EV_UNDEF;
20.406 + break;
20.407 + case EX_SAMESIGN:
20.408 + res.e_v.e_con = (leaf1.e_v.e_con ^ leaf2.e_v.e_con) >= 0;
20.409 + break;
20.410 + case EX_ROM:
20.411 + if ((sp = iargs[pexp->ex_lnode - 1].ia_sp) != (sym_p) 0 &&
20.412 + sp->s_rom != (offset *) 0) {
20.413 + leaf2 = compute(&enodes[pexp->ex_rnode]);
20.414 + if (leaf2.e_typ != EV_CONST ||
20.415 + leaf2.e_v.e_con < 0 ||
20.416 + leaf2.e_v.e_con >= MAXROM)
20.417 + return(undefres);
20.418 + res.e_v.e_con = sp->s_rom[leaf2.e_v.e_con];
20.419 + break;
20.420 + } else
20.421 + return(undefres);
20.422 + case EX_SFIT:
20.423 + mask = 0;
20.424 + for (i=leaf2.e_v.e_con - 1;i < 8*sizeof(offset); i++)
20.425 + mask |= 1<<i;
20.426 + res.e_v.e_con = (leaf1.e_v.e_con&mask) == 0 ||
20.427 + (leaf1.e_v.e_con&mask) == mask;
20.428 + break;
20.429 + case EX_UFIT:
20.430 + mask = 0;
20.431 + for (i=leaf2.e_v.e_con;i < 8*sizeof(offset); i++)
20.432 + mask |= 1<<i;
20.433 + res.e_v.e_con = (leaf1.e_v.e_con&mask) == 0;
20.434 + break;
20.435 + case EX_ROTATE:
20.436 + res.e_v.e_con = rotate(leaf1.e_v.e_con,leaf2.e_v.e_con);
20.437 + break;
20.438 + }
20.439 + return(res);
20.440 +}
20.441 +
20.442 +#ifdef ALLOWSPECIAL
20.443 +extern bool special();
20.444 +#endif
20.445 +
20.446 +bool tryrepl(lpp,bp,patlen)
20.447 +line_p *lpp;
20.448 +register byte *bp;
20.449 +int patlen;
20.450 +{
20.451 + int rpllen,instr,rplval;
20.452 + register line_p lp;
20.453 + line_p replacement,*rlpp,tp;
20.454 +
20.455 + rpllen = *bp++&BMASK;
20.456 + if (rpllen == BMASK) {
20.457 + rpllen = *bp++&BMASK;
20.458 + rpllen |= (*bp++&BMASK)<<8;
20.459 + }
20.460 +#ifdef ALLOWSPECIAL
20.461 + if (rpllen == 1 && *bp == 0)
20.462 + return(special(lpp,bp+1,patlen));
20.463 +#endif
20.464 + replacement = (line_p) 0;
20.465 + rlpp = &replacement;
20.466 + while (rpllen--) {
20.467 + instr = *bp++&BMASK;
20.468 + rplval = *bp++&BMASK;
20.469 + if (rplval == BMASK) {
20.470 + rplval = (*bp++&BMASK);
20.471 + rplval |= (*bp++&BMASK)<<8;
20.472 + }
20.473 + if (rplval)
20.474 + lp = repline(compute(&enodes[rplval]),patlen);
20.475 + else
20.476 + lp = newline(OPNO);
20.477 +
20.478 + /*
20.479 + * One replacement instruction is generated,
20.480 + * link in list and proceed with the next one.
20.481 + */
20.482 +
20.483 + if (instr == op_lab)
20.484 + lp->l_a.la_np->n_line = lp;
20.485 + *rlpp = lp;
20.486 + rlpp = &lp->l_next;
20.487 + lp->l_instr = instr;
20.488 + }
20.489 +
20.490 + /*
20.491 + * Replace instructions matched by the created replacement
20.492 + */
20.493 +
20.494 +
20.495 + OPTIM((bp[0]&BMASK)|(bp[1]&BMASK)<<8);
20.496 + for (lp= *lpp;patlen>0;patlen--,tp=lp,lp=lp->l_next)
20.497 + ;
20.498 + tp->l_next = (line_p) 0;
20.499 + *rlpp = lp;
20.500 + lp = *lpp;
20.501 + *lpp = replacement;
20.502 + while ( lp != (line_p) 0 ) {
20.503 + tp = lp->l_next;
20.504 + oldline(lp);
20.505 + lp = tp;
20.506 + }
20.507 + return(TRUE);
20.508 +}
20.509 +
20.510 +bool trypat(lpp,bp,len)
20.511 +line_p *lpp;
20.512 +register byte *bp;
20.513 +int len;
20.514 +{
20.515 + register iarg_p iap;
20.516 + int i,patlen;
20.517 + register line_p lp;
20.518 + eval_t result;
20.519 +
20.520 + patlen = *bp++&BMASK;
20.521 + if (patlen == BMASK) {
20.522 + patlen = *bp++&BMASK;
20.523 + patlen |= (*bp++&BMASK)<<8;
20.524 + }
20.525 + if (len == 3) {
20.526 + if (patlen<3)
20.527 + return(FALSE);
20.528 + } else {
20.529 + if (patlen != len)
20.530 + return(FALSE);
20.531 + }
20.532 +
20.533 + /*
20.534 + * Length is ok, now check opcodes
20.535 + */
20.536 +
20.537 + for (i=0,lp= *lpp;i<patlen && lp != (line_p) 0;i++,lp=lp->l_next)
20.538 + if (lp->l_instr != *bp++)
20.539 + return(FALSE);
20.540 + if (i != patlen)
20.541 + return(FALSE);
20.542 +
20.543 + /*
20.544 + * opcodes are also correct, now comes the hard part
20.545 + */
20.546 +
20.547 + for(i=0,lp= *lpp,iap= iargs; i<patlen;i++,iap++,lp=lp->l_next) {
20.548 + switch(lp->l_optyp) {
20.549 + case OPNO:
20.550 + iap->ia_ev.e_typ = EV_UNDEF;
20.551 + break;
20.552 + default:
20.553 + iap->ia_ev.e_typ = EV_CONST;
20.554 + iap->ia_ev.e_v.e_con = (lp->l_optyp&BMASK)-Z_OPMINI;
20.555 + break;
20.556 + case OPSHORT:
20.557 + iap->ia_ev.e_typ = EV_CONST;
20.558 + iap->ia_ev.e_v.e_con = lp->l_a.la_short;
20.559 + break;
20.560 +#ifdef LONGOFF
20.561 + case OPOFFSET:
20.562 + iap->ia_ev.e_typ = EV_CONST;
20.563 + iap->ia_ev.e_v.e_con = lp->l_a.la_offset;
20.564 + break;
20.565 +#endif
20.566 + case OPNUMLAB:
20.567 + iap->ia_ev.e_typ = EV_NUMLAB;
20.568 + iap->ia_ev.e_v.e_np = lp->l_a.la_np;
20.569 + break;
20.570 + case OPSYMBOL:
20.571 + iap->ia_ev.e_typ = lp->l_a.la_sp->s_frag;
20.572 + iap->ia_sp = lp->l_a.la_sp;
20.573 + iap->ia_ev.e_v.e_con = lp->l_a.la_sp->s_value;
20.574 + break;
20.575 + case OPSVAL:
20.576 + iap->ia_ev.e_typ = lp->l_a.la_sval.lasv_sp->s_frag;
20.577 + iap->ia_sp = lp->l_a.la_sval.lasv_sp;
20.578 + iap->ia_ev.e_v.e_con = lp->l_a.la_sval.lasv_sp->s_value + lp->l_a.la_sval.lasv_short;
20.579 + break;
20.580 +#ifdef LONGOFF
20.581 + case OPLVAL:
20.582 + iap->ia_ev.e_typ = lp->l_a.la_lval.lalv_sp->s_frag;
20.583 + iap->ia_sp = lp->l_a.la_lval.lalv_sp;
20.584 + iap->ia_ev.e_v.e_con = lp->l_a.la_lval.lalv_sp->s_value + lp->l_a.la_lval.lalv_offset;
20.585 + break;
20.586 +#endif
20.587 + }
20.588 + }
20.589 + i = *bp++&BMASK;
20.590 + if ( i==BMASK ) {
20.591 + i = *bp++&BMASK;
20.592 + i |= (*bp++&BMASK)<<8;
20.593 + }
20.594 + if ( i != 0) {
20.595 + /* there is a condition */
20.596 + result = compute(&enodes[i]);
20.597 + if (result.e_typ != EV_CONST || result.e_v.e_con == 0)
20.598 + return(FALSE);
20.599 + }
20.600 + return(tryrepl(lpp,bp,patlen));
20.601 +}
20.602 +
20.603 +basicblock(alpp) line_p *alpp; {
20.604 + register line_p *lpp,lp;
20.605 + bool madeopt;
20.606 + unsigned short hash[3];
20.607 + line_p *next;
20.608 + register byte *bp;
20.609 + int i;
20.610 + short index;
20.611 +
20.612 + do { /* make pass over basicblock */
20.613 + lpp = alpp; madeopt = FALSE;
20.614 + while ((*lpp) != (line_p) 0 && ((*lpp)->l_instr&BMASK) != op_lab) {
20.615 + lp = *lpp; next = &lp->l_next;
20.616 + hash[0] = lp->l_instr&BMASK;
20.617 + lp=lp->l_next;
20.618 + if (lp != (line_p) 0) {
20.619 + hash[1] = (hash[0]<<4)^(lp->l_instr&BMASK);
20.620 + lp=lp->l_next;
20.621 + if (lp != (line_p) 0)
20.622 + hash[2] = (hash[1]<<4)^(lp->l_instr&BMASK);
20.623 + else
20.624 + hash[2] = ILLHASH;
20.625 + } else {
20.626 + hash[1] = ILLHASH;
20.627 + hash[2] = ILLHASH;
20.628 + }
20.629 +
20.630 + /*
20.631 + * hashvalues computed. Try for longest pattern first
20.632 + */
20.633 +
20.634 + for (i=2;i>=0;i--) {
20.635 + index = pathash[hash[i]&BMASK];
20.636 + while (index != 0) {
20.637 + bp = &pattern[index];
20.638 + if((bp[PO_HASH]&BMASK) == (hash[i]>>8))
20.639 + if(trypat(lpp,&bp[PO_MATCH],i+1)) {
20.640 + madeopt = TRUE;
20.641 + next = lpp;
20.642 + i = 0; /* dirty way of double break */
20.643 + break;
20.644 + }
20.645 + index=(bp[PO_NEXT]&BMASK)|(bp[PO_NEXT+1]<<8);
20.646 + }
20.647 + }
20.648 + lpp = next;
20.649 + }
20.650 + } while(madeopt); /* as long as there is progress */
20.651 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/util/opt/process.c Thu May 17 13:42:36 1984 +0000
21.3 @@ -0,0 +1,181 @@
21.4 +#include "param.h"
21.5 +#include "types.h"
21.6 +#include "assert.h"
21.7 +#include "../../h/em_spec.h"
21.8 +#include "../../h/em_pseu.h"
21.9 +#include "alloc.h"
21.10 +#include "line.h"
21.11 +#include "lookup.h"
21.12 +#include "proinf.h"
21.13 +#include "ext.h"
21.14 +
21.15 +/*
21.16 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
21.17 + *
21.18 + * This product is part of the Amsterdam Compiler Kit.
21.19 + *
21.20 + * Permission to use, sell, duplicate or disclose this software must be
21.21 + * obtained in writing. Requests for such permissions may be sent to
21.22 + *
21.23 + * Dr. Andrew S. Tanenbaum
21.24 + * Wiskundig Seminarium
21.25 + * Vrije Universiteit
21.26 + * Postbox 7161
21.27 + * 1007 MC Amsterdam
21.28 + * The Netherlands
21.29 + *
21.30 + * Author: Hans van Staveren
21.31 + */
21.32 +
21.33 +process() {
21.34 +
21.35 + if (wordsize == 0 || pointersize == 0)
21.36 + error("No MES EMX encountered");
21.37 + backward(); /* reverse and cleanup list */
21.38 + symknown(); /* symbol scope is now known */
21.39 + if (!nflag)
21.40 + symvalue(); /* give symbols value */
21.41 + if (prodepth != 0) {
21.42 + if (!nflag) {
21.43 + checklocs(); /* check definition of locals */
21.44 + peephole(); /* local optimization */
21.45 + relabel(); /* relabel local labels */
21.46 + flow(); /* throw away unreachable code */
21.47 + }
21.48 + outpro(); /* generate PRO pseudo */
21.49 + outregs(); /* generate MES ms_reg pseudos */
21.50 + }
21.51 + putlines(pseudos); /* pseudos first */
21.52 + if (prodepth != 0) {
21.53 + putlines(instrs); /* instructions next */
21.54 + outend(); /* generate END pseudo */
21.55 + cleanlocals(); /* forget instruction labels */
21.56 + } else if(instrs != (line_p) 0)
21.57 + error("instructions outside procedure");
21.58 +#ifdef COREDEBUG
21.59 + coreverbose();
21.60 +#endif
21.61 +}
21.62 +
21.63 +relabel() {
21.64 + register num_p *npp,np,tp;
21.65 + register num_p repl,ttp;
21.66 +
21.67 + /*
21.68 + * For each label find its final destination after crossjumping.
21.69 + * Care has to be taken to prevent a loop in the program to
21.70 + * cause same in the optimizer.
21.71 + */
21.72 +
21.73 + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++)
21.74 + for (np = *npp; np != (num_p) 0; np = np->n_next) {
21.75 + assert((np->n_line->l_instr&BMASK) == op_lab
21.76 + && np->n_line->l_a.la_np == np);
21.77 + for(tp=np; (tp->n_flags&(NUMKNOWN|NUMMARK))==0;
21.78 + tp = tp->n_repl)
21.79 + tp->n_flags |= NUMMARK;
21.80 + repl = tp->n_repl;
21.81 + for(tp=np; tp->n_flags&NUMMARK; tp = ttp) {
21.82 + ttp = tp->n_repl;
21.83 + tp->n_repl = repl;
21.84 + tp->n_flags &= ~ NUMMARK;
21.85 + tp->n_flags |= NUMKNOWN;
21.86 + }
21.87 + }
21.88 +}
21.89 +
21.90 +symknown() {
21.91 + register sym_p *spp,sp;
21.92 +
21.93 + for (spp = symhash; spp < &symhash[NSYMHASH]; spp++)
21.94 + for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
21.95 + sp->s_flags |= SYMKNOWN;
21.96 +}
21.97 +
21.98 +cleanlocals() {
21.99 + register num_p *npp,np,tp;
21.100 +
21.101 + for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) {
21.102 + np = *npp;
21.103 + while (np != (num_p) 0) {
21.104 + tp = np->n_next;
21.105 + oldnum(np);
21.106 + np = tp;
21.107 + }
21.108 + *npp = (num_p) 0;
21.109 + }
21.110 +}
21.111 +
21.112 +checklocs() {
21.113 + register num_p *npp,np;
21.114 +
21.115 + for (npp=curpro.numhash; npp < & curpro.numhash[NNUMHASH]; npp++)
21.116 + for (np = *npp; np != (num_p) 0; np=np->n_next)
21.117 + if (np->n_line == (line_p) 0)
21.118 + error("local label %u undefined",
21.119 + (unsigned) np->n_number);
21.120 +}
21.121 +
21.122 +offset align(count,alignment) offset count,alignment; {
21.123 +
21.124 + assert(alignment==1||alignment==2||alignment==4);
21.125 + return((count+alignment-1)&~(alignment-1));
21.126 +}
21.127 +
21.128 +symvalue() {
21.129 + register line_p lp;
21.130 + register sym_p sp;
21.131 + register arg_p ap;
21.132 + register argb_p abp;
21.133 + short curfrag = 0;
21.134 + offset count;
21.135 +
21.136 + for (lp=pseudos; lp != (line_p) 0; lp = lp->l_next)
21.137 + switch(lp->l_instr&BMASK) {
21.138 + default:
21.139 + assert(FALSE);
21.140 + case ps_sym:
21.141 + sp = lp->l_a.la_sp;
21.142 + if (sp->s_frag != curfrag) {
21.143 + count = 0;
21.144 + curfrag = sp->s_frag;
21.145 + }
21.146 + count = align(count,wordsize);
21.147 + sp->s_value = count;
21.148 + break;
21.149 + case ps_bss:
21.150 + case ps_hol:
21.151 + /* nothing to do, all bss pseudos are in diff frags */
21.152 + case ps_mes:
21.153 + break;
21.154 + case ps_con:
21.155 + case ps_rom:
21.156 + for (ap=lp->l_a.la_arg; ap != (arg_p) 0; ap = ap->a_next)
21.157 + switch(ap->a_typ) {
21.158 + default:
21.159 + assert(FALSE);
21.160 + case ARGOFF:
21.161 + count = align(count,wordsize)+wordsize;
21.162 + break;
21.163 + case ARGNUM:
21.164 + case ARGSYM:
21.165 + case ARGVAL:
21.166 + count = align(count,wordsize)+pointersize;
21.167 + break;
21.168 + case ARGICN:
21.169 + case ARGUCN:
21.170 + case ARGFCN:
21.171 + if (ap->a_a.a_con.ac_length < wordsize)
21.172 + count = align(count,(offset)ap->a_a.a_con.ac_length);
21.173 + else
21.174 + count = align(count,wordsize);
21.175 + count += ap->a_a.a_con.ac_length;
21.176 + break;
21.177 + case ARGSTR:
21.178 + for (abp = &ap->a_a.a_string; abp != (argb_p) 0;
21.179 + abp = abp->ab_next)
21.180 + count += abp->ab_index;
21.181 + break;
21.182 + }
21.183 + }
21.184 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/util/opt/proinf.h Thu May 17 13:42:36 1984 +0000
22.3 @@ -0,0 +1,33 @@
22.4 +struct num {
22.5 + num_p n_next;
22.6 + unsigned n_number;
22.7 + unsigned n_jumps;
22.8 + num_p n_repl;
22.9 + short n_flags;
22.10 + line_p n_line;
22.11 +};
22.12 +
22.13 +/* contents of .n_flags */
22.14 +#define NUMDATA 000001
22.15 +#define NUMREACH 000002
22.16 +#define NUMKNOWN 000004
22.17 +#define NUMMARK 000010
22.18 +#define NUMSCAN 000020
22.19 +
22.20 +#define NNUMHASH 37
22.21 +extern num_p numlookup();
22.22 +
22.23 +struct regs {
22.24 + reg_p r_next;
22.25 + offset r_par[4];
22.26 +};
22.27 +
22.28 +typedef struct proinf {
22.29 + offset localbytes;
22.30 + line_p lastline;
22.31 + sym_p symbol;
22.32 + reg_p freg;
22.33 + num_p numhash[NNUMHASH];
22.34 +} proinf;
22.35 +
22.36 +extern proinf curpro;
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/util/opt/putline.c Thu May 17 13:42:36 1984 +0000
23.3 @@ -0,0 +1,375 @@
23.4 +#include "param.h"
23.5 +#include "types.h"
23.6 +#include "assert.h"
23.7 +#include "../../h/em_spec.h"
23.8 +#include "../../h/em_pseu.h"
23.9 +#include "../../h/em_mnem.h"
23.10 +#include "../../h/em_flag.h"
23.11 +#include "alloc.h"
23.12 +#include "line.h"
23.13 +#include "lookup.h"
23.14 +#include "proinf.h"
23.15 +#include "optim.h"
23.16 +#include "ext.h"
23.17 +
23.18 +/*
23.19 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
23.20 + *
23.21 + * This product is part of the Amsterdam Compiler Kit.
23.22 + *
23.23 + * Permission to use, sell, duplicate or disclose this software must be
23.24 + * obtained in writing. Requests for such permissions may be sent to
23.25 + *
23.26 + * Dr. Andrew S. Tanenbaum
23.27 + * Wiskundig Seminarium
23.28 + * Vrije Universiteit
23.29 + * Postbox 7161
23.30 + * 1007 MC Amsterdam
23.31 + * The Netherlands
23.32 + *
23.33 + * Author: Hans van Staveren
23.34 + */
23.35 +
23.36 +#define outbyte(b) putc(b,outfile)
23.37 +
23.38 +putlines(lnp) register line_p lnp; {
23.39 + register arg_p ap;
23.40 + line_p temp;
23.41 + register instr;
23.42 + short curlin= -2;
23.43 + short thislin;
23.44 +
23.45 + while ( lnp != (line_p) 0) {
23.46 + instr = lnp->l_instr&BMASK;
23.47 + switch(lnp->l_optyp) {
23.48 + case OPSYMBOL:
23.49 + if ((lnp->l_instr&BMASK) == ps_sym)
23.50 + outdef(lnp->l_a.la_sp);
23.51 + else
23.52 + outocc(lnp->l_a.la_sp);
23.53 + break;
23.54 + case OPSVAL:
23.55 + outocc(lnp->l_a.la_sval.lasv_sp);
23.56 + break;
23.57 +#ifdef LONGOFF
23.58 + case OPLVAL:
23.59 + outocc(lnp->l_a.la_lval.lalv_sp);
23.60 + break;
23.61 +#endif
23.62 + case OPLIST:
23.63 + ap = lnp->l_a.la_arg;
23.64 + while (ap != (arg_p) 0) {
23.65 + switch(ap->a_typ) {
23.66 + case ARGSYM:
23.67 + outocc(ap->a_a.a_sp);
23.68 + break;
23.69 + case ARGVAL:
23.70 + outocc(ap->a_a.a_val.av_sp);
23.71 + break;
23.72 + }
23.73 + ap = ap->a_next;
23.74 + }
23.75 + break;
23.76 + }
23.77 +
23.78 + /*
23.79 + * global symbols now taken care of
23.80 + */
23.81 +
23.82 +
23.83 + switch(instr) {
23.84 + case ps_sym:
23.85 + break;
23.86 + case op_lni:
23.87 + if (curlin != -2)
23.88 + curlin++;
23.89 + outinst(instr);
23.90 + break;
23.91 + case op_lin:
23.92 + switch(lnp->l_optyp) {
23.93 + case OPNO:
23.94 + case OPOFFSET:
23.95 + case OPNUMLAB:
23.96 + case OPSYMBOL:
23.97 + case OPSVAL:
23.98 + case OPLVAL:
23.99 + case OPLIST:
23.100 + outinst(instr);
23.101 + goto processoperand;
23.102 + case OPSHORT:
23.103 + thislin = lnp->l_a.la_short;
23.104 + break;
23.105 + default:
23.106 + thislin = (lnp->l_optyp&BMASK)-Z_OPMINI;
23.107 + break;
23.108 + }
23.109 + if (thislin == curlin && !nflag) {
23.110 + temp = lnp->l_next;
23.111 + oldline(lnp);
23.112 + lnp = temp;
23.113 + OPTIM(O_LINGONE);
23.114 + continue;
23.115 + } else if (thislin == curlin+1 && !nflag) {
23.116 + instr = op_lni;
23.117 + outinst(instr);
23.118 + temp = lnp->l_next;
23.119 + oldline(lnp);
23.120 + OPTIM(O_LINLNI);
23.121 + lnp = newline(OPNO);
23.122 + lnp->l_next = temp;
23.123 + lnp->l_instr = instr;
23.124 + } else {
23.125 + outinst(instr);
23.126 + }
23.127 + curlin = thislin;
23.128 + break;
23.129 + case op_lab:
23.130 + curlin = -2;
23.131 + break;
23.132 + default:
23.133 + outinst(instr);
23.134 + }
23.135 +processoperand:
23.136 + switch(lnp->l_optyp) {
23.137 + case OPNO:
23.138 + if ((em_flag[instr-sp_fmnem]&EM_PAR)!=PAR_NO)
23.139 + outbyte( (byte) sp_cend) ;
23.140 + break;
23.141 + default:
23.142 + outint((lnp->l_optyp&BMASK)-Z_OPMINI);
23.143 + break;
23.144 + case OPSHORT:
23.145 + outint(lnp->l_a.la_short);
23.146 + break;
23.147 +#ifdef LONGOFF
23.148 + case OPOFFSET:
23.149 + outoff(lnp->l_a.la_offset);
23.150 + break;
23.151 +#endif
23.152 + case OPNUMLAB:
23.153 + if (instr == op_lab)
23.154 + numlab(lnp->l_a.la_np->n_repl);
23.155 + else if (instr < sp_fpseu) /* plain instruction */
23.156 + outint((short) lnp->l_a.la_np->n_repl->n_number);
23.157 + else
23.158 + outnum(lnp->l_a.la_np->n_repl);
23.159 + break;
23.160 + case OPSYMBOL:
23.161 + outsym(lnp->l_a.la_sp);
23.162 + break;
23.163 + case OPSVAL:
23.164 + outbyte( (byte) sp_doff) ;
23.165 + outsym(lnp->l_a.la_sval.lasv_sp);
23.166 + outint(lnp->l_a.la_sval.lasv_short);
23.167 + break;
23.168 +#ifdef LONGOFF
23.169 + case OPLVAL:
23.170 + outbyte( (byte) sp_doff) ;
23.171 + outsym(lnp->l_a.la_lval.lalv_sp);
23.172 + outoff(lnp->l_a.la_lval.lalv_offset);
23.173 + break;
23.174 +#endif
23.175 + case OPLIST:
23.176 + putargs(lnp->l_a.la_arg);
23.177 + switch(instr) {
23.178 + case ps_con:
23.179 + case ps_rom:
23.180 + case ps_mes:
23.181 + outbyte( (byte) sp_cend) ;
23.182 + }
23.183 + }
23.184 + /*
23.185 + * instruction is output now.
23.186 + * remove its useless body
23.187 + */
23.188 +
23.189 + temp = lnp->l_next;
23.190 + oldline(lnp);
23.191 + lnp = temp;
23.192 + if (ferror(outfile))
23.193 + error("write error");
23.194 + }
23.195 +}
23.196 +
23.197 +putargs(ap) register arg_p ap; {
23.198 +
23.199 + while (ap != (arg_p) 0) {
23.200 + switch(ap->a_typ) {
23.201 + default:
23.202 + assert(FALSE);
23.203 + case ARGOFF:
23.204 + outoff(ap->a_a.a_offset);
23.205 + break;
23.206 + case ARGNUM:
23.207 + outnum(ap->a_a.a_np->n_repl);
23.208 + break;
23.209 + case ARGSYM:
23.210 + outsym(ap->a_a.a_sp);
23.211 + break;
23.212 + case ARGVAL:
23.213 + outbyte( (byte) sp_doff) ;
23.214 + outsym(ap->a_a.a_val.av_sp);
23.215 + outoff(ap->a_a.a_val.av_offset);
23.216 + break;
23.217 + case ARGSTR:
23.218 + outbyte( (byte) sp_scon) ;
23.219 + putstr(&ap->a_a.a_string);
23.220 + break;
23.221 + case ARGICN:
23.222 + outbyte( (byte) sp_icon) ;
23.223 + goto casecon;
23.224 + case ARGUCN:
23.225 + outbyte( (byte) sp_ucon) ;
23.226 + goto casecon;
23.227 + case ARGFCN:
23.228 + outbyte( (byte) sp_fcon) ;
23.229 + casecon:
23.230 + outint(ap->a_a.a_con.ac_length);
23.231 + putstr(&ap->a_a.a_con.ac_con);
23.232 + break;
23.233 + }
23.234 + ap = ap->a_next;
23.235 + }
23.236 +}
23.237 +
23.238 +putstr(abp) register argb_p abp; {
23.239 + register argb_p tbp;
23.240 + register length;
23.241 +
23.242 + length = 0;
23.243 + tbp = abp;
23.244 + while (tbp!= (argb_p) 0) {
23.245 + length += tbp->ab_index;
23.246 + tbp = tbp->ab_next;
23.247 + }
23.248 + outint(length);
23.249 + while (abp != (argb_p) 0) {
23.250 + for (length=0;length<abp->ab_index;length++)
23.251 + outbyte( (byte) abp->ab_contents[length] );
23.252 + abp = abp->ab_next;
23.253 + }
23.254 +}
23.255 +
23.256 +outdef(sp) register sym_p sp; {
23.257 +
23.258 + /*
23.259 + * The surrounding If statement is removed to be friendly
23.260 + * to Backend writers having to deal with assemblers
23.261 + * not following our conventions.
23.262 + if ((sp->s_flags&SYMOUT)==0) {
23.263 + */
23.264 + sp->s_flags |= SYMOUT;
23.265 + if (sp->s_flags&SYMGLOBAL) {
23.266 + outinst(sp->s_flags&SYMPRO ? ps_exp : ps_exa);
23.267 + outsym(sp);
23.268 + }
23.269 + /*
23.270 + }
23.271 + */
23.272 +}
23.273 +
23.274 +outocc(sp) register sym_p sp; {
23.275 +
23.276 + if ((sp->s_flags&SYMOUT)==0) {
23.277 + sp->s_flags |= SYMOUT;
23.278 + if ((sp->s_flags&SYMGLOBAL)==0) {
23.279 + outinst(sp->s_flags&SYMPRO ? ps_inp : ps_ina);
23.280 + outsym(sp);
23.281 + }
23.282 + }
23.283 +}
23.284 +
23.285 +outpro() {
23.286 +
23.287 + outdef(curpro.symbol);
23.288 + outinst(ps_pro);
23.289 + outsym(curpro.symbol);
23.290 + outoff(curpro.localbytes);
23.291 +}
23.292 +
23.293 +outend() {
23.294 +
23.295 + outinst(ps_end);
23.296 + outoff(curpro.localbytes);
23.297 +}
23.298 +
23.299 +outinst(m) {
23.300 +
23.301 + outbyte( (byte) m );
23.302 +}
23.303 +
23.304 +outoff(off) offset off; {
23.305 +
23.306 +#ifdef LONGOFF
23.307 + if ((short) off == off)
23.308 +#endif
23.309 + outint((short) off);
23.310 +#ifdef LONGOFF
23.311 + else {
23.312 + outbyte( (byte) sp_cst4) ;
23.313 + outshort( (short) (off&0177777L) );
23.314 + outshort( (short) (off>>16) );
23.315 + }
23.316 +#endif
23.317 +}
23.318 +
23.319 +outint(i) short i; {
23.320 +
23.321 + if (i>= -sp_zcst0 && i< sp_ncst0-sp_zcst0)
23.322 + outbyte( (byte) (i+sp_zcst0+sp_fcst0) );
23.323 + else {
23.324 + outbyte( (byte) sp_cst2) ;
23.325 + outshort(i);
23.326 + }
23.327 +}
23.328 +
23.329 +outshort(i) short i; {
23.330 +
23.331 + outbyte( (byte) (i&BMASK) );
23.332 + outbyte( (byte) (i>>8) );
23.333 +}
23.334 +
23.335 +numlab(np) register num_p np; {
23.336 +
23.337 + if (np->n_number < sp_nilb0)
23.338 + outbyte( (byte) (np->n_number + sp_filb0) );
23.339 + else
23.340 + outnum(np);
23.341 +}
23.342 +
23.343 +outnum(np) register num_p np; {
23.344 +
23.345 + if(np->n_number<256) {
23.346 + outbyte( (byte) sp_ilb1) ;
23.347 + outbyte( (byte) (np->n_number) );
23.348 + } else {
23.349 + outbyte( (byte) sp_ilb2) ;
23.350 + outshort((short) np->n_number);
23.351 + }
23.352 +}
23.353 +
23.354 +outsym(sp) register sym_p sp; {
23.355 + register byte *p;
23.356 + register unsigned num;
23.357 +
23.358 + if (sp->s_name[0] == '.') {
23.359 + num = atoi(&sp->s_name[1]);
23.360 + if (num < 256) {
23.361 + outbyte( (byte) sp_dlb1) ;
23.362 + outbyte( (byte) (num) );
23.363 + } else {
23.364 + outbyte( (byte) sp_dlb2) ;
23.365 + outshort((short) num);
23.366 + }
23.367 + } else {
23.368 + p= sp->s_name;
23.369 + while (*p && p < &sp->s_name[IDL])
23.370 + p++;
23.371 + num = p - sp->s_name;
23.372 + outbyte( (byte) (sp->s_flags&SYMPRO ? sp_pnam : sp_dnam) );
23.373 + outint((short) num);
23.374 + p = sp->s_name;
23.375 + while (num--)
23.376 + outbyte( (byte) *p++ );
23.377 + }
23.378 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
24.2 +++ b/util/opt/reg.c Thu May 17 13:42:36 1984 +0000
24.3 @@ -0,0 +1,94 @@
24.4 +#include "assert.h"
24.5 +#include "param.h"
24.6 +#include "types.h"
24.7 +#include "line.h"
24.8 +#include "proinf.h"
24.9 +#include "alloc.h"
24.10 +#include "../../h/em_spec.h"
24.11 +#include "../../h/em_pseu.h"
24.12 +#include "../../h/em_mes.h"
24.13 +#include "ext.h"
24.14 +
24.15 +/*
24.16 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
24.17 + *
24.18 + * This product is part of the Amsterdam Compiler Kit.
24.19 + *
24.20 + * Permission to use, sell, duplicate or disclose this software must be
24.21 + * obtained in writing. Requests for such permissions may be sent to
24.22 + *
24.23 + * Dr. Andrew S. Tanenbaum
24.24 + * Wiskundig Seminarium
24.25 + * Vrije Universiteit
24.26 + * Postbox 7161
24.27 + * 1007 MC Amsterdam
24.28 + * The Netherlands
24.29 + *
24.30 + * Author: Hans van Staveren
24.31 + */
24.32 +
24.33 +regvar(ap) register arg_p ap; {
24.34 + register reg_p rp;
24.35 + register i;
24.36 +
24.37 + rp = newreg();
24.38 + i=0;
24.39 + while (ap!=(arg_p)0 && ap->a_typ==ARGOFF && i<4) {
24.40 + rp->r_par[i++]=ap->a_a.a_offset;
24.41 + ap=ap->a_next;
24.42 + }
24.43 + /*
24.44 + * Omit incomplete messages
24.45 + */
24.46 + switch(i) {
24.47 + default:assert(FALSE);
24.48 + case 0:
24.49 + case 1:
24.50 + case 2: oldreg(rp); return;
24.51 + case 3: rp->r_par[3]= (offset) 0; break;
24.52 + case 4: break;
24.53 + }
24.54 + rp->r_next = curpro.freg;
24.55 + curpro.freg = rp;
24.56 +}
24.57 +
24.58 +inreg(off) offset off; {
24.59 + register reg_p rp;
24.60 +
24.61 + for (rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
24.62 + if( rp->r_par[0] == off)
24.63 + return(TRUE);
24.64 + return(FALSE);
24.65 +}
24.66 +
24.67 +outregs() {
24.68 + register reg_p rp,tp;
24.69 + register i;
24.70 +
24.71 + for(rp=curpro.freg; rp != (reg_p) 0; rp = tp) {
24.72 + tp = rp->r_next;
24.73 + if (rp->r_par[3] != 0) {
24.74 + outinst(ps_mes);
24.75 + outoff((offset)ms_reg);
24.76 + for(i=0;i<4;i++)
24.77 + outoff(rp->r_par[i]);
24.78 + outinst(sp_cend);
24.79 + }
24.80 + oldreg(rp);
24.81 + }
24.82 + /* Now an empty mes 3 to signal the end. */
24.83 + outinst(ps_mes);
24.84 + outoff((offset)ms_reg);
24.85 + outinst(sp_cend);
24.86 + curpro.freg = (reg_p) 0;
24.87 +}
24.88 +
24.89 +incregusage(off) offset off; {
24.90 + register reg_p rp;
24.91 +
24.92 + for(rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
24.93 + if (rp->r_par[0]==off) {
24.94 + rp->r_par[3]++;
24.95 + return;
24.96 + }
24.97 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/util/opt/scan.l Thu May 17 13:42:36 1984 +0000
25.3 @@ -0,0 +1,71 @@
25.4 +%{
25.5 +/*
25.6 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
25.7 + *
25.8 + * This product is part of the Amsterdam Compiler Kit.
25.9 + *
25.10 + * Permission to use, sell, duplicate or disclose this software must be
25.11 + * obtained in writing. Requests for such permissions may be sent to
25.12 + *
25.13 + * Dr. Andrew S. Tanenbaum
25.14 + * Wiskundig Seminarium
25.15 + * Vrije Universiteit
25.16 + * Postbox 7161
25.17 + * 1007 MC Amsterdam
25.18 + * The Netherlands
25.19 + *
25.20 + * Author: Hans van Staveren
25.21 + */
25.22 +
25.23 +extern long atol();
25.24 +%}
25.25 +%%
25.26 +notreg return(NOTREG);
25.27 +sfit return(SFIT);
25.28 +ufit return(UFIT);
25.29 +rotate return(ROTATE);
25.30 +p return(PSIZE);
25.31 +w return(WSIZE);
25.32 +defined return(DEFINED);
25.33 +samesign return(SAMESIGN);
25.34 +rom return(ROM);
25.35 +[a-zA-Z]{3} {
25.36 + int m;
25.37 + m = mlookup(yytext);
25.38 + if (m==0) {
25.39 + REJECT;
25.40 + } else {
25.41 + yylval.y_int = m;
25.42 + return(MNEM);
25.43 + }
25.44 + }
25.45 +"&&" return(AND2);
25.46 +"||" return(OR2);
25.47 +"&" return(AND1);
25.48 +"|" return(OR1);
25.49 +"^" return(XOR1);
25.50 +"+" return(ARPLUS);
25.51 +"-" return(ARMINUS);
25.52 +"*" return(ARTIMES);
25.53 +"/" return(ARDIVIDE);
25.54 +"%" return(ARMOD);
25.55 +"==" return(CMPEQ);
25.56 +"!=" return(CMPNE);
25.57 +"<" return(CMPLT);
25.58 +"<=" return(CMPLE);
25.59 +">" return(CMPGT);
25.60 +">=" return(CMPGE);
25.61 +"!" return(NOT);
25.62 +"~" return(COMP);
25.63 +"<<" return(LSHIFT);
25.64 +">>" return(RSHIFT);
25.65 +[0-9]+ { long l= atol(yytext);
25.66 + if (l>32767) yyerror("Number too big");
25.67 + yylval.y_int= (int) l;
25.68 + return(NUMBER);
25.69 + }
25.70 +[ \t] ;
25.71 +. return(yytext[0]);
25.72 +\n { lino++; return(yytext[0]); }
25.73 +:[ \t]*\n[ \t]+ { lino++; return(':'); }
25.74 +^"# "[0-9]+.*\n { lino=atoi(yytext+2); }
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/util/opt/special.c Thu May 17 13:42:36 1984 +0000
26.3 @@ -0,0 +1,29 @@
26.4 +#include "param.h"
26.5 +#include "types.h"
26.6 +
26.7 +/*
26.8 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
26.9 + *
26.10 + * This product is part of the Amsterdam Compiler Kit.
26.11 + *
26.12 + * Permission to use, sell, duplicate or disclose this software must be
26.13 + * obtained in writing. Requests for such permissions may be sent to
26.14 + *
26.15 + * Dr. Andrew S. Tanenbaum
26.16 + * Wiskundig Seminarium
26.17 + * Vrije Universiteit
26.18 + * Postbox 7161
26.19 + * 1007 MC Amsterdam
26.20 + * The Netherlands
26.21 + *
26.22 + * Author: Hans van Staveren
26.23 + */
26.24 +
26.25 +bool special(lpp,bp,patlen)
26.26 +line_p *lpp;
26.27 +byte *bp;
26.28 +int patlen;
26.29 +{
26.30 +
26.31 + return(FALSE);
26.32 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/util/opt/testopt Thu May 17 13:42:36 1984 +0000
27.3 @@ -0,0 +1,7 @@
27.4 +while true
27.5 +do
27.6 + (echo ' mes 2,2,2
27.7 + pro $foo,0';cat;echo ' end') >t.e
27.8 + npc -2=${1-opt} -O -2 t.e;npc -D t.m
27.9 + cat t.e
27.10 +done
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
28.2 +++ b/util/opt/types.h Thu May 17 13:42:36 1984 +0000
28.3 @@ -0,0 +1,19 @@
28.4 +typedef char byte;
28.5 +typedef char bool;
28.6 +typedef struct line line_t;
28.7 +typedef struct line *line_p;
28.8 +typedef struct sym sym_t;
28.9 +typedef struct sym *sym_p;
28.10 +typedef struct num num_t;
28.11 +typedef struct num *num_p;
28.12 +typedef struct arg arg_t;
28.13 +typedef struct arg *arg_p;
28.14 +typedef struct argbytes argb_t;
28.15 +typedef struct argbytes *argb_p;
28.16 +typedef struct regs reg_t;
28.17 +typedef struct regs *reg_p;
28.18 +#ifdef LONGOFF
28.19 +typedef long offset;
28.20 +#else
28.21 +typedef short offset;
28.22 +#endif
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
29.2 +++ b/util/opt/util.c Thu May 17 13:42:36 1984 +0000
29.3 @@ -0,0 +1,58 @@
29.4 +#include <stdio.h>
29.5 +#include "param.h"
29.6 +#include "types.h"
29.7 +#include "assert.h"
29.8 +#include "lookup.h"
29.9 +#include "proinf.h"
29.10 +#include "optim.h"
29.11 +#include "ext.h"
29.12 +
29.13 +/*
29.14 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
29.15 + *
29.16 + * This product is part of the Amsterdam Compiler Kit.
29.17 + *
29.18 + * Permission to use, sell, duplicate or disclose this software must be
29.19 + * obtained in writing. Requests for such permissions may be sent to
29.20 + *
29.21 + * Dr. Andrew S. Tanenbaum
29.22 + * Wiskundig Seminarium
29.23 + * Vrije Universiteit
29.24 + * Postbox 7161
29.25 + * 1007 MC Amsterdam
29.26 + * The Netherlands
29.27 + *
29.28 + * Author: Hans van Staveren
29.29 + */
29.30 +
29.31 +
29.32 +/* VARARGS1 */
29.33 +error(s,a) char *s,*a; {
29.34 +
29.35 + fprintf(stderr,"%s: error on line %u",progname,linecount);
29.36 + if (prodepth != 0)
29.37 + fprintf(stderr,"(%.*s)",IDL,curpro.symbol->s_name);
29.38 + fprintf(stderr,": ");
29.39 + fprintf(stderr,s,a);
29.40 + fprintf(stderr,"\n");
29.41 + abort();
29.42 + exit(-1);
29.43 +}
29.44 +
29.45 +#ifndef NDEBUG
29.46 +badassertion(file,line) char *file; unsigned line; {
29.47 +
29.48 + fprintf(stderr,"assertion failed file %s, line %u\n",file,line);
29.49 + error("assertion");
29.50 +}
29.51 +#endif
29.52 +
29.53 +#ifdef DIAGOPT
29.54 +optim(n) {
29.55 +
29.56 + fprintf(stderr,"Made optimization %d",n);
29.57 + if (inpro)
29.58 + fprintf(stderr," (%.*s)",IDL,curpro.symbol->s_name);
29.59 + fprintf(stderr,"\n");
29.60 +}
29.61 +#endif
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/util/opt/var.c Thu May 17 13:42:36 1984 +0000
30.3 @@ -0,0 +1,36 @@
30.4 +#include <stdio.h>
30.5 +#include "param.h"
30.6 +#include "types.h"
30.7 +#include "lookup.h"
30.8 +#include "proinf.h"
30.9 +
30.10 +/*
30.11 + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
30.12 + *
30.13 + * This product is part of the Amsterdam Compiler Kit.
30.14 + *
30.15 + * Permission to use, sell, duplicate or disclose this software must be
30.16 + * obtained in writing. Requests for such permissions may be sent to
30.17 + *
30.18 + * Dr. Andrew S. Tanenbaum
30.19 + * Wiskundig Seminarium
30.20 + * Vrije Universiteit
30.21 + * Postbox 7161
30.22 + * 1007 MC Amsterdam
30.23 + * The Netherlands
30.24 + *
30.25 + * Author: Hans van Staveren
30.26 + */
30.27 +
30.28 +unsigned linecount = 0; /* "line"number for errormessages */
30.29 +int prodepth = 0; /* Level of nesting */
30.30 +bool Lflag = 0; /* make library module */
30.31 +bool nflag = 0; /* do not optimize */
30.32 +line_p instrs,pseudos; /* pointers to chains */
30.33 +sym_p symhash[NSYMHASH]; /* array of pointers to chains */
30.34 +FILE *outfile;
30.35 +char template[] = "/usr/tmp/emoptXXXXXX";
30.36 +offset wordsize = 0;
30.37 +offset pointersize = 0;
30.38 +char *progname;
30.39 +proinf curpro; /* collected information about current pro */