1984-05-17 13:57:07 +00:00
|
|
|
#ifndef NORCSID
|
|
|
|
static char rcsid[] = "$Header$";
|
|
|
|
#endif
|
|
|
|
|
1984-05-17 13:42:36 +00:00
|
|
|
#include "param.h"
|
|
|
|
#include "types.h"
|
1990-09-04 16:42:43 +00:00
|
|
|
#include "tes.h"
|
1984-05-17 13:42:36 +00:00
|
|
|
#include "assert.h"
|
1988-09-12 09:13:49 +00:00
|
|
|
#include <em_spec.h>
|
|
|
|
#include <em_pseu.h>
|
1984-05-17 13:42:36 +00:00
|
|
|
#include "alloc.h"
|
|
|
|
#include "line.h"
|
|
|
|
#include "lookup.h"
|
|
|
|
#include "proinf.h"
|
|
|
|
#include "ext.h"
|
|
|
|
|
|
|
|
/*
|
1987-03-10 01:42:07 +00:00
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
1984-05-17 13:42:36 +00:00
|
|
|
*
|
|
|
|
* Author: Hans van Staveren
|
|
|
|
*/
|
|
|
|
|
|
|
|
process() {
|
|
|
|
|
|
|
|
if (wordsize == 0 || pointersize == 0)
|
|
|
|
error("No MES EMX encountered");
|
|
|
|
backward(); /* reverse and cleanup list */
|
|
|
|
symknown(); /* symbol scope is now known */
|
|
|
|
if (!nflag)
|
|
|
|
symvalue(); /* give symbols value */
|
|
|
|
if (prodepth != 0) {
|
|
|
|
if (!nflag) {
|
1989-02-06 14:39:08 +00:00
|
|
|
int npasses = 0;
|
|
|
|
bool madeopt;
|
|
|
|
|
|
|
|
checklocs(); /* check definition of locals */
|
|
|
|
do {
|
|
|
|
madeopt = peephole(); /* local optimization */
|
1984-05-17 13:42:36 +00:00
|
|
|
relabel(); /* relabel local labels */
|
|
|
|
flow(); /* throw away unreachable code */
|
1989-02-06 14:39:08 +00:00
|
|
|
} while (madeopt && ++npasses < 5000);
|
|
|
|
assert(!madeopt);
|
1984-05-17 13:42:36 +00:00
|
|
|
}
|
1990-09-04 16:42:43 +00:00
|
|
|
do_tes(); /* top elt. size computation phase */
|
1984-05-17 13:42:36 +00:00
|
|
|
outpro(); /* generate PRO pseudo */
|
|
|
|
outregs(); /* generate MES ms_reg pseudos */
|
1990-09-04 16:42:43 +00:00
|
|
|
outtes(); /* generate MES ms_tes pseudos */
|
1984-05-17 13:42:36 +00:00
|
|
|
}
|
|
|
|
putlines(pseudos); /* pseudos first */
|
|
|
|
if (prodepth != 0) {
|
|
|
|
putlines(instrs); /* instructions next */
|
|
|
|
outend(); /* generate END pseudo */
|
|
|
|
cleanlocals(); /* forget instruction labels */
|
|
|
|
} else if(instrs != (line_p) 0)
|
|
|
|
error("instructions outside procedure");
|
|
|
|
#ifdef COREDEBUG
|
|
|
|
coreverbose();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
relabel() {
|
|
|
|
register num_p *npp,np,tp;
|
|
|
|
register num_p repl,ttp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each label find its final destination after crossjumping.
|
|
|
|
* Care has to be taken to prevent a loop in the program to
|
|
|
|
* cause same in the optimizer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++)
|
|
|
|
for (np = *npp; np != (num_p) 0; np = np->n_next) {
|
1989-10-04 14:39:55 +00:00
|
|
|
assert(! np->n_line ||
|
|
|
|
((np->n_line->l_instr&BMASK) == op_lab
|
|
|
|
&& np->n_line->l_a.la_np == np));
|
1984-05-17 13:42:36 +00:00
|
|
|
for(tp=np; (tp->n_flags&(NUMKNOWN|NUMMARK))==0;
|
|
|
|
tp = tp->n_repl)
|
|
|
|
tp->n_flags |= NUMMARK;
|
|
|
|
repl = tp->n_repl;
|
|
|
|
for(tp=np; tp->n_flags&NUMMARK; tp = ttp) {
|
|
|
|
ttp = tp->n_repl;
|
|
|
|
tp->n_repl = repl;
|
|
|
|
tp->n_flags &= ~ NUMMARK;
|
|
|
|
tp->n_flags |= NUMKNOWN;
|
|
|
|
}
|
|
|
|
}
|
1989-02-06 14:39:08 +00:00
|
|
|
for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++)
|
|
|
|
for (np = *npp; np != (num_p) 0; np = np->n_next) {
|
|
|
|
np->n_flags &= ~(NUMKNOWN|NUMSCAN|NUMREACH);
|
|
|
|
np->n_jumps = 0;
|
|
|
|
}
|
1984-05-17 13:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
symknown() {
|
|
|
|
register sym_p *spp,sp;
|
|
|
|
|
|
|
|
for (spp = symhash; spp < &symhash[NSYMHASH]; spp++)
|
|
|
|
for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
|
1987-03-09 10:15:51 +00:00
|
|
|
if (sp->s_flags & SYMSEEN)
|
|
|
|
sp->s_flags |= SYMKNOWN;
|
1984-05-17 13:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanlocals() {
|
|
|
|
register num_p *npp,np,tp;
|
|
|
|
|
1990-07-18 14:33:07 +00:00
|
|
|
delete_labels();
|
1984-05-17 13:42:36 +00:00
|
|
|
for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) {
|
|
|
|
np = *npp;
|
|
|
|
while (np != (num_p) 0) {
|
|
|
|
tp = np->n_next;
|
|
|
|
oldnum(np);
|
|
|
|
np = tp;
|
|
|
|
}
|
|
|
|
*npp = (num_p) 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checklocs() {
|
|
|
|
register num_p *npp,np;
|
|
|
|
|
|
|
|
for (npp=curpro.numhash; npp < & curpro.numhash[NNUMHASH]; npp++)
|
|
|
|
for (np = *npp; np != (num_p) 0; np=np->n_next)
|
|
|
|
if (np->n_line == (line_p) 0)
|
|
|
|
error("local label %u undefined",
|
|
|
|
(unsigned) np->n_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset align(count,alignment) offset count,alignment; {
|
|
|
|
|
|
|
|
assert(alignment==1||alignment==2||alignment==4);
|
|
|
|
return((count+alignment-1)&~(alignment-1));
|
|
|
|
}
|
|
|
|
|
|
|
|
symvalue() {
|
|
|
|
register line_p lp;
|
|
|
|
register sym_p sp;
|
|
|
|
register arg_p ap;
|
|
|
|
register argb_p abp;
|
|
|
|
short curfrag = 0;
|
|
|
|
offset count;
|
|
|
|
|
|
|
|
for (lp=pseudos; lp != (line_p) 0; lp = lp->l_next)
|
|
|
|
switch(lp->l_instr&BMASK) {
|
|
|
|
default:
|
|
|
|
assert(FALSE);
|
|
|
|
case ps_sym:
|
|
|
|
sp = lp->l_a.la_sp;
|
|
|
|
if (sp->s_frag != curfrag) {
|
|
|
|
count = 0;
|
|
|
|
curfrag = sp->s_frag;
|
|
|
|
}
|
|
|
|
count = align(count,wordsize);
|
|
|
|
sp->s_value = count;
|
|
|
|
break;
|
|
|
|
case ps_bss:
|
|
|
|
case ps_hol:
|
|
|
|
/* nothing to do, all bss pseudos are in diff frags */
|
|
|
|
case ps_mes:
|
|
|
|
break;
|
|
|
|
case ps_con:
|
|
|
|
case ps_rom:
|
|
|
|
for (ap=lp->l_a.la_arg; ap != (arg_p) 0; ap = ap->a_next)
|
|
|
|
switch(ap->a_typ) {
|
|
|
|
default:
|
|
|
|
assert(FALSE);
|
|
|
|
case ARGOFF:
|
|
|
|
count = align(count,wordsize)+wordsize;
|
|
|
|
break;
|
|
|
|
case ARGNUM:
|
|
|
|
case ARGSYM:
|
|
|
|
case ARGVAL:
|
|
|
|
count = align(count,wordsize)+pointersize;
|
|
|
|
break;
|
|
|
|
case ARGICN:
|
|
|
|
case ARGUCN:
|
|
|
|
case ARGFCN:
|
|
|
|
if (ap->a_a.a_con.ac_length < wordsize)
|
|
|
|
count = align(count,(offset)ap->a_a.a_con.ac_length);
|
|
|
|
else
|
|
|
|
count = align(count,wordsize);
|
|
|
|
count += ap->a_a.a_con.ac_length;
|
|
|
|
break;
|
|
|
|
case ARGSTR:
|
|
|
|
for (abp = &ap->a_a.a_string; abp != (argb_p) 0;
|
|
|
|
abp = abp->ab_next)
|
|
|
|
count += abp->ab_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1990-07-18 14:33:07 +00:00
|
|
|
|
1990-09-04 16:42:43 +00:00
|
|
|
do_tes()
|
1990-07-18 14:33:07 +00:00
|
|
|
{
|
|
|
|
register line_p insptr = instrs, oldlin = NULL;
|
|
|
|
|
|
|
|
init_state();
|
1990-09-04 16:42:43 +00:00
|
|
|
tes_pseudos();
|
1990-07-18 14:33:07 +00:00
|
|
|
while (insptr != NULL) {
|
1990-09-04 16:42:43 +00:00
|
|
|
insptr->l_prev = oldlin;
|
|
|
|
oldlin = insptr;
|
|
|
|
tes_instr(insptr);
|
|
|
|
insptr = insptr->l_next;
|
1990-07-18 14:33:07 +00:00
|
|
|
}
|
|
|
|
}
|