2 static char rcsid[] = "$Id: move.c,v 2.5 1994/06/24 13:23:53 ceriel Exp $";
9 #include <cg_pattern.h>
15 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
16 * See the copyright notice in the ACK home directory, in the file "Copyright".
18 * Author: Hans van Staveren
23 move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
26 register struct reginfo *rp;
33 if (tp2->t_token == -1) {
34 if (tp1->t_token == -1) {
35 if (eqtoken(&machregs[tp1->t_att[0].ar].r_contents,
36 &machregs[tp2->t_att[0].ar].r_contents) &&
37 machregs[tp1->t_att[0].ar].r_contents.t_token!=0)
39 if (tp1->t_att[0].ar!=1) { /* COCO reg; tmp kludge */
40 erasereg(tp2->t_att[0].ar);
41 machregs[tp2->t_att[0].ar].r_contents =
42 machregs[tp1->t_att[0].ar].r_contents ;
44 machregs[tp1->t_att[0].ar].r_contents =
45 machregs[tp2->t_att[0].ar].r_contents ;
47 if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
49 erasereg(tp2->t_att[0].ar);
50 machregs[tp2->t_att[0].ar].r_contents = *tp1;
52 for (rp=machregs;rp<machregs+NREGS;rp++) {
53 if (rp->r_contents.t_token == 0)
55 assert(rp->r_contents.t_token > 0);
56 tdp = &tokens[rp->r_contents.t_token];
57 for (i=0;i<TOKENSIZE;i++)
58 if (tdp->t_type[i] == EV_REG &&
59 clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
60 erasereg((int)(rp-machregs));
64 } else if (tp1->t_token == -1) {
65 if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
67 machregs[tp1->t_att[0].ar].r_contents = *tp2;
70 * If we arrive here the move must really be executed
72 for (mp=moves;mp<moves+NMOVES;mp++) {
73 if (!match(tp1,&machsets[mp->m_set1],mp->m_expr1))
75 if (match(tp2,&machsets[mp->m_set2],mp->m_expr2))
78 * Correct move rule is found
81 assert(mp<moves+NMOVES);
83 * To get correct interpretation of things like %[1]
84 * in move code we stack tp2 and tp1. This little trick
85 * saves a lot of testing in other places.
88 if (mp->m_cindex!=0) {
89 fakestack[stackheight] = *tp2;
90 fakestack[stackheight+1] = *tp1;
92 t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0);
94 t += costcalc(mp->m_cost);